Person.js 114 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711
  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. if(this.shuttleNode)return;
  567. this.shuttleNode = new Element("div.shuttleNode", {
  568. "styles": this.css.shuttleNode
  569. }).inject(this.contentNode);
  570. this.shuttleInnerNode = new Element("div.shuttleInnerNode", {
  571. "styles": this.css.shuttleInnerNode
  572. }).inject(this.shuttleNode);
  573. this.goRightNode = new Element("div.goRightNode", {
  574. "styles": this.css.goRightNode
  575. }).inject(this.shuttleInnerNode);
  576. this.goLeftNode = new Element("div.goLeftNode", {
  577. "styles": this.css.goLeftNode
  578. }).inject(this.shuttleInnerNode);
  579. },
  580. loadSelectNode: function(){
  581. this.selectNode = new Element("div.selectNode", {
  582. "styles": this.css.selectNode //(this.options.count.toInt()===1) ? this.css.selectNodeSingle : this.css.selectNode
  583. }).inject(this.contentNode);
  584. if( this.options.hasTop ){ //if( this.options.embedded && this.options.count.toInt()!==1 ){
  585. this.selectTopNode = new Element("div.selectTopNode",{
  586. "styles" : this.css.selectTopNode
  587. }).inject( this.selectNode );
  588. this.selectTopTextNode = new Element("div",{
  589. "text" : MWF.SelectorLP.waitingSelect,
  590. "styles" : this.css.selectTopTextNode
  591. }).inject( this.selectTopNode );
  592. }
  593. if( this.options.searchbarInTopNode ){
  594. this.searchInputDiv = new Element("div", {
  595. "styles": this.css.searchInputDiv
  596. }).inject( this.selectTopNode || this.selectNode);
  597. }else{
  598. this.searchInputDiv = new Element("div.searchInputDiv", {
  599. "styles": this.css.searchInputDiv
  600. }).inject( this.selectNode);
  601. }
  602. this.searchInput = new Element("input", {
  603. "styles": this.css.searchInput, //(this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
  604. "placeholder" : MWF.SelectorLP.searchDescription,
  605. "type": "text"
  606. }).inject(this.searchInputDiv);
  607. this.initSearchInput();
  608. if( this.options.hasLetter ){
  609. this.letterAreaNode = new Element("div", {
  610. "styles": this.css.letterAreaNode
  611. }).inject(this.selectNode);
  612. this.loadLetters();
  613. }
  614. this.itemAreaScrollNode = new Element("div", {
  615. "styles": this.css.itemAreaScrollNode
  616. }).inject(this.selectNode);
  617. this.itemAreaNode = new Element("div", {
  618. "styles": this.css.itemAreaNode
  619. }).inject(this.itemAreaScrollNode);
  620. this.itemSearchAreaNode = new Element("div", {
  621. "styles": this.css.itemAreaNode
  622. }).inject(this.itemAreaScrollNode);
  623. this.itemSearchAreaNode.setStyle("display", "none");
  624. this.loadSelectNodeScroll();
  625. this.initLoadSelectItems();
  626. this.checkLoadSelectItems();
  627. },
  628. loadSelectNodeScroll: function(){
  629. var overflowY = this.itemAreaScrollNode.getStyle("overflow-y");
  630. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") )return;
  631. MWF.require("MWF.widget.ScrollBar", function(){
  632. var _self = this;
  633. new MWF.widget.ScrollBar(this.itemAreaScrollNode, {
  634. "style":"xApp_Organization_Explorer",
  635. "where": "before",
  636. "distance": 30,
  637. "friction": 4,
  638. "axis": {"x": false, "y": true},
  639. "onScroll": function(y){
  640. _self._scrollEvent(y);
  641. }
  642. });
  643. }.bind(this));
  644. },
  645. initSearchInput: function(){
  646. this.searchInput.addEvents({
  647. "keydown": function(e){
  648. var iTimerID = this.searchInput.retrieve("searchTimer", null);
  649. if (iTimerID){
  650. window.clearTimeout(iTimerID);
  651. this.searchInput.eliminate("searchTimer");
  652. }
  653. iTimerID = window.setTimeout(function(){
  654. this.search();
  655. }.bind(this), 800);
  656. this.searchInput.store("searchTimer", iTimerID);
  657. }.bind(this),
  658. "change": function(e){
  659. var key = this.searchInput.get("value");
  660. if (!key) this.initSearchArea(false);
  661. }.bind(this),
  662. "blur": function(){
  663. var key = this.searchInput.get("value");
  664. if (!key) this.initSearchArea(false);
  665. }.bind(this)
  666. });
  667. },
  668. initSearchArea: function(flag){
  669. this.searchItems = [];
  670. if (flag){
  671. this.itemSearchAreaNode.empty();
  672. this.itemAreaNode.setStyle("display", "none");
  673. if( this.itemSearchAreaNode.getParent() !== this.itemAreaScrollNode ){
  674. this.itemAreaScrollNode.setStyle("display", "none");
  675. }
  676. if(this.flatCategoryScrollNode){
  677. this.flatCategoryScrollNode.setStyle("display", "none");
  678. }
  679. if( this.itemSearchAreaScrollNode )this.itemSearchAreaScrollNode.setStyle("display", "block");
  680. this.itemSearchAreaNode.setStyle("display", "block");
  681. }else{
  682. this.itemAreaScrollNode.setStyle("display", "block");
  683. this.itemAreaNode.setStyle("display", "block");
  684. if(this.flatCategoryScrollNode && this.flatSubCategoryNodeList && this.flatSubCategoryNodeList.length > 1 ){
  685. this.flatCategoryScrollNode.setStyle("display", "block");
  686. }
  687. if( this.itemSearchAreaScrollNode )this.itemSearchAreaScrollNode.setStyle("display", "none");
  688. this.itemSearchAreaNode.setStyle("display", "none");
  689. }
  690. },
  691. search: function(){
  692. if (!this.options.groups.length && !this.options.roles.length && !this.options.forceSearchInItem ){
  693. var key = this.searchInput.get("value");
  694. if (key){
  695. this._listItemByKey(function(json){
  696. this.initSearchArea(true);
  697. json.data.each(function(data){
  698. if( !this.isExcluded( data ) ) {
  699. var itemSearch = this._newItemSearch(data, this, this.itemSearchAreaNode);
  700. this.searchItems.push( itemSearch );
  701. }
  702. //this._newItem(data, this, this.itemSearchAreaNode);
  703. }.bind(this));
  704. }.bind(this), null, key);
  705. }else{
  706. this.initSearchArea(false);
  707. }
  708. }else{
  709. var key = this.searchInput.get("value");
  710. if (key){
  711. this.initSearchArea(true);
  712. this.searchInItems(key);
  713. }else{
  714. this.initSearchArea(false);
  715. }
  716. }
  717. },
  718. searchInItems: function(key){
  719. var createdId = [];
  720. this.createItemsSearchData(function(){
  721. var word = key.toLowerCase();
  722. this.itemsSearchData.each(function(obj){
  723. var text = obj.text+"#"+obj.pinyin+"#"+obj.firstPY;
  724. var id = obj.data.distinguishedName || obj.data.id || obj.data.name || obj.data.text;
  725. if (text.indexOf(word)!==-1){
  726. if (createdId.indexOf( id )===-1){
  727. this._newItem(obj.data, this, this.itemSearchAreaNode);
  728. createdId.push( id );
  729. }
  730. }
  731. }.bind(this));
  732. //delete createdId;
  733. }.bind(this));
  734. return createdId;
  735. },
  736. createItemsSearchData: function(callback){
  737. if (!this.itemsSearchData){
  738. this.itemsSearchData = [];
  739. MWF.require("MWF.widget.PinYin", function(){
  740. var initIds = [];
  741. this.items.each(function(item){
  742. var id = item.data.distinguishedName || item.data.id || item.data.name || item.data.text;
  743. if (initIds.indexOf( id )==-1){
  744. var text = item._getShowName().toLowerCase();
  745. var pinyin = text.toPY().toLowerCase();
  746. var firstPY = text.toPYFirst().toLowerCase();
  747. this.itemsSearchData.push({
  748. "text": text,
  749. "pinyin": pinyin,
  750. "firstPY": firstPY,
  751. "data": item.data
  752. });
  753. initIds.push( id );
  754. }
  755. }.bind(this));
  756. delete initIds;
  757. if (callback) callback();
  758. }.bind(this));
  759. }else{
  760. if (callback) callback();
  761. }
  762. },
  763. initSelectedSearchInput: function(){
  764. this.selectedSearchInput.addEvents({
  765. "keydown": function(e){
  766. var iTimerID = this.selectedSearchInput.retrieve("searchTimer", null);
  767. if (iTimerID){
  768. window.clearTimeout(iTimerID);
  769. this.selectedSearchInput.eliminate("searchTimer");
  770. }
  771. iTimerID = window.setTimeout(function(){
  772. this.selectedSearch();
  773. }.bind(this), 800);
  774. this.selectedSearchInput.store("searchTimer", iTimerID);
  775. }.bind(this),
  776. "change": function(e){
  777. var key = this.selectedSearchInput.get("value");
  778. if (!key) this.selectedSearch();
  779. }.bind(this),
  780. "blur": function(){
  781. var key = this.selectedSearchInput.get("value");
  782. if (!key) this.selectedSearch();
  783. }.bind(this)
  784. });
  785. },
  786. selectedSearch: function(){
  787. var key = this.selectedSearchInput.get("value");
  788. if (key){
  789. this.selectedSearchInItems(key);
  790. }else{
  791. this.showAllSelectedItem()
  792. }
  793. },
  794. selectedSearchInItems: function(key){
  795. var word = key.toLowerCase();
  796. MWF.require("MWF.widget.PinYin", function() {
  797. this.selectedItems.each(function (item) {
  798. if (!item.searchedText) {
  799. var text = item._getShowName().toLowerCase();
  800. var pinyin = text.toPY().toLowerCase();
  801. var firstPY = text.toPYFirst().toLowerCase();
  802. item.searchedText = text + "#" + pinyin + "#" + firstPY
  803. }
  804. if (item.searchedText.indexOf(word) !== -1) {
  805. item.node.show()
  806. } else {
  807. item.node.hide()
  808. }
  809. }.bind(this));
  810. }.bind(this), null, false);
  811. },
  812. showAllSelectedItem: function(){
  813. this.selectedItems.each(function(item){
  814. item.node.show()
  815. })
  816. },
  817. loadSelectedNode: function( callback ){
  818. if( this.selectedContainerNode )return;
  819. this.selectedContainerNode = new Element("div", {
  820. "styles": this.css.selectedContainerNode
  821. }).inject(this.contentNode);
  822. if( this.options.noSelectedContainer ){
  823. this.selectedContainerNode.hide();
  824. }
  825. //if( this.options.embedded && this.options.count.toInt()!==1 ){
  826. if( this.options.hasTop ){
  827. this.selectedTopNode = new Element("div",{
  828. "styles" : this.css.selectedTopNode
  829. }).inject( this.selectedContainerNode );
  830. this.selectedTopTextNode = new Element("div",{
  831. "text" : MWF.SelectorLP.selected,
  832. "styles" : this.css.selectedTopTextNode
  833. }).inject( this.selectedTopNode );
  834. this.emptySelectedNode = new Element("div",{
  835. "text" : MWF.SelectorLP.empty,
  836. "styles" : this.css.selectedTopActionNode,
  837. "events" : {
  838. "click" : function(){
  839. this.emptySelectedItems()
  840. }.bind(this)
  841. }
  842. }).inject( this.selectedTopNode );
  843. }
  844. if( this.options.hasSelectedSearchbar ){
  845. if( this.options.searchbarInTopNode ){
  846. this.selectedSearchInputDiv = new Element("div", {
  847. "styles": this.css.searchInputDiv
  848. }).inject( this.selectedTopNode || this.selectedContainerNode);
  849. }else{
  850. this.selectedSearchInputDiv = new Element("div.selectedSearchInputDiv", {
  851. "styles": this.css.searchInputDiv
  852. }).inject( this.selectedContainerNode);
  853. }
  854. this.selectedSearchInput = new Element("input", {
  855. "styles": this.css.searchInput, //(this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
  856. "placeholder" : MWF.SelectorLP.searchDescription,
  857. "type": "text"
  858. }).inject(this.selectedSearchInputDiv);
  859. this.initSelectedSearchInput();
  860. }
  861. this.selectedScrollNode = new Element("div.selectedScrollNode", {
  862. "styles": this.css.selectedScrollNode
  863. }).inject(this.selectedContainerNode);
  864. this.selectedNode = new Element("div.selectedNode", {
  865. "styles": this.css.selectedNode
  866. }).inject(this.selectedScrollNode);
  867. if( this.options.hasSelectedSearchbar ){
  868. this.selectedItemSearchAreaNode = new Element("div.selectedItemSearchAreaNode", {
  869. "styles": this.css.itemAreaNode
  870. }).inject(this.selectedScrollNode);
  871. this.selectedItemSearchAreaNode.setStyle("display", "none");
  872. }
  873. this.setSelectedItem();
  874. this.loadSelectedNodeScroll();
  875. if(callback)callback();
  876. },
  877. emptySelectedItems : function(){
  878. while (this.selectedItems.length){
  879. this.selectedItems[0].clickItem();
  880. }
  881. },
  882. loadSelectedNodeScroll: function(){
  883. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  884. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") )return;
  885. MWF.require("MWF.widget.ScrollBar", function(){
  886. var _self = this;
  887. new MWF.widget.ScrollBar(this.selectedScrollNode, {
  888. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  889. });
  890. }.bind(this));
  891. },
  892. loadSelectedNodeMobile: function(){
  893. this.selectedScrollNode = new Element("div.selectedScrollNode", {
  894. "styles": this.css.selectedScrollNode
  895. }).inject(this.contentNode);
  896. this.selectedNode = new Element("div.selectedNode", {
  897. "styles": this.css.selectedNode
  898. }).inject(this.selectedScrollNode);
  899. this.setSelectedItem();
  900. MWF.require("MWF.widget.ScrollBar", function(){
  901. var _self = this;
  902. new MWF.widget.ScrollBar(this.selectedScrollNode, {
  903. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  904. });
  905. }.bind(this));
  906. this.selectedScrollNode.setStyle("display", "none");
  907. },
  908. setSelectedItem: function(){
  909. if (this.options.values.length){
  910. this.options.values.each(function(v, i){
  911. if (typeOf(v)==="object"){
  912. this.selectedItems.push(this._newItemSelected(v, this, null));
  913. }else{
  914. this._getItem(function(json){
  915. this.options.values[i] = json.data;
  916. this.selectedItems.push(this._newItemSelected(json.data, this, null));
  917. }.bind(this), null, v, false);
  918. }
  919. // this._getItem(function(json){
  920. // this.selectedItems.push(this._newItemSelected(json.data, this, null));
  921. // }.bind(this), null, v, false);
  922. }.bind(this));
  923. }
  924. },
  925. loadLetters: function(){
  926. var _self = this;
  927. 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"];
  928. var letterNodeCss = this.css.letterNode;
  929. var letterNodeCss_over = this.css.letterNode_over;
  930. if (layout.mobile){
  931. letterNodeCss = this.css.letterNode_mobile || letterNodeCss;
  932. letterNodeCss_over = this.css.letterNode_mobile_over || letterNodeCss_over;
  933. var size = this.container.getSize();
  934. var w = (layout.mobile) ? (size.x-18)/13 : (size.x-20-4-18)/13;
  935. //letterNode.setStyle("width", ""+w+"px");
  936. letterNodeCss.width = ""+w+"px";
  937. letterNodeCss_over.width = ""+w+"px";
  938. }
  939. letters.each(function(l){
  940. var letterNode = new Element("div", {
  941. "styles": letterNodeCss,
  942. "text": l
  943. }).inject(this.letterAreaNode);
  944. if (layout.mobile){
  945. letterNode.addEvents({
  946. "click": function(){
  947. _self.listPersonByPinyin(this);
  948. }
  949. });
  950. }else{
  951. letterNode.addEvents({
  952. "mouseover": function(e){
  953. e.target.setStyles(letterNodeCss_over);
  954. var showNode = new Element("div", {
  955. "styles": this.css.letterShowNode,
  956. "text": e.target.get("text")
  957. }).inject(this.selectNode);
  958. showNode.position({
  959. relativeTo: this.itemAreaScrollNode,
  960. position: "center",
  961. edge: "center"
  962. });
  963. e.target.store("showNode", showNode);
  964. }.bind(this),
  965. "mouseout": function(e){
  966. var showNode = e.target.retrieve("showNode");
  967. showNode.destroy();
  968. e.target.setStyles(letterNodeCss);
  969. }.bind(this),
  970. "click": function(){
  971. _self.listPersonByPinyin(this);
  972. }
  973. });
  974. }
  975. }.bind(this));
  976. },
  977. listPersonByPinyin: function(node){
  978. this.searchInput.focus();
  979. var pinyin = this.searchInput.get("value");
  980. pinyin = pinyin+node.get("text");
  981. this.searchInput.set("value", pinyin);
  982. if (!this.options.groups.length && !this.options.roles.length){
  983. if (pinyin){
  984. this._listItemByPinyin(function(json){
  985. this.initSearchArea(true);
  986. json.data.each(function(data){
  987. // var flag = true;
  988. // if (this.options.departments){
  989. // if (this.options.departments.length){
  990. // if (this.options.departments.indexOf(data.departmentName)==-1) flag = false;
  991. // }
  992. // }
  993. // if (this.options.companys){
  994. // if (this.options.companys.length){
  995. // if (this.options.companys.indexOf(data.company)==-1) flag = false;
  996. // }
  997. // }
  998. if( !this.isExcluded( data ) ) {
  999. this._newItemSearch(data, this, this.itemSearchAreaNode);
  1000. }
  1001. //this._newItem(data, this, this.itemSearchAreaNode);
  1002. //this._newItem(data, this, this.itemSearchAreaNode);
  1003. }.bind(this));
  1004. }.bind(this), null, pinyin.toLowerCase());
  1005. }
  1006. }else{
  1007. if (pinyin){
  1008. this.initSearchArea(true);
  1009. this.searchInItems(pinyin);
  1010. }else{
  1011. this.initSearchArea(false);
  1012. }
  1013. }
  1014. },
  1015. initLoadSelectItems: function(){
  1016. this.loaddingItems = false;
  1017. this.isItemLoaded = false;
  1018. this.loadItemsQueue = 0;
  1019. this.initSearchArea(false);
  1020. },
  1021. //loadSelectItems: function(addToNext){
  1022. // if (!this.isItemLoaded){
  1023. // if (!this.loaddingItems){
  1024. // this.loaddingItems = true;
  1025. // var count = 20;
  1026. // this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  1027. // if (json.data.length){
  1028. // json.data.each(function(data){
  1029. // var item = this._newItem(data, this, this.itemAreaNode);
  1030. // this.items.push(item);
  1031. // }.bind(this));
  1032. // this.loaddingItems = false;
  1033. //
  1034. // if (json.data.length<count){
  1035. // this.isItemLoaded = true;
  1036. // }else{
  1037. // if (this.loadItemsQueue>0){
  1038. // this.loadItemsQueue--;
  1039. // this.loadSelectItems();
  1040. // }
  1041. // }
  1042. // }else{
  1043. // this.isItemLoaded = true;
  1044. // this.loaddingItems = false;
  1045. // }
  1046. // }.bind(this));
  1047. // }else{
  1048. // if (addToNext) this.loadItemsQueue++;
  1049. // }
  1050. // }
  1051. //},
  1052. loadSelectItems: function(addToNext, lastExcludeCount ){
  1053. //lastExcludeCount 参数:表示本次加载是为了补足上次load的时候被排除的数量
  1054. if (!this.isItemLoaded){
  1055. if (!this.loaddingItems){
  1056. this.loaddingItems = true;
  1057. var count = 20;
  1058. this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  1059. if (json.data.length){
  1060. var excludedCount = 0;
  1061. json.data.each(function(data, i){
  1062. if( this.isExcluded( data ) ){
  1063. excludedCount++;
  1064. if( i+1 === count )this.tailExcludeItemId = data.distinguishedName
  1065. }else{
  1066. var item = this._newItem(data, this, this.itemAreaNode);
  1067. this.items.push(item);
  1068. if( i+1 === count )this.tailExcludeItemId = null;
  1069. }
  1070. }.bind(this));
  1071. this.loaddingItems = false;
  1072. if( lastExcludeCount ){ //如果是因为上次load的时候被排除而加载的
  1073. if( count - lastExcludeCount - excludedCount < 0 ){ //如果本次load的数量还不够补足排除的数量,需要再次load
  1074. excludedCount = lastExcludeCount + excludedCount - count; //把不足的数量作为再次load的参数
  1075. this.loadItemsQueue++
  1076. }
  1077. }else if( excludedCount > 0 ){ //把排除的数量作为再次load的参数
  1078. this.loadItemsQueue++
  1079. }
  1080. if (json.data.length<count){
  1081. this.isItemLoaded = true;
  1082. }else{
  1083. if (this.loadItemsQueue>0){
  1084. this.loadItemsQueue--;
  1085. this.loadSelectItems( addToNext, excludedCount );
  1086. }
  1087. }
  1088. }else{
  1089. this.isItemLoaded = true;
  1090. this.loaddingItems = false;
  1091. }
  1092. if( this.afterLoadSelectItem )this.afterLoadSelectItem();
  1093. }.bind(this));
  1094. }else{
  1095. if (addToNext) this.loadItemsQueue++;
  1096. }
  1097. }
  1098. },
  1099. getLastLoadedItemId: function(){
  1100. if( this.tailExcludeItemId )return this.tailExcludeItemId;
  1101. return (this.items.length) ? this.items[this.items.length-1].data.distinguishedName : "(0)";
  1102. },
  1103. //loadSelectItemsByCondition: function(){
  1104. // this.options.groups.each(function(group){
  1105. //
  1106. // this.orgAction.listGroupByKey(function(json){
  1107. // if (json.data.length){
  1108. // var groupData = json.data[0];
  1109. // var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  1110. // this._getChildrenItemIds(groupData).each(function(id){
  1111. // this._getItem(function(json){
  1112. // var item = this._newItem(json.data, this, category.children);
  1113. // this.items.push(item);
  1114. // }.bind(this), null, id);
  1115. // }.bind(this));
  1116. // }
  1117. // }.bind(this), null, group);
  1118. // }.bind(this));
  1119. //
  1120. // this.options.roles.each(function(role){
  1121. // this.orgAction.listRoleByKey(function(json){
  1122. // if (json.data.length){
  1123. // var roleData = json.data[0];
  1124. // var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  1125. // this._getChildrenItemIds(roleData).each(function(id){
  1126. // this._getItem(function(json){
  1127. // var item = this._newItem(json.data, this, category.children);
  1128. // this.items.push(item);
  1129. // }.bind(this), null, id)
  1130. // }.bind(this));
  1131. // }
  1132. // }.bind(this), null, role);
  1133. // }.bind(this));
  1134. //},
  1135. loadSelectItemsByCondition: function(){
  1136. this.options.groups.each(function(group){
  1137. this.orgAction.listGroupByKey(function(json){
  1138. if (json.data.length){
  1139. var groupData = json.data[0];
  1140. var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  1141. this.subCategorys.push(category);
  1142. this._getChildrenItemIds(groupData).each(function(id){
  1143. this._getItem(function(json){
  1144. if( !this.isExcluded( json.data ) ) {
  1145. var item = this._newItem(json.data, this, category.children);
  1146. this.items.push(item);
  1147. }
  1148. }.bind(this), null, id);
  1149. }.bind(this));
  1150. }
  1151. }.bind(this), null, group);
  1152. }.bind(this));
  1153. this.options.roles.each(function(role){
  1154. this.orgAction.listRoleByKey(function(json){
  1155. if (json.data.length){
  1156. var roleData = json.data[0];
  1157. var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  1158. this.subCategorys.push(category);
  1159. this._getChildrenItemIds(roleData).each(function(id){
  1160. this._getItem(function(json){
  1161. if( !this.isExcluded( json.data ) ) {
  1162. var item = this._newItem(json.data, this, category.children);
  1163. this.items.push(item);
  1164. }
  1165. }.bind(this), null, id)
  1166. }.bind(this));
  1167. }
  1168. }.bind(this), null, role);
  1169. }.bind(this));
  1170. },
  1171. isExcluded : function( d ){
  1172. if( this.options.exclude.length === 0 )return false;
  1173. if( !this.excludeFlagMap ){
  1174. this.excludeFlagMap = {};
  1175. this.options.exclude.each( function( e ){
  1176. if( !e )return;
  1177. this.excludeFlagMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.id || e.unique || e.employee || e.levelName) ] = true;
  1178. }.bind(this));
  1179. }
  1180. var map = this.excludeFlagMap;
  1181. return ( d.distinguishedName && map[ d.distinguishedName ] ) ||
  1182. ( d.id && map[ d.id ] ) ||
  1183. ( d.unique && map[ d.unique ] ) ||
  1184. ( d.employee && map[ d.employee ] ) ||
  1185. ( d.levelName && map[ d.levelName ] );
  1186. },
  1187. _getChildrenItemIds: function(data){
  1188. return data.personList;
  1189. },
  1190. _newItemCategory: function(type, data, selector, item){
  1191. return new MWF.xApplication.Selector.Person[type](data, selector, item)
  1192. },
  1193. _listItemByKey: function(callback, failure, key){
  1194. this.orgAction.listPersonByKey(function(json){
  1195. if (callback) callback.apply(this, [json]);
  1196. }.bind(this), failure, key);
  1197. },
  1198. _getItem: function(callback, failure, id, async){
  1199. this.orgAction.getPerson(function(json){
  1200. if (callback) callback.apply(this, [json]);
  1201. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  1202. },
  1203. _newItemSelected: function(data, selector, item, selectedNode){
  1204. return new MWF.xApplication.Selector.Person.ItemSelected(data, selector, item, selectedNode)
  1205. },
  1206. _listItemByPinyin: function(callback, failure, key){
  1207. this.orgAction.listPersonByPinyin(function(json){
  1208. if (callback) callback.apply(this, [json]);
  1209. }.bind(this), failure, key);
  1210. },
  1211. _newItem: function(data, selector, container){
  1212. return new MWF.xApplication.Selector.Person.Item(data, selector, container);
  1213. },
  1214. _newItemSearch: function(data, selector, container){
  1215. return this._newItem(data, selector, container);
  1216. },
  1217. _listItemNext: function(last, count, callback){
  1218. this.orgAction.listPersonNext(last, count, function(json){
  1219. if (callback) callback.apply(this, [json]);
  1220. }.bind(this));
  1221. },
  1222. _scrollEvent: function(y){
  1223. if (!this.options.groups.length && !this.options.roles.length){
  1224. var scrollSize = this.itemAreaScrollNode.getScrollSize();
  1225. var clientSize = this.itemAreaScrollNode.getSize();
  1226. var scrollHeight = scrollSize.y-clientSize.y;
  1227. if (y+30>scrollHeight) {
  1228. if (!this.isItemLoaded) this.loadSelectItems();
  1229. }
  1230. }
  1231. },
  1232. afterLoadSelectItem : function(){
  1233. if( this.items.length === 0 && this.subItems.length === 0 && this.subCategorys.length === 0 ){
  1234. this.noSelectableItemTextDiv = new Element("div", {
  1235. text : MWF.SelectorLP.noSelectableItemText,
  1236. styles : this.css.noSelectableItemText
  1237. }).inject( this.itemAreaNode );
  1238. }
  1239. if( this.options.selectSingleItem ){
  1240. this.selectSingleItem()
  1241. }
  1242. this.fireEvent("afterLoadSelectItem", [this]);
  1243. },
  1244. selectSingleItem: function(){
  1245. if( !this.options.contentUrl && !layout.mobile){
  1246. if( this.options.hasShuttle && !this.shuttleNode ){
  1247. this.loadShuttleNode();
  1248. }
  1249. if( !this.selectedContainerNode ) {
  1250. this.loadSelectedNode(function () {
  1251. this._selectSingleItem();
  1252. }.bind(this));
  1253. }else{
  1254. this._selectSingleItem();
  1255. }
  1256. }
  1257. },
  1258. _selectSingleItem : function(){
  1259. var checkItem = function () {
  1260. if(this.items.length === 1 || this.subItems.length === 1 ){
  1261. if( this.items.length === 1 && this.subItems.length === 0 ){
  1262. if( !this.items[0].isSelected )this.items[0].clickItem();
  1263. }else if( this.items.length === 0 && this.subItems.length === 1 ){
  1264. if( !this.items[0].isSelected )this.subItems[0].clickItem();
  1265. }else if( this.items.length === 1 && this.subItems.length === 1 ){
  1266. if( this.items[0] === this.subItems[0] ){
  1267. if( !this.items[0].isSelected )this.items[0].clickItem();
  1268. }
  1269. }
  1270. }
  1271. }.bind(this);
  1272. var checkCategoryItem = function (category) {
  1273. if( !category.subCategorys || category.subCategorys.length === 0 ){
  1274. if( category.subItems && category.subItems.length === 1 ){
  1275. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1276. }
  1277. }else if(category.subCategorys.length === 1){
  1278. if( !category.subCategorys[0]._hasChild || !category.subCategorys[0]._hasChild() ){ //category.subCategorys[0].isItem &&
  1279. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1280. }else{
  1281. checkCategory( category.subCategorys[0] )
  1282. }
  1283. }else{
  1284. var list = [];
  1285. for( var i=0; i<category.subCategorys.length; i++ ){
  1286. if( category.subCategorys[i]._hasChild && category.subCategorys[i]._hasChild() ){
  1287. list.push( category.subCategorys[i] );
  1288. }
  1289. }
  1290. if( list.length === 1 ){
  1291. if( !category.subItems || category.subItems.length === 0 ){
  1292. checkCategory( list[0] );
  1293. }
  1294. }
  1295. if( list.length === 0 ){
  1296. if( category.subItems && category.subItems.length === 1 ){
  1297. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1298. }
  1299. }
  1300. }
  1301. };
  1302. var checkCategory = function ( category ) {
  1303. if( category.loaded ){
  1304. checkCategoryItem( category )
  1305. }else if( category.loading ){
  1306. window.setTimeout( function () {
  1307. checkCategory( category )
  1308. }, 100 )
  1309. }
  1310. };
  1311. if( this.subCategorys.length === 1 ) {
  1312. checkCategory( this.subCategorys[0] );
  1313. }else if( this.subCategorys.length === 0 ){
  1314. checkItem();
  1315. }
  1316. },
  1317. setSize : function(){
  1318. if( !this.options.width && !this.options.height )return;
  1319. var getOffsetX = function(node){
  1320. return (node.getStyle("margin-left").toInt() || 0 )+
  1321. (node.getStyle("margin-right").toInt() || 0 ) +
  1322. (node.getStyle("padding-left").toInt() || 0 ) +
  1323. (node.getStyle("padding-right").toInt() || 0 ) +
  1324. (node.getStyle("border-left-width").toInt() || 0 ) +
  1325. (node.getStyle("border-right-width").toInt() || 0 );
  1326. };
  1327. var getOffsetY = function(node){
  1328. return (node.getStyle("margin-top").toInt() || 0 ) +
  1329. (node.getStyle("margin-bottom").toInt() || 0 ) +
  1330. (node.getStyle("padding-top").toInt() || 0 ) +
  1331. (node.getStyle("padding-bottom").toInt() || 0 )+
  1332. (node.getStyle("border-top-width").toInt() || 0 ) +
  1333. (node.getStyle("border-bottom-width").toInt() || 0 );
  1334. };
  1335. if( this.options.width && this.options.width === "auto" ){
  1336. //if (this.options.count.toInt() !== 1){
  1337. if( this.node )this.node.setStyle("width", "auto");
  1338. this.selectNode.setStyles({
  1339. "width": "50%",
  1340. "float" : "left"
  1341. });
  1342. //this.searchInput.setStyle("width", "99%");
  1343. if(this.letterAreaNode ){
  1344. this.letterAreaNode.setStyle("width", "auto");
  1345. }
  1346. this.selectedContainerNode.setStyle("width", "auto");
  1347. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  1348. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
  1349. this.selectedScrollNode.setStyle("width", "auto");
  1350. }else{
  1351. this.selectedScrollNode.setStyle("margin-right", "8px");
  1352. }
  1353. //}else{
  1354. // this.node.setStyle("width", "auto");
  1355. // this.selectNode.setStyle("width", "auto");
  1356. //}
  1357. }else if( this.options.width && typeOf( this.options.width.toInt() ) === "number" ){
  1358. var nodeWidth;
  1359. if( this.node ){
  1360. nodeWidth = this.options.width.toInt() - getOffsetX(this.node);
  1361. this.node.setStyle("width", nodeWidth);
  1362. }else{
  1363. nodeWidth = this.options.width.toInt();
  1364. }
  1365. nodeWidth = nodeWidth - getOffsetX( this.contentNode );
  1366. if( this.shuttleNode ){
  1367. nodeWidth = nodeWidth - getOffsetX(this.shuttleNode) - this.shuttleNode.getStyle("width").toInt();
  1368. }
  1369. //if (this.options.count.toInt() !== 1){
  1370. var width = nodeWidth - getOffsetX(this.selectNode) - getOffsetX(this.selectedContainerNode);
  1371. var halfWidth = this.options.noSelectedContainer ? width : Math.floor(width / 2);
  1372. this.selectNode.setStyle("width", halfWidth);
  1373. //this.searchInput.setStyle("width", halfWidth - 6);
  1374. if(this.letterAreaNode ){
  1375. this.letterAreaNode.setStyle("width", halfWidth - 19);
  1376. }
  1377. this.selectedContainerNode.setStyle("width", halfWidth);
  1378. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  1379. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
  1380. this.selectedScrollNode.setStyle("width", halfWidth);
  1381. }else{
  1382. this.selectedScrollNode.setStyle("width", halfWidth - 8);
  1383. }
  1384. //}else{
  1385. // var width = nodeWidth - getOffsetX(this.selectNode);
  1386. // this.selectNode.setStyle("width", width);
  1387. //}
  1388. }
  1389. if( this.options.height && typeOf( this.options.height.toInt() ) === "number" ){
  1390. var nodeHeight;
  1391. if( this.node ){
  1392. nodeHeight = this.options.height.toInt() - getOffsetY(this.node);
  1393. this.node.setStyle("height", nodeHeight);
  1394. }else{
  1395. nodeHeight = this.options.height.toInt();
  1396. }
  1397. nodeHeight = nodeHeight - getOffsetY( this.contentNode );
  1398. if( this.titleNode ){
  1399. nodeHeight = nodeHeight - getOffsetY( this.titleNode ) - this.titleNode.getStyle("height").toInt();
  1400. }
  1401. if( this.actionNode ){
  1402. nodeHeight = nodeHeight - getOffsetY( this.actionNode ) - this.actionNode.getStyle("height").toInt();
  1403. }
  1404. var selectNodeHeight = nodeHeight - getOffsetY(this.selectNode);
  1405. this.selectNode.setStyle("height", selectNodeHeight);
  1406. if( this.shuttleNode ){
  1407. this.shuttleNode.setStyle("height", selectNodeHeight);
  1408. var shuttleInnerHieght = getOffsetY( this.shuttleInnerNode ) + this.shuttleInnerNode.getStyle("height").toInt();
  1409. this.shuttleInnerNode.setStyle("margin-top", (selectNodeHeight-shuttleInnerHieght)/2 +"px" )
  1410. }
  1411. var itemAreaScrollNodeHeight = selectNodeHeight - getOffsetY( this.searchInputDiv ) - this.searchInputDiv.getStyle("height").toInt();
  1412. if( !this.options.searchbarInTopNode && this.selectTopNode ){
  1413. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.selectTopNode ) - this.selectTopNode.getStyle("height").toInt();
  1414. }
  1415. if(this.letterAreaNode ){
  1416. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.letterAreaNode ) - this.letterAreaNode.getStyle("height").toInt();
  1417. }
  1418. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.itemAreaScrollNode );
  1419. this.itemAreaScrollNode.setStyle("height", itemAreaScrollNodeHeight);
  1420. var selectedContainerNodeHeight = nodeHeight - getOffsetY(this.selectedContainerNode);
  1421. this.selectedContainerNode.setStyle("height", selectedContainerNodeHeight);
  1422. var selectedScrollNodeHeight = selectedContainerNodeHeight;
  1423. if( this.selectedTopNode ) {
  1424. selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY(this.selectedTopNode) - this.selectedTopNode.getStyle("height").toInt();
  1425. }
  1426. if( !this.options.searchbarInTopNode && this.selectedSearchInputDiv ){
  1427. selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY( this.selectedSearchInputDiv ) - this.selectedSearchInputDiv.getStyle("height").toInt();
  1428. }
  1429. this.selectedScrollNode.setStyle("height", selectedScrollNodeHeight);
  1430. }
  1431. this.fireEvent("setSize",[this])
  1432. },
  1433. addFlatCategoryItem : function( categoryItemNode, hasChildrenItem, itemNodeContainer, isCreateSubCategoryListNode ){
  1434. if(!this.flatSubCategoryNodeList)this.flatSubCategoryNodeList = [];
  1435. if( hasChildrenItem )this.flatSubCategoryNodeList.push( categoryItemNode );
  1436. if( !this.isFlatCategoryLoaded && this.flatSubCategoryNodeList.length > 1 ){
  1437. this.flatCategoryScrollNode.show();
  1438. this.flatCategoryScrollNode.setStyles( this.css.flatCategoryScrollNode );
  1439. var height = this.itemAreaScrollNode.getStyle("height").toInt();
  1440. this.flatCategoryScrollNode.setStyle("height", ""+height+"px");
  1441. this.flatCategoryNode.setStyles( this.css.flatCategoryNode );
  1442. this.isFlatCategoryLoaded = true;
  1443. this.itemAreaScrollNode.setStyles( this.css.itemAreaScrollNode_flatCategory );
  1444. //alert(this.flatSubCategoryNodeList[0].outerHTML)
  1445. }
  1446. if( hasChildrenItem )categoryItemNode.inject( itemNodeContainer || this.flatCategoryNode );
  1447. var subCategoryListNode;
  1448. if( isCreateSubCategoryListNode ){
  1449. subCategoryListNode = new Element("div.subCategoryListNode").inject( itemNodeContainer || this.flatCategoryNode );
  1450. }
  1451. //this.setFlatCategorySequence(categoryItemNode, itemNodeContainer, subCategoryListNode);
  1452. if( hasChildrenItem ){
  1453. //if( this.checkClickFlatCategoryItem(categoryItemNode, itemNodeContainer) ){
  1454. // categoryItemNode.click();
  1455. //}
  1456. if( !this.currentCategoryItemNode ){
  1457. categoryItemNode.click();
  1458. this.currentCategoryItemNode = categoryItemNode
  1459. }else{
  1460. //var date = new Date();
  1461. var first = this.flatCategoryNode.getElement(".flatCategoryItemNode");
  1462. //if(first)console.log(first.get("title"));
  1463. //console.log(new Date() - date );
  1464. //console.log(" " );
  1465. if( first ){
  1466. var dn1 = first.retrieve("dn");
  1467. var dn2 = this.currentCategoryItemNode.retrieve("dn");
  1468. if( dn1 && dn2 ){
  1469. if( dn1 != dn2 ){
  1470. categoryItemNode.click();
  1471. this.currentCategoryItemNode = categoryItemNode
  1472. }
  1473. }else{
  1474. var title1 = first.get("title");
  1475. var title2 = this.currentCategoryItemNode.get("title");
  1476. if( title1 && title1 ){
  1477. if( title1 != title2 ){
  1478. categoryItemNode.click();
  1479. this.currentCategoryItemNode = categoryItemNode
  1480. }
  1481. }else{
  1482. var text1 = first.get("text");
  1483. var text2 = this.currentCategoryItemNode.get("text");
  1484. if( text1 != text2 ){
  1485. categoryItemNode.click();
  1486. this.currentCategoryItemNode = categoryItemNode
  1487. }
  1488. }
  1489. }
  1490. }
  1491. }
  1492. }
  1493. return subCategoryListNode;
  1494. }
  1495. //checkClickFlatCategoryItem : function(categoryItemNode, itemNodeContainer){
  1496. // if( !this.flatCategorySeqObj_current ){
  1497. // this.flatCategorySeqObj_current = categoryItemNode.retrieve("seq");
  1498. // //console.log(this.flatCategorySeqObj_current)
  1499. // return true;
  1500. // }
  1501. // var seq_cur = this.flatCategorySeqObj_current;
  1502. // var seq = categoryItemNode ? categoryItemNode.retrieve("seq") : [];
  1503. // for( var i=0; i<seq.length; i++ ){
  1504. // if( seq_cur[i] && seq[i] < seq_cur[i] ){
  1505. // //console.log(seq)
  1506. // this.flatCategorySeqObj_current = seq;
  1507. // return true;
  1508. // }else if( !seq_cur[i] || seq[i] > seq_cur[i] ){
  1509. // return false;
  1510. // }
  1511. // }
  1512. // return false;
  1513. //},
  1514. //setFlatCategorySequence: function(categoryItemNode, itemNodeContainer, subCategoryListNode){
  1515. // if( !this.flatCategorySeqObj )this.flatCategorySeqObj = {};
  1516. // var parentSeq = itemNodeContainer ? itemNodeContainer.retrieve("seq") : [];
  1517. // var seq = Array.clone( parentSeq );
  1518. // if( this.flatCategorySeqObj[ parentSeq.length ] ){
  1519. // seq.push( this.flatCategorySeqObj[ parentSeq.length ] + 1 );
  1520. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1521. //
  1522. // categoryItemNode.store( "seq", seq );
  1523. // categoryItemNode.set( "seq", seq );
  1524. //
  1525. // if(subCategoryListNode){
  1526. // seq = Array.clone( seq );
  1527. // seq[ seq.length - 1 ] = seq[ seq.length - 1 ]+1;
  1528. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1529. // subCategoryListNode.store("seq", seq );
  1530. // subCategoryListNode.set( "seq", seq );
  1531. // }
  1532. // }else{
  1533. // seq.push( 1 );
  1534. // this.flatCategorySeqObj[ parentSeq.length ] = 1;
  1535. // categoryItemNode.store( "seq", seq );
  1536. // categoryItemNode.set( "seq", seq );
  1537. //
  1538. // if(subCategoryListNode) {
  1539. // seq = Array.clone(seq);
  1540. // seq[seq.length - 1] = seq[seq.length - 1]+1;
  1541. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1542. // subCategoryListNode.store("seq", seq);
  1543. // subCategoryListNode.set("seq", seq);
  1544. // }
  1545. // }
  1546. //}
  1547. });
  1548. MWF.xApplication.Selector.Person.Item = new Class({
  1549. initialize: function(data, selector, container, level, category, delay){
  1550. this.clazz = "Item";
  1551. this.data = data;
  1552. this.selector = selector;
  1553. this.container = container;
  1554. this.isSelected = false;
  1555. this.level = (level) ? level.toInt() : 1;
  1556. this.category = category;
  1557. this.subItems = [];
  1558. this.subCategorys = [];
  1559. if(!delay)this.load();
  1560. },
  1561. _getShowName: function(){
  1562. return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
  1563. },
  1564. _getTtiteText: function(){
  1565. return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
  1566. },
  1567. _setIcon: function(){
  1568. var style = this.selector.options.style;
  1569. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
  1570. },
  1571. load: function(){
  1572. if( this.clazz === "Item" ){
  1573. this.selector.fireEvent("queryLoadItem",[this]);
  1574. }
  1575. if( !this.node )this.node = new Element("div", {
  1576. "styles": this.selector.css.selectorItem
  1577. }).inject(this.container);
  1578. this.levelNode = new Element("div", {
  1579. "styles": this.selector.css.selectorItemLevelNode
  1580. }).inject(this.node);
  1581. var indent = this.selector.options.level1Indent + (this.level-1)*this.selector.options.indent;
  1582. this.levelNode.setStyle("width", ""+indent+"px");
  1583. this.iconNode = new Element("div", {
  1584. "styles": this.selector.css.selectorItemIconNode
  1585. }).inject(this.node);
  1586. this._setIcon();
  1587. this.actionNode = new Element("div", {
  1588. "styles": this.selector.css.selectorItemActionNode
  1589. }).inject(this.node);
  1590. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1591. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1592. }
  1593. this.textNode = new Element("div", {
  1594. "styles": this.selector.css.selectorItemTextNode,
  1595. "text": this._getShowName(),
  1596. "title": this._getTtiteText()
  1597. }).inject(this.node);
  1598. this.textNode.store("indent", indent);
  1599. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  1600. this.textNode.setStyle("margin-left", ""+m+"px");
  1601. if(this.postLoad)this.postLoad();
  1602. this.loadSubItem();
  1603. this.setEvent();
  1604. this.check();
  1605. if( this.clazz === "Item" ) {
  1606. this.selector.fireEvent("postLoadItem", [this]);
  1607. }
  1608. },
  1609. loadSubItem: function(){},
  1610. disable : function(){
  1611. this.node.hide();
  1612. this.disabled = true;
  1613. },
  1614. enable : function(){
  1615. this.node.show();
  1616. this.disabled = false;
  1617. },
  1618. check: function(){
  1619. //if (this.selector.options.count.toInt()===1){
  1620. // this.checkSelectedSingle();
  1621. //}else{
  1622. this.checkSelected();
  1623. //}
  1624. },
  1625. checkSelectedSingle: function(){
  1626. var selectedItem = this.selector.options.values.filter(function(item, index){
  1627. if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
  1628. if (typeOf(item)==="string") return this.data.distinguishedName === item;
  1629. return false;
  1630. }.bind(this));
  1631. if (selectedItem.length){
  1632. this.selectedSingle();
  1633. }
  1634. },
  1635. checkSelected: function(){
  1636. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  1637. return item.data.distinguishedName === this.data.distinguishedName;
  1638. }.bind(this));
  1639. if (selectedItem.length){
  1640. //selectedItem[0].item = this;
  1641. selectedItem[0].addItem(this);
  1642. this.selectedItem = selectedItem[0];
  1643. this.setSelected();
  1644. }
  1645. },
  1646. checkTextNodeIndent : function( textNode, styles ){
  1647. var indent = textNode.retrieve("indent");
  1648. if( indent && styles && styles["margin-left"] ){
  1649. var m = styles["margin-left"].toFloat()+indent;
  1650. textNode.setStyle("margin-left", ""+m+"px");
  1651. }
  1652. },
  1653. setSelected: function(){
  1654. this.isSelected = true;
  1655. this.node.setStyles(this.selector.css.selectorItem_selected);
  1656. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1657. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
  1658. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1659. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1660. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1661. }
  1662. // if( this.category ){
  1663. // this.category.checkSelectAll();
  1664. // }
  1665. },
  1666. setEvent: function(){
  1667. this.node.addEvents({
  1668. "mouseover": function(){
  1669. this.overItem();
  1670. }.bind(this),
  1671. "mouseout": function(){
  1672. this.outItem();
  1673. }.bind(this),
  1674. "click": function(){
  1675. this.clickItem( null, true );
  1676. }.bind(this)
  1677. });
  1678. },
  1679. clickItem: function( callback, checkValid ){
  1680. if ( layout.mobile && this.selector.options.count.toInt()===1){
  1681. this.selectedSingle( checkValid );
  1682. }else{
  1683. if (this.isSelected){
  1684. this.unSelected( checkValid );
  1685. }else{
  1686. this.selected( checkValid );
  1687. }
  1688. }
  1689. },
  1690. overItem: function(){
  1691. if (!this.isSelected ){
  1692. this.node.setStyles(this.selector.css.selectorItem_over);
  1693. }else if( this.selector.css.selectorItem_over_force ){
  1694. this.node.setStyles(this.selector.css.selectorItem_over_force);
  1695. }
  1696. if (!this.isSelected){
  1697. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  1698. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_over ){
  1699. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_over );
  1700. }
  1701. }else if( this.selector.css.selectorItemActionNode_over_force ){
  1702. this.node.setStyles(this.selector.css.selectorItemActionNode_over_force);
  1703. }
  1704. },
  1705. outItem: function(){
  1706. if (!this.isSelected){
  1707. this.node.setStyles(this.selector.css.selectorItem);
  1708. }else if( this.selector.css.selectorItem_over_force ){
  1709. this.node.setStyles(this.selector.css.selectorItem_selected);
  1710. }
  1711. if (!this.isSelected){
  1712. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1713. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1714. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1715. }
  1716. }else if( this.selector.css.selectorItemActionNode_over_force ){
  1717. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1718. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1719. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1720. }
  1721. }
  1722. },
  1723. selectedSingle: function( checkValid ){
  1724. if (!this.isSelected){
  1725. if (this.selector.currentItem) this.selector.currentItem.unSelectedSingle();
  1726. this.getData(function(){
  1727. this.selector.currentItem = this;
  1728. this.isSelected = true;
  1729. this.selector.selectedItems.push(this);
  1730. this.node.setStyles(this.selector.css.selectorItem_selected);
  1731. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1732. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
  1733. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1734. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1735. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1736. }
  1737. this.selector.fireEvent("selectItem",[this]);
  1738. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1739. }.bind(this));
  1740. }else {
  1741. this.unSelectedSingle( checkValid );
  1742. }
  1743. },
  1744. getData: function(callback){
  1745. if (callback) callback();
  1746. },
  1747. unSelectedSingle: function(checkValid){
  1748. this.selector.currentItem = null;
  1749. this.isSelected = false;
  1750. this.selector.selectedItems.erase(this);
  1751. this.node.setStyles(this.selector.css.selectorItem);
  1752. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1753. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode );
  1754. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1755. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1756. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1757. }
  1758. this.selector.fireEvent("unselectItem",[this]);
  1759. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1760. },
  1761. selected: function( checkValid, callback, selectedNode ){
  1762. var count = this.selector.options.maxCount || this.selector.options.count;
  1763. count = count.toInt();
  1764. if (!count) count = 0;
  1765. if( count == 1 && this.selector.emptySelectedItems){
  1766. this.selector.emptySelectedItems();
  1767. }
  1768. if ((count===0) || (this.selector.selectedItems.length+1)<=count) {
  1769. this.isSelected = true;
  1770. if( this.node ){
  1771. this.node.setStyles(this.selector.css.selectorItem_selected);
  1772. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1773. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
  1774. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1775. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1776. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1777. }
  1778. }
  1779. this.selectedItem = this.selector._newItemSelected(this.data, this.selector, this, selectedNode);
  1780. this.selectedItem.check();
  1781. this.selector.selectedItems.push(this.selectedItem);
  1782. // if( this.category ){
  1783. // this.category.checkSelectAll();
  1784. // }
  1785. this.selector.fireEvent("selectItem",[this]);
  1786. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1787. if(callback)callback();
  1788. }else{
  1789. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
  1790. }
  1791. },
  1792. unSelected: function( checkValid, callback ){
  1793. this.isSelected = false;
  1794. if( this.node ){
  1795. this.node.setStyles(this.selector.css.selectorItem);
  1796. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1797. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode );
  1798. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1799. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1800. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1801. }
  1802. }
  1803. if( this.category ){
  1804. this.category.checkUnselectAll();
  1805. }
  1806. if( this.selector.searchItems && this.selector.searchItems.length ){
  1807. this.selector.searchItems.each( function(itemSearch){
  1808. var sd = itemSearch.data;
  1809. var d = this.data;
  1810. if(
  1811. ( sd.distinguishedName && (sd.distinguishedName === d.distinguishedName) ) ||
  1812. ( sd.id && (sd.id === d.id) ) ||
  1813. ( sd.unique && (sd.unique === d.unique) ) ||
  1814. ( sd.employee && (sd.employee === d.employee) ) ||
  1815. ( sd.levelName && (sd.levelName === d.levelName) )
  1816. ){
  1817. itemSearch.isSelected = false;
  1818. itemSearch.node.setStyles(this.selector.css.selectorItem);
  1819. itemSearch.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1820. this.checkTextNodeIndent( itemSearch.textNode, this.selector.css.selectorItemTextNode );
  1821. itemSearch.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1822. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1823. itemSearch.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1824. }
  1825. }
  1826. }.bind(this))
  1827. }
  1828. if (this.selectedItem){
  1829. this.selector.selectedItems.erase(this.selectedItem);
  1830. this.selectedItem.items.each(function(item){
  1831. if (item != this){
  1832. item.isSelected = false;
  1833. item.node.setStyles(this.selector.css.selectorItem);
  1834. item.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1835. this.checkTextNodeIndent( item.textNode, this.selector.css.selectorItemTextNode );
  1836. item.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1837. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1838. item.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1839. }
  1840. }
  1841. }.bind(this));
  1842. this.selectedItem.destroy();
  1843. this.selectedItem = null;
  1844. }
  1845. this.selector.fireEvent("unselectItem",[this]);
  1846. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1847. if(callback)callback();
  1848. },
  1849. postLoad : function(){},
  1850. getParentCategoryByLevel : function( level ){
  1851. var category = this.category;
  1852. do{
  1853. if( category.level === level ){
  1854. return category;
  1855. }else{
  1856. category = category.category;
  1857. }
  1858. }while( category )
  1859. }
  1860. });
  1861. MWF.xApplication.Selector.Person.ItemSelected = new Class({
  1862. Extends: MWF.xApplication.Selector.Person.Item,
  1863. initialize: function(data, selector, item, selectedNode){
  1864. this.data = data;
  1865. this.selector = selector;
  1866. this.container = selectedNode || this.selector.selectedNode;
  1867. this.isSelected = false;
  1868. this.clazz = "ItemSelected";
  1869. this.items = [];
  1870. if (item) this.items.push(item);
  1871. this.level = 0;
  1872. this.node = new Element("div", {
  1873. "styles": this.selector.css.selectorItem
  1874. }).inject(this.container);
  1875. this.node.setStyle("display","none");
  1876. this.getData(function(){
  1877. this.node.setStyle("display","");
  1878. this.load();
  1879. }.bind(this));
  1880. },
  1881. postLoad : function(){
  1882. if( this.selector.css.selectorSelectedItemActionNode ){
  1883. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode );
  1884. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorSelectedItemActionNode_single ){
  1885. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode_single );
  1886. }
  1887. }
  1888. if( this.selector.css.selectorSelectedItemTextNode ){
  1889. this.textNode.setStyles(this.selector.css.selectorSelectedItemTextNode);
  1890. }
  1891. },
  1892. getData: function(callback){
  1893. if (callback) callback();
  1894. },
  1895. clickItem: function( callback, checkValid ){
  1896. if (this.items.length){
  1897. this.items.each(function(item){
  1898. item.unSelected( checkValid );
  1899. });
  1900. if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
  1901. }else{
  1902. //this.item.selectedItem = null;
  1903. //this.item.isSelected = false;
  1904. this.destroy();
  1905. this.selector.selectedItems.erase(this);
  1906. if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
  1907. }
  1908. },
  1909. //overItem: function(){
  1910. // if (!this.isSelected){
  1911. // this.node.setStyles(this.selector.css.selectorItem_over);
  1912. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  1913. // }
  1914. //},
  1915. overItem: function(){
  1916. if (!this.isSelected ){
  1917. if( this.selector.css.selectorItem_selected_over ){
  1918. this.node.setStyles(this.selector.css.selectorItem_selected_over);
  1919. }else{
  1920. this.node.setStyles(this.selector.css.selectorItem_over);
  1921. }
  1922. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  1923. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected_over ){
  1924. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected_over );
  1925. }
  1926. }
  1927. },
  1928. outItem: function(){
  1929. if (!this.isSelected){
  1930. var styles = this.selector.css.selectorSelectedItem || this.selector.css.selectorItem;
  1931. this.node.setStyles(styles);
  1932. }else if( this.selector.css.selectorItem_over_force ){
  1933. this.node.setStyles(this.selector.css.selectorItem_selected);
  1934. }
  1935. if (!this.isSelected){
  1936. var styles = this.selector.css.selectorSelectedItemActionNode || this.selector.css.selectorItemActionNode;
  1937. this.actionNode.setStyles(styles);
  1938. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) &&
  1939. ( this.selector.css.selectorSelectedItemActionNode_single || this.selector.css.selectorItemActionNode_single ) ){
  1940. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode_single || this.selector.css.selectorItemActionNode_single );
  1941. }
  1942. }else if( this.selector.css.selectorItemActionNode_over_force ){
  1943. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1944. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1945. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1946. }
  1947. }
  1948. },
  1949. addItem: function(item){
  1950. if (this.items.indexOf(item)===-1) this.items.push(item);
  1951. },
  1952. check: function(){
  1953. if (this.selector.items.length){
  1954. var items = this.selector.items.filter(function(item, index){
  1955. return item.data.distinguishedName === this.data.distinguishedName;
  1956. }.bind(this));
  1957. this.items = items;
  1958. if (items.length){
  1959. items.each(function(item){
  1960. item.selectedItem = this;
  1961. item.setSelected();
  1962. }.bind(this));
  1963. }
  1964. }
  1965. },
  1966. destroy: function(){
  1967. if(this.node){
  1968. // var parent = this.node.getParent(".categorySelectedNode");
  1969. // if( parent && !this.node.getPrevious() && !this.node.getNext() ){ //parent.getChildren().length <= 1
  1970. // parent.destroy();
  1971. // }else{
  1972. this.node.destroy();
  1973. // }
  1974. }
  1975. delete this;
  1976. }
  1977. });
  1978. MWF.xApplication.Selector.Person.ItemCategory = new Class({
  1979. Extends: MWF.xApplication.Selector.Person.Item,
  1980. initialize: function(data, selector, container, level, parentCategory, delay){
  1981. this.data = data;
  1982. this.selector = selector;
  1983. this.container = container;
  1984. this.isSelected = false;
  1985. this.level = (level) ? level.toInt() : 1;
  1986. this.category = parentCategory;
  1987. this.subItems = [];
  1988. this.subCategorys = [];
  1989. if(!delay)this.load();
  1990. },
  1991. load : function(){
  1992. if( this.selector.isFlatCategory ){
  1993. this.loadForFlat();
  1994. }else{
  1995. this.loadForNormal();
  1996. }
  1997. },
  1998. loadForFlat : function(){
  1999. this.selector.fireEvent("queryLoadCategory",[this]);
  2000. //this.createNode();
  2001. this.node = new Element("div.flatCategoryItemNode", {
  2002. "styles": this.selector.css.flatCategoryItemNode,
  2003. "title" : this._getTtiteText()
  2004. });
  2005. this.node.store( "category", this );
  2006. this.node.store( "dn", this.data.distinguishedName );
  2007. this.textNode = new Element("div", {
  2008. "styles": this.selector.css.flatCategoryItemTextNode,
  2009. "text": this._getShowName()
  2010. }).inject(this.node);
  2011. //var level = this.level;
  2012. //var category = this;
  2013. //while( category.category ){
  2014. // level = category.category + "_" + level;
  2015. // category = category.category;
  2016. //}
  2017. this.children = new Element("div", {
  2018. "styles": this.selector.css.selectorItemCategoryChildrenNode
  2019. }).inject(this.selector.itemAreaNode); //this.container
  2020. //if (!this.selector.options.expand)
  2021. this.children.setStyle("display", "none");
  2022. if( this.selector.options.selectAllEnable && this.selector.options.count.toInt()!==1 ){
  2023. var selectAllWrap = new Element("div",{
  2024. styles : this.selector.css.flatCategory_selectAllWrap
  2025. }).inject(this.children);
  2026. this.selectAllNode = new Element("div", {
  2027. "styles": this.selector.css.flatCategory_selectAll,
  2028. "text" : "全选"
  2029. }).inject(selectAllWrap);
  2030. this.selectAllNode.addEvent( "click", function(ev){
  2031. if( this.isSelectedAll ){
  2032. this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
  2033. this.selector.fireEvent("unselectCatgory",[this])
  2034. }else{
  2035. this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev, true) : this.selectAll(ev, true);
  2036. this.selector.fireEvent("selectCatgory",[this])
  2037. }
  2038. ev.stopPropagation();
  2039. }.bind(this));
  2040. }
  2041. // var subIdList = this.selector._getChildrenItemIds(this.data);
  2042. // if (subIdList){
  2043. // var count = subIdList.length;
  2044. // this.childrenHeight = count*this.selector.options.itemHeight;
  2045. // this.children.setStyle("height", ""+this.childrenHeight+"px");
  2046. // }
  2047. //if (!this._hasChild()){
  2048. // this.textNode.setStyle("color", "#333");
  2049. //}
  2050. if( this.selectAllNode ){
  2051. if( this.selector.options.selectAllRange === "direct" && !this._hasChildItem() ){
  2052. this.selectAllNode.setStyle("display", "none");
  2053. }
  2054. }
  2055. this.node.addEvents({
  2056. //"mouseover": function(){
  2057. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode_over );
  2058. //}.bind(this),
  2059. //"mouseout": function(){
  2060. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode );
  2061. //}.bind(this),
  2062. "click": function(){
  2063. if( this.selector.currentFlatCategory === this )return;
  2064. if( this.selector.currentFlatCategory ){
  2065. this.selector.currentFlatCategory.clickFlatCategoryItem(null, true); //取消原来选择的
  2066. }
  2067. this.selector.currentFlatCategory = this;
  2068. this.clickFlatCategoryItem();
  2069. }.bind(this)
  2070. });
  2071. //this.setEvent();
  2072. var isCreateSubCategoryListNode = this._hasChildCategory ? this._hasChildCategory() : true;
  2073. var nodeContainer;
  2074. if( this.nodeContainer ){
  2075. nodeContainer = this.nodeContainer;
  2076. }else{
  2077. nodeContainer = (this.category && this.category.subCategoryListNode) ? this.category.subCategoryListNode : null;
  2078. }
  2079. this.subCategoryListNode = this.selector.addFlatCategoryItem( this.node, this._hasChildItem(), nodeContainer, isCreateSubCategoryListNode );
  2080. this.check();
  2081. if( this.loadCategoryChildren )this.loadCategoryChildren();
  2082. //this.afterLoad();
  2083. this.selector.fireEvent("postLoadCategory",[this]);
  2084. },
  2085. loadForNormal : function(){
  2086. this.selector.fireEvent("queryLoadCategory",[this]);
  2087. this.createNode();
  2088. this.levelNode = new Element("div", {
  2089. "styles": this.selector.css.selectorItemLevelNode
  2090. }).inject(this.node);
  2091. var indent = this.selector.options.level1Indent + (this.level-1)*this.selector.options.indent;
  2092. this.levelNode.setStyle("width", ""+indent+"px");
  2093. this.iconNode = new Element("div", {
  2094. "styles": this.selector.css.selectorItemCategoryIconNode || this.selector.css.selectorItemIconNode
  2095. }).inject(this.node);
  2096. this._setIcon();
  2097. this.actionNode = new Element("div", {
  2098. "styles": (this.selector.options.expand) ? this.selector.css.selectorItemCategoryActionNode_expand : this.selector.css.selectorItemCategoryActionNode_collapse
  2099. }).inject(this.node);
  2100. if( this.selector.options.selectAllEnable && this.selector.options.count.toInt()!==1 ){
  2101. this.selectAllNode = new Element("div", {
  2102. "styles": this.selector.css.selectorItemCategoryActionNode_selectAll,
  2103. "title" : "全选下级"
  2104. }).inject(this.node);
  2105. this.selectAllNode.addEvent( "click", function(ev){
  2106. if( this.isSelectedAll ){
  2107. // this.unselectAll(ev);
  2108. this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
  2109. this.selector.fireEvent("unselectCatgory",[this]);
  2110. }else{
  2111. // this.selectAll(ev);
  2112. if( this.selector.options.selectAllRange === "all" ){
  2113. var node = new Element("div.categorySelectedNode").inject( this.selector.selectedNode );
  2114. this.selectAllNested(ev, true, node );
  2115. }else{
  2116. this.selectAll(ev, true)
  2117. }
  2118. this.selector.fireEvent("selectCatgory",[this]);
  2119. }
  2120. ev.stopPropagation();
  2121. }.bind(this));
  2122. if( this.selector.css.selectorItemCategoryActionNode_selectAll_over ){
  2123. this.selectAllNode.addEvents( {
  2124. "mouseover" : function(ev){
  2125. if( !this.isSelectedAll )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_over );
  2126. //ev.stopPropagation();
  2127. }.bind(this),
  2128. "mouseout" : function(ev){
  2129. if( !this.isSelectedAll )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2130. //ev.stopPropagation();
  2131. }.bind(this)
  2132. })
  2133. }
  2134. }
  2135. this.textNode = new Element("div", {
  2136. "styles": this.selector.css.selectorItemCategoryTextNode,
  2137. "text": this._getShowName()
  2138. }).inject(this.node);
  2139. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  2140. this.textNode.setStyle("margin-left", ""+m+"px");
  2141. this.children = new Element("div", {
  2142. "styles": this.selector.css.selectorItemCategoryChildrenNode
  2143. }).inject(this.node, "after");
  2144. if (!this.selector.options.expand) this.children.setStyle("display", "none");
  2145. if( this.selector.options.expandEmptyCategory && !this._hasChildItem() ){ //点击允许展开空分类
  2146. this.children.hide();
  2147. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  2148. this.isExpand = false;
  2149. }else{
  2150. var subIdList = this.selector._getChildrenItemIds(this.data);
  2151. if (subIdList){
  2152. var count = subIdList.length;
  2153. this.childrenHeight = count*this.selector.options.itemHeight;
  2154. this.children.setStyle("height", ""+this.childrenHeight+"px");
  2155. }
  2156. if ( !this._hasChild()){
  2157. this.actionNode.setStyle("background", "transparent");
  2158. this.textNode.setStyle("color", "#777");
  2159. }
  2160. if( this.selectAllNode ){
  2161. if( this.selector.options.selectAllRange === "direct" && !this._hasChildItem() ){
  2162. this.selectAllNode.setStyle("display", "none");
  2163. }
  2164. }
  2165. }
  2166. this.setEvent();
  2167. this.check();
  2168. this.afterLoad();
  2169. this.selector.fireEvent("postLoadCategory",[this]);
  2170. },
  2171. createNode: function(){
  2172. this.node = new Element("div", {
  2173. "styles": this.selector.css.selectorItemCategory,
  2174. "title" : this._getTtiteText()
  2175. }).inject(this.container);
  2176. },
  2177. isSelectAllEnable : function(){
  2178. },
  2179. unselectAll : function(ev, exclude, checkValid ){
  2180. var excludeList = exclude || [];
  2181. if( exclude && typeOf(exclude) !== "array" )excludeList = [exclude];
  2182. ( this.subItems || [] ).each( function(item){
  2183. if(item.isSelected && !excludeList.contains(item) ){
  2184. item.unSelected( checkValid );
  2185. }
  2186. }.bind(this));
  2187. if( this.selectAllNode ){
  2188. if( this.selector.isFlatCategory ){
  2189. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  2190. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll){
  2191. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2192. }
  2193. }
  2194. this.isSelectedAll = false;
  2195. },
  2196. unselectAllNested : function( ev, exclude, checkValid ){
  2197. this.unselectAll(ev, exclude, checkValid);
  2198. if( this.subCategorys && this.subCategorys.length ){
  2199. this.subCategorys.each( function( category ){
  2200. category.unselectAllNested( ev, exclude, checkValid )
  2201. })
  2202. }
  2203. },
  2204. selectAllNested : function( ev, checkValid, selectedNode ){
  2205. var node;
  2206. if(selectedNode)node = new Element("div.categorySelectedNode").inject( selectedNode );
  2207. this.selectAll(ev, checkValid, node);
  2208. if( this.subCategorys && this.subCategorys.length ){
  2209. this.subCategorys.each( function( category ){
  2210. if(selectedNode)var node = new Element("div.categorySelectedNode").inject( selectedNode );
  2211. category.selectAllNested(ev, checkValid, node)
  2212. })
  2213. }
  2214. },
  2215. selectAll: function(ev, checkValid, selectedNode){
  2216. if( this.loaded || this.selector.isFlatCategory ){
  2217. this._selectAll( ev, checkValid, selectedNode );
  2218. }else{
  2219. this.clickItem( function(){
  2220. this._selectAll( ev, checkValid, selectedNode );
  2221. //this.children.setStyles({
  2222. // "display": "none",
  2223. // "height": "0px"
  2224. //});
  2225. //this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  2226. }.bind(this));
  2227. }
  2228. },
  2229. _selectAll : function( ev, checkValid, selectedNode ){
  2230. if( this.selector.options.selectAllRange === "direct" && ( !this.subItems || !this.subItems.length ) )return;
  2231. var count = this.selector.options.maxCount || this.selector.options.count;
  2232. if (!count) count = 0;
  2233. var selectedSubItemCount = 0;
  2234. this.subItems.each( function(item){
  2235. if(item.isSelected)selectedSubItemCount++
  2236. }.bind(this));
  2237. if ((count.toInt()===0) || (this.selector.selectedItems.length+(this.subItems.length-selectedSubItemCount))<=count){
  2238. var checkedCount = 0;
  2239. var doSelectAll = function () {
  2240. this.subItems.each( function(item){
  2241. if(!item.isSelected && !item.disabled )item.selected( false, function () {
  2242. checkedCount++;
  2243. if( this.subItems.length === checkedCount ){
  2244. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  2245. }
  2246. }.bind(this), selectedNode);
  2247. }.bind(this));
  2248. if( this.selectAllNode ){
  2249. if( this.selector.isFlatCategory ){
  2250. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
  2251. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll_selected){
  2252. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_selected );
  2253. }
  2254. }
  2255. this.isSelectedAll = true;
  2256. }.bind(this);
  2257. if( this._beforeSelectAll ){
  2258. this._beforeSelectAll( doSelectAll );
  2259. }else{
  2260. doSelectAll();
  2261. }
  2262. }else{
  2263. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
  2264. }
  2265. },
  2266. checkSelectAll : function(){
  2267. if( this.isSelectedAll )return;
  2268. if( !this.selectAllNode )return;
  2269. if( !this.subItems )return;
  2270. var isAllItemSelected = true;
  2271. for( var i=0; i< this.subItems.length; i++ ){
  2272. if( !this.subItems[i].isSelected ){
  2273. isAllItemSelected = false;
  2274. break;
  2275. }
  2276. }
  2277. if( isAllItemSelected ){
  2278. if( this.selector.isFlatCategory ){
  2279. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
  2280. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll_selected ){
  2281. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_selected );
  2282. }
  2283. this.isSelectedAll = true;
  2284. }
  2285. },
  2286. checkUnselectAll : function(){
  2287. if( !this.isSelectedAll )return;
  2288. if( !this.selectAllNode )return;
  2289. if( !this.subItems )return;
  2290. var hasSelectedItem = false;
  2291. for( var i=0; i< this.subItems.length; i++ ){
  2292. if( this.subItems[i].isSelected ){
  2293. hasSelectedItem = true;
  2294. break;
  2295. }
  2296. }
  2297. if( !hasSelectedItem ){
  2298. if( this.selector.isFlatCategory ){
  2299. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  2300. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll ){
  2301. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2302. }
  2303. this.isSelectedAll = false;
  2304. }
  2305. },
  2306. afterLoad: function(){
  2307. if (this.level===1) this.clickItem();
  2308. },
  2309. clickFlatCategoryItem : function( callback, hidden ){
  2310. if (this._hasChildItem()){
  2311. var display = this.children.getStyle("display");
  2312. if( hidden ){
  2313. this.children.setStyles({ "display": "none" });
  2314. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  2315. this.isExpand = false;
  2316. }else if (display === "none"){
  2317. this.children.setStyles({
  2318. "display": "block",
  2319. "height": "auto"
  2320. });
  2321. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  2322. this.isExpand = true;
  2323. }else{
  2324. this.children.setStyles({
  2325. "display": "none"
  2326. });
  2327. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  2328. this.isExpand = false;
  2329. }
  2330. if(callback)callback()
  2331. }
  2332. },
  2333. clickItem: function( callback ){
  2334. if (this._hasChild() || this.selector.options.expandEmptyCategory ){
  2335. if (!this.fx){
  2336. this.fx = new Fx.Tween(this.children, {
  2337. "duration": 200
  2338. // "transition": Fx.Transitions.Cubic.easeIn
  2339. });
  2340. }
  2341. if (!this.fx.isRunning()){
  2342. var display = this.children.getStyle("display");
  2343. if (display === "none"){
  2344. this.selector.fireEvent("expand", [this] );
  2345. this.children.setStyles({
  2346. "display": "block",
  2347. "height": "0px"
  2348. });
  2349. this.fx.start("height", "0px", ""+this.childrenHeight+"px");
  2350. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  2351. this.isExpand = true;
  2352. }else{
  2353. this.selector.fireEvent("collapse", [this] );
  2354. if (!this.childrenHeight) this.childrenHeight = this.children.getStyle("height").toFloat();
  2355. this.fx.start("height", ""+this.childrenHeight+"px", "0px").chain(function(){
  2356. this.children.setStyles({
  2357. "display": "none",
  2358. "height": "0px"
  2359. });
  2360. }.bind(this));
  2361. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  2362. this.isExpand = false;
  2363. }
  2364. }
  2365. if(callback)callback()
  2366. }
  2367. },
  2368. overItem: function(){
  2369. //if (!this.isSelected){
  2370. // this.node.setStyles(this.selector.css.selectorItem_over);
  2371. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  2372. //}
  2373. if( this.selector.css.selectorItemCategory_over ){
  2374. this.node.setStyles(this.selector.css.selectorItemCategory_over);
  2375. }
  2376. var display = this.children.getStyle("display");
  2377. if( display === "none" ){
  2378. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
  2379. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse_over )
  2380. }
  2381. }else{
  2382. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
  2383. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand_over )
  2384. }
  2385. }
  2386. },
  2387. outItem: function(){
  2388. //if (!this.isSelected){
  2389. // this.node.setStyles(this.selector.css.selectorItem);
  2390. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  2391. //}
  2392. if( this.selector.css.selectorItemCategory_over ){
  2393. this.node.setStyles(this.selector.css.selectorItemCategory);
  2394. }
  2395. var display = this.children.getStyle("display");
  2396. if( display === "none" ){
  2397. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
  2398. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse )
  2399. }
  2400. }else{
  2401. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
  2402. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand )
  2403. }
  2404. }
  2405. },
  2406. _hasChild: function(){
  2407. var subIdList = this.selector._getChildrenItemIds(this.data);
  2408. if (subIdList) if (subIdList.length) return true;
  2409. return false;
  2410. },
  2411. _hasChildCategory: function(){
  2412. return null;
  2413. },
  2414. _hasChildItem: function(){
  2415. return this._hasChild();
  2416. },
  2417. _getTtiteText: function(){
  2418. if( this.data.levelName ){
  2419. return this.data.name+"("+ this.data.levelName +")";
  2420. }else{
  2421. return this.data.name;
  2422. }
  2423. }
  2424. });
  2425. MWF.xApplication.Selector.Person.ItemGroupCategory = new Class({
  2426. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  2427. _getShowName: function(){
  2428. return this.data.name;
  2429. },
  2430. _setIcon: function(){
  2431. var style = this.selector.options.style;
  2432. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  2433. }
  2434. });
  2435. MWF.xApplication.Selector.Person.ItemRoleCategory = new Class({
  2436. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  2437. _getShowName: function(){
  2438. return this.data.name;
  2439. },
  2440. _setIcon: function(){
  2441. var style = this.selector.options.style;
  2442. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/roleicon.png)");
  2443. }
  2444. });
  2445. MWF.xApplication.Selector.Person.Filter = new Class({
  2446. Implements: [Options, Events],
  2447. options: {
  2448. "style": "default",
  2449. "groups": [],
  2450. "roles": []
  2451. },
  2452. initialize: function(value, options){
  2453. this.setOptions(options);
  2454. this.value = value;
  2455. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  2456. },
  2457. filter: function(value, callback){
  2458. this.value = value;
  2459. var key = this.value;
  2460. if (this.options.groups.length || this.options.roles.length) key = {"key": key, "groupList": this.options.groupList, "roleList": this.options.roleList};
  2461. this.orgAction.listPersonByKey(function(json){
  2462. data = json.data;
  2463. if (callback) callback(data)
  2464. }.bind(this), null, key);
  2465. }
  2466. });