Person.js 106 KB

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