Person.js 104 KB

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