Person.js 105 KB

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