Person.js 114 KB

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