Person.js 121 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871
  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 _self = this;
  1312. var checkItem = function () {
  1313. if(this.items.length === 1 || this.subItems.length === 1 ){
  1314. if( this.items.length === 1 && this.subItems.length === 0 ){
  1315. if( !this.items[0].isSelected )this.items[0].clickItem();
  1316. this.fireEvent("afterSelectSingleItem",[this, this.items[0]]);
  1317. }else if( this.items.length === 0 && this.subItems.length === 1 ){
  1318. if( !this.items[0].isSelected )this.subItems[0].clickItem();
  1319. this.fireEvent("afterSelectSingleItem",[this, this.items[0]])
  1320. }else if( this.items.length === 1 && this.subItems.length === 1 ){
  1321. if( this.items[0] === this.subItems[0] ){
  1322. if( !this.items[0].isSelected )this.items[0].clickItem();
  1323. this.fireEvent("afterSelectSingleItem",[this, this.items[0]])
  1324. }else{
  1325. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1326. }
  1327. }else{
  1328. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1329. }
  1330. }else{
  1331. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1332. }
  1333. }.bind(this);
  1334. var checkCategoryItem = function (category) {
  1335. if( !category.subCategorys || category.subCategorys.length === 0 ){
  1336. if( category.subItems && category.subItems.length === 1 ){
  1337. isSingleItem = true;
  1338. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1339. _self.fireEvent("afterSelectSingleItem",[_self, category.subItems[0]])
  1340. }else{
  1341. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1342. }
  1343. }else if(category.subCategorys.length === 1){
  1344. if( category.subItems && category.subItems.length > 0 ){
  1345. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1346. }else if( !category.subCategorys[0]._hasChild || !category.subCategorys[0]._hasChild() ){ //category.subCategorys[0].isItem &&
  1347. isSingleItem = true;
  1348. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1349. _self.fireEvent("afterSelectSingleItem",[_self, category.subItems[0]])
  1350. }else{
  1351. checkCategory( category.subCategorys[0] )
  1352. }
  1353. }else{
  1354. var list = [];
  1355. for( var i=0; i<category.subCategorys.length; i++ ){
  1356. if( category.subCategorys[i]._hasChild && category.subCategorys[i]._hasChild() ){
  1357. list.push( category.subCategorys[i] );
  1358. }
  1359. }
  1360. if( list.length === 1 ){
  1361. if( !category.subItems || category.subItems.length === 0 ){
  1362. checkCategory( list[0] );
  1363. }
  1364. }
  1365. if( list.length === 0 ){
  1366. if( category.subItems && category.subItems.length === 1 ){
  1367. isSingleItem = true;
  1368. if( !category.subItems[0].isSelected )category.subItems[0].clickItem();
  1369. _self.fireEvent("afterSelectSingleItem",[_self, category.subItems[0]])
  1370. }else{
  1371. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1372. }
  1373. }else{
  1374. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1375. }
  1376. }
  1377. };
  1378. var checkCategory = function ( category ) {
  1379. if( category.loaded ){
  1380. checkCategoryItem( category )
  1381. }else if( category.loading ){
  1382. window.setTimeout( function () {
  1383. checkCategory( category )
  1384. }, 100 )
  1385. }
  1386. };
  1387. if( this.subCategorys.length === 1 && this.subItems.length === 0) {
  1388. checkCategory( this.subCategorys[0] );
  1389. }else if( this.subCategorys.length === 0 ){
  1390. checkItem();
  1391. }else{
  1392. _self.fireEvent("afterCheckSelectSingleItem",[_self])
  1393. }
  1394. },
  1395. setSize : function(){
  1396. debugger;
  1397. if( !this.options.width && !this.options.height )return;
  1398. var getOffsetX = function(node){
  1399. return (node.getStyle("margin-left").toInt() || 0 )+
  1400. (node.getStyle("margin-right").toInt() || 0 ) +
  1401. (node.getStyle("padding-left").toInt() || 0 ) +
  1402. (node.getStyle("padding-right").toInt() || 0 ) +
  1403. (node.getStyle("border-left-width").toInt() || 0 ) +
  1404. (node.getStyle("border-right-width").toInt() || 0 );
  1405. };
  1406. var getOffsetY = function(node){
  1407. return (node.getStyle("margin-top").toInt() || 0 ) +
  1408. (node.getStyle("margin-bottom").toInt() || 0 ) +
  1409. (node.getStyle("padding-top").toInt() || 0 ) +
  1410. (node.getStyle("padding-bottom").toInt() || 0 )+
  1411. (node.getStyle("border-top-width").toInt() || 0 ) +
  1412. (node.getStyle("border-bottom-width").toInt() || 0 );
  1413. };
  1414. if( this.options.width && this.options.width === "auto" ){
  1415. //if (this.options.count.toInt() !== 1){
  1416. if( this.node )this.node.setStyle("width", "auto");
  1417. this.selectNode.setStyles({
  1418. "width": "50%",
  1419. "float" : "left"
  1420. });
  1421. //this.searchInput.setStyle("width", "99%");
  1422. if(this.letterAreaNode ){
  1423. this.letterAreaNode.setStyle("width", "auto");
  1424. }
  1425. this.selectedContainerNode.setStyle("width", "auto");
  1426. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  1427. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
  1428. this.selectedScrollNode.setStyle("width", "auto");
  1429. }else{
  1430. this.selectedScrollNode.setStyle("margin-right", "8px");
  1431. }
  1432. //}else{
  1433. // this.node.setStyle("width", "auto");
  1434. // this.selectNode.setStyle("width", "auto");
  1435. //}
  1436. }else if( this.options.width && typeOf( this.options.width.toInt() ) === "number" ){
  1437. var nodeWidth;
  1438. if( this.node ){
  1439. nodeWidth = this.options.width.toInt() - getOffsetX(this.node);
  1440. this.node.setStyle("width", nodeWidth);
  1441. }else{
  1442. nodeWidth = this.options.width.toInt();
  1443. }
  1444. nodeWidth = nodeWidth - getOffsetX( this.contentNode );
  1445. if( this.shuttleNode ){
  1446. nodeWidth = nodeWidth - getOffsetX(this.shuttleNode) - this.shuttleNode.getStyle("width").toInt();
  1447. }
  1448. //if (this.options.count.toInt() !== 1){
  1449. var width = nodeWidth - getOffsetX(this.selectNode) - getOffsetX(this.selectedContainerNode);
  1450. var halfWidth = this.options.noSelectedContainer ? width : ( Math.floor(width / 2) - 2);
  1451. this.selectNode.setStyle("width", halfWidth);
  1452. //this.searchInput.setStyle("width", halfWidth - 6);
  1453. if(this.letterAreaNode ){
  1454. this.letterAreaNode.setStyle("width", halfWidth - 19);
  1455. }
  1456. this.selectedContainerNode.setStyle("width", halfWidth);
  1457. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  1458. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
  1459. this.selectedScrollNode.setStyle("width", halfWidth);
  1460. }else{
  1461. this.selectedScrollNode.setStyle("width", halfWidth - 8);
  1462. }
  1463. //}else{
  1464. // var width = nodeWidth - getOffsetX(this.selectNode);
  1465. // this.selectNode.setStyle("width", width);
  1466. //}
  1467. }
  1468. if( this.options.height && typeOf( this.options.height.toInt() ) === "number" ){
  1469. var nodeHeight;
  1470. if( this.node ){
  1471. nodeHeight = this.options.height.toInt() - getOffsetY(this.node);
  1472. this.node.setStyle("height", nodeHeight);
  1473. }else{
  1474. nodeHeight = this.options.height.toInt();
  1475. }
  1476. nodeHeight = nodeHeight - getOffsetY( this.contentNode ) - 1;
  1477. if( this.titleNode ){
  1478. nodeHeight = nodeHeight - getOffsetY( this.titleNode ) - this.titleNode.getStyle("height").toInt();
  1479. }
  1480. if( this.actionNode ){
  1481. nodeHeight = nodeHeight - getOffsetY( this.actionNode ) - this.actionNode.getStyle("height").toInt();
  1482. }
  1483. var selectNodeHeight = nodeHeight - getOffsetY(this.selectNode);
  1484. this.selectNode.setStyle("height", selectNodeHeight);
  1485. if( this.shuttleNode ){
  1486. this.shuttleNode.setStyle("height", selectNodeHeight);
  1487. var shuttleInnerHieght = getOffsetY( this.shuttleInnerNode ) + this.shuttleInnerNode.getStyle("height").toInt();
  1488. this.shuttleInnerNode.setStyle("margin-top", (selectNodeHeight-shuttleInnerHieght)/2 +"px" )
  1489. }
  1490. var itemAreaScrollNodeHeight = selectNodeHeight - getOffsetY( this.searchInputDiv ) - this.searchInputDiv.getStyle("height").toInt();
  1491. if( !this.options.searchbarInTopNode && this.selectTopNode ){
  1492. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.selectTopNode ) - this.selectTopNode.getStyle("height").toInt();
  1493. }
  1494. if(this.letterAreaNode ){
  1495. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.letterAreaNode ) - this.letterAreaNode.getStyle("height").toInt();
  1496. }
  1497. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.itemAreaScrollNode );
  1498. this.itemAreaScrollNode.setStyle("height", itemAreaScrollNodeHeight);
  1499. var selectedContainerNodeHeight = nodeHeight - getOffsetY(this.selectedContainerNode);
  1500. this.selectedContainerNode.setStyle("height", selectedContainerNodeHeight);
  1501. var selectedScrollNodeHeight = selectedContainerNodeHeight;
  1502. if( this.selectedTopNode ) {
  1503. selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY(this.selectedTopNode) - this.selectedTopNode.getStyle("height").toInt();
  1504. }
  1505. if( !this.options.searchbarInTopNode && this.selectedSearchInputDiv ){
  1506. selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY( this.selectedSearchInputDiv ) - this.selectedSearchInputDiv.getStyle("height").toInt();
  1507. }
  1508. this.selectedScrollNode.setStyle("height", selectedScrollNodeHeight);
  1509. }
  1510. this.fireEvent("setSize",[this])
  1511. },
  1512. addFlatCategoryItem : function( categoryItemNode, hasChildrenItem, itemNodeContainer, isCreateSubCategoryListNode ){
  1513. if(!this.flatSubCategoryNodeList)this.flatSubCategoryNodeList = [];
  1514. if( hasChildrenItem )this.flatSubCategoryNodeList.push( categoryItemNode );
  1515. if( !this.isFlatCategoryLoaded && this.flatSubCategoryNodeList.length > 1 ){
  1516. this.flatCategoryScrollNode.show();
  1517. this.flatCategoryScrollNode.setStyles( this.css.flatCategoryScrollNode );
  1518. var height = this.itemAreaScrollNode.getStyle("height").toInt();
  1519. this.flatCategoryScrollNode.setStyle("height", ""+height+"px");
  1520. this.flatCategoryNode.setStyles( this.css.flatCategoryNode );
  1521. this.isFlatCategoryLoaded = true;
  1522. this.itemAreaScrollNode.setStyles( this.css.itemAreaScrollNode_flatCategory );
  1523. //alert(this.flatSubCategoryNodeList[0].outerHTML)
  1524. }
  1525. if( hasChildrenItem )categoryItemNode.inject( itemNodeContainer || this.flatCategoryNode );
  1526. var subCategoryListNode;
  1527. if( isCreateSubCategoryListNode ){
  1528. subCategoryListNode = new Element("div.subCategoryListNode").inject( itemNodeContainer || this.flatCategoryNode );
  1529. }
  1530. //this.setFlatCategorySequence(categoryItemNode, itemNodeContainer, subCategoryListNode);
  1531. if( hasChildrenItem ){
  1532. //if( this.checkClickFlatCategoryItem(categoryItemNode, itemNodeContainer) ){
  1533. // categoryItemNode.click();
  1534. //}
  1535. if( !this.currentCategoryItemNode ){
  1536. categoryItemNode.click();
  1537. this.currentCategoryItemNode = categoryItemNode
  1538. }else{
  1539. //var date = new Date();
  1540. var first = this.flatCategoryNode.getElement(".flatCategoryItemNode");
  1541. //if(first)console.log(first.get("title"));
  1542. //console.log(new Date() - date );
  1543. //console.log(" " );
  1544. if( first ){
  1545. var dn1 = first.retrieve("dn");
  1546. var dn2 = this.currentCategoryItemNode.retrieve("dn");
  1547. if( dn1 && dn2 ){
  1548. if( dn1 != dn2 ){
  1549. categoryItemNode.click();
  1550. this.currentCategoryItemNode = categoryItemNode
  1551. }
  1552. }else{
  1553. var title1 = first.get("title");
  1554. var title2 = this.currentCategoryItemNode.get("title");
  1555. if( title1 && title1 ){
  1556. if( title1 != title2 ){
  1557. categoryItemNode.click();
  1558. this.currentCategoryItemNode = categoryItemNode
  1559. }
  1560. }else{
  1561. var text1 = first.get("text");
  1562. var text2 = this.currentCategoryItemNode.get("text");
  1563. if( text1 != text2 ){
  1564. categoryItemNode.click();
  1565. this.currentCategoryItemNode = categoryItemNode
  1566. }
  1567. }
  1568. }
  1569. }
  1570. }
  1571. }
  1572. return subCategoryListNode;
  1573. }
  1574. //checkClickFlatCategoryItem : function(categoryItemNode, itemNodeContainer){
  1575. // if( !this.flatCategorySeqObj_current ){
  1576. // this.flatCategorySeqObj_current = categoryItemNode.retrieve("seq");
  1577. // //console.log(this.flatCategorySeqObj_current)
  1578. // return true;
  1579. // }
  1580. // var seq_cur = this.flatCategorySeqObj_current;
  1581. // var seq = categoryItemNode ? categoryItemNode.retrieve("seq") : [];
  1582. // for( var i=0; i<seq.length; i++ ){
  1583. // if( seq_cur[i] && seq[i] < seq_cur[i] ){
  1584. // //console.log(seq)
  1585. // this.flatCategorySeqObj_current = seq;
  1586. // return true;
  1587. // }else if( !seq_cur[i] || seq[i] > seq_cur[i] ){
  1588. // return false;
  1589. // }
  1590. // }
  1591. // return false;
  1592. //},
  1593. //setFlatCategorySequence: function(categoryItemNode, itemNodeContainer, subCategoryListNode){
  1594. // if( !this.flatCategorySeqObj )this.flatCategorySeqObj = {};
  1595. // var parentSeq = itemNodeContainer ? itemNodeContainer.retrieve("seq") : [];
  1596. // var seq = Array.clone( parentSeq );
  1597. // if( this.flatCategorySeqObj[ parentSeq.length ] ){
  1598. // seq.push( this.flatCategorySeqObj[ parentSeq.length ] + 1 );
  1599. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1600. //
  1601. // categoryItemNode.store( "seq", seq );
  1602. // categoryItemNode.set( "seq", seq );
  1603. //
  1604. // if(subCategoryListNode){
  1605. // seq = Array.clone( seq );
  1606. // seq[ seq.length - 1 ] = seq[ seq.length - 1 ]+1;
  1607. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1608. // subCategoryListNode.store("seq", seq );
  1609. // subCategoryListNode.set( "seq", seq );
  1610. // }
  1611. // }else{
  1612. // seq.push( 1 );
  1613. // this.flatCategorySeqObj[ parentSeq.length ] = 1;
  1614. // categoryItemNode.store( "seq", seq );
  1615. // categoryItemNode.set( "seq", seq );
  1616. //
  1617. // if(subCategoryListNode) {
  1618. // seq = Array.clone(seq);
  1619. // seq[seq.length - 1] = seq[seq.length - 1]+1;
  1620. // this.flatCategorySeqObj[parentSeq.length] = this.flatCategorySeqObj[parentSeq.length]+1;
  1621. // subCategoryListNode.store("seq", seq);
  1622. // subCategoryListNode.set("seq", seq);
  1623. // }
  1624. // }
  1625. //}
  1626. });
  1627. MWF.xApplication.Selector.Person.Item = new Class({
  1628. initialize: function(data, selector, container, level, category, delay){
  1629. this.clazz = "Item";
  1630. this.data = data;
  1631. this.selector = selector;
  1632. this.container = container;
  1633. this.isSelected = false;
  1634. this.level = (level) ? level.toInt() : 1;
  1635. this.category = category;
  1636. this.subItems = [];
  1637. this.subCategorys = [];
  1638. if(!delay)this.load();
  1639. },
  1640. _getShowName: function(){
  1641. return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
  1642. },
  1643. _getTtiteText: function(){
  1644. return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
  1645. },
  1646. _setIcon: function(){
  1647. var style = this.selector.options.style;
  1648. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)");
  1649. },
  1650. load: function(){
  1651. if( this.clazz === "Item" ){
  1652. this.selector.fireEvent("queryLoadItem",[this]);
  1653. }
  1654. if( !this.node )this.node = new Element("div", {
  1655. "styles": this.selector.css.selectorItem
  1656. }).inject(this.container);
  1657. this.levelNode = new Element("div", {
  1658. "styles": this.selector.css.selectorItemLevelNode
  1659. }).inject(this.node);
  1660. if( this.selector.selectType !== "identity" || this.selector.options.identityItemWidth === 0 ) {
  1661. var indent = this.selector.options.level1Indent + (this.level - 1) * this.selector.options.indent;
  1662. this.levelNode.setStyle("width", "" + indent + "px");
  1663. }
  1664. this.iconNode = new Element("div", {
  1665. "styles": this.selector.css.selectorItemIconNode
  1666. }).inject(this.node);
  1667. this._setIcon();
  1668. this.actionNode = new Element("div", {
  1669. "styles": this.selector.css.selectorItemActionNode
  1670. }).inject(this.node);
  1671. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1672. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1673. }
  1674. this.textNode = new Element("div", {
  1675. "styles": this.selector.css.selectorItemTextNode,
  1676. "text": this._getShowName(),
  1677. "title": this._getTtiteText()
  1678. }).inject(this.node);
  1679. this.textNode.store("indent", indent);
  1680. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  1681. this.textNode.setStyle("margin-left", ""+m+"px");
  1682. if( this.selector.options.identityItemWidth && this.selector.selectType === "identity"){
  1683. this.node.setStyles({
  1684. "float" : "left",
  1685. "min-width" : this.selector.options.identityItemWidth + "px"
  1686. })
  1687. }
  1688. if(this.postLoad)this.postLoad();
  1689. this.loadSubItem();
  1690. this.setEvent();
  1691. this.check();
  1692. if( this.clazz === "Item" ) {
  1693. this.selector.fireEvent("postLoadItem", [this]);
  1694. }
  1695. },
  1696. loadSubItem: function(){},
  1697. disable : function(){
  1698. this.node.hide();
  1699. this.disabled = true;
  1700. },
  1701. enable : function(){
  1702. this.node.show();
  1703. this.disabled = false;
  1704. },
  1705. check: function(){
  1706. //if (this.selector.options.count.toInt()===1){
  1707. // this.checkSelectedSingle();
  1708. //}else{
  1709. this.checkSelected();
  1710. //}
  1711. },
  1712. checkSelectedSingle: function(){
  1713. var selectedItem = this.selector.options.values.filter(function(item, index){
  1714. if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
  1715. if (typeOf(item)==="string") return this.data.distinguishedName === item;
  1716. return false;
  1717. }.bind(this));
  1718. if (selectedItem.length){
  1719. this.selectedSingle();
  1720. }
  1721. },
  1722. checkSelected: function(){
  1723. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  1724. return item.data.distinguishedName === this.data.distinguishedName;
  1725. }.bind(this));
  1726. if (selectedItem.length){
  1727. //selectedItem[0].item = this;
  1728. selectedItem[0].addItem(this);
  1729. this.selectedItem = selectedItem[0];
  1730. this.setSelected();
  1731. }
  1732. },
  1733. checkTextNodeIndent : function( textNode, styles ){
  1734. var indent = textNode.retrieve("indent");
  1735. if( indent && styles && styles["margin-left"] ){
  1736. var m = styles["margin-left"].toFloat()+indent;
  1737. textNode.setStyle("margin-left", ""+m+"px");
  1738. }
  1739. },
  1740. setSelected: function(){
  1741. this.isSelected = true;
  1742. this.node.setStyles(this.selector.css.selectorItem_selected);
  1743. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1744. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
  1745. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1746. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1747. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1748. }
  1749. // if( this.category ){
  1750. // this.category.checkSelectAll();
  1751. // }
  1752. },
  1753. setEvent: function(){
  1754. this.node.addEvents({
  1755. "mouseover": function(){
  1756. this.overItem();
  1757. }.bind(this),
  1758. "mouseout": function(){
  1759. this.outItem();
  1760. }.bind(this),
  1761. "click": function(){
  1762. this.clickItem( null, true );
  1763. }.bind(this)
  1764. });
  1765. },
  1766. clickItem: function( callback, checkValid ){
  1767. // if ( layout.mobile && this.selector.options.count.toInt()===1){
  1768. // this.selectedSingle( checkValid );
  1769. // }else{
  1770. if (this.isSelected){
  1771. this.unSelected( checkValid );
  1772. }else{
  1773. this.selected( checkValid );
  1774. }
  1775. // }
  1776. },
  1777. overItem: function(){
  1778. if (!this.isSelected ){
  1779. this.node.setStyles(this.selector.css.selectorItem_over);
  1780. }else if( this.selector.css.selectorItem_over_force ){
  1781. this.node.setStyles(this.selector.css.selectorItem_over_force);
  1782. }
  1783. if (!this.isSelected){
  1784. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  1785. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_over ){
  1786. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_over );
  1787. }
  1788. }else if( this.selector.css.selectorItemActionNode_over_force ){
  1789. this.node.setStyles(this.selector.css.selectorItemActionNode_over_force);
  1790. }
  1791. },
  1792. outItem: function(){
  1793. if (!this.isSelected){
  1794. this.node.setStyles(this.selector.css.selectorItem);
  1795. }else if( this.selector.css.selectorItem_over_force ){
  1796. this.node.setStyles(this.selector.css.selectorItem_selected);
  1797. }
  1798. if (!this.isSelected){
  1799. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1800. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1801. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1802. }
  1803. }else if( this.selector.css.selectorItemActionNode_over_force ){
  1804. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1805. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1806. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1807. }
  1808. }
  1809. },
  1810. selectedSingle: function( checkValid ){
  1811. if (!this.isSelected){
  1812. if (this.selector.currentItem) this.selector.currentItem.unSelectedSingle();
  1813. this.selector.emptySelectedItems();
  1814. this.getData(function(){
  1815. this.selector.currentItem = this;
  1816. this.isSelected = true;
  1817. this.selector.selectedItems.push(this);
  1818. this.node.setStyles(this.selector.css.selectorItem_selected);
  1819. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1820. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
  1821. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1822. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1823. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1824. }
  1825. this.selector.fireEvent("selectItem",[this]);
  1826. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1827. }.bind(this));
  1828. }else {
  1829. this.selector.emptySelectedItems();
  1830. this.unSelectedSingle( checkValid );
  1831. }
  1832. },
  1833. getData: function(callback){
  1834. if (callback) callback();
  1835. },
  1836. unSelectedSingle: function(checkValid){
  1837. this.selector.currentItem = null;
  1838. this.isSelected = false;
  1839. this.selector.selectedItems.erase(this);
  1840. this.node.setStyles(this.selector.css.selectorItem);
  1841. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1842. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode );
  1843. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1844. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1845. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1846. }
  1847. this.selector.fireEvent("unselectItem",[this]);
  1848. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1849. },
  1850. selected: function( checkValid, callback, selectedNode, bySelectAll ){
  1851. var count = this.selector.options.maxCount || this.selector.options.count;
  1852. count = count.toInt();
  1853. if (!count) count = 0;
  1854. if( count == 1 && this.selector.emptySelectedItems){
  1855. this.selector.emptySelectedItems();
  1856. }
  1857. if ((count===0) || (this.selector.selectedItems.length+1)<=count) {
  1858. this.isSelected = true;
  1859. if( this.node ){
  1860. this.node.setStyles(this.selector.css.selectorItem_selected);
  1861. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1862. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode_selected );
  1863. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1864. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  1865. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  1866. }
  1867. }
  1868. this.selectedItem = this.selector._newItemSelected(this.data, this.selector, this, selectedNode);
  1869. // this.selectedItem.check();
  1870. this.selector.selectedItems.push(this.selectedItem);
  1871. // if( this.category ){
  1872. // this.category.checkSelectAll();
  1873. // }
  1874. this.selector.fireEvent("selectItem",[this]);
  1875. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1876. if(callback)callback();
  1877. }else{
  1878. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
  1879. }
  1880. },
  1881. unSelected: function( checkValid, callback ){
  1882. var isSelected = this.isSelected;
  1883. this.isSelected = false;
  1884. if( this.node ){
  1885. this.node.setStyles(this.selector.css.selectorItem);
  1886. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1887. this.checkTextNodeIndent( this.textNode, this.selector.css.selectorItemTextNode );
  1888. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1889. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1890. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1891. }
  1892. }
  1893. if( this.category && this.selector.options.selectAllRange !== "all" ){
  1894. this.category.checkUnselectAll();
  1895. }
  1896. if( this.selector.searchItems && this.selector.searchItems.length ){
  1897. this.selector.searchItems.each( function(itemSearch){
  1898. var sd = itemSearch.data;
  1899. var d = this.data;
  1900. if(
  1901. ( sd.distinguishedName && (sd.distinguishedName === d.distinguishedName) ) ||
  1902. ( sd.id && (sd.id === d.id) ) ||
  1903. ( sd.unique && (sd.unique === d.unique) ) ||
  1904. ( sd.employee && (sd.employee === d.employee) ) ||
  1905. ( sd.levelName && (sd.levelName === d.levelName) )
  1906. ){
  1907. itemSearch.isSelected = false;
  1908. itemSearch.node.setStyles(this.selector.css.selectorItem);
  1909. itemSearch.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1910. this.checkTextNodeIndent( itemSearch.textNode, this.selector.css.selectorItemTextNode );
  1911. itemSearch.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1912. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1913. itemSearch.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1914. }
  1915. }
  1916. }.bind(this))
  1917. }
  1918. if (this.selectedItem){
  1919. this.selector.selectedItems.erase(this.selectedItem);
  1920. this.selectedItem.items.each(function(item){
  1921. if( item.isSelected || ( item === this && isSelected ) ){
  1922. var flag = this.selector.options.selectAllRange === "all" ||
  1923. ( this.selector.selectType == "identity" && ( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ));
  1924. if( flag ){
  1925. if(item.category && item.category._addSelectedCount )item.category._addSelectedCount( -1, true );
  1926. }
  1927. }
  1928. if (item != this){
  1929. item.isSelected = false;
  1930. item.node.setStyles(this.selector.css.selectorItem);
  1931. item.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1932. this.checkTextNodeIndent( item.textNode, this.selector.css.selectorItemTextNode );
  1933. item.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1934. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single ){
  1935. item.actionNode.setStyles( this.selector.css.selectorItemActionNode_single );
  1936. }
  1937. }
  1938. }.bind(this));
  1939. this.selectedItem.destroy();
  1940. this.selectedItem = null;
  1941. }
  1942. this.selector.fireEvent("unselectItem",[this]);
  1943. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  1944. if(callback)callback();
  1945. },
  1946. postLoad : function(){},
  1947. getParentCategoryByLevel : function( level ){
  1948. var category = this.category;
  1949. do{
  1950. if( category.level === level ){
  1951. return category;
  1952. }else{
  1953. category = category.category;
  1954. }
  1955. }while( category )
  1956. }
  1957. });
  1958. MWF.xApplication.Selector.Person.ItemSelected = new Class({
  1959. Extends: MWF.xApplication.Selector.Person.Item,
  1960. initialize: function(data, selector, item, selectedNode){
  1961. this.data = data;
  1962. this.selector = selector;
  1963. this.container = selectedNode || this.selector.selectedNode;
  1964. this.isSelected = false;
  1965. this.clazz = "ItemSelected";
  1966. this.items = [];
  1967. if (item) this.items.push(item);
  1968. this.level = 0;
  1969. this.node = new Element("div", {
  1970. "styles": this.selector.css.selectorItem
  1971. }).inject(this.container);
  1972. this.node.setStyle("display","none");
  1973. this.getData(function(){
  1974. this.node.setStyle("display","");
  1975. this.load();
  1976. }.bind(this));
  1977. },
  1978. postLoad : function(){
  1979. if( this.selector.css.selectorSelectedItemActionNode ){
  1980. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode );
  1981. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorSelectedItemActionNode_single ){
  1982. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode_single );
  1983. }
  1984. }
  1985. if( this.selector.css.selectorSelectedItemTextNode ){
  1986. this.textNode.setStyles(this.selector.css.selectorSelectedItemTextNode);
  1987. }
  1988. },
  1989. getData: function(callback){
  1990. if (callback) callback();
  1991. },
  1992. clickItem: function( callback, checkValid ){
  1993. if (this.items.length){
  1994. this.items.each(function(item){
  1995. item.unSelected( checkValid );
  1996. });
  1997. if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
  1998. }else{
  1999. //this.item.selectedItem = null;
  2000. //this.item.isSelected = false;
  2001. this.destroy();
  2002. this.selector.selectedItems.erase(this);
  2003. if( checkValid )this.selector.fireEvent("valid", [this.selector, this])
  2004. }
  2005. },
  2006. //overItem: function(){
  2007. // if (!this.isSelected){
  2008. // this.node.setStyles(this.selector.css.selectorItem_over);
  2009. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  2010. // }
  2011. //},
  2012. overItem: function(){
  2013. if (!this.isSelected ){
  2014. if( this.selector.css.selectorItem_selected_over ){
  2015. this.node.setStyles(this.selector.css.selectorItem_selected_over);
  2016. }else{
  2017. this.node.setStyles(this.selector.css.selectorItem_over);
  2018. }
  2019. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  2020. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected_over ){
  2021. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected_over );
  2022. }
  2023. }
  2024. },
  2025. outItem: function(){
  2026. if (!this.isSelected){
  2027. var styles = this.selector.css.selectorSelectedItem || this.selector.css.selectorItem;
  2028. this.node.setStyles(styles);
  2029. }else if( this.selector.css.selectorItem_over_force ){
  2030. this.node.setStyles(this.selector.css.selectorItem_selected);
  2031. }
  2032. if (!this.isSelected){
  2033. var styles = this.selector.css.selectorSelectedItemActionNode || this.selector.css.selectorItemActionNode;
  2034. this.actionNode.setStyles(styles);
  2035. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) &&
  2036. ( this.selector.css.selectorSelectedItemActionNode_single || this.selector.css.selectorItemActionNode_single ) ){
  2037. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode_single || this.selector.css.selectorItemActionNode_single );
  2038. }
  2039. }else if( this.selector.css.selectorItemActionNode_over_force ){
  2040. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  2041. if( ( this.selector.options.count.toInt() === 1 || this.selector.options.noSelectedContainer ) && this.selector.css.selectorItemActionNode_single_selected ){
  2042. this.actionNode.setStyles( this.selector.css.selectorItemActionNode_single_selected );
  2043. }
  2044. }
  2045. },
  2046. addItem: function(item){
  2047. if (this.items.indexOf(item)===-1) this.items.push(item);
  2048. },
  2049. check: function(){
  2050. if (this.selector.items.length){
  2051. var items = this.selector.items.filter(function(item, index){
  2052. return item.data.distinguishedName === this.data.distinguishedName;
  2053. }.bind(this));
  2054. this.items = items;
  2055. if (items.length){
  2056. items.each(function(item){
  2057. item.selectedItem = this;
  2058. item.setSelected();
  2059. // if( this.selector.options.showSelectedCount ){
  2060. // if(item.category)item.category._addSelectedCount( 1, true );
  2061. // }
  2062. }.bind(this));
  2063. }
  2064. }
  2065. if( this.afterCheck )this.afterCheck();
  2066. },
  2067. destroy: function(){
  2068. if(this.node){
  2069. // var parent = this.node.getParent(".categorySelectedNode");
  2070. // if( parent && !this.node.getPrevious() && !this.node.getNext() ){ //parent.getChildren().length <= 1
  2071. // parent.destroy();
  2072. // }else{
  2073. this.node.destroy();
  2074. // }
  2075. }
  2076. delete this;
  2077. }
  2078. });
  2079. MWF.xApplication.Selector.Person.ItemCategory = new Class({
  2080. Extends: MWF.xApplication.Selector.Person.Item,
  2081. initialize: function(data, selector, container, level, parentCategory, delay){
  2082. this.data = data;
  2083. this.selector = selector;
  2084. this.container = container;
  2085. this.isSelected = false;
  2086. this.level = (level) ? level.toInt() : 1;
  2087. this.category = parentCategory;
  2088. this.subItems = [];
  2089. this.subCategorys = [];
  2090. if(!delay)this.load();
  2091. },
  2092. load : function(){
  2093. if( this.selector.isFlatCategory ){
  2094. this.loadForFlat();
  2095. }else{
  2096. this.loadForNormal();
  2097. }
  2098. },
  2099. loadForFlat : function(){
  2100. this.selector.fireEvent("queryLoadCategory",[this]);
  2101. //this.createNode();
  2102. this.node = new Element("div.flatCategoryItemNode", {
  2103. "styles": this.selector.css.flatCategoryItemNode,
  2104. "title" : this._getTtiteText()
  2105. });
  2106. this.node.store( "category", this );
  2107. this.node.store( "dn", this.data.distinguishedName );
  2108. this.textNode = new Element("div", {
  2109. "styles": this.selector.css.flatCategoryItemTextNode,
  2110. "text": this._getShowName()
  2111. }).inject(this.node);
  2112. //var level = this.level;
  2113. //var category = this;
  2114. //while( category.category ){
  2115. // level = category.category + "_" + level;
  2116. // category = category.category;
  2117. //}
  2118. this.children = new Element("div", {
  2119. "styles": this.selector.css.selectorItemCategoryChildrenNode
  2120. }).inject(this.selector.itemAreaNode); //this.container
  2121. //if (!this.selector.options.expand)
  2122. this.children.setStyle("display", "none");
  2123. if( this.selector.options.selectAllEnable && this.selector.options.count.toInt()!==1 ){
  2124. var selectAllWrap = new Element("div",{
  2125. styles : this.selector.css.flatCategory_selectAllWrap
  2126. }).inject(this.children);
  2127. this.selectAllNode = new Element("div", {
  2128. "styles": this.selector.css.flatCategory_selectAll,
  2129. "text" : "全选"
  2130. }).inject(selectAllWrap);
  2131. this.selectAllNode.addEvent( "click", function(ev){
  2132. if( this.isSelectedAll ){
  2133. this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
  2134. this.selector.fireEvent("unselectCatgory",[this]);
  2135. this.selector.fireEvent("unselectCatgeory",[this]);
  2136. }else{
  2137. this.selector.options.selectAllRange === "all" ? this.selectAllNested(ev, true) : this.selectAll(ev, true);
  2138. this.selector.fireEvent("selectCatgory",[this]);
  2139. this.selector.fireEvent("selectCatgeory",[this]);
  2140. }
  2141. ev.stopPropagation();
  2142. }.bind(this));
  2143. }
  2144. // var subIdList = this.selector._getChildrenItemIds(this.data);
  2145. // if (subIdList){
  2146. // var count = subIdList.length;
  2147. // this.childrenHeight = count*this.selector.options.itemHeight;
  2148. // this.children.setStyle("height", ""+this.childrenHeight+"px");
  2149. // }
  2150. //if (!this._hasChild()){
  2151. // this.textNode.setStyle("color", "#333");
  2152. //}
  2153. if( this.selectAllNode ){
  2154. if( this.selector.options.selectAllRange === "direct" && !this._hasChildItem() ){
  2155. this.selectAllNode.setStyle("display", "none");
  2156. }
  2157. }
  2158. this.node.addEvents({
  2159. //"mouseover": function(){
  2160. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode_over );
  2161. //}.bind(this),
  2162. //"mouseout": function(){
  2163. // if (!this.isSelected )this.node.setStyles(this.selector.css.flatCategoryItemNode );
  2164. //}.bind(this),
  2165. "click": function(){
  2166. if( this.selector.currentFlatCategory === this )return;
  2167. if( this.selector.currentFlatCategory ){
  2168. this.selector.currentFlatCategory.clickFlatCategoryItem(null, true); //取消原来选择的
  2169. }
  2170. this.selector.currentFlatCategory = this;
  2171. this.clickFlatCategoryItem();
  2172. }.bind(this)
  2173. });
  2174. //this.setEvent();
  2175. var isCreateSubCategoryListNode = this._hasChildCategory ? this._hasChildCategory() : true;
  2176. var nodeContainer;
  2177. if( this.nodeContainer ){
  2178. nodeContainer = this.nodeContainer;
  2179. }else{
  2180. nodeContainer = (this.category && this.category.subCategoryListNode) ? this.category.subCategoryListNode : null;
  2181. }
  2182. this.subCategoryListNode = this.selector.addFlatCategoryItem( this.node, this._hasChildItem(), nodeContainer, isCreateSubCategoryListNode );
  2183. this.check();
  2184. if( this.loadCategoryChildren )this.loadCategoryChildren();
  2185. //this.afterLoad();
  2186. this.selector.fireEvent("postLoadCategory",[this]);
  2187. },
  2188. loadForNormal : function(){
  2189. this.selector.fireEvent("queryLoadCategory",[this]);
  2190. this.createNode();
  2191. this.levelNode = new Element("div", {
  2192. "styles": this.selector.css.selectorItemLevelNode
  2193. }).inject(this.node);
  2194. if(this.selector.selectType !== "identity" || this.selector.options.identityItemWidth === 0 ){
  2195. var indent = this.selector.options.level1Indent + (this.level - 1) * this.selector.options.indent;
  2196. this.levelNode.setStyle("width", "" + indent + "px");
  2197. }else{
  2198. this.node.setStyle("clear","both");
  2199. }
  2200. this.iconNode = new Element("div", {
  2201. "styles": this.selector.css.selectorItemCategoryIconNode || this.selector.css.selectorItemIconNode
  2202. }).inject(this.node);
  2203. this._setIcon();
  2204. this.actionNode = new Element("div", {
  2205. "styles": (this.selector.options.expand) ? this.selector.css.selectorItemCategoryActionNode_expand : this.selector.css.selectorItemCategoryActionNode_collapse
  2206. }).inject(this.node);
  2207. if( this.selector.options.selectAllEnable && this.selector.options.count.toInt()!==1 ){
  2208. this.selectAllNode = new Element("div", {
  2209. "styles": this.selector.css.selectorItemCategoryActionNode_selectAll,
  2210. "title" : "全选下级"
  2211. }).inject(this.node);
  2212. this.selectAllNode.addEvent( "click", function(ev){
  2213. if( this.isSelectedAll ){
  2214. // this.unselectAll(ev);
  2215. this.selector.options.selectAllRange === "all" ? this.unselectAllNested(ev, null, true ) : this.unselectAll(ev, null, true);
  2216. this.selector.fireEvent("unselectCatgory",[this]);
  2217. this.selector.fireEvent("unselectCategory",[this]);
  2218. }else{
  2219. // this.selectAll(ev);
  2220. if( this.selector.options.selectAllRange === "all" ){
  2221. var node = new Element("div.categorySelectedNode").inject( this.selector.selectedNode );
  2222. this.selectAllNested(ev, true, node );
  2223. }else{
  2224. this.selectAll(ev, true)
  2225. }
  2226. this.selector.fireEvent("selectCatgory",[this]);
  2227. this.selector.fireEvent("selectCategory",[this]);
  2228. }
  2229. ev.stopPropagation();
  2230. }.bind(this));
  2231. if( this.selector.css.selectorItemCategoryActionNode_selectAll_over ){
  2232. this.selectAllNode.addEvents( {
  2233. "mouseover" : function(ev){
  2234. if( !this.isSelectedAll && !this.isSelectedSome )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_over );
  2235. //ev.stopPropagation();
  2236. }.bind(this),
  2237. "mouseout" : function(ev){
  2238. if( !this.isSelectedAll && !this.isSelectedSome )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2239. //ev.stopPropagation();
  2240. }.bind(this)
  2241. })
  2242. }
  2243. }
  2244. this.textNode = new Element("div", {
  2245. "styles": this.selector.css.selectorItemCategoryTextNode,
  2246. "text": this._getShowName()
  2247. }).inject(this.node);
  2248. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  2249. this.textNode.setStyle("margin-left", ""+m+"px");
  2250. if( this.selector.options.showSelectedCount && this.selector.selectType == "identity" ){
  2251. this.selectedCountNode = new Element("span").inject(this.textNode);
  2252. }
  2253. this.children = new Element("div.children", {
  2254. "styles": this.selector.css.selectorItemCategoryChildrenNode
  2255. }).inject(this.node, "after");
  2256. if (!this.selector.options.expand) this.children.setStyle("display", "none");
  2257. if( this.selector.options.expandEmptyCategory && !this._hasChildItem() ){ //点击允许展开空分类
  2258. this.children.hide();
  2259. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  2260. this.isExpand = false;
  2261. }else{
  2262. var subIdList = this.selector._getChildrenItemIds(this.data);
  2263. if (subIdList){
  2264. var count = subIdList.length;
  2265. this.childrenHeight = count*this.selector.options.itemHeight;
  2266. this.children.setStyle("height", ""+this.childrenHeight+"px");
  2267. }
  2268. if(this.selector.options.identityItemWidth && this.selector.selectType === "identity"){
  2269. var indent = this.level === 0 ? this.selector.options.level1Indent : this.selector.options.indent;
  2270. this.children.setStyles({
  2271. "padding-left": "" + indent + "px",
  2272. "overflow" : "hidden"
  2273. });
  2274. }
  2275. if ( !this._hasChild()){
  2276. if( this.selector.options.hiddenEmptyCategory ){
  2277. this.node.hide()
  2278. }else{
  2279. this.actionNode.setStyle("background", "transparent");
  2280. this.textNode.setStyle("color", "#777");
  2281. }
  2282. }
  2283. if( this.selectAllNode ){
  2284. if( this.selector.options.selectAllRange === "direct" && !this._hasChildItem() ){
  2285. this.selectAllNode.setStyle("display", "none");
  2286. }
  2287. }
  2288. }
  2289. this.setEvent();
  2290. this.check();
  2291. this.afterLoad();
  2292. this.selector.fireEvent("postLoadCategory",[this]);
  2293. },
  2294. createNode: function(){
  2295. this.node = new Element("div", {
  2296. "styles": this.selector.css.selectorItemCategory,
  2297. "title" : this._getTtiteText()
  2298. }).inject(this.container);
  2299. },
  2300. unselectAll : function(ev, exclude, checkValid ){
  2301. var fun = function(){
  2302. var excludeList = exclude || [];
  2303. if( exclude && typeOf(exclude) !== "array" )excludeList = [exclude];
  2304. ( this.subItems || [] ).each( function(item){
  2305. if(item.isSelected && !excludeList.contains(item) ){
  2306. item.unSelected( checkValid );
  2307. }
  2308. }.bind(this));
  2309. if( this.selectAllNode ){
  2310. if( this.selector.isFlatCategory ){
  2311. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  2312. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll){
  2313. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2314. }
  2315. }
  2316. this.isSelectedAll = false;
  2317. }.bind(this);
  2318. if( this.loaded ){
  2319. fun();
  2320. }else{
  2321. this.clickItem( function(){
  2322. fun();
  2323. }.bind(this))
  2324. }
  2325. },
  2326. unselectAllNested : function( ev, exclude, checkValid ){
  2327. this.unselectAll(ev, exclude, checkValid);
  2328. if( this.subCategorys && this.subCategorys.length ){
  2329. this.subCategorys.each( function( category ){
  2330. category.unselectAllNested( ev, exclude, checkValid )
  2331. })
  2332. }
  2333. },
  2334. selectAllNested : function( ev, checkValid, selectedNode ){
  2335. var node;
  2336. if(selectedNode)node = new Element("div.categorySelectedNode").inject( selectedNode );
  2337. this.selectAll(ev, checkValid, node, function () {
  2338. if( this.subCategorys && this.subCategorys.length ){
  2339. this.subCategorys.each( function( category ){
  2340. if(selectedNode)var node = new Element("div.categorySelectedNode").inject( selectedNode );
  2341. category.selectAllNested(ev, checkValid, node)
  2342. })
  2343. }
  2344. }.bind(this));
  2345. },
  2346. selectAll: function(ev, checkValid, selectedNode, callback){
  2347. if( this.loaded || this.selector.isFlatCategory ){
  2348. this._selectAll( ev, checkValid, selectedNode );
  2349. if(callback)callback();
  2350. }else{
  2351. this.clickItem( function(){
  2352. this._selectAll( ev, checkValid, selectedNode );
  2353. if(callback)callback();
  2354. //this.children.setStyles({
  2355. // "display": "none",
  2356. // "height": "0px"
  2357. //});
  2358. //this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  2359. }.bind(this));
  2360. }
  2361. },
  2362. _selectAll : function( ev, checkValid, selectedNode ){
  2363. if( this.selector.options.selectAllRange === "direct" && ( !this.subItems || !this.subItems.length ) )return;
  2364. var count = this.selector.options.maxCount || this.selector.options.count;
  2365. if (!count) count = 0;
  2366. var selectedSubItemCount = 0;
  2367. this.subItems.each( function(item){
  2368. if(item.isSelected)selectedSubItemCount++
  2369. }.bind(this));
  2370. if ((count.toInt()===0) || (this.selector.selectedItems.length+(this.subItems.length-selectedSubItemCount))<=count){
  2371. var checkedCount = 0;
  2372. var doSelectAll = function () {
  2373. this.subItems.each( function(item){
  2374. if(!item.isSelected && !item.disabled )item.selected( false, function () {
  2375. checkedCount++;
  2376. if( this.subItems.length === checkedCount ){
  2377. if( checkValid )this.selector.fireEvent("valid", [this.selector, this]);
  2378. }
  2379. }.bind(this), selectedNode);
  2380. }.bind(this));
  2381. if( this.selectAllNode ){
  2382. if( this.selector.isFlatCategory ){
  2383. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
  2384. }else if(this.selector.css.selectorItemCategoryActionNode_selectAll_selected){
  2385. var styles = this.selector.css.selectorItemCategoryActionNode_selectAll_selected;
  2386. if( this.selector.options.isCheckStatus && this.selector.selectType === "identity" ){
  2387. if( this._getSelectedCount() < this._getTotalCount() ){
  2388. styles = this.selector.css.selectorItemCategoryActionNode_selectsome_selected;
  2389. }
  2390. }
  2391. this.selectAllNode.setStyles( styles );
  2392. }
  2393. }
  2394. this.isSelectedAll = true;
  2395. }.bind(this);
  2396. if( this._beforeSelectAll ){
  2397. this._beforeSelectAll( doSelectAll );
  2398. }else{
  2399. doSelectAll();
  2400. }
  2401. }else{
  2402. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
  2403. }
  2404. },
  2405. checkSelectAll : function(){
  2406. if( this.isSelectedAll )return;
  2407. if( !this.selectAllNode )return;
  2408. if( !this.subItems )return;
  2409. var isAllItemSelected = true;
  2410. for( var i=0; i< this.subItems.length; i++ ){
  2411. if( !this.subItems[i].isSelected ){
  2412. isAllItemSelected = false;
  2413. break;
  2414. }
  2415. }
  2416. if( isAllItemSelected ){
  2417. if( this.selector.isFlatCategory ){
  2418. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll_selected );
  2419. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll_selected ){
  2420. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_selected );
  2421. }
  2422. this.isSelectedAll = true;
  2423. }
  2424. },
  2425. checkUnselectAll : function(){
  2426. if( !this.isSelectedAll )return;
  2427. if( !this.selectAllNode )return;
  2428. if( !this.subItems )return;
  2429. var hasSelectedItem = false;
  2430. for( var i=0; i< this.subItems.length; i++ ){
  2431. if( this.subItems[i].isSelected ){
  2432. hasSelectedItem = true;
  2433. break;
  2434. }
  2435. }
  2436. if( !hasSelectedItem ){
  2437. if( this.selector.isFlatCategory ){
  2438. this.selectAllNode.setStyles( this.selector.css.flatCategory_selectAll );
  2439. }else if( this.selector.css.selectorItemCategoryActionNode_selectAll ){
  2440. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  2441. }
  2442. this.isSelectedAll = false;
  2443. }
  2444. },
  2445. afterLoad: function(){
  2446. if (this.level===1) this.clickItem();
  2447. },
  2448. clickFlatCategoryItem : function( callback, hidden ){
  2449. if (this._hasChildItem()){
  2450. var display = this.children.getStyle("display");
  2451. if( hidden ){
  2452. this.children.setStyles({ "display": "none" });
  2453. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  2454. this.isExpand = false;
  2455. }else if (display === "none"){
  2456. this.children.setStyles({
  2457. "display": "block",
  2458. "height": "auto"
  2459. });
  2460. this.node.setStyles( this.selector.css.flatCategoryItemNode_selected );
  2461. this.isExpand = true;
  2462. }else{
  2463. this.children.setStyles({
  2464. "display": "none"
  2465. });
  2466. this.node.setStyles( this.selector.css.flatCategoryItemNode );
  2467. this.isExpand = false;
  2468. }
  2469. if(callback)callback()
  2470. }
  2471. },
  2472. clickItem: function( callback ){
  2473. if (this._hasChild() || this.selector.options.expandEmptyCategory ){
  2474. if (!this.fx){
  2475. this.fx = new Fx.Tween(this.children, {
  2476. "duration": 200
  2477. // "transition": Fx.Transitions.Cubic.easeIn
  2478. });
  2479. }
  2480. if (!this.fx.isRunning()){
  2481. var display = this.children.getStyle("display");
  2482. if (display === "none"){
  2483. this.children.setStyles({
  2484. "display": "block",
  2485. "height": "0px"
  2486. });
  2487. this.fx.start("height", "0px", ""+this.childrenHeight+"px");
  2488. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  2489. this.isExpand = true;
  2490. this.selector.fireEvent("expand", [this] );
  2491. }else{
  2492. if (!this.childrenHeight) this.childrenHeight = this.children.getStyle("height").toFloat();
  2493. this.fx.start("height", ""+this.childrenHeight+"px", "0px").chain(function(){
  2494. this.children.setStyles({
  2495. "display": "none",
  2496. "height": "0px"
  2497. });
  2498. }.bind(this));
  2499. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  2500. this.isExpand = false;
  2501. this.selector.fireEvent("collapse", [this] );
  2502. }
  2503. }
  2504. if(callback)callback()
  2505. }
  2506. },
  2507. overItem: function(){
  2508. //if (!this.isSelected){
  2509. // this.node.setStyles(this.selector.css.selectorItem_over);
  2510. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  2511. //}
  2512. if( this.selector.css.selectorItemCategory_over ){
  2513. this.node.setStyles(this.selector.css.selectorItemCategory_over);
  2514. }
  2515. var display = this.children.getStyle("display");
  2516. if( display === "none" ){
  2517. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
  2518. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse_over )
  2519. }
  2520. }else{
  2521. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
  2522. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand_over )
  2523. }
  2524. }
  2525. },
  2526. outItem: function(){
  2527. //if (!this.isSelected){
  2528. // this.node.setStyles(this.selector.css.selectorItem);
  2529. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  2530. //}
  2531. if( this.selector.css.selectorItemCategory_over ){
  2532. this.node.setStyles(this.selector.css.selectorItemCategory);
  2533. }
  2534. var display = this.children.getStyle("display");
  2535. if( display === "none" ){
  2536. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
  2537. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse )
  2538. }
  2539. }else{
  2540. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
  2541. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand )
  2542. }
  2543. }
  2544. },
  2545. _hasChild: function(){
  2546. var subIdList = this.selector._getChildrenItemIds(this.data);
  2547. if (subIdList) if (subIdList.length) return true;
  2548. return false;
  2549. },
  2550. _hasChildCategory: function(){
  2551. return null;
  2552. },
  2553. _hasChildItem: function(){
  2554. return this._hasChild();
  2555. },
  2556. _getTtiteText: function(){
  2557. if( this.data.levelName ){
  2558. return this.data.name+"("+ this.data.levelName +")";
  2559. }else{
  2560. return this.data.name;
  2561. }
  2562. }
  2563. });
  2564. MWF.xApplication.Selector.Person.ItemGroupCategory = new Class({
  2565. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  2566. _getShowName: function(){
  2567. return this.data.name;
  2568. },
  2569. _setIcon: function(){
  2570. var style = this.selector.options.style;
  2571. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)");
  2572. }
  2573. });
  2574. MWF.xApplication.Selector.Person.ItemRoleCategory = new Class({
  2575. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  2576. _getShowName: function(){
  2577. return this.data.name;
  2578. },
  2579. _setIcon: function(){
  2580. var style = this.selector.options.style;
  2581. this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/roleicon.png)");
  2582. }
  2583. });
  2584. MWF.xApplication.Selector.Person.Filter = new Class({
  2585. Implements: [Options, Events],
  2586. options: {
  2587. "style": "default",
  2588. "groups": [],
  2589. "roles": []
  2590. },
  2591. initialize: function(value, options){
  2592. this.setOptions(options);
  2593. this.value = value;
  2594. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  2595. },
  2596. filter: function(value, callback){
  2597. this.value = value;
  2598. var key = this.value;
  2599. if (this.options.groups.length || this.options.roles.length) key = {"key": key, "groupList": this.options.groupList, "roleList": this.options.roleList};
  2600. this.orgAction.listPersonByKey(function(json){
  2601. data = json.data;
  2602. if (callback) callback(data)
  2603. }.bind(this), null, key);
  2604. }
  2605. });