Person.js 104 KB

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