Person.js 104 KB

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