Person.js 105 KB

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