Person.js 120 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845
  1. MWF.xApplication.Selector = MWF.xApplication.Selector || {};
  2. MWF.xDesktop.requireApp("Selector", "lp."+MWF.language, null, false);
  3. //MWF.xDesktop.requireApp("Selector", "Actions.RestActions", null, false);
  4. MWF.xApplication.Selector.Person = new Class({
  5. Extends: MWF.widget.Common,
  6. Implements: [Options, Events],
  7. options: {
  8. "style": "default",
  9. "count": 0,
  10. "title": MWF.xApplication.Selector.LP.selectPerson,
  11. "groups": [],
  12. "roles": [],
  13. "values": [],
  14. "exclude" : [],
  15. "zIndex": 1000,
  16. "expand": true,
  17. "embedded" : false, //是否嵌入在其他容器中
  18. "selectAllEnable" : false, //是否允许全选
  19. "selectAllRange" : "direct", //全选直属人员 还是 所有下级人员
  20. "level1Indent" : 10, //第一级的缩进
  21. "indent" : 10, //后续的缩进
  22. "hasLetter" : true, //字母
  23. "hasTop" : false, //可选、已选的标题
  24. "hasShuttle" : false, //穿梭按钮
  25. "searchbarInTopNode" : true, //搜索框在标题上还是另起一行
  26. "hasSelectedSearchbar" : false, //已选是不是有搜索框
  27. "noSelectedContainer" : false, //是否隐藏右侧已选区域
  28. "contentUrl" : "", //和默认的页面布局不一样的话,可以传入页面布局HTML URL
  29. "injectToBody" : false, //当传入HTML URL的时候是否插入到document.body, false的时候插入到this.container
  30. "selectSingleItem" : false, //当只有一个候选项的时候,是否默认选中
  31. "hiddenEmptyCategory" : false,
  32. "flatCategory" : false, //扁平化展现分类,
  33. "selectType" : "person",
  34. "isCheckStatus" : false,
  35. "showSelectedCount" : false,
  36. "itemHeight" : 29,
  37. "identityItemWidth" : 0, //选项宽度,如果不为0,设置为float:left,
  38. "showEmptyText" : true
  39. },
  40. initialize: function(container, options){
  41. this.active = true;
  42. this.setOptions(options);
  43. this.path = "../x_component_Selector/$Selector/";
  44. this.cssPath = "../x_component_Selector/$Selector/"+this.options.style+"/css.wcss";
  45. this._loadCss(true);
  46. this.container = $(container);
  47. Object.defineProperties(this, {
  48. "orgAction": {"get": function(){return o2.Actions.get("x_organization_assemble_control");}},
  49. "processAction": {"get": function(){return o2.Actions.get("x_processplatform_assemble_surface");}},
  50. "designerAction": {"get": function(){return o2.Actions.get("x_processplatform_assemble_designer");}},
  51. "portalAction": {"get": function(){return o2.Actions.get("x_portal_assemble_surface");}},
  52. "portalDesignerAction": {"get": function(){return o2.Actions.get("x_portal_assemble_designer");}},
  53. "cmsAction": {"get": function(){return o2.Actions.get("x_cms_assemble_control");}},
  54. "queryAction": {"get": function(){return o2.Actions.get("x_query_assemble_designer");}}
  55. });
  56. // this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  57. // //this.org2Action = MWF.Actions.get("x_organization_assemble_express");
  58. // this.processAction = MWF.Actions.get("x_processplatform_assemble_surface");
  59. // this.designerAction = MWF.Actions.get("x_processplatform_assemble_designer");
  60. // this.portalAction = MWF.Actions.get("x_portal_assemble_surface");
  61. // this.portalDesignerAction = MWF.Actions.get("x_portal_assemble_designer");
  62. // this.cmsAction = MWF.Actions.get("x_cms_assemble_control");
  63. // this.queryAction = MWF.Actions.get("x_query_assemble_designer");
  64. //this.action = new MWF.xApplication.Selector.Actions.RestActions();
  65. this.lastPeople = "";
  66. this.pageCount = "13";
  67. this.selectedItems = []; //所有已选项
  68. this.items = []; //所有选择项
  69. this.subCategorys = []; //直接的分类
  70. this.subItems = []; //直接的选择项
  71. if( !this.options.values ){
  72. this.options.values = [];
  73. }
  74. this._init();
  75. },
  76. _init : function(){
  77. this.selectType = "person";
  78. this.className = "Person"
  79. },
  80. load: function(){
  81. this.fireEvent("queryLoad",[this]);
  82. if( this.options.contentUrl ){
  83. this.loadWithUrl()
  84. }else{
  85. if (layout.mobile){
  86. this.loadMobile();
  87. }else{
  88. this.loadPc();
  89. }
  90. this.fireEvent("load");
  91. }
  92. },
  93. loadMobile: function(){
  94. this.maskRelativeNode = $(document.body);
  95. this.maskRelativeNode.mask({
  96. "destroyOnHide": true,
  97. "style": this.css.maskNode
  98. });
  99. this.node = new Element("div", {"styles": this.css.containerNodeMobile});
  100. this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  101. this.node.setStyle("height", ( $(document.body).getSize().y ) + "px");
  102. this.titleNode = new Element("div", {
  103. "styles": this.css.titleNodeMobile
  104. }).inject(this.node);
  105. this.titleCancelActionNode = new Element("div", {
  106. "styles": this.css.titleCancelActionNodeMobile,
  107. "text": MWF.SelectorLP.back
  108. }).inject(this.titleNode);
  109. this.titleOkActionNode = new Element("div", {
  110. "styles": this.css.titleOkActionNodeMobile,
  111. "text": MWF.SelectorLP.ok
  112. }).inject(this.titleNode);
  113. this.titleTextNode = new Element("div", {
  114. "styles": this.css.titleTextNodeMobile,
  115. "text": this.options.title
  116. }).inject(this.titleNode);
  117. this.contentNode = new Element("div", {
  118. "styles": this.css.contentNode
  119. }).inject(this.node);
  120. var size = $(document.body).getSize();
  121. var height = size.y-40;
  122. //var height = size.y;
  123. this.contentNode.setStyle("height", ""+height+"px");
  124. this.loadContent();
  125. this.node.inject($(document.body));
  126. this.node.setStyles({
  127. "top": "0px",
  128. "left": "0px"
  129. });
  130. this.setEvent();
  131. },
  132. setMaskResize: function(){
  133. var size = this.container.getSize();
  134. this.mask.resize();
  135. this.maskInterval = window.setInterval(function(){
  136. var resize = this.container.getSize();
  137. if ((size.x!==resize.x) || (size.y!==resize.y)){
  138. this.mask.position();
  139. this.mask.resize();
  140. size.x = resize.x;
  141. size.y = resize.y;
  142. }
  143. }.bind(this), 66);
  144. },
  145. loadPc: function(){
  146. if( this.options.embedded ){
  147. this.node = new Element("div", {
  148. "styles": this.css.containerNode_embedded, //(this.options.count.toInt()===1) ? this.css.containerNodeSingle_embedded : this.css.containerNode_embedded,
  149. "events": {
  150. "click": function(e){e.stopPropagation();},
  151. "mousedown": function(e){e.stopPropagation();},
  152. "mouseover": function(e){e.stopPropagation();},
  153. "mouseout": function(e){e.stopPropagation();},
  154. "keydown": function(e){e.stopPropagation();}
  155. }
  156. });
  157. this.contentNode = new Element("div", {
  158. "styles": this.css.contentNode_embedded ? this.css.contentNode_embedded : this.css.contentNode
  159. }).inject(this.node);
  160. this.loadContent();
  161. if( this.options.width || this.options.height ){
  162. this.setSize()
  163. }
  164. this.node.inject(this.container);
  165. } else {
  166. this.css.maskNode["z-index"] = this.options.zIndex;
  167. var position = this.container.getPosition(this.container.getOffsetParent());
  168. this.mask = new Mask(this.container, {
  169. "destroyOnHide": true,
  170. "style": this.css.maskNode,
  171. "useIframeShim": true,
  172. "iframeShimOptions": {"browsers": true},
  173. "onShow": function () {
  174. this.shim.shim.setStyles({
  175. "opacity": 0,
  176. "top": "" + position.y + "px",
  177. "left": "" + position.x + "px"
  178. });
  179. }
  180. //
  181. // "destroyOnHide": true,
  182. // "style": this.css.maskNode,
  183. // "useIframeShim": true,
  184. // "iframeShimOptions": {"browsers": true},
  185. // "onShow": function(){
  186. // this.shim.shim.setStyles({
  187. // "opacity": 0,
  188. // "top": ""+position.y+"px",
  189. // "left": ""+position.x+"px"
  190. // });
  191. // }
  192. });
  193. this.mask.show();
  194. this.setMaskResize();
  195. // this.container.setStyle("z-index", this.options.zIndex);
  196. this.node = new Element("div", {
  197. "styles": this.options.noSelectedContainer ? this.css.containerNodeSingle : this.css.containerNode, //(this.options.count.toInt()===1)
  198. "events": {
  199. "click": function(e){e.stopPropagation();},
  200. "mousedown": function(e){e.stopPropagation();},
  201. "mouseover": function(e){e.stopPropagation();},
  202. "mouseout": function(e){e.stopPropagation();},
  203. "keydown": function(e){e.stopPropagation();}
  204. }
  205. });
  206. this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  207. this.titleNode = new Element("div.titleNode", {
  208. "styles": this.css.titleNode
  209. }).inject(this.node);
  210. this.titleActionNode = new Element("div", {
  211. "styles": this.css.titleActionNode
  212. }).inject(this.titleNode);
  213. this.titleTextNode = new Element("div", {
  214. "styles": this.css.titleTextNode,
  215. "text": this.options.title
  216. }).inject(this.titleNode);
  217. this.contentNode = new Element("div", {
  218. "styles": this.css.contentNode
  219. }).inject(this.node);
  220. this.loadContent();
  221. this.actionNode = new Element("div", {
  222. "styles": this.css.actionNode
  223. }).inject(this.node);
  224. //if (this.options.count.toInt() === 1) this.actionNode.setStyle("text-align", "center");
  225. this.loadAction();
  226. this.node.inject(this.container);
  227. this.node.position({
  228. relativeTo: this.container,
  229. position: "center",
  230. edge: "center"
  231. });
  232. var size = this.container.getSize();
  233. var nodeSize = this.node.getSize();
  234. this.node.makeDraggable({
  235. "handle": this.titleNode,
  236. "limit": {
  237. "x": [0, size.x - nodeSize.x],
  238. "y": [0, size.y - nodeSize.y]
  239. }
  240. });
  241. if( this.options.width || this.options.height ){
  242. this.setSize()
  243. }
  244. this.setEvent();
  245. }
  246. },
  247. loadWithUrl : function(){
  248. var request = new Request.HTML({
  249. url: this.options.contentUrl,
  250. method: "GET",
  251. async: false,
  252. onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript){
  253. this.node = responseTree[0];
  254. this.loadContentWithHTML();
  255. this.fireEvent("load");
  256. }.bind(this),
  257. onFailure: function(xhr){
  258. alert(xhr);
  259. }
  260. });
  261. request.send();
  262. },
  263. loadContentWithHTML : function(){
  264. var container = this.options.injectToBody ? $(document.body) : this.container;
  265. if( !this.options.embedded ){
  266. this.maskRelativeNode = container;
  267. this.css.maskNode["z-index"] = this.options.zIndex;
  268. this.maskRelativeNode.mask({
  269. "destroyOnHide": true,
  270. "style": this.css.maskNode
  271. });
  272. }
  273. if( !this.options.embedded ) {
  274. this.node.setStyles(this.css.containerNodeMobile);
  275. this.node.setStyle("z-index", this.options.zIndex.toInt() + 1);
  276. }
  277. this.node.setStyle("height", ( container.getSize().y ) + "px");
  278. this.titleNode = this.node.getElement(".MWF_selector_titleNode");
  279. this.titleTextNode = this.node.getElement(".MWF_selector_titleTextNode");
  280. this.titleCancelActionNode = this.node.getElement(".MWF_selector_titleCancelActionNode");
  281. this.titleOkActionNode = this.node.getElement(".MWF_selector_titleOkActionNode");
  282. this.contentNode = this.node.getElement(".MWF_selector_contentNode");
  283. this.selectNode = this.node.getElement(".MWF_selector_selectNode");
  284. this.searchInputDiv = this.node.getElement(".MWF_selector_searchInputDiv");
  285. this.searchInput = this.node.getElement(".MWF_selector_searchInput");
  286. this.flatCategoryScrollNode = this.node.getElement(".MWF_selector_flatCategoryScrollNode");
  287. this.flatCategoryNode = this.node.getElement(".MWF_selector_flatCategoryNode");
  288. if( this.options.flatCategory && this.flatCategoryScrollNode ){
  289. this.isFlatCategory = true;
  290. this.flatSubCategoryNodeList = [];
  291. }
  292. this.letterAreaNode = this.node.getElement(".MWF_selector_letterAreaNode");
  293. this.itemAreaScrollNode = this.node.getElement(".MWF_selector_itemAreaScrollNode");
  294. this.itemAreaNode = this.node.getElement(".MWF_selector_itemAreaNode");
  295. this.itemSearchAreaScrollNode = this.node.getElement(".MWF_selector_itemSearchAreaScrollNode");
  296. this.itemSearchAreaNode = this.node.getElement(".MWF_selector_itemSearchAreaNode");
  297. this.selectedScrollNode = this.node.getElement(".MWF_selector_selectedScrollNode");
  298. this.selectedNode = this.node.getElement(".MWF_selector_selectedNode");
  299. this.selectedItemSearchAreaNode = this.node.getElement(".MWF_selector_selectedItemSearchAreaNode");
  300. this.actionNode = this.node.getElement(".MWF_selector_actionNode");
  301. this.okActionNode = this.node.getElement(".MWF_selector_okActionNode");
  302. this.cancelActionNode = this.node.getElement(".MWF_selector_cancelActionNode");
  303. if (this.titleNode) this.titleNode.setStyles(this.css.titleNodeMobile);
  304. if (this.titleTextNode){
  305. this.titleTextNode.setStyles(this.css.titleTextNodeMobile);
  306. if(this.options.title)this.titleTextNode.set("text", this.options.title);
  307. }
  308. if (this.titleCancelActionNode) this.titleCancelActionNode.setStyles(this.css.titleCancelActionNodeMobile);
  309. if (this.titleOkActionNode) this.titleOkActionNode.setStyles(this.css.titleOkActionNodeMobile);
  310. if (this.contentNode) this.contentNode.setStyles(this.css.contentNode);
  311. if (this.selectNode) this.selectNode.setStyles(this.css.selectNodeMobile);
  312. if (this.searchInputDiv) this.searchInputDiv.setStyles(this.css.searchInputDiv);
  313. if (this.searchInput) this.searchInput.setStyles( (this.options.count.toInt()===1 || this.options.noSelectedContainer) ? this.css.searchInputSingle : this.css.searchInput );
  314. if (this.letterAreaNode) this.letterAreaNode.setStyles(this.css.letterAreaNode);
  315. if (this.itemAreaScrollNode) this.itemAreaScrollNode.setStyles(this.css.itemAreaScrollNode);
  316. if (this.itemAreaNode) this.itemAreaNode.setStyles(this.css.itemAreaNode);
  317. if (this.itemSearchAreaScrollNode) this.itemSearchAreaScrollNode.setStyles(this.css.itemSearchAreaScrollNode);
  318. if (this.itemSearchAreaNode) this.itemSearchAreaNode.setStyles(this.css.itemAreaNode);
  319. if (this.selectedScrollNode) this.selectedScrollNode.setStyles(this.css.selectedScrollNode);
  320. if (this.selectedNode) this.selectedNode.setStyles(this.css.selectedNode);
  321. if (this.selectedItemSearchAreaNode) this.selectedItemSearchAreaNode.setStyles(this.css.itemAreaNode);
  322. if (this.actionNode) this.actionNode.setStyles(this.css.actionNode);
  323. if (this.okActionNode) {
  324. this.okActionNode.setStyles(this.css.okActionNode);
  325. this.okActionNode.set("text", MWF.SelectorLP.ok);
  326. }
  327. if (this.cancelActionNode) {
  328. this.cancelActionNode.setStyles(this.css.cancelActionNode);
  329. this.cancelActionNode.set("text", MWF.SelectorLP.cancel);
  330. }
  331. this.loadContent();
  332. if( this.actionNode ){
  333. this.loadAction();
  334. }
  335. this.node.inject( container );
  336. if( !this.options.embedded ){
  337. this.node.setStyles({
  338. "top": "0px",
  339. "left": "0px"
  340. });
  341. }
  342. this.setEvent();
  343. },
  344. getUnitIdentityCount : function(){
  345. },
  346. getUnitSelecteIndentityCount : function( unitLevelName ){ //根据组织获取已选身份数
  347. var count;
  348. this.selectedItems.each( function (item) {
  349. if( item.data.unitLevelName.indexOf( unitLevelName ) === 0 )count++;
  350. }.bind(this));
  351. return count;
  352. },
  353. getGroupNestCount : function(){
  354. // o2.Actions.load("x_organization_assemble_express").
  355. },
  356. getGroupSelecteIndentityCount : function( groupName ){ //根据组织获取已选身份数
  357. var count;
  358. this.selectedItems.each( function (item) {
  359. if( item.data.unitLevelName.indexOf( unitLevelName ) === 0 )count++;
  360. }.bind(this));
  361. return count;
  362. },
  363. setEvent: function(){
  364. if (this.titleActionNode){
  365. this.titleActionNode.addEvent("click", function(){
  366. this.fireEvent("cancel");
  367. this.close();
  368. }.bind(this));
  369. }
  370. if (this.titleCancelActionNode){
  371. this.titleCancelActionNode.addEvent("click", function(){
  372. this.fireEvent("cancel");
  373. this.close();
  374. }.bind(this));
  375. }
  376. if (this.titleOkActionNode){
  377. this.titleOkActionNode.addEvent("click", function(){
  378. this.fireEvent("complete", [this.selectedItems]);
  379. if( this.options.closeOnclickOk !== false )this.close();
  380. }.bind(this));
  381. }
  382. },
  383. close: function(){
  384. this.fireEvent("close");
  385. this.node.destroy();
  386. //if (this.mask) this.mask.hide();
  387. if( !this.options.embedded ){
  388. (this.maskRelativeNode || this.container).unmask();
  389. }
  390. if (this.maskInterval){
  391. window.clearInterval(this.maskInterval);
  392. this.maskInterval = null;
  393. }
  394. this.active = false;
  395. MWF.release(this);
  396. delete this;
  397. },
  398. loadAction: function(){
  399. if( !this.okActionNode ){
  400. this.okActionNode = new Element("button", {
  401. "styles": this.css.okActionNode,
  402. "text": MWF.SelectorLP.ok
  403. }).inject(this.actionNode);
  404. }
  405. if( !this.cancelActionNode ){
  406. this.cancelActionNode = new Element("button", {
  407. "styles": this.css.cancelActionNode,
  408. "text": MWF.SelectorLP.cancel
  409. }).inject(this.actionNode);
  410. }
  411. this.okActionNode.addEvent("click", function(){
  412. this.fireEvent("complete", [this.selectedItems]);
  413. if( this.options.closeOnclickOk !== false )this.close();
  414. }.bind(this));
  415. this.cancelActionNode.addEvent("click", function(){this.fireEvent("cancel"); this.close();}.bind(this));
  416. },
  417. loadContent: function( contentNode, isHTML ){
  418. this.fireEvent("queryLoadContent",[this]);
  419. if( contentNode )this.contentNode = contentNode;
  420. if( this.options.contentUrl || isHTML ){
  421. // if (this.options.count.toInt()!==1){
  422. // this.loadSelectedNodeHTML();
  423. // this.loadSelectNodeHTML(contentNode);
  424. // }else{
  425. // this.setSelectedItem();
  426. // this.loadSelectNodeHTML(contentNode);
  427. // }
  428. this.loadSelectedNodeHTML();
  429. this.loadSelectNodeHTML(contentNode);
  430. }else{
  431. if (layout.mobile){
  432. // if (this.options.count.toInt()!==1) this.loadSelectedNodeMobile();
  433. this.loadSelectedNodeMobile();
  434. this.loadSelectNodeMobile();
  435. }else{
  436. this.loadSelectNode();
  437. if( this.options.hasShuttle ){
  438. this.loadShuttleNode();
  439. }
  440. //if (this.options.count.toInt()!==1) this.loadSelectedNode();
  441. this.loadSelectedNode();
  442. }
  443. }
  444. this.fireEvent("postLoadContent", [this]);
  445. },
  446. getOffsetX : function(node){
  447. return (node.getStyle("margin-left").toInt() || 0 )+
  448. (node.getStyle("margin-right").toInt() || 0 ) +
  449. (node.getStyle("padding-left").toInt() || 0 ) +
  450. (node.getStyle("padding-right").toInt() || 0 ) +
  451. (node.getStyle("border-left-width").toInt() || 0 ) +
  452. (node.getStyle("border-right-width").toInt() || 0 );
  453. },
  454. getOffsetY : function(node){
  455. return (node.getStyle("margin-top").toInt() || 0 ) +
  456. (node.getStyle("margin-bottom").toInt() || 0 ) +
  457. (node.getStyle("padding-top").toInt() || 0 ) +
  458. (node.getStyle("padding-bottom").toInt() || 0 )+
  459. (node.getStyle("border-top-width").toInt() || 0 ) +
  460. (node.getStyle("border-bottom-width").toInt() || 0 );
  461. },
  462. loadSelectNodeHTML: function(contentNode){
  463. var size;
  464. var height;
  465. if( contentNode ){
  466. size = contentNode.getSize();
  467. height = size.y;
  468. if( height === 0 ){
  469. height = contentNode.getStyle("height").toInt();
  470. }
  471. }else{
  472. var container = this.options.injectToBody ? $(document.body) : this.container;
  473. //var containerSize = this.container.getSize();
  474. //var bodySize = $(document.body).getSize();
  475. size = container.getSize();
  476. if(size.y === 0){
  477. size.y = $(document.body).getSize().y
  478. }
  479. //size = {
  480. // "x" : Math.min( containerSize.x, bodySize.x ),
  481. // "y" : Math.min( containerSize.y, bodySize.y )
  482. //};
  483. if(this.node){
  484. var zoom = this.node.getStyle("zoom").toInt() || 0;
  485. if( zoom ){
  486. size.x = size.x * 100 / zoom;
  487. size.y = size.y * 100 / zoom;
  488. }
  489. this.node.setStyles({
  490. "width" : size.x+"px",
  491. "height" : size.y+"px"
  492. })
  493. }
  494. height = size.y-this.getOffsetY( this.contentNode );
  495. if( this.titleNode ){
  496. height = height - this.getOffsetY( this.titleNode ) - ( this.titleNode.getStyle("height").toInt() || 0 )
  497. }
  498. if( this.actionNode ){
  499. height = height - this.getOffsetY( this.actionNode ) - ( this.actionNode.getStyle("height").toInt() || 0 )
  500. }
  501. this.contentNode.setStyle("height", ""+height+"px");
  502. }
  503. var isFormWithAction = window.location.href.toLowerCase().indexOf("workmobilewithaction.html") > -1;
  504. this.selectNode.setStyle("height", ""+height+"px");
  505. if( this.searchInput ){
  506. this.initSearchInput();
  507. height = height - this.getOffsetY( this.searchInputDiv ) - ( this.searchInputDiv.getStyle("height").toInt() || 0 )
  508. }
  509. if( this.options.hasLetter && this.letterAreaNode ){
  510. width = size.x - 18;
  511. this.letterAreaNode.setStyle("width", "" + width + "px");
  512. this.loadLetters();
  513. height = height - this.getOffsetY( this.letterAreaNode ) - ( this.letterAreaNode.getStyle("height").toInt() || 0 )
  514. }
  515. this.itemAreaScrollNode.setStyle("height", ""+height+"px");
  516. this.itemAreaScrollNode.setStyle("overflow", "auto");
  517. if(this.itemSearchAreaScrollNode){
  518. this.itemSearchAreaScrollNode.setStyles({
  519. "display": "none",
  520. "height": ""+height+"px",
  521. "overflow" : "hidden"
  522. });
  523. }
  524. this.itemSearchAreaNode.setStyle("display", "none");
  525. this.initLoadSelectItems();
  526. this.checkLoadSelectItems();
  527. },
  528. loadSelectNodeMobile: function(){
  529. this.selectNode = new Element("div.selectNode", {
  530. "styles": this.css.selectNodeMobile
  531. }).inject(this.contentNode);
  532. var containerSize = this.container.getSize();
  533. var bodySize = $(document.body).getSize();
  534. var size = {
  535. "x" : Math.min( containerSize.x, bodySize.x ),
  536. "y" : Math.min( containerSize.y, bodySize.y )
  537. };
  538. var isFormWithAction = window.location.href.toLowerCase().indexOf("workmobilewithaction.html") > -1;
  539. var height;
  540. if( isFormWithAction ){
  541. height = size.y-40-20-6-20;
  542. }else{
  543. height = size.y;
  544. }
  545. this.selectNode.setStyle("height", ""+height+"px");
  546. this.searchInputDiv = new Element("div.searchInputDiv", {
  547. "styles": this.css.searchInputDiv
  548. }).inject(this.selectNode);
  549. this.searchInput = new Element("input.searchInput", {
  550. "styles": (this.options.count.toInt()===1 || this.options.noSelectedContainer) ? this.css.searchInputSingle : this.css.searchInput,
  551. "type": "text"
  552. }).inject(this.searchInputDiv);
  553. var width = size.x-20-18;
  554. this.searchInput.setStyle("width", ""+width+"px");
  555. this.searchInput.setStyle("height", "20px");
  556. this.initSearchInput();
  557. if( this.options.hasLetter ) {
  558. this.letterAreaNode = new Element("div", {
  559. "styles": this.css.letterAreaMobileNode
  560. }).inject(this.selectNode);
  561. width = size.x - 18;
  562. this.letterAreaNode.setStyle("width", "" + width + "px");
  563. this.loadLetters();
  564. }
  565. this.itemAreaScrollNode = new Element("div.itemAreaScrollNode", {
  566. "styles": this.css.itemAreaScrollNode
  567. }).inject(this.selectNode);
  568. if( isFormWithAction ){
  569. height = size.y-40-20-78-20;
  570. }else{
  571. height = size.y-42-31-40;
  572. }
  573. this.itemAreaScrollNode.setStyle("height", ""+height+"px");
  574. this.itemAreaScrollNode.setStyle("overflow", "auto");
  575. this.itemAreaNode = new Element("div.itemAreaNode", {
  576. "styles": this.css.itemAreaNode
  577. }).inject(this.itemAreaScrollNode);
  578. this.itemSearchAreaNode = new Element("div.itemSearchAreaNode", {
  579. "styles": this.css.itemAreaNode
  580. }).inject(this.itemAreaScrollNode);
  581. this.itemSearchAreaNode.setStyle("display", "none");
  582. //MWF.require("MWF.widget.ScrollBar", function(){
  583. // var _self = this;
  584. // new MWF.widget.ScrollBar(this.itemAreaScrollNode, {
  585. // "style":"xApp_Organization_Explorer",
  586. // "where": "before",
  587. // "distance": 30,
  588. // "friction": 4,
  589. // "axis": {"x": false, "y": true},
  590. // "onScroll": function(y){
  591. // _self._scrollEvent(y);
  592. // }
  593. // });
  594. //}.bind(this));
  595. this.initLoadSelectItems();
  596. this.checkLoadSelectItems();
  597. },
  598. loadSelectedNodeHTML: function(){
  599. this.setSelectedItem();
  600. //MWF.require("MWF.widget.ScrollBar", function(){
  601. // var _self = this;
  602. // new MWF.widget.ScrollBar(this.selectedScrollNode, {
  603. // "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  604. // });
  605. //}.bind(this));
  606. if(this.selectedScrollNode)this.selectedScrollNode.setStyle("display", "none");
  607. },
  608. checkLoadSelectItems: function(){
  609. if (!this.options.groups.length && !this.options.roles.length){
  610. this.loadSelectItems();
  611. }else{
  612. this.loadSelectItemsByCondition();
  613. }
  614. },
  615. loadShuttleNode : function(){
  616. if(this.shuttleNode)return;
  617. this.shuttleNode = new Element("div.shuttleNode", {
  618. "styles": this.css.shuttleNode
  619. }).inject(this.contentNode);
  620. this.shuttleInnerNode = new Element("div.shuttleInnerNode", {
  621. "styles": this.css.shuttleInnerNode
  622. }).inject(this.shuttleNode);
  623. this.goRightNode = new Element("div.goRightNode", {
  624. "styles": this.css.goRightNode
  625. }).inject(this.shuttleInnerNode);
  626. this.goLeftNode = new Element("div.goLeftNode", {
  627. "styles": this.css.goLeftNode
  628. }).inject(this.shuttleInnerNode);
  629. },
  630. loadSelectNode: function(){
  631. this.selectNode = new Element("div.selectNode", {
  632. "styles": this.css.selectNode //(this.options.count.toInt()===1) ? this.css.selectNodeSingle : this.css.selectNode
  633. }).inject(this.contentNode);
  634. if( this.options.hasTop ){ //if( this.options.embedded && this.options.count.toInt()!==1 ){
  635. this.selectTopNode = new Element("div.selectTopNode",{
  636. "styles" : this.css.selectTopNode
  637. }).inject( this.selectNode );
  638. this.selectTopTextNode = new Element("div",{
  639. "text" : MWF.SelectorLP.waitingSelect,
  640. "styles" : this.css.selectTopTextNode
  641. }).inject( this.selectTopNode );
  642. }
  643. if( this.options.searchbarInTopNode ){
  644. this.searchInputDiv = new Element("div", {
  645. "styles": this.css.searchInputDiv
  646. }).inject( this.selectTopNode || this.selectNode);
  647. }else{
  648. this.searchInputDiv = new Element("div.searchInputDiv", {
  649. "styles": this.css.searchInputDiv
  650. }).inject( this.selectNode);
  651. }
  652. this.searchInput = new Element("input", {
  653. "styles": this.css.searchInput, //(this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
  654. "placeholder" : MWF.SelectorLP.searchDescription,
  655. "type": "text"
  656. }).inject(this.searchInputDiv);
  657. this.initSearchInput();
  658. if( this.options.hasLetter ){
  659. this.letterAreaNode = new Element("div", {
  660. "styles": this.css.letterAreaNode
  661. }).inject(this.selectNode);
  662. this.loadLetters();
  663. }
  664. this.itemAreaScrollNode = new Element("div", {
  665. "styles": this.css.itemAreaScrollNode
  666. }).inject(this.selectNode);
  667. this.itemAreaNode = new Element("div", {
  668. "styles": this.css.itemAreaNode
  669. }).inject(this.itemAreaScrollNode);
  670. this.itemSearchAreaNode = new Element("div", {
  671. "styles": this.css.itemAreaNode
  672. }).inject(this.itemAreaScrollNode);
  673. this.itemSearchAreaNode.setStyle("display", "none");
  674. this.loadSelectNodeScroll();
  675. this.initLoadSelectItems();
  676. this.checkLoadSelectItems();
  677. },
  678. loadSelectNodeScroll: function(){
  679. var overflowY = this.itemAreaScrollNode.getStyle("overflow-y");
  680. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") )return;
  681. MWF.require("MWF.widget.ScrollBar", function(){
  682. var _self = this;
  683. new MWF.widget.ScrollBar(this.itemAreaScrollNode, {
  684. "style":"xApp_Organization_Explorer",
  685. "where": "before",
  686. "distance": 30,
  687. "friction": 4,
  688. "axis": {"x": false, "y": true},
  689. "onScroll": function(y){
  690. _self._scrollEvent(y);
  691. }
  692. });
  693. }.bind(this));
  694. },
  695. initSearchInput: function(){
  696. this.searchInput.addEvents({
  697. "keydown": function(e){
  698. var iTimerID = this.searchInput.retrieve("searchTimer", null);
  699. if (iTimerID){
  700. window.clearTimeout(iTimerID);
  701. this.searchInput.eliminate("searchTimer");
  702. }
  703. iTimerID = window.setTimeout(function(){
  704. this.search();
  705. }.bind(this), 800);
  706. this.searchInput.store("searchTimer", iTimerID);
  707. }.bind(this),
  708. "change": function(e){
  709. var key = this.searchInput.get("value");
  710. if (!key) this.initSearchArea(false);
  711. }.bind(this),
  712. "blur": function(){
  713. var key = this.searchInput.get("value");
  714. if (!key) this.initSearchArea(false);
  715. }.bind(this)
  716. });
  717. },
  718. initSearchArea: function(flag){
  719. this.searchItems = [];
  720. if (flag){
  721. this.itemSearchAreaNode.empty();
  722. this.itemAreaNode.setStyle("display", "none");
  723. if( this.itemSearchAreaNode.getParent() !== this.itemAreaScrollNode ){
  724. this.itemAreaScrollNode.setStyle("display", "none");
  725. }
  726. if(this.flatCategoryScrollNode){
  727. this.flatCategoryScrollNode.setStyle("display", "none");
  728. }
  729. if( this.itemSearchAreaScrollNode )this.itemSearchAreaScrollNode.setStyle("display", "block");
  730. this.itemSearchAreaNode.setStyle("display", "block");
  731. }else{
  732. this.itemAreaScrollNode.setStyle("display", "block");
  733. this.itemAreaNode.setStyle("display", "block");
  734. if(this.flatCategoryScrollNode && this.flatSubCategoryNodeList && this.flatSubCategoryNodeList.length > 1 ){
  735. this.flatCategoryScrollNode.setStyle("display", "block");
  736. }
  737. if( this.itemSearchAreaScrollNode )this.itemSearchAreaScrollNode.setStyle("display", "none");
  738. this.itemSearchAreaNode.setStyle("display", "none");
  739. }
  740. },
  741. search: function(){
  742. if (!this.options.groups.length && !this.options.roles.length && !this.options.forceSearchInItem ){
  743. var key = this.searchInput.get("value");
  744. if (key){
  745. this._listItemByKey(function(json){
  746. this.initSearchArea(true);
  747. json.data.each(function(data){
  748. if( !this.isExcluded( data ) ) {
  749. var itemSearch = this._newItemSearch(data, this, this.itemSearchAreaNode);
  750. this.searchItems.push( itemSearch );
  751. }
  752. //this._newItem(data, this, this.itemSearchAreaNode);
  753. }.bind(this));
  754. }.bind(this), null, key);
  755. }else{
  756. this.initSearchArea(false);
  757. }
  758. }else{
  759. var key = this.searchInput.get("value");
  760. if (key){
  761. this.initSearchArea(true);
  762. this.searchInItems(key);
  763. }else{
  764. this.initSearchArea(false);
  765. }
  766. }
  767. },
  768. searchInItems: function(key){
  769. var createdId = [];
  770. this.createItemsSearchData(function(){
  771. var word = key.toLowerCase();
  772. this.itemsSearchData.each(function(obj){
  773. var text = obj.text+"#"+obj.pinyin+"#"+obj.firstPY;
  774. var id = obj.data.distinguishedName || obj.data.id || obj.data.name || obj.data.text;
  775. if (text.indexOf(word)!==-1){
  776. if (createdId.indexOf( id )===-1){
  777. this._newItem(obj.data, this, this.itemSearchAreaNode);
  778. createdId.push( id );
  779. }
  780. }
  781. }.bind(this));
  782. //delete createdId;
  783. }.bind(this));
  784. return createdId;
  785. },
  786. createItemsSearchData: function(callback){
  787. if (!this.itemsSearchData){
  788. this.itemsSearchData = [];
  789. MWF.require("MWF.widget.PinYin", function(){
  790. var initIds = [];
  791. this.items.each(function(item){
  792. var id = item.data.distinguishedName || item.data.id || item.data.name || item.data.text;
  793. if (initIds.indexOf( id )==-1){
  794. var text = item._getShowName().toLowerCase();
  795. var pinyin = text.toPY().toLowerCase();
  796. var firstPY = text.toPYFirst().toLowerCase();
  797. this.itemsSearchData.push({
  798. "text": text,
  799. "pinyin": pinyin,
  800. "firstPY": firstPY,
  801. "data": item.data
  802. });
  803. initIds.push( id );
  804. }
  805. }.bind(this));
  806. delete initIds;
  807. if (callback) callback();
  808. }.bind(this));
  809. }else{
  810. if (callback) callback();
  811. }
  812. },
  813. initSelectedSearchInput: function(){
  814. this.selectedSearchInput.addEvents({
  815. "keydown": function(e){
  816. var iTimerID = this.selectedSearchInput.retrieve("searchTimer", null);
  817. if (iTimerID){
  818. window.clearTimeout(iTimerID);
  819. this.selectedSearchInput.eliminate("searchTimer");
  820. }
  821. iTimerID = window.setTimeout(function(){
  822. this.selectedSearch();
  823. }.bind(this), 800);
  824. this.selectedSearchInput.store("searchTimer", iTimerID);
  825. }.bind(this),
  826. "change": function(e){
  827. var key = this.selectedSearchInput.get("value");
  828. if (!key) this.selectedSearch();
  829. }.bind(this),
  830. "blur": function(){
  831. var key = this.selectedSearchInput.get("value");
  832. if (!key) this.selectedSearch();
  833. }.bind(this)
  834. });
  835. },
  836. selectedSearch: function(){
  837. var key = this.selectedSearchInput.get("value");
  838. if (key){
  839. this.selectedSearchInItems(key);
  840. }else{
  841. this.showAllSelectedItem()
  842. }
  843. },
  844. selectedSearchInItems: function(key){
  845. var word = key.toLowerCase();
  846. MWF.require("MWF.widget.PinYin", function() {
  847. this.selectedItems.each(function (item) {
  848. if (!item.searchedText) {
  849. var text = item._getShowName().toLowerCase();
  850. var pinyin = text.toPY().toLowerCase();
  851. var firstPY = text.toPYFirst().toLowerCase();
  852. item.searchedText = text + "#" + pinyin + "#" + firstPY
  853. }
  854. if (item.searchedText.indexOf(word) !== -1) {
  855. item.node.show()
  856. } else {
  857. item.node.hide()
  858. }
  859. }.bind(this));
  860. }.bind(this), null, false);
  861. },
  862. showAllSelectedItem: function(){
  863. this.selectedItems.each(function(item){
  864. item.node.show()
  865. })
  866. },
  867. loadSelectedNode: function( callback ){
  868. if( this.selectedContainerNode )return;
  869. this.selectedContainerNode = new Element("div", {
  870. "styles": this.css.selectedContainerNode
  871. }).inject(this.contentNode);
  872. if( this.options.noSelectedContainer ){
  873. this.selectedContainerNode.hide();
  874. }
  875. //if( this.options.embedded && this.options.count.toInt()!==1 ){
  876. if( this.options.hasTop ){
  877. this.selectedTopNode = new Element("div",{
  878. "styles" : this.css.selectedTopNode
  879. }).inject( this.selectedContainerNode );
  880. this.selectedTopTextNode = new Element("div",{
  881. "text" : MWF.SelectorLP.selected,
  882. "styles" : this.css.selectedTopTextNode
  883. }).inject( this.selectedTopNode );
  884. this.emptySelectedNode = new Element("div",{
  885. "text" : MWF.SelectorLP.empty,
  886. "styles" : this.css.selectedTopActionNode,
  887. "events" : {
  888. "click" : function(){
  889. this.emptySelectedItems()
  890. }.bind(this)
  891. }
  892. }).inject( this.selectedTopNode );
  893. }
  894. if( this.options.hasSelectedSearchbar ){
  895. if( this.options.searchbarInTopNode ){
  896. this.selectedSearchInputDiv = new Element("div", {
  897. "styles": this.css.searchInputDiv
  898. }).inject( this.selectedTopNode || this.selectedContainerNode);
  899. }else{
  900. this.selectedSearchInputDiv = new Element("div.selectedSearchInputDiv", {
  901. "styles": this.css.searchInputDiv
  902. }).inject( this.selectedContainerNode);
  903. }
  904. this.selectedSearchInput = new Element("input", {
  905. "styles": this.css.searchInput, //(this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
  906. "placeholder" : MWF.SelectorLP.searchDescription,
  907. "type": "text"
  908. }).inject(this.selectedSearchInputDiv);
  909. this.initSelectedSearchInput();
  910. }
  911. this.selectedScrollNode = new Element("div.selectedScrollNode", {
  912. "styles": this.css.selectedScrollNode
  913. }).inject(this.selectedContainerNode);
  914. this.selectedNode = new Element("div.selectedNode", {
  915. "styles": this.css.selectedNode
  916. }).inject(this.selectedScrollNode);
  917. if( this.options.hasSelectedSearchbar ){
  918. this.selectedItemSearchAreaNode = new Element("div.selectedItemSearchAreaNode", {
  919. "styles": this.css.itemAreaNode
  920. }).inject(this.selectedScrollNode);
  921. this.selectedItemSearchAreaNode.setStyle("display", "none");
  922. }
  923. this.setSelectedItem();
  924. this.loadSelectedNodeScroll();
  925. if(callback)callback();
  926. },
  927. emptySelectedItems : function(){
  928. while (this.selectedItems.length){
  929. this.selectedItems[0].clickItem();
  930. }
  931. },
  932. loadSelectedNodeScroll: function(){
  933. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  934. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") )return;
  935. MWF.require("MWF.widget.ScrollBar", function(){
  936. var _self = this;
  937. new MWF.widget.ScrollBar(this.selectedScrollNode, {
  938. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  939. });
  940. }.bind(this));
  941. },
  942. loadSelectedNodeMobile: function(){
  943. this.selectedScrollNode = new Element("div.selectedScrollNode", {
  944. "styles": this.css.selectedScrollNode
  945. }).inject(this.contentNode);
  946. this.selectedNode = new Element("div.selectedNode", {
  947. "styles": this.css.selectedNode
  948. }).inject(this.selectedScrollNode);
  949. this.setSelectedItem();
  950. // MWF.require("MWF.widget.ScrollBar", function(){
  951. // var _self = this;
  952. // new MWF.widget.ScrollBar(this.selectedScrollNode, {
  953. // "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  954. // });
  955. // }.bind(this));
  956. this.selectedScrollNode.setStyle("display", "none");
  957. },
  958. setSelectedItem: function(){
  959. if (this.options.values.length){
  960. this.options.values.each(function(v, i){
  961. if (typeOf(v)==="object"){
  962. this.selectedItems.push(this._newItemSelected(v, this, null));
  963. }else{
  964. this._getItem(function(json){
  965. this.options.values[i] = json.data;
  966. this.selectedItems.push(this._newItemSelected(json.data, this, null));
  967. }.bind(this), null, v, false);
  968. }
  969. // this._getItem(function(json){
  970. // this.selectedItems.push(this._newItemSelected(json.data, this, null));
  971. // }.bind(this), null, v, false);
  972. }.bind(this));
  973. }
  974. },
  975. loadLetters: function(){
  976. var _self = this;
  977. letters = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"];
  978. var letterNodeCss = this.css.letterNode;
  979. var letterNodeCss_over = this.css.letterNode_over;
  980. if (layout.mobile){
  981. letterNodeCss = this.css.letterNode_mobile || letterNodeCss;
  982. letterNodeCss_over = this.css.letterNode_mobile_over || letterNodeCss_over;
  983. var size = this.container.getSize();
  984. var w = (layout.mobile) ? (size.x-18)/13 : (size.x-20-4-18)/13;
  985. //letterNode.setStyle("width", ""+w+"px");
  986. letterNodeCss.width = ""+w+"px";
  987. letterNodeCss_over.width = ""+w+"px";
  988. }
  989. letters.each(function(l){
  990. var letterNode = new Element("div", {
  991. "styles": letterNodeCss,
  992. "text": l
  993. }).inject(this.letterAreaNode);
  994. if (layout.mobile){
  995. letterNode.addEvents({
  996. "click": function(){
  997. _self.listPersonByPinyin(this);
  998. }
  999. });
  1000. }else{
  1001. letterNode.addEvents({
  1002. "mouseover": function(e){
  1003. e.target.setStyles(letterNodeCss_over);
  1004. var showNode = new Element("div", {
  1005. "styles": this.css.letterShowNode,
  1006. "text": e.target.get("text")
  1007. }).inject(this.selectNode);
  1008. showNode.position({
  1009. relativeTo: this.itemAreaScrollNode,
  1010. position: "center",
  1011. edge: "center"
  1012. });
  1013. e.target.store("showNode", showNode);
  1014. }.bind(this),
  1015. "mouseout": function(e){
  1016. var showNode = e.target.retrieve("showNode");
  1017. showNode.destroy();
  1018. e.target.setStyles(letterNodeCss);
  1019. }.bind(this),
  1020. "click": function(){
  1021. _self.listPersonByPinyin(this);
  1022. }
  1023. });
  1024. }
  1025. }.bind(this));
  1026. },
  1027. listPersonByPinyin: function(node){
  1028. this.searchInput.focus();
  1029. var pinyin = this.searchInput.get("value");
  1030. pinyin = pinyin+node.get("text");
  1031. this.searchInput.set("value", pinyin);
  1032. if (!this.options.groups.length && !this.options.roles.length){
  1033. if (pinyin){
  1034. this._listItemByPinyin(function(json){
  1035. this.initSearchArea(true);
  1036. json.data.each(function(data){
  1037. // var flag = true;
  1038. // if (this.options.departments){
  1039. // if (this.options.departments.length){
  1040. // if (this.options.departments.indexOf(data.departmentName)==-1) flag = false;
  1041. // }
  1042. // }
  1043. // if (this.options.companys){
  1044. // if (this.options.companys.length){
  1045. // if (this.options.companys.indexOf(data.company)==-1) flag = false;
  1046. // }
  1047. // }
  1048. if( !this.isExcluded( data ) ) {
  1049. this._newItemSearch(data, this, this.itemSearchAreaNode);
  1050. }
  1051. //this._newItem(data, this, this.itemSearchAreaNode);
  1052. //this._newItem(data, this, this.itemSearchAreaNode);
  1053. }.bind(this));
  1054. }.bind(this), null, pinyin.toLowerCase());
  1055. }
  1056. }else{
  1057. if (pinyin){
  1058. this.initSearchArea(true);
  1059. this.searchInItems(pinyin);
  1060. }else{
  1061. this.initSearchArea(false);
  1062. }
  1063. }
  1064. },
  1065. initLoadSelectItems: function(){
  1066. this.loaddingItems = false;
  1067. this.isItemLoaded = false;
  1068. this.loadItemsQueue = 0;
  1069. this.initSearchArea(false);
  1070. },
  1071. //loadSelectItems: function(addToNext){
  1072. // if (!this.isItemLoaded){
  1073. // if (!this.loaddingItems){
  1074. // this.loaddingItems = true;
  1075. // var count = 20;
  1076. // this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  1077. // if (json.data.length){
  1078. // json.data.each(function(data){
  1079. // var item = this._newItem(data, this, this.itemAreaNode);
  1080. // this.items.push(item);
  1081. // }.bind(this));
  1082. // this.loaddingItems = false;
  1083. //
  1084. // if (json.data.length<count){
  1085. // this.isItemLoaded = true;
  1086. // }else{
  1087. // if (this.loadItemsQueue>0){
  1088. // this.loadItemsQueue--;
  1089. // this.loadSelectItems();
  1090. // }
  1091. // }
  1092. // }else{
  1093. // this.isItemLoaded = true;
  1094. // this.loaddingItems = false;
  1095. // }
  1096. // }.bind(this));
  1097. // }else{
  1098. // if (addToNext) this.loadItemsQueue++;
  1099. // }
  1100. // }
  1101. //},
  1102. loadSelectItems: function(addToNext, lastExcludeCount ){
  1103. //lastExcludeCount 参数:表示本次加载是为了补足上次load的时候被排除的数量
  1104. if (!this.isItemLoaded){
  1105. if (!this.loaddingItems){
  1106. this.loaddingItems = true;
  1107. var count = 20;
  1108. this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  1109. if (json.data.length){
  1110. var excludedCount = 0;
  1111. json.data.each(function(data, i){
  1112. if( this.isExcluded( data ) ){
  1113. excludedCount++;
  1114. if( i+1 === count )this.tailExcludeItemId = data.distinguishedName
  1115. }else{
  1116. var item = this._newItem(data, this, this.itemAreaNode);
  1117. this.items.push(item);
  1118. if( i+1 === count )this.tailExcludeItemId = null;
  1119. }
  1120. }.bind(this));
  1121. this.loaddingItems = false;
  1122. if( lastExcludeCount ){ //如果是因为上次load的时候被排除而加载的
  1123. if( count - lastExcludeCount - excludedCount < 0 ){ //如果本次load的数量还不够补足排除的数量,需要再次load
  1124. excludedCount = lastExcludeCount + excludedCount - count; //把不足的数量作为再次load的参数
  1125. this.loadItemsQueue++
  1126. }
  1127. }else if( excludedCount > 0 ){ //把排除的数量作为再次load的参数
  1128. this.loadItemsQueue++
  1129. }
  1130. if (json.data.length<count){
  1131. this.isItemLoaded = true;
  1132. }else{
  1133. if (this.loadItemsQueue>0){
  1134. this.loadItemsQueue--;
  1135. this.loadSelectItems( addToNext, excludedCount );
  1136. }
  1137. }
  1138. }else{
  1139. this.isItemLoaded = true;
  1140. this.loaddingItems = false;
  1141. }
  1142. if( this.afterLoadSelectItem )this.afterLoadSelectItem();
  1143. }.bind(this));
  1144. }else{
  1145. if (addToNext) this.loadItemsQueue++;
  1146. }
  1147. }
  1148. },
  1149. getLastLoadedItemId: function(){
  1150. if( this.tailExcludeItemId )return this.tailExcludeItemId;
  1151. return (this.items.length) ? this.items[this.items.length-1].data.distinguishedName : "(0)";
  1152. },
  1153. //loadSelectItemsByCondition: function(){
  1154. // this.options.groups.each(function(group){
  1155. //
  1156. // this.orgAction.listGroupByKey(function(json){
  1157. // if (json.data.length){
  1158. // var groupData = json.data[0];
  1159. // var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  1160. // this._getChildrenItemIds(groupData).each(function(id){
  1161. // this._getItem(function(json){
  1162. // var item = this._newItem(json.data, this, category.children);
  1163. // this.items.push(item);
  1164. // }.bind(this), null, id);
  1165. // }.bind(this));
  1166. // }
  1167. // }.bind(this), null, group);
  1168. // }.bind(this));
  1169. //
  1170. // this.options.roles.each(function(role){
  1171. // this.orgAction.listRoleByKey(function(json){
  1172. // if (json.data.length){
  1173. // var roleData = json.data[0];
  1174. // var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  1175. // this._getChildrenItemIds(roleData).each(function(id){
  1176. // this._getItem(function(json){
  1177. // var item = this._newItem(json.data, this, category.children);
  1178. // this.items.push(item);
  1179. // }.bind(this), null, id)
  1180. // }.bind(this));
  1181. // }
  1182. // }.bind(this), null, role);
  1183. // }.bind(this));
  1184. //},
  1185. loadSelectItemsByCondition: function(){
  1186. this.options.groups.each(function(group){
  1187. this.orgAction.listGroupByKey(function(json){
  1188. if (json.data.length){
  1189. var groupData = json.data[0];
  1190. var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  1191. this.subCategorys.push(category);
  1192. this._getChildrenItemIds(groupData).each(function(id){
  1193. this._getItem(function(json){
  1194. if( !this.isExcluded( json.data ) ) {
  1195. var item = this._newItem(json.data, this, category.children);
  1196. this.items.push(item);
  1197. }
  1198. }.bind(this), null, id);
  1199. }.bind(this));
  1200. }
  1201. }.bind(this), null, group);
  1202. }.bind(this));
  1203. this.options.roles.each(function(role){
  1204. this.orgAction.listRoleByKey(function(json){
  1205. if (json.data.length){
  1206. var roleData = json.data[0];
  1207. var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  1208. this.subCategorys.push(category);
  1209. this._getChildrenItemIds(roleData).each(function(id){
  1210. this._getItem(function(json){
  1211. if( !this.isExcluded( json.data ) ) {
  1212. var item = this._newItem(json.data, this, category.children);
  1213. this.items.push(item);
  1214. }
  1215. }.bind(this), null, id)
  1216. }.bind(this));
  1217. }
  1218. }.bind(this), null, role);
  1219. }.bind(this));
  1220. },
  1221. isExcluded : function( d ){
  1222. if( this.options.exclude.length === 0 )return false;
  1223. if( !this.excludeFlagMap ){
  1224. this.excludeFlagMap = {};
  1225. this.options.exclude.each( function( e ){
  1226. if( !e )return;
  1227. this.excludeFlagMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.id || e.unique || e.employee || e.levelName) ] = true;
  1228. }.bind(this));
  1229. }
  1230. var map = this.excludeFlagMap;
  1231. return ( d.distinguishedName && map[ d.distinguishedName ] ) ||
  1232. ( d.id && map[ d.id ] ) ||
  1233. ( d.unique && map[ d.unique ] ) ||
  1234. ( d.employee && map[ d.employee ] ) ||
  1235. ( d.levelName && map[ d.levelName ] );
  1236. },
  1237. _getChildrenItemIds: function(data){
  1238. return data.personList;
  1239. },
  1240. _newItemCategory: function(type, data, selector, item){
  1241. return new MWF.xApplication.Selector.Person[type](data, selector, item)
  1242. },
  1243. _listItemByKey: function(callback, failure, key){
  1244. this.orgAction.listPersonByKey(function(json){
  1245. if (callback) callback.apply(this, [json]);
  1246. }.bind(this), failure, key);
  1247. },
  1248. _getItem: function(callback, failure, id, async){
  1249. this.orgAction.getPerson(function(json){
  1250. if (callback) callback.apply(this, [json]);
  1251. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  1252. },
  1253. _newItemSelected: function(data, selector, item, selectedNode){
  1254. return new MWF.xApplication.Selector.Person.ItemSelected(data, selector, item, selectedNode)
  1255. },
  1256. _listItemByPinyin: function(callback, failure, key){
  1257. this.orgAction.listPersonByPinyin(function(json){
  1258. if (callback) callback.apply(this, [json]);
  1259. }.bind(this), failure, key);
  1260. },
  1261. _newItem: function(data, selector, container){
  1262. return new MWF.xApplication.Selector.Person.Item(data, selector, container);
  1263. },
  1264. _newItemSearch: function(data, selector, container){
  1265. return this._newItem(data, selector, container);
  1266. },
  1267. _listItemNext: function(last, count, callback){
  1268. this.orgAction.listPersonNext(last, count, function(json){
  1269. if (callback) callback.apply(this, [json]);
  1270. }.bind(this));
  1271. },
  1272. _scrollEvent: function(y){
  1273. if (!this.options.groups.length && !this.options.roles.length){
  1274. var scrollSize = this.itemAreaScrollNode.getScrollSize();
  1275. var clientSize = this.itemAreaScrollNode.getSize();
  1276. var scrollHeight = scrollSize.y-clientSize.y;
  1277. if (y+30>scrollHeight) {
  1278. if (!this.isItemLoaded) this.loadSelectItems();
  1279. }
  1280. }
  1281. },
  1282. afterLoadSelectItem : function(){
  1283. if( this.items.length === 0 && this.subItems.length === 0 && this.subCategorys.length === 0 ){
  1284. this.noSelectableItemTextDiv = new Element("div", {
  1285. text : MWF.SelectorLP.noSelectableItemText,
  1286. styles : this.css.noSelectableItemText
  1287. }).inject( this.itemAreaNode );
  1288. }
  1289. if( this.options.selectSingleItem ){
  1290. this.selectSingleItem()
  1291. }
  1292. this.fireEvent("afterLoadSelectItem", [this]);
  1293. },
  1294. selectSingleItem: function(){
  1295. if( !this.options.contentUrl && !layout.mobile){
  1296. if( this.options.hasShuttle && !this.shuttleNode ){
  1297. this.loadShuttleNode();
  1298. }
  1299. if( !this.selectedContainerNode ) {
  1300. this.loadSelectedNode(function () {
  1301. this._selectSingleItem();
  1302. }.bind(this));
  1303. }else{
  1304. this._selectSingleItem();
  1305. }
  1306. }else{
  1307. this._selectSingleItem();
  1308. }
  1309. },
  1310. _selectSingleItem : function(){
  1311. var _self = this;
  1312. var checkItem = function () {
  1313. if(this.items.length === 1 || this.subItems.length === 1 ){
  1314. if( this.items.length === 1 && this.subItems.length === 0 ){
  1315. if( !this.items[0].isSelected )this.items[0].clickItem();
  1316. this.fireEvent("afterSelectSingleItem",[this, this.items[0]])
  1317. }else if( this.items.length === 0 && this.subItems.length === 1 ){
  1318. if( !this.items[0].isSelected )this.subItems[0].clickItem();
  1319. this.fireEvent("afterSelectSingleItem",[this, this.items[0]])
  1320. }else if( this.items.length === 1 && this.subItems.length === 1 ){
  1321. if( this.items[0] === this.subItems[0] ){
  1322. if( !this.items[0].isSelected )this.items[0].clickItem();
  1323. this.fireEvent("afterSelectSingleItem",[this, this.items[0]])
  1324. }
  1325. }
  1326. }
  1327. }.bind(this);
  1328. var checkCategoryItem = function (category) {
  1329. if( !category.subCategorys || category.subCategorys.length === 0 ){
  1330. if( category.subItems && category.subItems.length === 1 ){
  1331. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1332. _self.fireEvent("afterSelectSingleItem",[_self, category.subItems[0]])
  1333. }
  1334. }else if(category.subCategorys.length === 1){
  1335. if( category.subItems && category.subItems.length > 0 ){
  1336. }else if( !category.subCategorys[0]._hasChild || !category.subCategorys[0]._hasChild() ){ //category.subCategorys[0].isItem &&
  1337. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1338. _self.fireEvent("afterSelectSingleItem",[_self, category.subItems[0]])
  1339. }else{
  1340. checkCategory( category.subCategorys[0] )
  1341. }
  1342. }else{
  1343. var list = [];
  1344. for( var i=0; i<category.subCategorys.length; i++ ){
  1345. if( category.subCategorys[i]._hasChild && category.subCategorys[i]._hasChild() ){
  1346. list.push( category.subCategorys[i] );
  1347. }
  1348. }
  1349. if( list.length === 1 ){
  1350. if( !category.subItems || category.subItems.length === 0 ){
  1351. checkCategory( list[0] );
  1352. }
  1353. }
  1354. if( list.length === 0 ){
  1355. if( category.subItems && category.subItems.length === 1 ){
  1356. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1357. _self.fireEvent("afterSelectSingleItem",[_self, category.subItems[0]])
  1358. }
  1359. }
  1360. }
  1361. };
  1362. var checkCategory = function ( category ) {
  1363. if( category.loaded ){
  1364. checkCategoryItem( category )
  1365. }else if( category.loading ){
  1366. window.setTimeout( function () {
  1367. checkCategory( category )
  1368. }, 100 )
  1369. }
  1370. };
  1371. if( this.subCategorys.length === 1 ) {
  1372. checkCategory( this.subCategorys[0] );
  1373. }else if( this.subCategorys.length === 0 ){
  1374. checkItem();
  1375. }
  1376. },
  1377. setSize : function(){
  1378. debugger;
  1379. if( !this.options.width && !this.options.height )return;
  1380. var getOffsetX = function(node){
  1381. return (node.getStyle("margin-left").toInt() || 0 )+
  1382. (node.getStyle("margin-right").toInt() || 0 ) +
  1383. (node.getStyle("padding-left").toInt() || 0 ) +
  1384. (node.getStyle("padding-right").toInt() || 0 ) +
  1385. (node.getStyle("border-left-width").toInt() || 0 ) +
  1386. (node.getStyle("border-right-width").toInt() || 0 );
  1387. };
  1388. var getOffsetY = function(node){
  1389. return (node.getStyle("margin-top").toInt() || 0 ) +
  1390. (node.getStyle("margin-bottom").toInt() || 0 ) +
  1391. (node.getStyle("padding-top").toInt() || 0 ) +
  1392. (node.getStyle("padding-bottom").toInt() || 0 )+
  1393. (node.getStyle("border-top-width").toInt() || 0 ) +
  1394. (node.getStyle("border-bottom-width").toInt() || 0 );
  1395. };
  1396. if( this.options.width && this.options.width === "auto" ){
  1397. //if (this.options.count.toInt() !== 1){
  1398. if( this.node )this.node.setStyle("width", "auto");
  1399. this.selectNode.setStyles({
  1400. "width": "50%",
  1401. "float" : "left"
  1402. });
  1403. //this.searchInput.setStyle("width", "99%");
  1404. if(this.letterAreaNode ){
  1405. this.letterAreaNode.setStyle("width", "auto");
  1406. }
  1407. this.selectedContainerNode.setStyle("width", "auto");
  1408. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  1409. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
  1410. this.selectedScrollNode.setStyle("width", "auto");
  1411. }else{
  1412. this.selectedScrollNode.setStyle("margin-right", "8px");
  1413. }
  1414. //}else{
  1415. // this.node.setStyle("width", "auto");
  1416. // this.selectNode.setStyle("width", "auto");
  1417. //}
  1418. }else if( this.options.width && typeOf( this.options.width.toInt() ) === "number" ){
  1419. var nodeWidth;
  1420. if( this.node ){
  1421. nodeWidth = this.options.width.toInt() - getOffsetX(this.node);
  1422. this.node.setStyle("width", nodeWidth);
  1423. }else{
  1424. nodeWidth = this.options.width.toInt();
  1425. }
  1426. nodeWidth = nodeWidth - getOffsetX( this.contentNode );
  1427. if( this.shuttleNode ){
  1428. nodeWidth = nodeWidth - getOffsetX(this.shuttleNode) - this.shuttleNode.getStyle("width").toInt();
  1429. }
  1430. //if (this.options.count.toInt() !== 1){
  1431. var width = nodeWidth - getOffsetX(this.selectNode) - getOffsetX(this.selectedContainerNode);
  1432. var halfWidth = this.options.noSelectedContainer ? width : ( Math.floor(width / 2) - 2);
  1433. this.selectNode.setStyle("width", halfWidth);
  1434. //this.searchInput.setStyle("width", halfWidth - 6);
  1435. if(this.letterAreaNode ){
  1436. this.letterAreaNode.setStyle("width", halfWidth - 19);
  1437. }
  1438. this.selectedContainerNode.setStyle("width", halfWidth);
  1439. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  1440. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
  1441. this.selectedScrollNode.setStyle("width", halfWidth);
  1442. }else{
  1443. this.selectedScrollNode.setStyle("width", halfWidth - 8);
  1444. }
  1445. //}else{
  1446. // var width = nodeWidth - getOffsetX(this.selectNode);
  1447. // this.selectNode.setStyle("width", width);
  1448. //}
  1449. }
  1450. if( this.options.height && typeOf( this.options.height.toInt() ) === "number" ){
  1451. var nodeHeight;
  1452. if( this.node ){
  1453. nodeHeight = this.options.height.toInt() - getOffsetY(this.node);
  1454. this.node.setStyle("height", nodeHeight);
  1455. }else{
  1456. nodeHeight = this.options.height.toInt();
  1457. }
  1458. nodeHeight = nodeHeight - getOffsetY( this.contentNode ) - 1;
  1459. if( this.titleNode ){
  1460. nodeHeight = nodeHeight - getOffsetY( this.titleNode ) - this.titleNode.getStyle("height").toInt();
  1461. }
  1462. if( this.actionNode ){
  1463. nodeHeight = nodeHeight - getOffsetY( this.actionNode ) - this.actionNode.getStyle("height").toInt();
  1464. }
  1465. var selectNodeHeight = nodeHeight - getOffsetY(this.selectNode);
  1466. this.selectNode.setStyle("height", selectNodeHeight);
  1467. if( this.shuttleNode ){
  1468. this.shuttleNode.setStyle("height", selectNodeHeight);
  1469. var shuttleInnerHieght = getOffsetY( this.shuttleInnerNode ) + this.shuttleInnerNode.getStyle("height").toInt();
  1470. this.shuttleInnerNode.setStyle("margin-top", (selectNodeHeight-shuttleInnerHieght)/2 +"px" )
  1471. }
  1472. var itemAreaScrollNodeHeight = selectNodeHeight - getOffsetY( this.searchInputDiv ) - this.searchInputDiv.getStyle("height").toInt();
  1473. if( !this.options.searchbarInTopNode && this.selectTopNode ){
  1474. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.selectTopNode ) - this.selectTopNode.getStyle("height").toInt();
  1475. }
  1476. if(this.letterAreaNode ){
  1477. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.letterAreaNode ) - this.letterAreaNode.getStyle("height").toInt();
  1478. }
  1479. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.itemAreaScrollNode );
  1480. this.itemAreaScrollNode.setStyle("height", itemAreaScrollNodeHeight);
  1481. var selectedContainerNodeHeight = nodeHeight - getOffsetY(this.selectedContainerNode);
  1482. this.selectedContainerNode.setStyle("height", selectedContainerNodeHeight);
  1483. var selectedScrollNodeHeight = selectedContainerNodeHeight;
  1484. if( this.selectedTopNode ) {
  1485. selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY(this.selectedTopNode) - this.selectedTopNode.getStyle("height").toInt();
  1486. }
  1487. if( !this.options.searchbarInTopNode && this.selectedSearchInputDiv ){
  1488. selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY( this.selectedSearchInputDiv ) - this.selectedSearchInputDiv.getStyle("height").toInt();
  1489. }
  1490. this.selectedScrollNode.setStyle("height", selectedScrollNodeHeight);
  1491. }
  1492. this.fireEvent("setSize",[this])
  1493. },
  1494. addFlatCategoryItem : function( categoryItemNode, hasChildrenItem, itemNodeContainer, isCreateSubCategoryListNode ){
  1495. if(!this.flatSubCategoryNodeList)this.flatSubCategoryNodeList = [];
  1496. if( hasChildrenItem )this.flatSubCategoryNodeList.push( categoryItemNode );
  1497. if( !this.isFlatCategoryLoaded && this.flatSubCategoryNodeList.length > 1 ){
  1498. this.flatCategoryScrollNode.show();
  1499. this.flatCategoryScrollNode.setStyles( this.css.flatCategoryScrollNode );
  1500. var height = this.itemAreaScrollNode.getStyle("height").toInt();
  1501. this.flatCategoryScrollNode.setStyle("height", ""+height+"px");
  1502. this.flatCategoryNode.setStyles( this.css.flatCategoryNode );
  1503. this.isFlatCategoryLoaded = true;
  1504. this.itemAreaScrollNode.setStyles( this.css.itemAreaScrollNode_flatCategory );
  1505. //alert(this.flatSubCategoryNodeList[0].outerHTML)
  1506. }
  1507. if( hasChildrenItem )categoryItemNode.inject( itemNodeContainer || this.flatCategoryNode );
  1508. var subCategoryListNode;
  1509. if( isCreateSubCategoryListNode ){
  1510. subCategoryListNode = new Element("div.subCategoryListNode").inject( itemNodeContainer || this.flatCategoryNode );
  1511. }
  1512. //this.setFlatCategorySequence(categoryItemNode, itemNodeContainer, subCategoryListNode);
  1513. if( hasChildrenItem ){
  1514. //if( this.checkClickFlatCategoryItem(categoryItemNode, itemNodeContainer) ){
  1515. // categoryItemNode.click();
  1516. //}
  1517. if( !this.currentCategoryItemNode ){
  1518. categoryItemNode.click();
  1519. this.currentCategoryItemNode = categoryItemNode
  1520. }else{
  1521. //var date = new Date();
  1522. var first = this.flatCategoryNode.getElement(".flatCategoryItemNode");
  1523. //if(first)console.log(first.get("title"));
  1524. //console.log(new Date() - date );
  1525. //console.log(" " );
  1526. if( first ){
  1527. var dn1 = first.retrieve("dn");
  1528. var dn2 = this.currentCategoryItemNode.retrieve("dn");
  1529. if( dn1 && dn2 ){
  1530. if( dn1 != dn2 ){
  1531. categoryItemNode.click();
  1532. this.currentCategoryItemNode = categoryItemNode
  1533. }
  1534. }else{
  1535. var title1 = first.get("title");
  1536. var title2 = this.currentCategoryItemNode.get("title");
  1537. if( title1 && title1 ){
  1538. if( title1 != title2 ){
  1539. categoryItemNode.click();
  1540. this.currentCategoryItemNode = categoryItemNode
  1541. }
  1542. }else{
  1543. var text1 = first.get("text");
  1544. var text2 = this.currentCategoryItemNode.get("text");
  1545. if( text1 != text2 ){
  1546. categoryItemNode.click();
  1547. this.currentCategoryItemNode = categoryItemNode
  1548. }
  1549. }
  1550. }
  1551. }
  1552. }
  1553. }
  1554. return subCategoryListNode;
  1555. }
  1556. //checkClickFlatCategoryItem : function(categoryItemNode, itemNodeContainer){
  1557. // if( !this.flatCategorySeqObj_current ){
  1558. // this.flatCategorySeqObj_current = categoryItemNode.retrieve("seq");
  1559. // //console.log(this.flatCategorySeqObj_current)
  1560. // return true;
  1561. // }
  1562. // var seq_cur = this.flatCategorySeqObj_current;
  1563. // var seq = categoryItemNode ? categoryItemNode.retrieve("seq") : [];
  1564. // for( var i=0; i<seq.length; i++ ){
  1565. // if( seq_cur[i] && seq[i] < seq_cur[i] ){
  1566. // //console.log(seq)
  1567. // this.flatCategorySeqObj_current = seq;
  1568. // return true;
  1569. // }else if( !seq_cur[i] || seq[i] > seq_cur[i] ){
  1570. // return false;
  1571. // }
  1572. // }
  1573. // return false;
  1574. //},
  1575. //setFlatCategorySequence: function(categoryItemNode, itemNodeContainer, subCategoryListNode){
  1576. // if( !this.flatCategorySeqObj )this.flatCategorySeqObj = {};
  1577. // var parentSeq = itemNodeContainer ? itemNodeContainer.retrieve("seq") : [];
  1578. // var seq = Array.clone( parentSeq );
  1579. // if( this.flatCategorySeqObj[ parentSeq.length ] ){
  1580. // seq.push( this.flatCategorySeqObj[ parentSeq.length ] + 1 );
  1581. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1582. //
  1583. // categoryItemNode.store( "seq", seq );
  1584. // categoryItemNode.set( "seq", seq );
  1585. //
  1586. // if(subCategoryListNode){
  1587. // seq = Array.clone( seq );
  1588. // seq[ seq.length - 1 ] = seq[ seq.length - 1 ]+1;
  1589. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1590. // subCategoryListNode.store("seq", seq );
  1591. // subCategoryListNode.set( "seq", seq );
  1592. // }
  1593. // }else{
  1594. // seq.push( 1 );
  1595. // this.flatCategorySeqObj[ parentSeq.length ] = 1;
  1596. // categoryItemNode.store( "seq", seq );
  1597. // categoryItemNode.set( "seq", seq );
  1598. //
  1599. // if(subCategoryListNode) {
  1600. // seq = Array.clone(seq);
  1601. // seq[seq.length - 1] = seq[seq.length - 1]+1;
  1602. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1603. // subCategoryListNode.store("seq", seq);
  1604. // subCategoryListNode.set("seq", seq);
  1605. // }
  1606. // }
  1607. //}
  1608. });
  1609. MWF.xApplication.Selector.Person.Item = new Class({
  1610. initialize: function(data, selector, container, level, category, delay){
  1611. this.clazz = "Item";
  1612. this.data = data;
  1613. this.selector = selector;
  1614. this.container = container;
  1615. this.isSelected = false;
  1616. this.level = (level) ? level.toInt() : 1;
  1617. this.category = category;
  1618. this.subItems = [];
  1619. this.subCategorys = [];
  1620. if(!delay)this.load();
  1621. },
  1622. _getShowName: function(){
  1623. return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
  1624. },
  1625. _getTtiteText: function(){
  1626. return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
  1627. },
  1628. _setIcon: function(){
  1629. var style = this.selector.options.style;
  1630. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
  1631. },
  1632. load: function(){
  1633. if( this.clazz === "Item" ){
  1634. this.selector.fireEvent("queryLoadItem",[this]);
  1635. }
  1636. if( !this.node )this.node = new Element("div", {
  1637. "styles": this.selector.css.selectorItem
  1638. }).inject(this.container);
  1639. this.levelNode = new Element("div", {
  1640. "styles": this.selector.css.selectorItemLevelNode
  1641. }).inject(this.node);
  1642. if( this.selector.selectType !== "identity" || this.selector.options.identityItemWidth === 0 ) {
  1643. var indent = this.selector.options.level1Indent + (this.level - 1) * this.selector.options.indent;
  1644. this.levelNode.setStyle("width", "" + indent + "px");
  1645. }
  1646. this.iconNode = new Element("div", {
  1647. "styles": this.selector.css.selectorItemIconNode
  1648. }).inject(this.node);
  1649. this._setIcon();
  1650. this.actionNode = new Element("div", {
  1651. "styles": this.selector.css.selectorItemActionNode
  1652. }).inject(this.node);
  1653. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1654. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1655. }
  1656. this.textNode = new Element("div", {
  1657. "styles": this.selector.css.selectorItemTextNode,
  1658. "text": this._getShowName(),
  1659. "title": this._getTtiteText()
  1660. }).inject(this.node);
  1661. this.textNode.store("indent", indent);
  1662. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  1663. this.textNode.setStyle("margin-left", ""+m+"px");
  1664. if( this.selector.options.identityItemWidth && this.selector.selectType === "identity"){
  1665. this.node.setStyles({
  1666. "float" : "left",
  1667. "min-width" : this.selector.options.identityItemWidth + "px"
  1668. })
  1669. }
  1670. if(this.postLoad)this.postLoad();
  1671. this.loadSubItem();
  1672. this.setEvent();
  1673. this.check();
  1674. if( this.clazz === "Item" ) {
  1675. this.selector.fireEvent("postLoadItem", [this]);
  1676. }
  1677. },
  1678. loadSubItem: function(){},
  1679. disable : function(){
  1680. this.node.hide();
  1681. this.disabled = true;
  1682. },
  1683. enable : function(){
  1684. this.node.show();
  1685. this.disabled = false;
  1686. },
  1687. check: function(){
  1688. //if (this.selector.options.count.toInt()===1){
  1689. // this.checkSelectedSingle();
  1690. //}else{
  1691. this.checkSelected();
  1692. //}
  1693. },
  1694. checkSelectedSingle: function(){
  1695. var selectedItem = this.selector.options.values.filter(function(item, index){
  1696. if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
  1697. if (typeOf(item)==="string") return this.data.distinguishedName === item;
  1698. return false;
  1699. }.bind(this));
  1700. if (selectedItem.length){
  1701. this.selectedSingle();
  1702. }
  1703. },
  1704. checkSelected: function(){
  1705. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  1706. return item.data.distinguishedName === this.data.distinguishedName;
  1707. }.bind(this));
  1708. if (selectedItem.length){
  1709. //selectedItem[0].item = this;
  1710. selectedItem[0].addItem(this);
  1711. this.selectedItem = selectedItem[0];
  1712. this.setSelected();
  1713. }
  1714. },
  1715. checkTextNodeIndent : function( textNode, styles ){
  1716. var indent = textNode.retrieve("indent");
  1717. if( indent && styles && styles["margin-left"] ){
  1718. var m = styles["margin-left"].toFloat()+indent;
  1719. textNode.setStyle("margin-left", ""+m+"px");
  1720. }
  1721. },
  1722. setSelected: function(){
  1723. this.isSelected = true;
  1724. this.node.setStyles(this.selector.css.selectorItem_selected);
  1725. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1726. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
  1727. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1728. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1729. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1730. }
  1731. // if( this.category ){
  1732. // this.category.checkSelectAll();
  1733. // }
  1734. },
  1735. setEvent: function(){
  1736. this.node.addEvents({
  1737. "mouseover": function(){
  1738. this.overItem();
  1739. }.bind(this),
  1740. "mouseout": function(){
  1741. this.outItem();
  1742. }.bind(this),
  1743. "click": function(){
  1744. this.clickItem( null, true );
  1745. }.bind(this)
  1746. });
  1747. },
  1748. clickItem: function( callback, checkValid ){
  1749. // if ( layout.mobile && this.selector.options.count.toInt()===1){
  1750. // this.selectedSingle( checkValid );
  1751. // }else{
  1752. if (this.isSelected){
  1753. this.unSelected( checkValid );
  1754. }else{
  1755. this.selected( checkValid );
  1756. }
  1757. // }
  1758. },
  1759. overItem: function(){
  1760. if (!this.isSelected ){
  1761. this.node.setStyles(this.selector.css.selectorItem_over);
  1762. }else if( this.selector.css.selectorItem_over_force ){
  1763. this.node.setStyles(this.selector.css.selectorItem_over_force);
  1764. }
  1765. if (!this.isSelected){
  1766. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  1767. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_over ){
  1768. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_over );
  1769. }
  1770. }else if( this.selector.css.selectorItemActionNode_over_force ){
  1771. this.node.setStyles(this.selector.css.selectorItemActionNode_over_force);
  1772. }
  1773. },
  1774. outItem: function(){
  1775. if (!this.isSelected){
  1776. this.node.setStyles(this.selector.css.selectorItem);
  1777. }else if( this.selector.css.selectorItem_over_force ){
  1778. this.node.setStyles(this.selector.css.selectorItem_selected);
  1779. }
  1780. if (!this.isSelected){
  1781. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1782. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1783. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1784. }
  1785. }else if( this.selector.css.selectorItemActionNode_over_force ){
  1786. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1787. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1788. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1789. }
  1790. }
  1791. },
  1792. selectedSingle: function( checkValid ){
  1793. if (!this.isSelected){
  1794. if (this.selector.currentItem) this.selector.currentItem.unSelectedSingle();
  1795. this.selector.emptySelectedItems();
  1796. this.getData(function(){
  1797. this.selector.currentItem = this;
  1798. this.isSelected = true;
  1799. this.selector.selectedItems.push(this);
  1800. this.node.setStyles(this.selector.css.selectorItem_selected);
  1801. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1802. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
  1803. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1804. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1805. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1806. }
  1807. this.selector.fireEvent("selectItem",[this]);
  1808. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1809. }.bind(this));
  1810. }else {
  1811. this.selector.emptySelectedItems();
  1812. this.unSelectedSingle( checkValid );
  1813. }
  1814. },
  1815. getData: function(callback){
  1816. if (callback) callback();
  1817. },
  1818. unSelectedSingle: function(checkValid){
  1819. this.selector.currentItem = null;
  1820. this.isSelected = false;
  1821. this.selector.selectedItems.erase(this);
  1822. this.node.setStyles(this.selector.css.selectorItem);
  1823. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1824. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode );
  1825. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1826. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1827. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1828. }
  1829. this.selector.fireEvent("unselectItem",[this]);
  1830. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1831. },
  1832. selected: function( checkValid, callback, selectedNode, byelectAll ){
  1833. debugger;
  1834. var count = this.selector.options.maxCount || this.selector.options.count;
  1835. count = count.toInt();
  1836. if (!count) count = 0;
  1837. if( count == 1 && this.selector.emptySelectedItems){
  1838. this.selector.emptySelectedItems();
  1839. }
  1840. if ((count===0) || (this.selector.selectedItems.length+1)<=count) {
  1841. this.isSelected = true;
  1842. if( this.node ){
  1843. this.node.setStyles(this.selector.css.selectorItem_selected);
  1844. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1845. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
  1846. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1847. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1848. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1849. }
  1850. }
  1851. this.selectedItem = this.selector._newItemSelected(this.data, this.selector, this, selectedNode);
  1852. // this.selectedItem.check();
  1853. this.selector.selectedItems.push(this.selectedItem);
  1854. // if( this.category ){
  1855. // this.category.checkSelectAll();
  1856. // }
  1857. this.selector.fireEvent("selectItem",[this]);
  1858. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1859. if(callback)callback();
  1860. }else{
  1861. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
  1862. }
  1863. },
  1864. unSelected: function( checkValid, callback ){
  1865. this.isSelected = false;
  1866. if( this.node ){
  1867. this.node.setStyles(this.selector.css.selectorItem);
  1868. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1869. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode );
  1870. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1871. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1872. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1873. }
  1874. }
  1875. if( this.category ){
  1876. this.category.checkUnselectAll();
  1877. }
  1878. if( this.selector.searchItems && this.selector.searchItems.length ){
  1879. this.selector.searchItems.each( function(itemSearch){
  1880. var sd = itemSearch.data;
  1881. var d = this.data;
  1882. if(
  1883. ( sd.distinguishedName && (sd.distinguishedName === d.distinguishedName) ) ||
  1884. ( sd.id && (sd.id === d.id) ) ||
  1885. ( sd.unique && (sd.unique === d.unique) ) ||
  1886. ( sd.employee && (sd.employee === d.employee) ) ||
  1887. ( sd.levelName && (sd.levelName === d.levelName) )
  1888. ){
  1889. itemSearch.isSelected = false;
  1890. itemSearch.node.setStyles(this.selector.css.selectorItem);
  1891. itemSearch.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1892. this.checkTextNodeIndent( itemSearch.textNode, this.selector.css.selectorItemTextNode );
  1893. itemSearch.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1894. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1895. itemSearch.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1896. }
  1897. }
  1898. }.bind(this))
  1899. }
  1900. if (this.selectedItem){
  1901. this.selector.selectedItems.erase(this.selectedItem);
  1902. this.selectedItem.items.each(function(item){
  1903. if (item != this){
  1904. item.isSelected = false;
  1905. item.node.setStyles(this.selector.css.selectorItem);
  1906. item.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1907. this.checkTextNodeIndent( item.textNode, this.selector.css.selectorItemTextNode );
  1908. item.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1909. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1910. item.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1911. }
  1912. }
  1913. if( this.selector.selectType == "identity" && ( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ) ){
  1914. if(item.category && item.category._addSelectedCount )item.category._addSelectedCount( -1, true );
  1915. }
  1916. }.bind(this));
  1917. this.selectedItem.destroy();
  1918. this.selectedItem = null;
  1919. }
  1920. this.selector.fireEvent("unselectItem",[this]);
  1921. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1922. if(callback)callback();
  1923. },
  1924. postLoad : function(){},
  1925. getParentCategoryByLevel : function( level ){
  1926. var category = this.category;
  1927. do{
  1928. if( category.level === level ){
  1929. return category;
  1930. }else{
  1931. category = category.category;
  1932. }
  1933. }while( category )
  1934. }
  1935. });
  1936. MWF.xApplication.Selector.Person.ItemSelected = new Class({
  1937. Extends: MWF.xApplication.Selector.Person.Item,
  1938. initialize: function(data, selector, item, selectedNode){
  1939. this.data = data;
  1940. this.selector = selector;
  1941. this.container = selectedNode || this.selector.selectedNode;
  1942. this.isSelected = false;
  1943. this.clazz = "ItemSelected";
  1944. this.items = [];
  1945. if (item) this.items.push(item);
  1946. this.level = 0;
  1947. this.node = new Element("div", {
  1948. "styles": this.selector.css.selectorItem
  1949. }).inject(this.container);
  1950. this.node.setStyle("display","none");
  1951. this.getData(function(){
  1952. this.node.setStyle("display","");
  1953. this.load();
  1954. }.bind(this));
  1955. },
  1956. postLoad : function(){
  1957. if( this.selector.css.selectorSelectedItemActionNode ){
  1958. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode );
  1959. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorSelectedItemActionNode_single ){
  1960. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode_single );
  1961. }
  1962. }
  1963. if( this.selector.css.selectorSelectedItemTextNode ){
  1964. this.textNode.setStyles(this.selector.css.selectorSelectedItemTextNode);
  1965. }
  1966. },
  1967. getData: function(callback){
  1968. if (callback) callback();
  1969. },
  1970. clickItem: function( callback, checkValid ){
  1971. if (this.items.length){
  1972. this.items.each(function(item){
  1973. item.unSelected( checkValid );
  1974. });
  1975. if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
  1976. }else{
  1977. //this.item.selectedItem = null;
  1978. //this.item.isSelected = false;
  1979. this.destroy();
  1980. this.selector.selectedItems.erase(this);
  1981. if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
  1982. }
  1983. },
  1984. //overItem: function(){
  1985. // if (!this.isSelected){
  1986. // this.node.setStyles(this.selector.css.selectorItem_over);
  1987. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  1988. // }
  1989. //},
  1990. overItem: function(){
  1991. if (!this.isSelected ){
  1992. if( this.selector.css.selectorItem_selected_over ){
  1993. this.node.setStyles(this.selector.css.selectorItem_selected_over);
  1994. }else{
  1995. this.node.setStyles(this.selector.css.selectorItem_over);
  1996. }
  1997. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  1998. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected_over ){
  1999. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected_over );
  2000. }
  2001. }
  2002. },
  2003. outItem: function(){
  2004. if (!this.isSelected){
  2005. var styles = this.selector.css.selectorSelectedItem || this.selector.css.selectorItem;
  2006. this.node.setStyles(styles);
  2007. }else if( this.selector.css.selectorItem_over_force ){
  2008. this.node.setStyles(this.selector.css.selectorItem_selected);
  2009. }
  2010. if (!this.isSelected){
  2011. var styles = this.selector.css.selectorSelectedItemActionNode || this.selector.css.selectorItemActionNode;
  2012. this.actionNode.setStyles(styles);
  2013. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) &&
  2014. ( this.selector.css.selectorSelectedItemActionNode_single || this.selector.css.selectorItemActionNode_single ) ){
  2015. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode_single || this.selector.css.selectorItemActionNode_single );
  2016. }
  2017. }else if( this.selector.css.selectorItemActionNode_over_force ){
  2018. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  2019. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  2020. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  2021. }
  2022. }
  2023. },
  2024. addItem: function(item){
  2025. if (this.items.indexOf(item)===-1) this.items.push(item);
  2026. },
  2027. check: function(){
  2028. debugger;
  2029. if (this.selector.items.length){
  2030. var items = this.selector.items.filter(function(item, index){
  2031. return item.data.distinguishedName === this.data.distinguishedName;
  2032. }.bind(this));
  2033. this.items = items;
  2034. if (items.length){
  2035. items.each(function(item){
  2036. item.selectedItem = this;
  2037. item.setSelected();
  2038. // if( this.selector.options.showSelectedCount ){
  2039. // if(item.category)item.category._addSelectedCount( 1, true );
  2040. // }
  2041. }.bind(this));
  2042. }
  2043. }
  2044. if( this.afterCheck )this.afterCheck();
  2045. },
  2046. destroy: function(){
  2047. if(this.node){
  2048. // var parent = this.node.getParent(".categorySelectedNode");
  2049. // if( parent && !this.node.getPrevious() && !this.node.getNext() ){ //parent.getChildren().length <= 1
  2050. // parent.destroy();
  2051. // }else{
  2052. this.node.destroy();
  2053. // }
  2054. }
  2055. delete this;
  2056. }
  2057. });
  2058. MWF.xApplication.Selector.Person.ItemCategory = new Class({
  2059. Extends: MWF.xApplication.Selector.Person.Item,
  2060. initialize: function(data, selector, container, level, parentCategory, delay){
  2061. this.data = data;
  2062. this.selector = selector;
  2063. this.container = container;
  2064. this.isSelected = false;
  2065. this.level = (level) ? level.toInt() : 1;
  2066. this.category = parentCategory;
  2067. this.subItems = [];
  2068. this.subCategorys = [];
  2069. if(!delay)this.load();
  2070. },
  2071. load : function(){
  2072. if( this.selector.isFlatCategory ){
  2073. this.loadForFlat();
  2074. }else{
  2075. this.loadForNormal();
  2076. }
  2077. },
  2078. loadForFlat : function(){
  2079. this.selector.fireEvent("queryLoadCategory",[this]);
  2080. //this.createNode();
  2081. this.node = new Element("div.flatCategoryItemNode", {
  2082. "styles": this.selector.css.flatCategoryItemNode,
  2083. "title" : this._getTtiteText()
  2084. });
  2085. this.node.store( "category", this );
  2086. this.node.store( "dn", this.data.distinguishedName );
  2087. this.textNode = new Element("div", {
  2088. "styles": this.selector.css.flatCategoryItemTextNode,
  2089. "text": this._getShowName()
  2090. }).inject(this.node);
  2091. //var level = this.level;
  2092. //var category = this;
  2093. //while( category.category ){
  2094. // level = category.category + "_" + level;
  2095. // category = category.category;
  2096. //}
  2097. this.children = new Element("div", {
  2098. "styles": this.selector.css.selectorItemCategoryChildrenNode
  2099. }).inject(this.selector.itemAreaNode); //this.container
  2100. //if (!this.selector.options.expand)
  2101. this.children.setStyle("display", "none");
  2102. if( this.selector.options.selectAllEnable && this.selector.options.count.toInt()!==1 ){
  2103. var selectAllWrap = new Element("div",{
  2104. styles : this.selector.css.flatCategory_selectAllWrap
  2105. }).inject(this.children);
  2106. this.selectAllNode = new Element("div", {
  2107. "styles": this.selector.css.flatCategory_selectAll,
  2108. "text" : "全选"
  2109. }).inject(selectAllWrap);
  2110. this.selectAllNode.addEvent( "click", function(ev){
  2111. if( this.isSelectedAll ){
  2112. this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
  2113. this.selector.fireEvent("unselectCatgory",[this])
  2114. }else{
  2115. this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev, true) : this.selectAll(ev, true);
  2116. this.selector.fireEvent("selectCatgory",[this])
  2117. }
  2118. ev.stopPropagation();
  2119. }.bind(this));
  2120. }
  2121. // var subIdList = this.selector._getChildrenItemIds(this.data);
  2122. // if (subIdList){
  2123. // var count = subIdList.length;
  2124. // this.childrenHeight = count*this.selector.options.itemHeight;
  2125. // this.children.setStyle("height", ""+this.childrenHeight+"px");
  2126. // }
  2127. //if (!this._hasChild()){
  2128. // this.textNode.setStyle("color", "#333");
  2129. //}
  2130. if( this.selectAllNode ){
  2131. if( this.selector.options.selectAllRange === "direct" && !this._hasChildItem() ){
  2132. this.selectAllNode.setStyle("display", "none");
  2133. }
  2134. }
  2135. this.node.addEvents({
  2136. //"mouseover": function(){
  2137. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode_over );
  2138. //}.bind(this),
  2139. //"mouseout": function(){
  2140. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode );
  2141. //}.bind(this),
  2142. "click": function(){
  2143. if( this.selector.currentFlatCategory === this )return;
  2144. if( this.selector.currentFlatCategory ){
  2145. this.selector.currentFlatCategory.clickFlatCategoryItem(null, true); //取消原来选择的
  2146. }
  2147. this.selector.currentFlatCategory = this;
  2148. this.clickFlatCategoryItem();
  2149. }.bind(this)
  2150. });
  2151. //this.setEvent();
  2152. var isCreateSubCategoryListNode = this._hasChildCategory ? this._hasChildCategory() : true;
  2153. var nodeContainer;
  2154. if( this.nodeContainer ){
  2155. nodeContainer = this.nodeContainer;
  2156. }else{
  2157. nodeContainer = (this.category && this.category.subCategoryListNode) ? this.category.subCategoryListNode : null;
  2158. }
  2159. this.subCategoryListNode = this.selector.addFlatCategoryItem( this.node, this._hasChildItem(), nodeContainer, isCreateSubCategoryListNode );
  2160. this.check();
  2161. if( this.loadCategoryChildren )this.loadCategoryChildren();
  2162. //this.afterLoad();
  2163. this.selector.fireEvent("postLoadCategory",[this]);
  2164. },
  2165. loadForNormal : function(){
  2166. this.selector.fireEvent("queryLoadCategory",[this]);
  2167. this.createNode();
  2168. this.levelNode = new Element("div", {
  2169. "styles": this.selector.css.selectorItemLevelNode
  2170. }).inject(this.node);
  2171. if(this.selector.selectType !== "identity" || this.selector.options.identityItemWidth === 0 ){
  2172. var indent = this.selector.options.level1Indent + (this.level - 1) * this.selector.options.indent;
  2173. this.levelNode.setStyle("width", "" + indent + "px");
  2174. }else{
  2175. this.node.setStyle("clear","both");
  2176. }
  2177. this.iconNode = new Element("div", {
  2178. "styles": this.selector.css.selectorItemCategoryIconNode || this.selector.css.selectorItemIconNode
  2179. }).inject(this.node);
  2180. this._setIcon();
  2181. this.actionNode = new Element("div", {
  2182. "styles": (this.selector.options.expand) ? this.selector.css.selectorItemCategoryActionNode_expand : this.selector.css.selectorItemCategoryActionNode_collapse
  2183. }).inject(this.node);
  2184. if( this.selector.options.selectAllEnable && this.selector.options.count.toInt()!==1 ){
  2185. this.selectAllNode = new Element("div", {
  2186. "styles": this.selector.css.selectorItemCategoryActionNode_selectAll,
  2187. "title" : "全选下级"
  2188. }).inject(this.node);
  2189. this.selectAllNode.addEvent( "click", function(ev){
  2190. if( this.isSelectedAll ){
  2191. // this.unselectAll(ev);
  2192. this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
  2193. this.selector.fireEvent("unselectCatgory",[this]);
  2194. }else{
  2195. // this.selectAll(ev);
  2196. if( this.selector.options.selectAllRange === "all" ){
  2197. var node = new Element("div.categorySelectedNode").inject( this.selector.selectedNode );
  2198. this.selectAllNested(ev, true, node );
  2199. }else{
  2200. this.selectAll(ev, true)
  2201. }
  2202. this.selector.fireEvent("selectCatgory",[this]);
  2203. }
  2204. ev.stopPropagation();
  2205. }.bind(this));
  2206. if( this.selector.css.selectorItemCategoryActionNode_selectAll_over ){
  2207. this.selectAllNode.addEvents( {
  2208. "mouseover" : function(ev){
  2209. if( !this.isSelectedAll && !this.isSelectedSome )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_over );
  2210. //ev.stopPropagation();
  2211. }.bind(this),
  2212. "mouseout" : function(ev){
  2213. if( !this.isSelectedAll && !this.isSelectedSome )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2214. //ev.stopPropagation();
  2215. }.bind(this)
  2216. })
  2217. }
  2218. }
  2219. this.textNode = new Element("div", {
  2220. "styles": this.selector.css.selectorItemCategoryTextNode,
  2221. "text": this._getShowName()
  2222. }).inject(this.node);
  2223. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  2224. this.textNode.setStyle("margin-left", ""+m+"px");
  2225. if( this.selector.options.showSelectedCount && this.selector.selectType == "identity" ){
  2226. this.selectedCountNode = new Element("span").inject(this.textNode);
  2227. }
  2228. this.children = new Element("div.children", {
  2229. "styles": this.selector.css.selectorItemCategoryChildrenNode
  2230. }).inject(this.node, "after");
  2231. if (!this.selector.options.expand) this.children.setStyle("display", "none");
  2232. if( this.selector.options.expandEmptyCategory && !this._hasChildItem() ){ //点击允许展开空分类
  2233. this.children.hide();
  2234. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  2235. this.isExpand = false;
  2236. }else{
  2237. var subIdList = this.selector._getChildrenItemIds(this.data);
  2238. if (subIdList){
  2239. var count = subIdList.length;
  2240. this.childrenHeight = count*this.selector.options.itemHeight;
  2241. this.children.setStyle("height", ""+this.childrenHeight+"px");
  2242. }
  2243. if(this.selector.options.identityItemWidth && this.selector.selectType === "identity"){
  2244. var indent = this.level === 0 ? this.selector.options.level1Indent : this.selector.options.indent;
  2245. this.children.setStyles({
  2246. "padding-left": "" + indent + "px",
  2247. "overflow" : "hidden"
  2248. });
  2249. }
  2250. if ( !this._hasChild()){
  2251. if( this.selector.options.hiddenEmptyCategory ){
  2252. this.node.hide()
  2253. }else{
  2254. this.actionNode.setStyle("background", "transparent");
  2255. this.textNode.setStyle("color", "#777");
  2256. }
  2257. }
  2258. if( this.selectAllNode ){
  2259. if( this.selector.options.selectAllRange === "direct" && !this._hasChildItem() ){
  2260. this.selectAllNode.setStyle("display", "none");
  2261. }
  2262. }
  2263. }
  2264. this.setEvent();
  2265. this.check();
  2266. this.afterLoad();
  2267. this.selector.fireEvent("postLoadCategory",[this]);
  2268. },
  2269. createNode: function(){
  2270. this.node = new Element("div", {
  2271. "styles": this.selector.css.selectorItemCategory,
  2272. "title" : this._getTtiteText()
  2273. }).inject(this.container);
  2274. },
  2275. unselectAll : function(ev, exclude, checkValid ){
  2276. var fun = function(){
  2277. var excludeList = exclude || [];
  2278. if( exclude && typeOf(exclude) !== "array" )excludeList = [exclude];
  2279. ( this.subItems || [] ).each( function(item){
  2280. if(item.isSelected && !excludeList.contains(item) ){
  2281. item.unSelected( checkValid );
  2282. }
  2283. }.bind(this));
  2284. if( this.selectAllNode ){
  2285. if( this.selector.isFlatCategory ){
  2286. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  2287. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll){
  2288. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2289. }
  2290. }
  2291. this.isSelectedAll = false;
  2292. }.bind(this);
  2293. if( this.loaded ){
  2294. fun();
  2295. }else{
  2296. this.clickItem( function(){
  2297. fun();
  2298. }.bind(this))
  2299. }
  2300. },
  2301. unselectAllNested : function( ev, exclude, checkValid ){
  2302. this.unselectAll(ev, exclude, checkValid);
  2303. if( this.subCategorys && this.subCategorys.length ){
  2304. this.subCategorys.each( function( category ){
  2305. category.unselectAllNested( ev, exclude, checkValid )
  2306. })
  2307. }
  2308. },
  2309. selectAllNested : function( ev, checkValid, selectedNode ){
  2310. var node;
  2311. if(selectedNode)node = new Element("div.categorySelectedNode").inject( selectedNode );
  2312. this.selectAll(ev, checkValid, node, function () {
  2313. if( this.subCategorys && this.subCategorys.length ){
  2314. this.subCategorys.each( function( category ){
  2315. if(selectedNode)var node = new Element("div.categorySelectedNode").inject( selectedNode );
  2316. category.selectAllNested(ev, checkValid, node)
  2317. })
  2318. }
  2319. }.bind(this));
  2320. },
  2321. selectAll: function(ev, checkValid, selectedNode, callback){
  2322. if( this.loaded || this.selector.isFlatCategory ){
  2323. this._selectAll( ev, checkValid, selectedNode );
  2324. if(callback)callback();
  2325. }else{
  2326. this.clickItem( function(){
  2327. this._selectAll( ev, checkValid, selectedNode );
  2328. if(callback)callback();
  2329. //this.children.setStyles({
  2330. // "display": "none",
  2331. // "height": "0px"
  2332. //});
  2333. //this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  2334. }.bind(this));
  2335. }
  2336. },
  2337. _selectAll : function( ev, checkValid, selectedNode ){
  2338. if( this.selector.options.selectAllRange === "direct" && ( !this.subItems || !this.subItems.length ) )return;
  2339. var count = this.selector.options.maxCount || this.selector.options.count;
  2340. if (!count) count = 0;
  2341. var selectedSubItemCount = 0;
  2342. this.subItems.each( function(item){
  2343. if(item.isSelected)selectedSubItemCount++
  2344. }.bind(this));
  2345. if ((count.toInt()===0) || (this.selector.selectedItems.length+(this.subItems.length-selectedSubItemCount))<=count){
  2346. var checkedCount = 0;
  2347. var doSelectAll = function () {
  2348. this.subItems.each( function(item){
  2349. if(!item.isSelected && !item.disabled )item.selected( false, function () {
  2350. checkedCount++;
  2351. if( this.subItems.length === checkedCount ){
  2352. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  2353. }
  2354. }.bind(this), selectedNode);
  2355. }.bind(this));
  2356. if( this.selectAllNode ){
  2357. if( this.selector.isFlatCategory ){
  2358. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
  2359. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll_selected){
  2360. var styles = this.selector.css.selectorItemCategoryActionNode_selectAll_selected;
  2361. if( this.selector.options.isCheckStatus && this.selector.selectType === "identity" ){
  2362. if( this._getSelectedCount() < this._getTotalCount() ){
  2363. styles = this.selector.css.selectorItemCategoryActionNode_selectsome_selected;
  2364. }
  2365. }
  2366. this.selectAllNode.setStyles( styles );
  2367. }
  2368. }
  2369. this.isSelectedAll = true;
  2370. }.bind(this);
  2371. if( this._beforeSelectAll ){
  2372. this._beforeSelectAll( doSelectAll );
  2373. }else{
  2374. doSelectAll();
  2375. }
  2376. }else{
  2377. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
  2378. }
  2379. },
  2380. checkSelectAll : function(){
  2381. if( this.isSelectedAll )return;
  2382. if( !this.selectAllNode )return;
  2383. if( !this.subItems )return;
  2384. var isAllItemSelected = true;
  2385. for( var i=0; i< this.subItems.length; i++ ){
  2386. if( !this.subItems[i].isSelected ){
  2387. isAllItemSelected = false;
  2388. break;
  2389. }
  2390. }
  2391. if( isAllItemSelected ){
  2392. if( this.selector.isFlatCategory ){
  2393. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
  2394. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll_selected ){
  2395. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_selected );
  2396. }
  2397. this.isSelectedAll = true;
  2398. }
  2399. },
  2400. checkUnselectAll : function(){
  2401. if( !this.isSelectedAll )return;
  2402. if( !this.selectAllNode )return;
  2403. if( !this.subItems )return;
  2404. var hasSelectedItem = false;
  2405. for( var i=0; i< this.subItems.length; i++ ){
  2406. if( this.subItems[i].isSelected ){
  2407. hasSelectedItem = true;
  2408. break;
  2409. }
  2410. }
  2411. if( !hasSelectedItem ){
  2412. if( this.selector.isFlatCategory ){
  2413. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  2414. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll ){
  2415. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2416. }
  2417. this.isSelectedAll = false;
  2418. }
  2419. },
  2420. afterLoad: function(){
  2421. if (this.level===1) this.clickItem();
  2422. },
  2423. clickFlatCategoryItem : function( callback, hidden ){
  2424. if (this._hasChildItem()){
  2425. var display = this.children.getStyle("display");
  2426. if( hidden ){
  2427. this.children.setStyles({ "display": "none" });
  2428. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  2429. this.isExpand = false;
  2430. }else if (display === "none"){
  2431. this.children.setStyles({
  2432. "display": "block",
  2433. "height": "auto"
  2434. });
  2435. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  2436. this.isExpand = true;
  2437. }else{
  2438. this.children.setStyles({
  2439. "display": "none"
  2440. });
  2441. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  2442. this.isExpand = false;
  2443. }
  2444. if(callback)callback()
  2445. }
  2446. },
  2447. clickItem: function( callback ){
  2448. if (this._hasChild() || this.selector.options.expandEmptyCategory ){
  2449. if (!this.fx){
  2450. this.fx = new Fx.Tween(this.children, {
  2451. "duration": 200
  2452. // "transition": Fx.Transitions.Cubic.easeIn
  2453. });
  2454. }
  2455. if (!this.fx.isRunning()){
  2456. var display = this.children.getStyle("display");
  2457. if (display === "none"){
  2458. this.selector.fireEvent("expand", [this] );
  2459. this.children.setStyles({
  2460. "display": "block",
  2461. "height": "0px"
  2462. });
  2463. this.fx.start("height", "0px", ""+this.childrenHeight+"px");
  2464. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  2465. this.isExpand = true;
  2466. }else{
  2467. this.selector.fireEvent("collapse", [this] );
  2468. if (!this.childrenHeight) this.childrenHeight = this.children.getStyle("height").toFloat();
  2469. this.fx.start("height", ""+this.childrenHeight+"px", "0px").chain(function(){
  2470. this.children.setStyles({
  2471. "display": "none",
  2472. "height": "0px"
  2473. });
  2474. }.bind(this));
  2475. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  2476. this.isExpand = false;
  2477. }
  2478. }
  2479. if(callback)callback()
  2480. }
  2481. },
  2482. overItem: function(){
  2483. //if (!this.isSelected){
  2484. // this.node.setStyles(this.selector.css.selectorItem_over);
  2485. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  2486. //}
  2487. if( this.selector.css.selectorItemCategory_over ){
  2488. this.node.setStyles(this.selector.css.selectorItemCategory_over);
  2489. }
  2490. var display = this.children.getStyle("display");
  2491. if( display === "none" ){
  2492. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
  2493. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse_over )
  2494. }
  2495. }else{
  2496. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
  2497. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand_over )
  2498. }
  2499. }
  2500. },
  2501. outItem: function(){
  2502. //if (!this.isSelected){
  2503. // this.node.setStyles(this.selector.css.selectorItem);
  2504. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  2505. //}
  2506. if( this.selector.css.selectorItemCategory_over ){
  2507. this.node.setStyles(this.selector.css.selectorItemCategory);
  2508. }
  2509. var display = this.children.getStyle("display");
  2510. if( display === "none" ){
  2511. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
  2512. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse )
  2513. }
  2514. }else{
  2515. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
  2516. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand )
  2517. }
  2518. }
  2519. },
  2520. _hasChild: function(){
  2521. var subIdList = this.selector._getChildrenItemIds(this.data);
  2522. if (subIdList) if (subIdList.length) return true;
  2523. return false;
  2524. },
  2525. _hasChildCategory: function(){
  2526. return null;
  2527. },
  2528. _hasChildItem: function(){
  2529. return this._hasChild();
  2530. },
  2531. _getTtiteText: function(){
  2532. if( this.data.levelName ){
  2533. return this.data.name+"("+ this.data.levelName +")";
  2534. }else{
  2535. return this.data.name;
  2536. }
  2537. }
  2538. });
  2539. MWF.xApplication.Selector.Person.ItemGroupCategory = new Class({
  2540. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  2541. _getShowName: function(){
  2542. return this.data.name;
  2543. },
  2544. _setIcon: function(){
  2545. var style = this.selector.options.style;
  2546. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  2547. }
  2548. });
  2549. MWF.xApplication.Selector.Person.ItemRoleCategory = new Class({
  2550. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  2551. _getShowName: function(){
  2552. return this.data.name;
  2553. },
  2554. _setIcon: function(){
  2555. var style = this.selector.options.style;
  2556. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/roleicon.png)");
  2557. }
  2558. });
  2559. MWF.xApplication.Selector.Person.Filter = new Class({
  2560. Implements: [Options, Events],
  2561. options: {
  2562. "style": "default",
  2563. "groups": [],
  2564. "roles": []
  2565. },
  2566. initialize: function(value, options){
  2567. this.setOptions(options);
  2568. this.value = value;
  2569. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  2570. },
  2571. filter: function(value, callback){
  2572. this.value = value;
  2573. var key = this.value;
  2574. if (this.options.groups.length || this.options.roles.length) key = {"key": key, "groupList": this.options.groupList, "roleList": this.options.roleList};
  2575. this.orgAction.listPersonByKey(function(json){
  2576. data = json.data;
  2577. if (callback) callback(data)
  2578. }.bind(this), null, key);
  2579. }
  2580. });