Person.js 116 KB

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