Person.js 115 KB

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