Person.js 104 KB

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