Person.js 119 KB

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