Person.js 119 KB

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