Person.js 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885
  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. },
  27. initialize: function(container, options){
  28. this.setOptions(options);
  29. this.path = "/x_component_Selector/$Selector/";
  30. this.cssPath = "/x_component_Selector/$Selector/"+this.options.style+"/css.wcss";
  31. this._loadCss(true);
  32. this.container = $(container);
  33. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  34. //this.org2Action = MWF.Actions.get("x_organization_assemble_express");
  35. this.processAction = MWF.Actions.get("x_processplatform_assemble_surface");
  36. this.designerAction = MWF.Actions.get("x_processplatform_assemble_designer");
  37. this.portalAction = MWF.Actions.get("x_portal_assemble_surface");
  38. this.portalDesignerAction = MWF.Actions.get("x_portal_assemble_designer");
  39. this.cmsAction = MWF.Actions.get("x_cms_assemble_control");
  40. this.queryAction = MWF.Actions.get("x_query_assemble_designer");
  41. //this.action = new MWF.xApplication.Selector.Actions.RestActions();
  42. this.lastPeople = "";
  43. this.pageCount = "13";
  44. this.selectedItems = []; //所有已选项
  45. this.items = []; //所有选择项
  46. this.subCategorys = []; //直接的分类
  47. this.subItems = []; //直接的选择项
  48. },
  49. load: function(){
  50. this.fireEvent("queryLoad",[this]);
  51. if (layout.mobile){
  52. this.loadMobile();
  53. }else{
  54. this.loadPc();
  55. }
  56. this.fireEvent("load");
  57. },
  58. loadMobile: function(){
  59. this.maskRelativeNode = $(document.body);
  60. this.maskRelativeNode.mask({
  61. "destroyOnHide": true,
  62. "style": this.css.maskNode
  63. });
  64. this.node = new Element("div", {"styles": this.css.containerNodeMobile});
  65. this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  66. this.node.setStyle("height", ( document.body.getSize().y ) + "px");
  67. this.titleNode = new Element("div", {
  68. "styles": this.css.titleNodeMobile
  69. }).inject(this.node);
  70. this.titleCancelActionNode = new Element("div", {
  71. "styles": this.css.titleCancelActionNodeMobile,
  72. "text": MWF.SelectorLP.back
  73. }).inject(this.titleNode);
  74. this.titleOkActionNode = new Element("div", {
  75. "styles": this.css.titleOkActionNodeMobile,
  76. "text": MWF.SelectorLP.ok
  77. }).inject(this.titleNode);
  78. this.titleTextNode = new Element("div", {
  79. "styles": this.css.titleTextNodeMobile,
  80. "text": this.options.title
  81. }).inject(this.titleNode);
  82. this.contentNode = new Element("div", {
  83. "styles": this.css.contentNode
  84. }).inject(this.node);
  85. var size = document.body.getSize();
  86. var height = size.y-40;
  87. //var height = size.y;
  88. this.contentNode.setStyle("height", ""+height+"px");
  89. this.loadContent();
  90. this.node.inject(document.body);
  91. this.node.setStyles({
  92. "top": "0px",
  93. "left": "0px"
  94. });
  95. this.setEvent();
  96. },
  97. setMaskResize: function(){
  98. var size = this.container.getSize();
  99. this.mask.resize();
  100. this.maskInterval = window.setInterval(function(){
  101. var resize = this.container.getSize();
  102. if ((size.x!==resize.x) || (size.y!==resize.y)){
  103. this.mask.position();
  104. this.mask.resize();
  105. size.x = resize.x;
  106. size.y = resize.y;
  107. }
  108. }.bind(this), 66);
  109. },
  110. loadPc: function(){
  111. if( this.options.embedded ){
  112. this.node = new Element("div", {
  113. "styles": this.css.containerNode_embedded, //(this.options.count.toInt()===1) ? this.css.containerNodeSingle_embedded : this.css.containerNode_embedded,
  114. "events": {
  115. "click": function(e){e.stopPropagation();},
  116. "mousedown": function(e){e.stopPropagation();},
  117. "mouseover": function(e){e.stopPropagation();},
  118. "mouseout": function(e){e.stopPropagation();},
  119. "keydown": function(e){e.stopPropagation();}
  120. }
  121. });
  122. this.contentNode = new Element("div", {
  123. "styles": this.css.contentNode_embedded ? this.css.contentNode_embedded : this.css.contentNode
  124. }).inject(this.node);
  125. this.loadContent();
  126. if( this.options.width || this.options.height ){
  127. this.setSize()
  128. }
  129. this.node.inject(this.container);
  130. } else {
  131. this.css.maskNode["z-index"] = this.options.zIndex;
  132. var position = this.container.getPosition(this.container.getOffsetParent());
  133. this.mask = new Mask(this.container, {
  134. "destroyOnHide": true,
  135. "style": this.css.maskNode,
  136. "useIframeShim": true,
  137. "iframeShimOptions": {"browsers": true},
  138. "onShow": function () {
  139. this.shim.shim.setStyles({
  140. "opacity": 0,
  141. "top": "" + position.y + "px",
  142. "left": "" + position.x + "px"
  143. });
  144. }
  145. //
  146. // "destroyOnHide": true,
  147. // "style": this.css.maskNode,
  148. // "useIframeShim": true,
  149. // "iframeShimOptions": {"browsers": true},
  150. // "onShow": function(){
  151. // this.shim.shim.setStyles({
  152. // "opacity": 0,
  153. // "top": ""+position.y+"px",
  154. // "left": ""+position.x+"px"
  155. // });
  156. // }
  157. });
  158. this.mask.show();
  159. this.setMaskResize();
  160. // this.container.setStyle("z-index", this.options.zIndex);
  161. this.node = new Element("div", {
  162. "styles": this.css.containerNode, //(this.options.count.toInt()===1) ? this.css.containerNodeSingle : this.css.containerNode,
  163. "events": {
  164. "click": function(e){e.stopPropagation();},
  165. "mousedown": function(e){e.stopPropagation();},
  166. "mouseover": function(e){e.stopPropagation();},
  167. "mouseout": function(e){e.stopPropagation();},
  168. "keydown": function(e){e.stopPropagation();}
  169. }
  170. });
  171. this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  172. this.titleNode = new Element("div.titleNode", {
  173. "styles": this.css.titleNode
  174. }).inject(this.node);
  175. this.titleActionNode = new Element("div", {
  176. "styles": this.css.titleActionNode
  177. }).inject(this.titleNode);
  178. this.titleTextNode = new Element("div", {
  179. "styles": this.css.titleTextNode,
  180. "text": this.options.title
  181. }).inject(this.titleNode);
  182. this.contentNode = new Element("div", {
  183. "styles": this.css.contentNode
  184. }).inject(this.node);
  185. this.loadContent();
  186. this.actionNode = new Element("div", {
  187. "styles": this.css.actionNode
  188. }).inject(this.node);
  189. //if (this.options.count.toInt() === 1) this.actionNode.setStyle("text-align", "center");
  190. this.loadAction();
  191. this.node.inject(this.container);
  192. this.node.position({
  193. relativeTo: this.container,
  194. position: "center",
  195. edge: "center"
  196. });
  197. var size = this.container.getSize();
  198. var nodeSize = this.node.getSize();
  199. this.node.makeDraggable({
  200. "handle": this.titleNode,
  201. "limit": {
  202. "x": [0, size.x - nodeSize.x],
  203. "y": [0, size.y - nodeSize.y]
  204. }
  205. });
  206. if( this.options.width || this.options.height ){
  207. this.setSize()
  208. }
  209. this.setEvent();
  210. }
  211. },
  212. setEvent: function(){
  213. if (this.titleActionNode){
  214. this.titleActionNode.addEvent("click", function(){
  215. this.fireEvent("cancel");
  216. this.close();
  217. }.bind(this));
  218. }
  219. if (this.titleCancelActionNode){
  220. this.titleCancelActionNode.addEvent("click", function(){
  221. this.fireEvent("cancel");
  222. this.close();
  223. }.bind(this));
  224. }
  225. if (this.titleOkActionNode){
  226. this.titleOkActionNode.addEvent("click", function(){
  227. this.fireEvent("complete", [this.selectedItems]);
  228. this.close();
  229. }.bind(this));
  230. }
  231. },
  232. close: function(){
  233. this.fireEvent("close");
  234. this.node.destroy();
  235. //if (this.mask) this.mask.hide();
  236. if( !this.options.embedded ){
  237. (this.maskRelativeNode || this.container).unmask();
  238. }
  239. if (this.maskInterval){
  240. window.clearInterval(this.maskInterval);
  241. this.maskInterval = null;
  242. }
  243. MWF.release(this);
  244. delete this;
  245. },
  246. loadAction: function(){
  247. this.okActionNode = new Element("button", {
  248. "styles": this.css.okActionNode,
  249. "text": MWF.SelectorLP.ok
  250. }).inject(this.actionNode);
  251. this.cancelActionNode = new Element("button", {
  252. "styles": this.css.cancelActionNode,
  253. "text": MWF.SelectorLP.cancel
  254. }).inject(this.actionNode);
  255. this.okActionNode.addEvent("click", function(){
  256. this.fireEvent("complete", [this.selectedItems]);
  257. this.close();
  258. }.bind(this));
  259. this.cancelActionNode.addEvent("click", function(){this.fireEvent("cancel"); this.close();}.bind(this));
  260. },
  261. loadContent: function( contentNode ){
  262. if( contentNode )this.contentNode = contentNode;
  263. if (layout.mobile){
  264. if (this.options.count.toInt()!==1) this.loadSelectedNodeMobile();
  265. this.loadSelectNodeMobile();
  266. }else{
  267. this.loadSelectNode();
  268. if( this.options.hasShuttle ){
  269. this.loadShuttleNode();
  270. }
  271. //if (this.options.count.toInt()!==1) this.loadSelectedNode();
  272. this.loadSelectedNode();
  273. }
  274. },
  275. loadSelectNodeMobile: function(){
  276. this.selectNode = new Element("div", {
  277. "styles": this.css.selectNodeMobile
  278. }).inject(this.contentNode);
  279. var containerSize = this.container.getSize();
  280. var bodySize = $(document.body).getSize();
  281. var size = {
  282. "x" : Math.min( containerSize.x, bodySize.x ),
  283. "y" : Math.min( containerSize.y, bodySize.y )
  284. };
  285. var isFormWithAction = window.location.href.toLowerCase().indexOf("workmobilewithaction.html") > -1;
  286. var height;
  287. if( isFormWithAction ){
  288. height = size.y-40-20-6-20;
  289. }else{
  290. height = size.y;
  291. }
  292. this.selectNode.setStyle("height", ""+height+"px");
  293. this.searchInputDiv = new Element("div", {
  294. "styles": this.css.searchInputDiv
  295. }).inject(this.selectNode);
  296. this.searchInput = new Element("input", {
  297. "styles": (this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
  298. "type": "text"
  299. }).inject(this.searchInputDiv);
  300. var width = size.x-20-18;
  301. this.searchInput.setStyle("width", ""+width+"px");
  302. this.searchInput.setStyle("height", "20px");
  303. this.initSearchInput();
  304. this.letterAreaNode = new Element("div", {
  305. "styles": this.css.letterAreaMobileNode
  306. }).inject(this.selectNode);
  307. width = size.x-18;
  308. this.letterAreaNode.setStyle("width", ""+width+"px");
  309. this.loadLetters();
  310. this.itemAreaScrollNode = new Element("div.itemAreaScrollNode", {
  311. "styles": this.css.itemAreaScrollNode
  312. }).inject(this.selectNode);
  313. if( isFormWithAction ){
  314. height = size.y-40-20-78-20;
  315. }else{
  316. height = size.y-42-31-40;
  317. }
  318. this.itemAreaScrollNode.setStyle("height", ""+height+"px");
  319. this.itemAreaScrollNode.setStyle("overflow", "auto");
  320. this.itemAreaNode = new Element("div", {
  321. "styles": this.css.itemAreaNode
  322. }).inject(this.itemAreaScrollNode);
  323. this.itemSearchAreaNode = new Element("div", {
  324. "styles": this.css.itemAreaNode
  325. }).inject(this.itemAreaScrollNode);
  326. this.itemSearchAreaNode.setStyle("display", "none");
  327. //MWF.require("MWF.widget.ScrollBar", function(){
  328. // var _self = this;
  329. // new MWF.widget.ScrollBar(this.itemAreaScrollNode, {
  330. // "style":"xApp_Organization_Explorer",
  331. // "where": "before",
  332. // "distance": 30,
  333. // "friction": 4,
  334. // "axis": {"x": false, "y": true},
  335. // "onScroll": function(y){
  336. // _self._scrollEvent(y);
  337. // }
  338. // });
  339. //}.bind(this));
  340. this.initLoadSelectItems();
  341. this.checkLoadSelectItems();
  342. },
  343. checkLoadSelectItems: function(){
  344. if (!this.options.groups.length && !this.options.roles.length){
  345. this.loadSelectItems();
  346. }else{
  347. this.loadSelectItemsByCondition();
  348. }
  349. },
  350. loadShuttleNode : function(){
  351. this.shuttleNode = new Element("div.shuttleNode", {
  352. "styles": this.css.shuttleNode
  353. }).inject(this.contentNode);
  354. this.shuttleInnerNode = new Element("div.shuttleInnerNode", {
  355. "styles": this.css.shuttleInnerNode
  356. }).inject(this.shuttleNode);
  357. this.goRightNode = new Element("div.goRightNode", {
  358. "styles": this.css.goRightNode
  359. }).inject(this.shuttleInnerNode);
  360. this.goLeftNode = new Element("div.goLeftNode", {
  361. "styles": this.css.goLeftNode
  362. }).inject(this.shuttleInnerNode);
  363. },
  364. loadSelectNode: function(){
  365. this.selectNode = new Element("div.selectNode", {
  366. "styles": this.css.selectNode //(this.options.count.toInt()===1) ? this.css.selectNodeSingle : this.css.selectNode
  367. }).inject(this.contentNode);
  368. if( this.options.hasTop ){ //if( this.options.embedded && this.options.count.toInt()!==1 ){
  369. this.selectTopNode = new Element("div.selectTopNode",{
  370. "styles" : this.css.selectTopNode
  371. }).inject( this.selectNode );
  372. this.selectTopTextNode = new Element("div",{
  373. "text" : MWF.SelectorLP.waitingSelect,
  374. "styles" : this.css.selectTopTextNode
  375. }).inject( this.selectTopNode );
  376. }
  377. if( this.options.searchbarInTopNode ){
  378. this.searchInputDiv = new Element("div", {
  379. "styles": this.css.searchInputDiv
  380. }).inject( this.selectTopNode || this.selectNode);
  381. }else{
  382. this.searchInputDiv = new Element("div.searchInputDiv", {
  383. "styles": this.css.searchInputDiv
  384. }).inject( this.selectNode);
  385. }
  386. this.searchInput = new Element("input", {
  387. "styles": this.css.searchInput, //(this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
  388. "placeholder" : MWF.SelectorLP.searchDescription,
  389. "type": "text"
  390. }).inject(this.searchInputDiv);
  391. this.initSearchInput();
  392. if( this.options.hasLetter ){
  393. this.letterAreaNode = new Element("div", {
  394. "styles": this.css.letterAreaNode
  395. }).inject(this.selectNode);
  396. this.loadLetters();
  397. }
  398. this.itemAreaScrollNode = new Element("div", {
  399. "styles": this.css.itemAreaScrollNode
  400. }).inject(this.selectNode);
  401. this.itemAreaNode = new Element("div", {
  402. "styles": this.css.itemAreaNode
  403. }).inject(this.itemAreaScrollNode);
  404. this.itemSearchAreaNode = new Element("div", {
  405. "styles": this.css.itemAreaNode
  406. }).inject(this.itemAreaScrollNode);
  407. this.itemSearchAreaNode.setStyle("display", "none");
  408. this.loadSelectNodeScroll();
  409. this.initLoadSelectItems();
  410. this.checkLoadSelectItems();
  411. },
  412. loadSelectNodeScroll: function(){
  413. var overflowY = this.itemAreaScrollNode.getStyle("overflow-y");
  414. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") )return;
  415. MWF.require("MWF.widget.ScrollBar", function(){
  416. var _self = this;
  417. new MWF.widget.ScrollBar(this.itemAreaScrollNode, {
  418. "style":"xApp_Organization_Explorer",
  419. "where": "before",
  420. "distance": 30,
  421. "friction": 4,
  422. "axis": {"x": false, "y": true},
  423. "onScroll": function(y){
  424. _self._scrollEvent(y);
  425. }
  426. });
  427. }.bind(this));
  428. },
  429. initSearchInput: function(){
  430. this.searchInput.addEvents({
  431. "keydown": function(e){
  432. var iTimerID = this.searchInput.retrieve("searchTimer", null);
  433. if (iTimerID){
  434. window.clearTimeout(iTimerID);
  435. this.searchInput.eliminate("searchTimer");
  436. }
  437. iTimerID = window.setTimeout(function(){
  438. this.search();
  439. }.bind(this), 800);
  440. this.searchInput.store("searchTimer", iTimerID);
  441. }.bind(this),
  442. "change": function(e){
  443. var key = this.searchInput.get("value");
  444. if (!key) this.initSearchArea(false);
  445. }.bind(this),
  446. "blur": function(){
  447. var key = this.searchInput.get("value");
  448. if (!key) this.initSearchArea(false);
  449. }.bind(this)
  450. });
  451. },
  452. initSearchArea: function(flag){
  453. this.searchItems = [];
  454. if (flag){
  455. this.itemSearchAreaNode.empty();
  456. this.itemAreaNode.setStyle("display", "none");
  457. this.itemSearchAreaNode.setStyle("display", "block");
  458. }else{
  459. this.itemAreaNode.setStyle("display", "block");
  460. this.itemSearchAreaNode.setStyle("display", "none");
  461. }
  462. },
  463. search: function(){
  464. if (!this.options.groups.length && !this.options.roles.length){
  465. var key = this.searchInput.get("value");
  466. if (key){
  467. this._listItemByKey(function(json){
  468. this.initSearchArea(true);
  469. json.data.each(function(data){
  470. if( !this.isExcluded( data ) ) {
  471. var itemSearch = this._newItemSearch(data, this, this.itemSearchAreaNode);
  472. this.searchItems.push( itemSearch );
  473. }
  474. //this._newItem(data, this, this.itemSearchAreaNode);
  475. }.bind(this));
  476. }.bind(this), null, key);
  477. }else{
  478. this.initSearchArea(false);
  479. }
  480. }else{
  481. var key = this.searchInput.get("value");
  482. if (key){
  483. this.initSearchArea(true);
  484. this.searchInItems(key);
  485. }else{
  486. this.initSearchArea(false);
  487. }
  488. }
  489. },
  490. searchInItems: function(key){
  491. var createdId = [];
  492. this.createItemsSearchData(function(){
  493. var word = key.toLowerCase();
  494. this.itemsSearchData.each(function(obj){
  495. var text = obj.text+"#"+obj.pinyin+"#"+obj.firstPY;
  496. if (text.indexOf(word)!==-1){
  497. if (createdId.indexOf(obj.data.distinguishedName)===-1){
  498. this._newItem(obj.data, this, this.itemSearchAreaNode);
  499. createdId.push(obj.data.distinguishedName);
  500. }
  501. }
  502. }.bind(this));
  503. //delete createdId;
  504. }.bind(this));
  505. return createdId;
  506. },
  507. createItemsSearchData: function(callback){
  508. if (!this.itemsSearchData){
  509. this.itemsSearchData = [];
  510. MWF.require("MWF.widget.PinYin", function(){
  511. var initIds = [];
  512. this.items.each(function(item){
  513. if (initIds.indexOf(item.data.distinguishedName)==-1){
  514. var text = item._getShowName().toLowerCase();
  515. var pinyin = text.toPY().toLowerCase();
  516. var firstPY = text.toPYFirst().toLowerCase();
  517. this.itemsSearchData.push({
  518. "text": text,
  519. "pinyin": pinyin,
  520. "firstPY": firstPY,
  521. "data": item.data
  522. });
  523. initIds.push(item.data.distinguishedName);
  524. }
  525. }.bind(this));
  526. delete initIds;
  527. if (callback) callback();
  528. }.bind(this));
  529. }else{
  530. if (callback) callback();
  531. }
  532. },
  533. initSelectedSearchInput: function(){
  534. this.selectedSearchInput.addEvents({
  535. "keydown": function(e){
  536. var iTimerID = this.selectedSearchInput.retrieve("searchTimer", null);
  537. if (iTimerID){
  538. window.clearTimeout(iTimerID);
  539. this.selectedSearchInput.eliminate("searchTimer");
  540. }
  541. iTimerID = window.setTimeout(function(){
  542. this.selectedSearch();
  543. }.bind(this), 800);
  544. this.selectedSearchInput.store("searchTimer", iTimerID);
  545. }.bind(this),
  546. "change": function(e){
  547. var key = this.selectedSearchInput.get("value");
  548. if (!key) this.selectedSearch();
  549. }.bind(this),
  550. "blur": function(){
  551. var key = this.selectedSearchInput.get("value");
  552. if (!key) this.selectedSearch();
  553. }.bind(this)
  554. });
  555. },
  556. selectedSearch: function(){
  557. var key = this.selectedSearchInput.get("value");
  558. if (key){
  559. this.selectedSearchInItems(key);
  560. }else{
  561. this.showAllSelectedItem()
  562. }
  563. },
  564. selectedSearchInItems: function(key){
  565. var word = key.toLowerCase();
  566. MWF.require("MWF.widget.PinYin", function() {
  567. this.selectedItems.each(function (item) {
  568. if (!item.searchedText) {
  569. var text = item._getShowName().toLowerCase();
  570. var pinyin = text.toPY().toLowerCase();
  571. var firstPY = text.toPYFirst().toLowerCase();
  572. item.searchedText = text + "#" + pinyin + "#" + firstPY
  573. }
  574. if (item.searchedText.indexOf(word) !== -1) {
  575. item.node.show()
  576. } else {
  577. item.node.hide()
  578. }
  579. }.bind(this));
  580. }.bind(this), null, false);
  581. },
  582. showAllSelectedItem: function(){
  583. this.selectedItems.each(function(item){
  584. item.node.show()
  585. })
  586. },
  587. loadSelectedNode: function(){
  588. this.selectedContainerNode = new Element("div", {
  589. "styles": this.css.selectedContainerNode
  590. }).inject(this.contentNode);
  591. //if( this.options.embedded && this.options.count.toInt()!==1 ){
  592. if( this.options.hasTop ){
  593. this.selectedTopNode = new Element("div",{
  594. "styles" : this.css.selectedTopNode
  595. }).inject( this.selectedContainerNode );
  596. this.selectedTopTextNode = new Element("div",{
  597. "text" : MWF.SelectorLP.selected,
  598. "styles" : this.css.selectedTopTextNode
  599. }).inject( this.selectedTopNode );
  600. this.emptySelectedNode = new Element("div",{
  601. "text" : MWF.SelectorLP.empty,
  602. "styles" : this.css.selectedTopActionNode,
  603. "events" : {
  604. "click" : function(){
  605. this.emptySelectedItems()
  606. }.bind(this)
  607. }
  608. }).inject( this.selectedTopNode );
  609. }
  610. if( this.options.hasSelectedSearchbar ){
  611. if( this.options.searchbarInTopNode ){
  612. this.selectedSearchInputDiv = new Element("div", {
  613. "styles": this.css.searchInputDiv
  614. }).inject( this.selectedTopNode || this.selectedContainerNode);
  615. }else{
  616. this.selectedSearchInputDiv = new Element("div.selectedSearchInputDiv", {
  617. "styles": this.css.searchInputDiv
  618. }).inject( this.selectedContainerNode);
  619. }
  620. this.selectedSearchInput = new Element("input", {
  621. "styles": this.css.searchInput, //(this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
  622. "placeholder" : MWF.SelectorLP.searchDescription,
  623. "type": "text"
  624. }).inject(this.selectedSearchInputDiv);
  625. this.initSelectedSearchInput();
  626. }
  627. this.selectedScrollNode = new Element("div.selectedScrollNode", {
  628. "styles": this.css.selectedScrollNode
  629. }).inject(this.selectedContainerNode);
  630. this.selectedNode = new Element("div.selectedNode", {
  631. "styles": this.css.selectedNode
  632. }).inject(this.selectedScrollNode);
  633. if( this.options.hasSelectedSearchbar ){
  634. this.selectedItemSearchAreaNode = new Element("div", {
  635. "styles": this.css.itemAreaNode
  636. }).inject(this.selectedScrollNode);
  637. this.selectedItemSearchAreaNode.setStyle("display", "none");
  638. }
  639. this.setSelectedItem();
  640. this.loadSelectedNodeScroll();
  641. },
  642. emptySelectedItems : function(){
  643. while (this.selectedItems.length){
  644. this.selectedItems[0].clickItem();
  645. }
  646. },
  647. loadSelectedNodeScroll: function(){
  648. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  649. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") )return;
  650. MWF.require("MWF.widget.ScrollBar", function(){
  651. var _self = this;
  652. new MWF.widget.ScrollBar(this.selectedScrollNode, {
  653. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  654. });
  655. }.bind(this));
  656. },
  657. loadSelectedNodeMobile: function(){
  658. this.selectedScrollNode = new Element("div", {
  659. "styles": this.css.selectedScrollNode
  660. }).inject(this.contentNode);
  661. this.selectedNode = new Element("div", {
  662. "styles": this.css.selectedNode
  663. }).inject(this.selectedScrollNode);
  664. this.setSelectedItem();
  665. MWF.require("MWF.widget.ScrollBar", function(){
  666. var _self = this;
  667. new MWF.widget.ScrollBar(this.selectedScrollNode, {
  668. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  669. });
  670. }.bind(this));
  671. this.selectedScrollNode.setStyle("display", "none");
  672. },
  673. setSelectedItem: function(){
  674. if (this.options.values.length){
  675. this.options.values.each(function(v, i){
  676. if (typeOf(v)==="object"){
  677. this.selectedItems.push(this._newItemSelected(v, this, null));
  678. }else{
  679. this._getItem(function(json){
  680. this.options.values[i] = json.data;
  681. this.selectedItems.push(this._newItemSelected(json.data, this, null));
  682. }.bind(this), null, v, false);
  683. }
  684. // this._getItem(function(json){
  685. // this.selectedItems.push(this._newItemSelected(json.data, this, null));
  686. // }.bind(this), null, v, false);
  687. }.bind(this));
  688. }
  689. },
  690. loadLetters: function(){
  691. var _self = this;
  692. 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"];
  693. if (layout.mobile){
  694. var size = this.container.getSize();
  695. var w = (layout.mobile) ? (size.x-18)/13 : (size.x-20-4-18)/13;
  696. //letterNode.setStyle("width", ""+w+"px");
  697. this.css.letterNode.width = ""+w+"px";
  698. this.css.letterNode_over.width = ""+w+"px";
  699. }
  700. letters.each(function(l){
  701. var letterNode = new Element("div", {
  702. "styles": this.css.letterNode,
  703. "text": l
  704. }).inject(this.letterAreaNode);
  705. if (layout.mobile){
  706. letterNode.addEvents({
  707. "click": function(){
  708. _self.listPersonByPinyin(this);
  709. }
  710. });
  711. }else{
  712. letterNode.addEvents({
  713. "mouseover": function(e){
  714. e.target.setStyles(this.css.letterNode_over);
  715. var showNode = new Element("div", {
  716. "styles": this.css.letterShowNode,
  717. "text": e.target.get("text")
  718. }).inject(this.selectNode);
  719. showNode.position({
  720. relativeTo: this.itemAreaScrollNode,
  721. position: "center",
  722. edge: "center"
  723. });
  724. e.target.store("showNode", showNode);
  725. }.bind(this),
  726. "mouseout": function(e){
  727. var showNode = e.target.retrieve("showNode");
  728. showNode.destroy();
  729. e.target.setStyles(this.css.letterNode);
  730. }.bind(this),
  731. "click": function(){
  732. _self.listPersonByPinyin(this);
  733. }
  734. });
  735. }
  736. }.bind(this));
  737. },
  738. listPersonByPinyin: function(node){
  739. this.searchInput.focus();
  740. var pinyin = this.searchInput.get("value");
  741. pinyin = pinyin+node.get("text");
  742. this.searchInput.set("value", pinyin);
  743. if (!this.options.groups.length && !this.options.roles.length){
  744. if (pinyin){
  745. this._listItemByPinyin(function(json){
  746. this.initSearchArea(true);
  747. json.data.each(function(data){
  748. // var flag = true;
  749. // if (this.options.departments){
  750. // if (this.options.departments.length){
  751. // if (this.options.departments.indexOf(data.departmentName)==-1) flag = false;
  752. // }
  753. // }
  754. // if (this.options.companys){
  755. // if (this.options.companys.length){
  756. // if (this.options.companys.indexOf(data.company)==-1) flag = false;
  757. // }
  758. // }
  759. if( !this.isExcluded( data ) ) {
  760. this._newItemSearch(data, this, this.itemSearchAreaNode);
  761. }
  762. //this._newItem(data, this, this.itemSearchAreaNode);
  763. //this._newItem(data, this, this.itemSearchAreaNode);
  764. }.bind(this));
  765. }.bind(this), null, pinyin.toLowerCase());
  766. }
  767. }else{
  768. if (pinyin){
  769. this.initSearchArea(true);
  770. this.searchInItems(pinyin);
  771. }else{
  772. this.initSearchArea(false);
  773. }
  774. }
  775. },
  776. initLoadSelectItems: function(){
  777. this.loaddingItems = false;
  778. this.isItemLoaded = false;
  779. this.loadItemsQueue = 0;
  780. this.initSearchArea(false);
  781. },
  782. //loadSelectItems: function(addToNext){
  783. // if (!this.isItemLoaded){
  784. // if (!this.loaddingItems){
  785. // this.loaddingItems = true;
  786. // var count = 20;
  787. // this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  788. // if (json.data.length){
  789. // json.data.each(function(data){
  790. // var item = this._newItem(data, this, this.itemAreaNode);
  791. // this.items.push(item);
  792. // }.bind(this));
  793. // this.loaddingItems = false;
  794. //
  795. // if (json.data.length<count){
  796. // this.isItemLoaded = true;
  797. // }else{
  798. // if (this.loadItemsQueue>0){
  799. // this.loadItemsQueue--;
  800. // this.loadSelectItems();
  801. // }
  802. // }
  803. // }else{
  804. // this.isItemLoaded = true;
  805. // this.loaddingItems = false;
  806. // }
  807. // }.bind(this));
  808. // }else{
  809. // if (addToNext) this.loadItemsQueue++;
  810. // }
  811. // }
  812. //},
  813. loadSelectItems: function(addToNext, lastExcludeCount ){
  814. //lastExcludeCount 参数:表示本次加载是为了补足上次load的时候被排除的数量
  815. if (!this.isItemLoaded){
  816. if (!this.loaddingItems){
  817. this.loaddingItems = true;
  818. var count = 20;
  819. this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  820. if (json.data.length){
  821. var excludedCount = 0;
  822. json.data.each(function(data, i){
  823. if( this.isExcluded( data ) ){
  824. excludedCount++;
  825. if( i+1 === count )this.tailExcludeItemId = data.distinguishedName
  826. }else{
  827. var item = this._newItem(data, this, this.itemAreaNode);
  828. this.items.push(item);
  829. if( i+1 === count )this.tailExcludeItemId = null;
  830. }
  831. }.bind(this));
  832. this.loaddingItems = false;
  833. if( lastExcludeCount ){ //如果是因为上次load的时候被排除而加载的
  834. if( count - lastExcludeCount - excludedCount < 0 ){ //如果本次load的数量还不够补足排除的数量,需要再次load
  835. excludedCount = lastExcludeCount + excludedCount - count; //把不足的数量作为再次load的参数
  836. this.loadItemsQueue++
  837. }
  838. }else if( excludedCount > 0 ){ //把排除的数量作为再次load的参数
  839. this.loadItemsQueue++
  840. }
  841. if (json.data.length<count){
  842. this.isItemLoaded = true;
  843. }else{
  844. if (this.loadItemsQueue>0){
  845. this.loadItemsQueue--;
  846. this.loadSelectItems( addToNext, excludedCount );
  847. }
  848. }
  849. }else{
  850. this.isItemLoaded = true;
  851. this.loaddingItems = false;
  852. }
  853. }.bind(this));
  854. }else{
  855. if (addToNext) this.loadItemsQueue++;
  856. }
  857. }
  858. },
  859. getLastLoadedItemId: function(){
  860. if( this.tailExcludeItemId )return this.tailExcludeItemId;
  861. return (this.items.length) ? this.items[this.items.length-1].data.distinguishedName : "(0)";
  862. },
  863. //loadSelectItemsByCondition: function(){
  864. // this.options.groups.each(function(group){
  865. //
  866. // this.orgAction.listGroupByKey(function(json){
  867. // if (json.data.length){
  868. // var groupData = json.data[0];
  869. // var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  870. // this._getChildrenItemIds(groupData).each(function(id){
  871. // this._getItem(function(json){
  872. // var item = this._newItem(json.data, this, category.children);
  873. // this.items.push(item);
  874. // }.bind(this), null, id);
  875. // }.bind(this));
  876. // }
  877. // }.bind(this), null, group);
  878. // }.bind(this));
  879. //
  880. // this.options.roles.each(function(role){
  881. // this.orgAction.listRoleByKey(function(json){
  882. // if (json.data.length){
  883. // var roleData = json.data[0];
  884. // var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  885. // this._getChildrenItemIds(roleData).each(function(id){
  886. // this._getItem(function(json){
  887. // var item = this._newItem(json.data, this, category.children);
  888. // this.items.push(item);
  889. // }.bind(this), null, id)
  890. // }.bind(this));
  891. // }
  892. // }.bind(this), null, role);
  893. // }.bind(this));
  894. //},
  895. loadSelectItemsByCondition: function(){
  896. this.options.groups.each(function(group){
  897. this.orgAction.listGroupByKey(function(json){
  898. if (json.data.length){
  899. var groupData = json.data[0];
  900. var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  901. this.subCategorys.push(category);
  902. this._getChildrenItemIds(groupData).each(function(id){
  903. this._getItem(function(json){
  904. if( !this.isExcluded( json.data ) ) {
  905. var item = this._newItem(json.data, this, category.children);
  906. this.items.push(item);
  907. }
  908. }.bind(this), null, id);
  909. }.bind(this));
  910. }
  911. }.bind(this), null, group);
  912. }.bind(this));
  913. this.options.roles.each(function(role){
  914. this.orgAction.listRoleByKey(function(json){
  915. if (json.data.length){
  916. var roleData = json.data[0];
  917. var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  918. this.subCategorys.push(category);
  919. this._getChildrenItemIds(roleData).each(function(id){
  920. this._getItem(function(json){
  921. if( !this.isExcluded( json.data ) ) {
  922. var item = this._newItem(json.data, this, category.children);
  923. this.items.push(item);
  924. }
  925. }.bind(this), null, id)
  926. }.bind(this));
  927. }
  928. }.bind(this), null, role);
  929. }.bind(this));
  930. },
  931. isExcluded : function( d ){
  932. if( this.options.exclude.length === 0 )return false;
  933. if( !this.excludeFlagMap ){
  934. this.excludeFlagMap = {};
  935. this.options.exclude.each( function( e ){
  936. if( !e )return;
  937. this.excludeFlagMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.id || e.unique || e.employee || e.levelName) ] = true;
  938. }.bind(this));
  939. }
  940. var map = this.excludeFlagMap;
  941. return ( d.distinguishedName && map[ d.distinguishedName ] ) ||
  942. ( d.id && map[ d.id ] ) ||
  943. ( d.unique && map[ d.unique ] ) ||
  944. ( d.employee && map[ d.employee ] ) ||
  945. ( d.levelName && map[ d.levelName ] );
  946. },
  947. _getChildrenItemIds: function(data){
  948. return data.personList;
  949. },
  950. _newItemCategory: function(type, data, selector, item){
  951. return new MWF.xApplication.Selector.Person[type](data, selector, item)
  952. },
  953. _listItemByKey: function(callback, failure, key){
  954. this.orgAction.listPersonByKey(function(json){
  955. if (callback) callback.apply(this, [json]);
  956. }.bind(this), failure, key);
  957. },
  958. _getItem: function(callback, failure, id, async){
  959. this.orgAction.getPerson(function(json){
  960. if (callback) callback.apply(this, [json]);
  961. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  962. },
  963. _newItemSelected: function(data, selector, item){
  964. return new MWF.xApplication.Selector.Person.ItemSelected(data, selector, item)
  965. },
  966. _listItemByPinyin: function(callback, failure, key){
  967. this.orgAction.listPersonByPinyin(function(json){
  968. if (callback) callback.apply(this, [json]);
  969. }.bind(this), failure, key);
  970. },
  971. _newItem: function(data, selector, container){
  972. return new MWF.xApplication.Selector.Person.Item(data, selector, container);
  973. },
  974. _newItemSearch: function(data, selector, container){
  975. return this._newItem(data, selector, container);
  976. },
  977. _listItemNext: function(last, count, callback){
  978. this.orgAction.listPersonNext(last, count, function(json){
  979. if (callback) callback.apply(this, [json]);
  980. }.bind(this));
  981. },
  982. _scrollEvent: function(y){
  983. if (!this.options.groups.length && !this.options.roles.length){
  984. var scrollSize = this.itemAreaScrollNode.getScrollSize();
  985. var clientSize = this.itemAreaScrollNode.getSize();
  986. var scrollHeight = scrollSize.y-clientSize.y;
  987. if (y+30>scrollHeight) {
  988. if (!this.isItemLoaded) this.loadSelectItems();
  989. }
  990. }
  991. },
  992. setSize : function(){
  993. if( !this.options.width && !this.options.height )return;
  994. var getOffsetX = function(node){
  995. return (node.getStyle("margin-left").toInt() || 0 )+
  996. (node.getStyle("margin-right").toInt() || 0 ) +
  997. (node.getStyle("padding-left").toInt() || 0 ) +
  998. (node.getStyle("padding-right").toInt() || 0 ) +
  999. (node.getStyle("border-left-width").toInt() || 0 ) +
  1000. (node.getStyle("border-right-width").toInt() || 0 );
  1001. };
  1002. var getOffsetY = function(node){
  1003. return (node.getStyle("margin-top").toInt() || 0 ) +
  1004. (node.getStyle("margin-bottom").toInt() || 0 ) +
  1005. (node.getStyle("padding-top").toInt() || 0 ) +
  1006. (node.getStyle("padding-bottom").toInt() || 0 )+
  1007. (node.getStyle("border-top-width").toInt() || 0 ) +
  1008. (node.getStyle("border-bottom-width").toInt() || 0 );
  1009. };
  1010. if( this.options.width && this.options.width === "auto" ){
  1011. //if (this.options.count.toInt() !== 1){
  1012. if( this.node )this.node.setStyle("width", "auto");
  1013. this.selectNode.setStyles({
  1014. "width": "50%",
  1015. "float" : "left"
  1016. });
  1017. //this.searchInput.setStyle("width", "99%");
  1018. if(this.letterAreaNode ){
  1019. this.letterAreaNode.setStyle("width", "auto");
  1020. }
  1021. this.selectedContainerNode.setStyle("width", "auto");
  1022. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  1023. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
  1024. this.selectedScrollNode.setStyle("width", "auto");
  1025. }else{
  1026. this.selectedScrollNode.setStyle("margin-right", "8px");
  1027. }
  1028. //}else{
  1029. // this.node.setStyle("width", "auto");
  1030. // this.selectNode.setStyle("width", "auto");
  1031. //}
  1032. }else if( this.options.width && typeOf( this.options.width.toInt() ) === "number" ){
  1033. var nodeWidth;
  1034. if( this.node ){
  1035. nodeWidth = this.options.width.toInt() - getOffsetX(this.node);
  1036. this.node.setStyle("width", nodeWidth);
  1037. }else{
  1038. nodeWidth = this.options.width.toInt();
  1039. }
  1040. nodeWidth = nodeWidth - getOffsetX( this.contentNode );
  1041. if( this.shuttleNode ){
  1042. nodeWidth = nodeWidth - getOffsetX(this.shuttleNode) - this.shuttleNode.getStyle("width").toInt();
  1043. }
  1044. //if (this.options.count.toInt() !== 1){
  1045. var width = nodeWidth - getOffsetX(this.selectNode) - getOffsetX(this.selectedContainerNode);
  1046. var halfWidth = Math.floor(width / 2);
  1047. this.selectNode.setStyle("width", halfWidth);
  1048. //this.searchInput.setStyle("width", halfWidth - 6);
  1049. if(this.letterAreaNode ){
  1050. this.letterAreaNode.setStyle("width", halfWidth - 19);
  1051. }
  1052. this.selectedContainerNode.setStyle("width", halfWidth);
  1053. var overflowY = this.selectedScrollNode.getStyle("overflow-y");
  1054. if( typeOf(overflowY)==="string" && (overflowY.toLowerCase() === "auto" || overflowY.toLowerCase() === "scroll") ){
  1055. this.selectedScrollNode.setStyle("width", halfWidth);
  1056. }else{
  1057. this.selectedScrollNode.setStyle("width", halfWidth - 8);
  1058. }
  1059. //}else{
  1060. // var width = nodeWidth - getOffsetX(this.selectNode);
  1061. // this.selectNode.setStyle("width", width);
  1062. //}
  1063. }
  1064. if( this.options.height && typeOf( this.options.height.toInt() ) === "number" ){
  1065. var nodeHeight;
  1066. if( this.node ){
  1067. nodeHeight = this.options.height.toInt() - getOffsetY(this.node);
  1068. this.node.setStyle("height", nodeHeight);
  1069. }else{
  1070. nodeHeight = this.options.height.toInt();
  1071. }
  1072. nodeHeight = nodeHeight - getOffsetY( this.contentNode );
  1073. if( this.titleNode ){
  1074. nodeHeight = nodeHeight - getOffsetY( this.titleNode ) - this.titleNode.getStyle("height").toInt();
  1075. }
  1076. if( this.actionNode ){
  1077. nodeHeight = nodeHeight - getOffsetY( this.actionNode ) - this.actionNode.getStyle("height").toInt();
  1078. }
  1079. var selectNodeHeight = nodeHeight - getOffsetY(this.selectNode);
  1080. this.selectNode.setStyle("height", selectNodeHeight);
  1081. if( this.shuttleNode ){
  1082. this.shuttleNode.setStyle("height", selectNodeHeight);
  1083. var shuttleInnerHieght = getOffsetY( this.shuttleInnerNode ) + this.shuttleInnerNode.getStyle("height").toInt();
  1084. this.shuttleInnerNode.setStyle("margin-top", (selectNodeHeight-shuttleInnerHieght)/2 +"px" )
  1085. }
  1086. var itemAreaScrollNodeHeight = selectNodeHeight - getOffsetY( this.searchInputDiv ) - this.searchInputDiv.getStyle("height").toInt();
  1087. if( !this.options.searchbarInTopNode && this.selectTopNode ){
  1088. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.selectTopNode ) - this.selectTopNode.getStyle("height").toInt();
  1089. }
  1090. if(this.letterAreaNode ){
  1091. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.letterAreaNode ) - this.letterAreaNode.getStyle("height").toInt();
  1092. }
  1093. itemAreaScrollNodeHeight = itemAreaScrollNodeHeight - getOffsetY( this.itemAreaScrollNode );
  1094. this.itemAreaScrollNode.setStyle("height", itemAreaScrollNodeHeight);
  1095. var selectedContainerNodeHeight = nodeHeight - getOffsetY(this.selectedContainerNode);
  1096. this.selectedContainerNode.setStyle("height", selectedContainerNodeHeight);
  1097. var selectedScrollNodeHeight = selectedContainerNodeHeight;
  1098. if( this.selectedTopNode ) {
  1099. selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY(this.selectedTopNode) - this.selectedTopNode.getStyle("height").toInt();
  1100. }
  1101. if( !this.options.searchbarInTopNode && this.selectedSearchInputDiv ){
  1102. selectedScrollNodeHeight = selectedScrollNodeHeight - getOffsetY( this.selectedSearchInputDiv ) - this.selectedSearchInputDiv.getStyle("height").toInt();
  1103. }
  1104. this.selectedScrollNode.setStyle("height", selectedScrollNodeHeight);
  1105. }
  1106. this.fireEvent("setSize",[this])
  1107. }
  1108. });
  1109. MWF.xApplication.Selector.Person.Item = new Class({
  1110. initialize: function(data, selector, container, level, category){
  1111. this.data = data;
  1112. this.selector = selector;
  1113. this.container = container;
  1114. this.isSelected = false;
  1115. this.level = (level) ? level.toInt() : 1;
  1116. this.category = category;
  1117. this.subItems = [];
  1118. this.subCategorys = [];
  1119. this.load();
  1120. },
  1121. _getShowName: function(){
  1122. return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
  1123. },
  1124. _getTtiteText: function(){
  1125. return this.data.name + ( this.data.employee ? ("("+this.data.employee+")") : "" );
  1126. },
  1127. _setIcon: function(){
  1128. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  1129. },
  1130. load: function(){
  1131. this.selector.fireEvent("queryLoadItem",[this]);
  1132. if( !this.node )this.node = new Element("div", {
  1133. "styles": this.selector.css.selectorItem
  1134. }).inject(this.container);
  1135. this.levelNode = new Element("div", {
  1136. "styles": this.selector.css.selectorItemLevelNode
  1137. }).inject(this.node);
  1138. var indent = this.selector.options.level1Indent + (this.level-1)*this.selector.options.indent;
  1139. this.levelNode.setStyle("width", ""+indent+"px");
  1140. this.iconNode = new Element("div", {
  1141. "styles": this.selector.css.selectorItemIconNode
  1142. }).inject(this.node);
  1143. this._setIcon();
  1144. this.actionNode = new Element("div", {
  1145. "styles": this.selector.css.selectorItemActionNode
  1146. }).inject(this.node);
  1147. this.textNode = new Element("div", {
  1148. "styles": this.selector.css.selectorItemTextNode,
  1149. "text": this._getShowName(),
  1150. "title": this._getTtiteText()
  1151. }).inject(this.node);
  1152. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  1153. this.textNode.setStyle("margin-left", ""+m+"px");
  1154. if(this.postLoad)this.postLoad();
  1155. this.loadSubItem();
  1156. this.setEvent();
  1157. this.check();
  1158. this.selector.fireEvent("postLoadItem",[this]);
  1159. },
  1160. loadSubItem: function(){},
  1161. check: function(){
  1162. //if (this.selector.options.count.toInt()===1){
  1163. // this.checkSelectedSingle();
  1164. //}else{
  1165. this.checkSelected();
  1166. //}
  1167. },
  1168. checkSelectedSingle: function(){
  1169. var selectedItem = this.selector.options.values.filter(function(item, index){
  1170. if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
  1171. if (typeOf(item)==="string") return this.data.distinguishedName === item;
  1172. return false;
  1173. }.bind(this));
  1174. if (selectedItem.length){
  1175. this.selectedSingle();
  1176. }
  1177. },
  1178. checkSelected: function(){
  1179. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  1180. return item.data.distinguishedName === this.data.distinguishedName;
  1181. }.bind(this));
  1182. if (selectedItem.length){
  1183. //selectedItem[0].item = this;
  1184. selectedItem[0].addItem(this);
  1185. this.selectedItem = selectedItem[0];
  1186. this.setSelected();
  1187. }
  1188. },
  1189. setSelected: function(){
  1190. this.isSelected = true;
  1191. this.node.setStyles(this.selector.css.selectorItem_selected);
  1192. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1193. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1194. },
  1195. setEvent: function(){
  1196. this.node.addEvents({
  1197. "mouseover": function(){
  1198. this.overItem();
  1199. }.bind(this),
  1200. "mouseout": function(){
  1201. this.outItem();
  1202. }.bind(this),
  1203. "click": function(){
  1204. this.clickItem();
  1205. }.bind(this)
  1206. });
  1207. },
  1208. clickItem: function(){
  1209. if ( layout.mobile && this.selector.options.count.toInt()===1){
  1210. this.selectedSingle();
  1211. }else{
  1212. if (this.isSelected){
  1213. this.unSelected();
  1214. this.selector.fireEvent("unselectItem",[this])
  1215. }else{
  1216. this.selected();
  1217. this.selector.fireEvent("selectItem",[this])
  1218. }
  1219. }
  1220. },
  1221. overItem: function(){
  1222. if (!this.isSelected ){
  1223. this.node.setStyles(this.selector.css.selectorItem_over);
  1224. }else if( this.selector.css.selectorItem_over_force ){
  1225. this.node.setStyles(this.selector.css.selectorItem_over_force);
  1226. }
  1227. if (!this.isSelected){
  1228. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  1229. }else if( this.selector.css.selectorItemActionNode_over_force ){
  1230. this.node.setStyles(this.selector.css.selectorItemActionNode_over_force);
  1231. }
  1232. },
  1233. outItem: function(){
  1234. if (!this.isSelected){
  1235. this.node.setStyles(this.selector.css.selectorItem);
  1236. }else if( this.selector.css.selectorItem_over_force ){
  1237. this.node.setStyles(this.selector.css.selectorItem_selected);
  1238. }
  1239. if (!this.isSelected){
  1240. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1241. }else if( this.selector.css.selectorItemActionNode_over_force ){
  1242. this.node.setStyles(this.selector.css.selectorItemActionNode_selected);
  1243. }
  1244. },
  1245. selectedSingle: function(){
  1246. if (!this.isSelected){
  1247. if (this.selector.currentItem) this.selector.currentItem.unSelectedSingle();
  1248. this.getData(function(){
  1249. this.selector.currentItem = this;
  1250. this.isSelected = true;
  1251. this.selector.selectedItems.push(this);
  1252. this.node.setStyles(this.selector.css.selectorItem_selected);
  1253. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1254. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1255. }.bind(this));
  1256. }else {
  1257. this.unSelectedSingle();
  1258. }
  1259. },
  1260. getData: function(callback){
  1261. if (callback) callback();
  1262. },
  1263. unSelectedSingle: function(){
  1264. this.selector.currentItem = null;
  1265. this.isSelected = false;
  1266. this.selector.selectedItems.erase(this);
  1267. this.node.setStyles(this.selector.css.selectorItem);
  1268. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1269. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1270. },
  1271. selected: function(){
  1272. var count = this.selector.options.maxCount || this.selector.options.count;
  1273. if (!count) count = 0;
  1274. if( count == 1 && this.selector.emptySelectedItems){
  1275. this.selector.emptySelectedItems();
  1276. }
  1277. if ((count.toInt()===0) || (this.selector.selectedItems.length+1)<=count) {
  1278. this.isSelected = true;
  1279. this.node.setStyles(this.selector.css.selectorItem_selected);
  1280. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  1281. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  1282. this.selectedItem = this.selector._newItemSelected(this.data, this.selector, this);
  1283. this.selectedItem.check();
  1284. this.selector.selectedItems.push(this.selectedItem);
  1285. }else{
  1286. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
  1287. }
  1288. },
  1289. unSelected: function(){
  1290. this.isSelected = false;
  1291. this.node.setStyles(this.selector.css.selectorItem);
  1292. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1293. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1294. if( this.category ){
  1295. this.category.checkSelectAll();
  1296. }
  1297. if( this.selector.searchItems && this.selector.searchItems.length ){
  1298. this.selector.searchItems.each( function(itemSearch){
  1299. var sd = itemSearch.data;
  1300. var d = this.data;
  1301. if(
  1302. ( sd.distinguishedName && (sd.distinguishedName === d.distinguishedName) ) ||
  1303. ( sd.id && (sd.id === d.id) ) ||
  1304. ( sd.unique && (sd.unique === d.unique) ) ||
  1305. ( sd.employee && (sd.employee === d.employee) ) ||
  1306. ( sd.levelName && (sd.levelName === d.levelName) )
  1307. ){
  1308. itemSearch.isSelected = false;
  1309. itemSearch.node.setStyles(this.selector.css.selectorItem);
  1310. itemSearch.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1311. itemSearch.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1312. }
  1313. }.bind(this))
  1314. }
  1315. if (this.selectedItem){
  1316. this.selector.selectedItems.erase(this.selectedItem);
  1317. this.selectedItem.items.each(function(item){
  1318. if (item != this){
  1319. item.isSelected = false;
  1320. item.node.setStyles(this.selector.css.selectorItem);
  1321. item.textNode.setStyles(this.selector.css.selectorItemTextNode);
  1322. item.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1323. }
  1324. }.bind(this));
  1325. this.selectedItem.destroy();
  1326. this.selectedItem = null;
  1327. }
  1328. },
  1329. postLoad : function(){},
  1330. getParentCategoryByLevel : function( level ){
  1331. var category = this.category;
  1332. do{
  1333. if( category.level === level ){
  1334. return category;
  1335. }else{
  1336. category = category.category;
  1337. }
  1338. }while( category )
  1339. }
  1340. });
  1341. MWF.xApplication.Selector.Person.ItemSelected = new Class({
  1342. Extends: MWF.xApplication.Selector.Person.Item,
  1343. initialize: function(data, selector, item){
  1344. this.data = data;
  1345. this.selector = selector;
  1346. this.container = this.selector.selectedNode;
  1347. this.isSelected = false;
  1348. this.items = [];
  1349. if (item) this.items.push(item);
  1350. this.level = 0;
  1351. this.node = new Element("div", {
  1352. "styles": this.selector.css.selectorItem
  1353. }).inject(this.container);
  1354. this.node.setStyle("display","none");
  1355. this.getData(function(){
  1356. this.node.setStyle("display","");
  1357. this.load();
  1358. }.bind(this));
  1359. },
  1360. postLoad : function(){
  1361. if( this.selector.css.selectorSelectedItemActionNode ){
  1362. this.actionNode.setStyles( this.selector.css.selectorSelectedItemActionNode );
  1363. }
  1364. if( this.selector.css.selectorSelectedItemTextNode ){
  1365. this.textNode.setStyles(this.selector.css.selectorSelectedItemTextNode);
  1366. }
  1367. },
  1368. getData: function(callback){
  1369. if (callback) callback();
  1370. },
  1371. clickItem: function(){
  1372. if (this.items.length){
  1373. this.items.each(function(item){
  1374. item.unSelected();
  1375. });
  1376. }else{
  1377. //this.item.selectedItem = null;
  1378. //this.item.isSelected = false;
  1379. this.destroy();
  1380. this.selector.selectedItems.erase(this);
  1381. }
  1382. },
  1383. //overItem: function(){
  1384. // if (!this.isSelected){
  1385. // this.node.setStyles(this.selector.css.selectorItem_over);
  1386. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  1387. // }
  1388. //},
  1389. overItem: function(){
  1390. if (!this.isSelected ){
  1391. if( this.selector.css.selectorItem_selected_over ){
  1392. this.node.setStyles(this.selector.css.selectorItem_selected_over);
  1393. }else{
  1394. this.node.setStyles(this.selector.css.selectorItem_over);
  1395. }
  1396. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  1397. }
  1398. },
  1399. outItem: function(){
  1400. if (!this.isSelected){
  1401. var styles = this.selector.css.selectorSelectedItem || this.selector.css.selectorItem;
  1402. this.node.setStyles(styles);
  1403. }else if( this.selector.css.selectorItem_over_force ){
  1404. this.node.setStyles(this.selector.css.selectorItem_selected);
  1405. }
  1406. if (!this.isSelected){
  1407. var styles = this.selector.css.selectorSelectedItemActionNode || this.selector.css.selectorItemActionNode;
  1408. this.actionNode.setStyles(styles);
  1409. }else if( this.selector.css.selectorItemActionNode_over_force ){
  1410. this.node.setStyles(this.selector.css.selectorItemActionNode_selected);
  1411. }
  1412. },
  1413. addItem: function(item){
  1414. if (this.items.indexOf(item)===-1) this.items.push(item);
  1415. },
  1416. check: function(){
  1417. if (this.selector.items.length){
  1418. var items = this.selector.items.filter(function(item, index){
  1419. return item.data.distinguishedName === this.data.distinguishedName;
  1420. }.bind(this));
  1421. this.items = items;
  1422. if (items.length){
  1423. items.each(function(item){
  1424. item.selectedItem = this;
  1425. item.setSelected();
  1426. }.bind(this));
  1427. }
  1428. }
  1429. },
  1430. destroy: function(){
  1431. if(this.node)this.node.destroy();
  1432. delete this;
  1433. }
  1434. });
  1435. MWF.xApplication.Selector.Person.ItemCategory = new Class({
  1436. Extends: MWF.xApplication.Selector.Person.Item,
  1437. initialize: function(data, selector, container, level, parentCategory){
  1438. this.data = data;
  1439. this.selector = selector;
  1440. this.container = container;
  1441. this.isSelected = false;
  1442. this.level = (level) ? level.toInt() : 1;
  1443. this.category = parentCategory;
  1444. this.subItems = [];
  1445. this.subCategorys = [];
  1446. this.load();
  1447. },
  1448. createNode: function(){
  1449. this.node = new Element("div", {
  1450. "styles": this.selector.css.selectorItemCategory,
  1451. "title" : this._getTtiteText()
  1452. }).inject(this.container);
  1453. },
  1454. load: function(){
  1455. this.selector.fireEvent("queryLoadCategory",[this]);
  1456. this.createNode();
  1457. this.levelNode = new Element("div", {
  1458. "styles": this.selector.css.selectorItemLevelNode
  1459. }).inject(this.node);
  1460. var indent = this.selector.options.level1Indent + (this.level-1)*this.selector.options.indent;
  1461. this.levelNode.setStyle("width", ""+indent+"px");
  1462. this.iconNode = new Element("div", {
  1463. "styles": this.selector.css.selectorItemIconNode
  1464. }).inject(this.node);
  1465. this._setIcon();
  1466. this.actionNode = new Element("div", {
  1467. "styles": (this.selector.options.expand) ? this.selector.css.selectorItemCategoryActionNode_expand : this.selector.css.selectorItemCategoryActionNode_collapse
  1468. }).inject(this.node);
  1469. if( this.selector.options.selectAllEnable && this.selector.options.count.toInt()!==1 ){
  1470. this.selectAllNode = new Element("div", {
  1471. "styles": this.selector.css.selectorItemCategoryActionNode_selectAll,
  1472. "title" : "全选下级"
  1473. }).inject(this.node);
  1474. this.selectAllNode.addEvent( "click", function(ev){
  1475. if( this.isSelectedAll ){
  1476. this.unselectAll(ev);
  1477. this.selector.fireEvent("unselectCatgory",[this])
  1478. }else{
  1479. this.selectAll(ev);
  1480. this.selector.fireEvent("selectCatgory",[this])
  1481. }
  1482. ev.stopPropagation();
  1483. }.bind(this));
  1484. if( this.selector.css.selectorItemCategoryActionNode_selectAll_over ){
  1485. this.selectAllNode.addEvents( {
  1486. "mouseover" : function(ev){
  1487. if( !this.isSelectedAll )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_over );
  1488. //ev.stopPropagation();
  1489. }.bind(this),
  1490. "mouseout" : function(ev){
  1491. if( !this.isSelectedAll )this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  1492. //ev.stopPropagation();
  1493. }.bind(this)
  1494. })
  1495. }
  1496. }
  1497. this.textNode = new Element("div", {
  1498. "styles": this.selector.css.selectorItemCategoryTextNode,
  1499. "text": this._getShowName()
  1500. }).inject(this.node);
  1501. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  1502. this.textNode.setStyle("margin-left", ""+m+"px");
  1503. this.children = new Element("div", {
  1504. "styles": this.selector.css.selectorItemCategoryChildrenNode
  1505. }).inject(this.node, "after");
  1506. if (!this.selector.options.expand) this.children.setStyle("display", "none");
  1507. var subIdList = this.selector._getChildrenItemIds(this.data);
  1508. if (subIdList){
  1509. var count = subIdList.length;
  1510. this.childrenHeight = count*29;
  1511. this.children.setStyle("height", ""+this.childrenHeight+"px");
  1512. }
  1513. if (!this._hasChild()){
  1514. this.actionNode.setStyle("background", "transparent");
  1515. this.textNode.setStyle("color", "#777");
  1516. }
  1517. if( this.selectAllNode && !this._hasChildItem() ){
  1518. this.selectAllNode.setStyle("display", "none");
  1519. }
  1520. this.setEvent();
  1521. this.check();
  1522. this.afterLoad();
  1523. this.selector.fireEvent("postLoadCategory",[this]);
  1524. },
  1525. unselectAll : function(ev, exclude){
  1526. var excludeList = exclude || [];
  1527. if( exclude && typeOf(exclude) !== "array" )excludeList = [exclude];
  1528. ( this.subItems || [] ).each( function(item){
  1529. if(item.isSelected && !excludeList.contains(item) ){
  1530. item.unSelected();
  1531. }
  1532. }.bind(this));
  1533. if( this.selectAllNode && this.selector.css.selectorItemCategoryActionNode_selectAll ){
  1534. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  1535. }
  1536. this.isSelectedAll = false;
  1537. },
  1538. unselectAllNested : function( ev, exclude ){
  1539. this.unselectAll(ev, exclude );
  1540. if( this.subCategorys && this.subCategorys.length ){
  1541. this.subCategorys.each( function( category ){
  1542. category.unselectAllNested( ev, exclude )
  1543. })
  1544. }
  1545. },
  1546. selectAllNested : function(){
  1547. this.selectAll();
  1548. if( this.subCategorys && this.subCategorys.length ){
  1549. this.subCategorys.each( function( category ){
  1550. category.selectAllNested()
  1551. })
  1552. }
  1553. },
  1554. selectAll: function(ev){
  1555. if( this.loaded ){
  1556. this._selectAll( ev );
  1557. }else{
  1558. this.clickItem( function(){
  1559. this._selectAll( ev );
  1560. //this.children.setStyles({
  1561. // "display": "none",
  1562. // "height": "0px"
  1563. //});
  1564. //this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  1565. }.bind(this));
  1566. }
  1567. },
  1568. _selectAll : function( ev ){
  1569. if( !this.subItems || !this.subItems.length )return;
  1570. var count = this.selector.options.maxCount || this.selector.options.count;
  1571. if (!count) count = 0;
  1572. var selectedSubItemCount = 0;
  1573. this.subItems.each( function(item){
  1574. if(item.isSelected)selectedSubItemCount++
  1575. }.bind(this));
  1576. if ((count.toInt()===0) || (this.selector.selectedItems.length+(this.subItems.length-selectedSubItemCount))<=count){
  1577. this.subItems.each( function(item){
  1578. if(!item.isSelected)item.selected();
  1579. }.bind(this))
  1580. if( this.selectAllNode && this.selector.css.selectorItemCategoryActionNode_selectAll_selected ){
  1581. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll_selected );
  1582. }
  1583. this.isSelectedAll = true;
  1584. }else{
  1585. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+count+"个选项", this.node);
  1586. }
  1587. },
  1588. checkSelectAll : function(){
  1589. if( !this.isSelectedAll )return;
  1590. if( !this.selectAllNode || !this.selector.css.selectorItemCategoryActionNode_selectAll)return;
  1591. if( ! this.subItems )return;
  1592. var hasSelectedItem = false;
  1593. for( var i=0; i< this.subItems.length; i++ ){
  1594. if( this.subItems[i].isSelected ){
  1595. hasSelectedItem = true;
  1596. break;
  1597. }
  1598. }
  1599. if( !hasSelectedItem ){
  1600. this.selectAllNode.setStyles( this.selector.css.selectorItemCategoryActionNode_selectAll );
  1601. this.isSelectedAll = false;
  1602. }
  1603. },
  1604. afterLoad: function(){
  1605. if (this.level===1) this.clickItem();
  1606. },
  1607. clickItem: function( callback ){
  1608. if (this._hasChild()){
  1609. if (!this.fx){
  1610. this.fx = new Fx.Tween(this.children, {
  1611. "duration": 200
  1612. // "transition": Fx.Transitions.Cubic.easeIn
  1613. });
  1614. };
  1615. if (!this.fx.isRunning()){
  1616. var display = this.children.getStyle("display");
  1617. if (display === "none"){
  1618. this.children.setStyles({
  1619. "display": "block",
  1620. "height": "0px"
  1621. });
  1622. this.fx.start("height", "0px", ""+this.childrenHeight+"px");
  1623. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  1624. this.isExpand = true;
  1625. }else{
  1626. if (!this.childrenHeight) this.childrenHeight = this.children.getStyle("height").toFloat();
  1627. this.fx.start("height", ""+this.childrenHeight+"px", "0px").chain(function(){
  1628. this.children.setStyles({
  1629. "display": "none",
  1630. "height": "0px"
  1631. });
  1632. }.bind(this));
  1633. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  1634. this.isExpand = false;
  1635. }
  1636. }
  1637. if(callback)callback()
  1638. }
  1639. },
  1640. overItem: function(){
  1641. //if (!this.isSelected){
  1642. // this.node.setStyles(this.selector.css.selectorItem_over);
  1643. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  1644. //}
  1645. if( this.selector.css.selectorItemCategory_over ){
  1646. this.node.setStyles(this.selector.css.selectorItemCategory_over);
  1647. }
  1648. var display = this.children.getStyle("display");
  1649. if( display === "none" ){
  1650. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
  1651. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse_over )
  1652. }
  1653. }else{
  1654. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
  1655. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand_over )
  1656. }
  1657. }
  1658. },
  1659. outItem: function(){
  1660. //if (!this.isSelected){
  1661. // this.node.setStyles(this.selector.css.selectorItem);
  1662. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1663. //}
  1664. if( this.selector.css.selectorItemCategory_over ){
  1665. this.node.setStyles(this.selector.css.selectorItemCategory);
  1666. }
  1667. var display = this.children.getStyle("display");
  1668. if( display === "none" ){
  1669. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_collapse_over ){
  1670. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_collapse )
  1671. }
  1672. }else{
  1673. if( this._hasChild() && this.selector.css.selectorItemCategoryActionNode_expand_over ){
  1674. this.actionNode.setStyles( this.selector.css.selectorItemCategoryActionNode_expand )
  1675. }
  1676. }
  1677. },
  1678. _hasChild: function(){
  1679. var subIdList = this.selector._getChildrenItemIds(this.data);
  1680. if (subIdList) if (subIdList.length) return true;
  1681. return false;
  1682. },
  1683. _hasChildItem: function(){
  1684. return this._hasChild();
  1685. },
  1686. _getTtiteText: function(){
  1687. if( this.data.levelName ){
  1688. return this.data.name+"("+ this.data.levelName +")";
  1689. }else{
  1690. return this.data.name;
  1691. }
  1692. }
  1693. });
  1694. MWF.xApplication.Selector.Person.ItemGroupCategory = new Class({
  1695. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  1696. _getShowName: function(){
  1697. return this.data.name;
  1698. },
  1699. _setIcon: function(){
  1700. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/groupicon.png)");
  1701. }
  1702. });
  1703. MWF.xApplication.Selector.Person.ItemRoleCategory = new Class({
  1704. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  1705. _getShowName: function(){
  1706. return this.data.name;
  1707. },
  1708. _setIcon: function(){
  1709. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/roleicon.png)");
  1710. }
  1711. });
  1712. MWF.xApplication.Selector.Person.Filter = new Class({
  1713. Implements: [Options, Events],
  1714. options: {
  1715. "style": "default",
  1716. "groups": [],
  1717. "roles": []
  1718. },
  1719. initialize: function(value, options){
  1720. this.setOptions(options);
  1721. this.value = value;
  1722. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1723. },
  1724. filter: function(value, callback){
  1725. this.value = value;
  1726. var key = this.value;
  1727. if (this.options.groups.length || this.options.roles.length) key = {"key": key, "groupList": this.options.groupList, "roleList": this.options.roleList};
  1728. this.orgAction.listPersonByKey(function(json){
  1729. data = json.data;
  1730. if (callback) callback(data)
  1731. }.bind(this), null, key);
  1732. }
  1733. });