Person.js 119 KB

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