Person.js 121 KB

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