Person.js 114 KB

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