Person.js 109 KB

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