Person.js 104 KB

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