Person.js 121 KB

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