Person.js 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239
  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. },
  18. initialize: function(container, options){
  19. this.setOptions(options);
  20. this.path = "/x_component_Selector/$Selector/";
  21. this.cssPath = "/x_component_Selector/$Selector/"+this.options.style+"/css.wcss";
  22. this._loadCss(true);
  23. this.container = $(container);
  24. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  25. this.processAction = MWF.Actions.get("x_processplatform_assemble_surface");
  26. this.designerAction = MWF.Actions.get("x_processplatform_assemble_designer");
  27. this.portalAction = MWF.Actions.get("x_portal_assemble_surface");
  28. this.portalDesignerAction = MWF.Actions.get("x_portal_assemble_designer");
  29. this.cmsAction = MWF.Actions.get("x_cms_assemble_control");
  30. this.queryAction = MWF.Actions.get("x_query_assemble_designer");
  31. //this.action = new MWF.xApplication.Selector.Actions.RestActions();
  32. this.lastPeople = "";
  33. this.pageCount = "13";
  34. this.selectedItems = [];
  35. this.items = [];
  36. },
  37. load: function(){
  38. if (layout.mobile){
  39. this.loadMobile();
  40. }else{
  41. this.loadPc();
  42. }
  43. this.fireEvent("load");
  44. },
  45. loadMobile: function(){
  46. this.container.mask({
  47. "destroyOnHide": true,
  48. "style": this.css.maskNode
  49. });
  50. this.node = new Element("div", {"styles": this.css.containerNodeMobile});
  51. this.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  52. this.titleNode = new Element("div", {
  53. "styles": this.css.titleNodeMobile
  54. }).inject(this.node);
  55. this.titleCancelActionNode = new Element("div", {
  56. "styles": this.css.titleCancelActionNodeMobile,
  57. "text": MWF.SelectorLP.back
  58. }).inject(this.titleNode);
  59. this.titleOkActionNode = new Element("div", {
  60. "styles": this.css.titleOkActionNodeMobile,
  61. "text": MWF.SelectorLP.ok
  62. }).inject(this.titleNode);
  63. this.titleTextNode = new Element("div", {
  64. "styles": this.css.titleTextNodeMobile,
  65. "text": this.options.title
  66. }).inject(this.titleNode);
  67. this.contentNode = new Element("div", {
  68. "styles": this.css.contentNode
  69. }).inject(this.node);
  70. var size = this.container.getSize();
  71. var height = size.y-40;
  72. this.contentNode.setStyle("height", ""+height+"px");
  73. this.loadContent();
  74. this.node.inject(this.container);
  75. this.node.setStyles({
  76. "top": "0px",
  77. "left": "0px"
  78. });
  79. this.setEvent();
  80. },
  81. setMaskResize: function(){
  82. var size = this.container.getSize();
  83. this.maskInterval = window.setInterval(function(){
  84. var resize = this.container.getSize();
  85. if ((size.x!==resize.x) || (size.y!==resize.y)){
  86. this.mask.position();
  87. this.mask.resize();
  88. size.x = resize.x;
  89. size.y = resize.y;
  90. }
  91. }.bind(this), 66);
  92. },
  93. loadPc: function(){
  94. this.css.maskNode["z-index"] = this.options.zIndex;
  95. var position = this.container.getPosition(this.container.getOffsetParent());
  96. this.mask= new Mask(this.container, {
  97. "destroyOnHide": true,
  98. "style": this.css.maskNode,
  99. "useIframeShim": true,
  100. "iframeShimOptions": {"browsers": true},
  101. "onShow": function(){
  102. this.shim.shim.setStyles({
  103. "opacity": 0,
  104. "top": ""+position.y+"px",
  105. "left": ""+position.x+"px"
  106. });
  107. }
  108. });
  109. this.mask.show();
  110. this.setMaskResize();
  111. // this.container.setStyle("z-index", this.options.zIndex);
  112. this.node = new Element("div", {
  113. "styles": (this.options.count.toInt()===1) ? this.css.containerNodeSingle : this.css.containerNode,
  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.node.setStyle("z-index", this.options.zIndex.toInt()+1);
  123. this.titleNode = new Element("div", {
  124. "styles": this.css.titleNode
  125. }).inject(this.node);
  126. this.titleActionNode = new Element("div", {
  127. "styles": this.css.titleActionNode
  128. }).inject(this.titleNode);
  129. this.titleTextNode = new Element("div", {
  130. "styles": this.css.titleTextNode,
  131. "text": this.options.title
  132. }).inject(this.titleNode);
  133. this.contentNode = new Element("div", {
  134. "styles": this.css.contentNode
  135. }).inject(this.node);
  136. this.loadContent();
  137. this.actionNode = new Element("div", {
  138. "styles": this.css.actionNode
  139. }).inject(this.node);
  140. if (this.options.count.toInt()===1) this.actionNode.setStyle("text-align", "center");
  141. this.loadAction();
  142. this.node.inject(this.container);
  143. this.node.position({
  144. relativeTo: this.container,
  145. position: "center",
  146. edge: "center"
  147. });
  148. var size = this.container.getSize();
  149. var nodeSize = this.node.getSize();
  150. this.node.makeDraggable({
  151. "handle": this.titleNode,
  152. "limit": {
  153. "x": [0, size.x-nodeSize.x],
  154. "y": [0, size.y-nodeSize.y]
  155. }
  156. });
  157. this.setEvent();
  158. },
  159. setEvent: function(){
  160. if (this.titleActionNode){
  161. this.titleActionNode.addEvent("click", function(){
  162. this.fireEvent("cancel");
  163. this.close();
  164. }.bind(this));
  165. }
  166. if (this.titleCancelActionNode){
  167. this.titleCancelActionNode.addEvent("click", function(){
  168. this.fireEvent("cancel");
  169. this.close();
  170. }.bind(this));
  171. }
  172. if (this.titleOkActionNode){
  173. this.titleOkActionNode.addEvent("click", function(){
  174. this.fireEvent("complete", [this.selectedItems]);
  175. this.close();
  176. }.bind(this));
  177. }
  178. },
  179. close: function(){
  180. this.fireEvent("close");
  181. this.node.destroy();
  182. //if (this.mask) this.mask.hide();
  183. this.container.unmask();
  184. if (this.maskInterval){
  185. window.clearInterval(this.maskInterval);
  186. this.maskInterval = null;
  187. }
  188. MWF.release(this);
  189. delete this;
  190. },
  191. loadAction: function(){
  192. this.okActionNode = new Element("button", {
  193. "styles": this.css.okActionNode,
  194. "text": MWF.SelectorLP.ok
  195. }).inject(this.actionNode);
  196. this.cancelActionNode = new Element("button", {
  197. "styles": this.css.cancelActionNode,
  198. "text": MWF.SelectorLP.cancel
  199. }).inject(this.actionNode);
  200. this.okActionNode.addEvent("click", function(){
  201. this.fireEvent("complete", [this.selectedItems]);
  202. this.close();
  203. }.bind(this));
  204. this.cancelActionNode.addEvent("click", function(){this.fireEvent("cancel"); this.close();}.bind(this));
  205. },
  206. loadContent: function( contentNode ){
  207. if( contentNode )this.contentNode = contentNode;
  208. if (layout.mobile){
  209. if (this.options.count.toInt()!==1) this.loadSelectedNodeMobile();
  210. this.loadSelectNodeMobile();
  211. }else{
  212. if (this.options.count.toInt()!==1) this.loadSelectedNode();
  213. this.loadSelectNode();
  214. }
  215. },
  216. loadSelectNodeMobile: function(){
  217. this.selectNode = new Element("div", {
  218. "styles": this.css.selectNodeMobile
  219. }).inject(this.contentNode);
  220. var size = this.container.getSize();
  221. var height = size.y-40-20-6;
  222. this.selectNode.setStyle("height", ""+height+"px");
  223. this.searchInputDiv = new Element("div", {
  224. "styles": this.css.searchInputDiv
  225. }).inject(this.selectNode);
  226. this.searchInput = new Element("input", {
  227. "styles": (this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
  228. "type": "text"
  229. }).inject(this.searchInputDiv);
  230. var width = size.x-20-18;
  231. this.searchInput.setStyle("width", ""+width+"px");
  232. this.searchInput.setStyle("height", "20px");
  233. this.initSearchInput();
  234. this.letterAreaNode = new Element("div", {
  235. "styles": this.css.letterAreaMobileNode
  236. }).inject(this.selectNode);
  237. width = size.x-18;
  238. this.letterAreaNode.setStyle("width", ""+width+"px");
  239. this.loadLetters();
  240. this.itemAreaScrollNode = new Element("div", {
  241. "styles": this.css.itemAreaScrollNode
  242. }).inject(this.selectNode);
  243. height = size.y-40-20-78;
  244. this.itemAreaScrollNode.setStyle("height", ""+height+"px");
  245. this.itemAreaScrollNode.setStyle("overflow", "auto");
  246. this.itemAreaNode = new Element("div", {
  247. "styles": this.css.itemAreaNode
  248. }).inject(this.itemAreaScrollNode);
  249. this.itemSearchAreaNode = new Element("div", {
  250. "styles": this.css.itemAreaNode
  251. }).inject(this.itemAreaScrollNode);
  252. this.itemSearchAreaNode.setStyle("display", "none");
  253. //MWF.require("MWF.widget.ScrollBar", function(){
  254. // var _self = this;
  255. // new MWF.widget.ScrollBar(this.itemAreaScrollNode, {
  256. // "style":"xApp_Organization_Explorer",
  257. // "where": "before",
  258. // "distance": 30,
  259. // "friction": 4,
  260. // "axis": {"x": false, "y": true},
  261. // "onScroll": function(y){
  262. // _self._scrollEvent(y);
  263. // }
  264. // });
  265. //}.bind(this));
  266. this.initLoadSelectItems();
  267. this.checkLoadSelectItems();
  268. },
  269. checkLoadSelectItems: function(){
  270. if (!this.options.groups.length && !this.options.roles.length){
  271. this.loadSelectItems();
  272. }else{
  273. this.loadSelectItemsByCondition();
  274. }
  275. },
  276. loadSelectNode: function(){
  277. this.selectNode = new Element("div", {
  278. "styles": (this.options.count.toInt()===1) ? this.css.selectNodeSingle : this.css.selectNode
  279. }).inject(this.contentNode);
  280. this.searchInputDiv = new Element("div", {
  281. "styles": this.css.searchInputDiv
  282. }).inject(this.selectNode);
  283. this.searchInput = new Element("input", {
  284. "styles": (this.options.count.toInt()===1) ? this.css.searchInputSingle : this.css.searchInput,
  285. "type": "text"
  286. }).inject(this.searchInputDiv);
  287. this.initSearchInput();
  288. this.letterAreaNode = new Element("div", {
  289. "styles": this.css.letterAreaNode
  290. }).inject(this.selectNode);
  291. this.loadLetters();
  292. this.itemAreaScrollNode = new Element("div", {
  293. "styles": this.css.itemAreaScrollNode
  294. }).inject(this.selectNode);
  295. this.itemAreaNode = new Element("div", {
  296. "styles": this.css.itemAreaNode
  297. }).inject(this.itemAreaScrollNode);
  298. this.itemSearchAreaNode = new Element("div", {
  299. "styles": this.css.itemAreaNode
  300. }).inject(this.itemAreaScrollNode);
  301. this.itemSearchAreaNode.setStyle("display", "none");
  302. this.loadSelectNodeScroll();
  303. this.initLoadSelectItems();
  304. this.checkLoadSelectItems();
  305. },
  306. loadSelectNodeScroll: function(){
  307. MWF.require("MWF.widget.ScrollBar", function(){
  308. var _self = this;
  309. new MWF.widget.ScrollBar(this.itemAreaScrollNode, {
  310. "style":"xApp_Organization_Explorer",
  311. "where": "before",
  312. "distance": 30,
  313. "friction": 4,
  314. "axis": {"x": false, "y": true},
  315. "onScroll": function(y){
  316. _self._scrollEvent(y);
  317. }
  318. });
  319. }.bind(this));
  320. },
  321. initSearchInput: function(){
  322. this.searchInput.addEvents({
  323. "keydown": function(e){
  324. var iTimerID = this.searchInput.retrieve("searchTimer", null);
  325. if (iTimerID){
  326. window.clearTimeout(iTimerID);
  327. this.searchInput.eliminate("searchTimer");
  328. }
  329. iTimerID = window.setTimeout(function(){
  330. this.search();
  331. }.bind(this), 800);
  332. this.searchInput.store("searchTimer", iTimerID);
  333. }.bind(this),
  334. "change": function(e){
  335. var key = this.searchInput.get("value");
  336. if (!key) this.initSearchArea(false);
  337. }.bind(this),
  338. "blur": function(){
  339. var key = this.searchInput.get("value");
  340. if (!key) this.initSearchArea(false);
  341. }.bind(this)
  342. });
  343. },
  344. initSearchArea: function(flag){
  345. if (flag){
  346. this.itemSearchAreaNode.empty();
  347. this.itemAreaNode.setStyle("display", "none");
  348. this.itemSearchAreaNode.setStyle("display", "block");
  349. }else{
  350. this.itemAreaNode.setStyle("display", "block");
  351. this.itemSearchAreaNode.setStyle("display", "none");
  352. }
  353. },
  354. search: function(){
  355. if (!this.options.groups.length && !this.options.roles.length){
  356. var key = this.searchInput.get("value");
  357. if (key){
  358. this._listItemByKey(function(json){
  359. this.initSearchArea(true);
  360. json.data.each(function(data){
  361. this._newItemSearch(data, this, this.itemSearchAreaNode);
  362. //this._newItem(data, this, this.itemSearchAreaNode);
  363. }.bind(this));
  364. }.bind(this), null, key);
  365. }else{
  366. this.initSearchArea(false);
  367. }
  368. }else{
  369. var key = this.searchInput.get("value");
  370. if (key){
  371. this.initSearchArea(true);
  372. this.searchInItems(key);
  373. }else{
  374. this.initSearchArea(false);
  375. }
  376. }
  377. },
  378. searchInItems: function(key){
  379. this.createItemsSearchData(function(){
  380. var word = key.toLowerCase();
  381. var createdId = [];
  382. this.itemsSearchData.each(function(obj){
  383. var text = obj.text+"#"+obj.pinyin+"#"+obj.firstPY;
  384. if (text.indexOf(word)!==-1){
  385. if (createdId.indexOf(obj.data.distinguishedName)===-1){
  386. this._newItem(obj.data, this, this.itemSearchAreaNode);
  387. createdId.push(obj.data.distinguishedName);
  388. }
  389. }
  390. }.bind(this));
  391. //this.searchItemsData(this.itemsSearchData.name, word, createdId);
  392. //this.searchItemsData(this.itemsSearchData.pinyin, word, createdId);
  393. //this.searchItemsData(this.itemsSearchData.firstPY, word, createdId);
  394. delete createdId;
  395. }.bind(this));
  396. },
  397. createItemsSearchData: function(callback){
  398. if (!this.itemsSearchData){
  399. this.itemsSearchData = [];
  400. MWF.require("MWF.widget.PinYin", function(){
  401. var initIds = [];
  402. this.items.each(function(item){
  403. if (initIds.indexOf(item.data.distinguishedName)==-1){
  404. var text = item._getShowName().toLowerCase();
  405. var pinyin = text.toPY().toLowerCase();
  406. var firstPY = text.toPYFirst().toLowerCase();
  407. this.itemsSearchData.push({
  408. "text": text,
  409. "pinyin": pinyin,
  410. "firstPY": firstPY,
  411. "data": item.data
  412. });
  413. initIds.push(item.data.distinguishedName);
  414. }
  415. }.bind(this));
  416. delete initIds;
  417. if (callback) callback();
  418. }.bind(this));
  419. }else{
  420. if (callback) callback();
  421. }
  422. },
  423. loadSelectedNode: function(){
  424. this.selectedContainerNode = new Element("div", {
  425. "styles": this.css.selectedContainerNode
  426. }).inject(this.contentNode);
  427. this.selectedScrollNode = new Element("div", {
  428. "styles": this.css.selectedScrollNode
  429. }).inject(this.selectedContainerNode);
  430. this.selectedNode = new Element("div", {
  431. "styles": this.css.selectedNode
  432. }).inject(this.selectedScrollNode);
  433. this.setSelectedItem();
  434. MWF.require("MWF.widget.ScrollBar", function(){
  435. var _self = this;
  436. new MWF.widget.ScrollBar(this.selectedScrollNode, {
  437. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  438. });
  439. }.bind(this));
  440. },
  441. loadSelectedNodeMobile: function(){
  442. this.selectedScrollNode = new Element("div", {
  443. "styles": this.css.selectedScrollNode
  444. }).inject(this.contentNode);
  445. this.selectedNode = new Element("div", {
  446. "styles": this.css.selectedNode
  447. }).inject(this.selectedScrollNode);
  448. this.setSelectedItem();
  449. MWF.require("MWF.widget.ScrollBar", function(){
  450. var _self = this;
  451. new MWF.widget.ScrollBar(this.selectedScrollNode, {
  452. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  453. });
  454. }.bind(this));
  455. this.selectedScrollNode.setStyle("display", "none");
  456. },
  457. setSelectedItem: function(){
  458. if (this.options.values.length){
  459. this.options.values.each(function(v, i){
  460. if (typeOf(v)==="object"){
  461. this.selectedItems.push(this._newItemSelected(v, this, null));
  462. }else{
  463. this._getItem(function(json){
  464. this.options.values[i] = json.data;
  465. this.selectedItems.push(this._newItemSelected(json.data, this, null));
  466. }.bind(this), null, v, false);
  467. }
  468. // this._getItem(function(json){
  469. // this.selectedItems.push(this._newItemSelected(json.data, this, null));
  470. // }.bind(this), null, v, false);
  471. }.bind(this));
  472. }
  473. },
  474. loadLetters: function(){
  475. var _self = this;
  476. 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"];
  477. if (layout.mobile){
  478. var size = this.container.getSize();
  479. var w = (layout.mobile) ? (size.x-18)/13 : (size.x-20-4-18)/13;
  480. //letterNode.setStyle("width", ""+w+"px");
  481. this.css.letterNode.width = ""+w+"px";
  482. this.css.letterNode_over.width = ""+w+"px";
  483. }
  484. letters.each(function(l){
  485. var letterNode = new Element("div", {
  486. "styles": this.css.letterNode,
  487. "text": l
  488. }).inject(this.letterAreaNode);
  489. if (layout.mobile){
  490. letterNode.addEvents({
  491. "click": function(){
  492. _self.listPersonByPinyin(this);
  493. }
  494. });
  495. }else{
  496. letterNode.addEvents({
  497. "mouseover": function(e){
  498. e.target.setStyles(this.css.letterNode_over);
  499. var showNode = new Element("div", {
  500. "styles": this.css.letterShowNode,
  501. "text": e.target.get("text")
  502. }).inject(this.selectNode);
  503. showNode.position({
  504. relativeTo: this.itemAreaScrollNode,
  505. position: "center",
  506. edge: "center"
  507. });
  508. e.target.store("showNode", showNode);
  509. }.bind(this),
  510. "mouseout": function(e){
  511. var showNode = e.target.retrieve("showNode");
  512. showNode.destroy();
  513. e.target.setStyles(this.css.letterNode);
  514. }.bind(this),
  515. "click": function(){
  516. _self.listPersonByPinyin(this);
  517. }
  518. });
  519. }
  520. }.bind(this));
  521. },
  522. listPersonByPinyin: function(node){
  523. this.searchInput.focus();
  524. var pinyin = this.searchInput.get("value");
  525. pinyin = pinyin+node.get("text");
  526. this.searchInput.set("value", pinyin);
  527. if (!this.options.groups.length && !this.options.roles.length){
  528. if (pinyin){
  529. this._listItemByPinyin(function(json){
  530. this.initSearchArea(true);
  531. json.data.each(function(data){
  532. // var flag = true;
  533. // if (this.options.departments){
  534. // if (this.options.departments.length){
  535. // if (this.options.departments.indexOf(data.departmentName)==-1) flag = false;
  536. // }
  537. // }
  538. // if (this.options.companys){
  539. // if (this.options.companys.length){
  540. // if (this.options.companys.indexOf(data.company)==-1) flag = false;
  541. // }
  542. // }
  543. if( !this.isExcluded( data ) ) {
  544. this._newItemSearch(data, this, this.itemSearchAreaNode);
  545. }
  546. //this._newItem(data, this, this.itemSearchAreaNode);
  547. //this._newItem(data, this, this.itemSearchAreaNode);
  548. }.bind(this));
  549. }.bind(this), null, pinyin.toLowerCase());
  550. }
  551. }else{
  552. if (pinyin){
  553. this.initSearchArea(true);
  554. this.searchInItems(pinyin);
  555. }else{
  556. this.initSearchArea(false);
  557. }
  558. }
  559. },
  560. initLoadSelectItems: function(){
  561. this.loaddingItems = false;
  562. this.isItemLoaded = false;
  563. this.loadItemsQueue = 0;
  564. this.initSearchArea(false);
  565. },
  566. //loadSelectItems: function(addToNext){
  567. // if (!this.isItemLoaded){
  568. // if (!this.loaddingItems){
  569. // this.loaddingItems = true;
  570. // var count = 20;
  571. // this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  572. // if (json.data.length){
  573. // json.data.each(function(data){
  574. // var item = this._newItem(data, this, this.itemAreaNode);
  575. // this.items.push(item);
  576. // }.bind(this));
  577. // this.loaddingItems = false;
  578. //
  579. // if (json.data.length<count){
  580. // this.isItemLoaded = true;
  581. // }else{
  582. // if (this.loadItemsQueue>0){
  583. // this.loadItemsQueue--;
  584. // this.loadSelectItems();
  585. // }
  586. // }
  587. // }else{
  588. // this.isItemLoaded = true;
  589. // this.loaddingItems = false;
  590. // }
  591. // }.bind(this));
  592. // }else{
  593. // if (addToNext) this.loadItemsQueue++;
  594. // }
  595. // }
  596. //},
  597. loadSelectItems: function(addToNext, lastExcludeCount ){
  598. //lastExcludeCount 参数:表示本次加载是为了补足上次load的时候被排除的数量
  599. if (!this.isItemLoaded){
  600. if (!this.loaddingItems){
  601. this.loaddingItems = true;
  602. var count = 20;
  603. this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  604. if (json.data.length){
  605. var excludedCount = 0;
  606. json.data.each(function(data, i){
  607. if( this.isExcluded( data ) ){
  608. excludedCount++;
  609. if( i+1 === count )this.tailExcludeItemId = data.distinguishedName
  610. }else{
  611. var item = this._newItem(data, this, this.itemAreaNode);
  612. this.items.push(item);
  613. if( i+1 === count )this.tailExcludeItemId = null;
  614. }
  615. }.bind(this));
  616. this.loaddingItems = false;
  617. if( lastExcludeCount ){ //如果是因为上次load的时候被排除而加载的
  618. if( count - lastExcludeCount - excludedCount < 0 ){ //如果本次load的数量还不够补足排除的数量,需要再次load
  619. excludedCount = lastExcludeCount + excludedCount - count; //把不足的数量作为再次load的参数
  620. this.loadItemsQueue++
  621. }
  622. }else if( excludedCount > 0 ){ //把排除的数量作为再次load的参数
  623. this.loadItemsQueue++
  624. }
  625. if (json.data.length<count){
  626. this.isItemLoaded = true;
  627. }else{
  628. if (this.loadItemsQueue>0){
  629. this.loadItemsQueue--;
  630. this.loadSelectItems( addToNext, excludedCount );
  631. }
  632. }
  633. }else{
  634. this.isItemLoaded = true;
  635. this.loaddingItems = false;
  636. }
  637. }.bind(this));
  638. }else{
  639. if (addToNext) this.loadItemsQueue++;
  640. }
  641. }
  642. },
  643. getLastLoadedItemId: function(){
  644. if( this.tailExcludeItemId )return this.tailExcludeItemId;
  645. return (this.items.length) ? this.items[this.items.length-1].data.distinguishedName : "(0)";
  646. },
  647. //loadSelectItemsByCondition: function(){
  648. // this.options.groups.each(function(group){
  649. //
  650. // this.orgAction.listGroupByKey(function(json){
  651. // if (json.data.length){
  652. // var groupData = json.data[0];
  653. // var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  654. // this._getChildrenItemIds(groupData).each(function(id){
  655. // this._getItem(function(json){
  656. // var item = this._newItem(json.data, this, category.children);
  657. // this.items.push(item);
  658. // }.bind(this), null, id);
  659. // }.bind(this));
  660. // }
  661. // }.bind(this), null, group);
  662. // }.bind(this));
  663. //
  664. // this.options.roles.each(function(role){
  665. // this.orgAction.listRoleByKey(function(json){
  666. // if (json.data.length){
  667. // var roleData = json.data[0];
  668. // var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  669. // this._getChildrenItemIds(roleData).each(function(id){
  670. // this._getItem(function(json){
  671. // var item = this._newItem(json.data, this, category.children);
  672. // this.items.push(item);
  673. // }.bind(this), null, id)
  674. // }.bind(this));
  675. // }
  676. // }.bind(this), null, role);
  677. // }.bind(this));
  678. //},
  679. loadSelectItemsByCondition: function(){
  680. this.options.groups.each(function(group){
  681. this.orgAction.listGroupByKey(function(json){
  682. if (json.data.length){
  683. var groupData = json.data[0];
  684. var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  685. this._getChildrenItemIds(groupData).each(function(id){
  686. this._getItem(function(json){
  687. if( !this.isExcluded( json.data ) ) {
  688. var item = this._newItem(json.data, this, category.children);
  689. this.items.push(item);
  690. }
  691. }.bind(this), null, id);
  692. }.bind(this));
  693. }
  694. }.bind(this), null, group);
  695. }.bind(this));
  696. this.options.roles.each(function(role){
  697. this.orgAction.listRoleByKey(function(json){
  698. if (json.data.length){
  699. var roleData = json.data[0];
  700. var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  701. this._getChildrenItemIds(roleData).each(function(id){
  702. this._getItem(function(json){
  703. if( !this.isExcluded( json.data ) ) {
  704. var item = this._newItem(json.data, this, category.children);
  705. this.items.push(item);
  706. }
  707. }.bind(this), null, id)
  708. }.bind(this));
  709. }
  710. }.bind(this), null, role);
  711. }.bind(this));
  712. },
  713. isExcluded : function( d ){
  714. if( this.options.exclude.length === 0 )return false;
  715. if( !this.excludeFlagMap ){
  716. this.excludeFlagMap = {};
  717. this.options.exclude.each( function( e ){
  718. if( !e )return;
  719. this.excludeFlagMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.id || e.unique || e.employee || e.levelName) ] = true;
  720. }.bind(this));
  721. }
  722. var map = this.excludeFlagMap;
  723. return ( d.distinguishedName && map[ d.distinguishedName ] ) ||
  724. ( d.id && map[ d.id ] ) ||
  725. ( d.unique && map[ d.unique ] ) ||
  726. ( d.employee && map[ d.employee ] ) ||
  727. ( d.levelName && map[ d.levelName ] );
  728. },
  729. _getChildrenItemIds: function(data){
  730. return data.personList;
  731. },
  732. _newItemCategory: function(type, data, selector, item){
  733. return new MWF.xApplication.Selector.Person[type](data, selector, item)
  734. },
  735. _listItemByKey: function(callback, failure, key){
  736. this.orgAction.listPersonByKey(function(json){
  737. if (callback) callback.apply(this, [json]);
  738. }.bind(this), failure, key);
  739. },
  740. _getItem: function(callback, failure, id, async){
  741. this.orgAction.getPerson(function(json){
  742. if (callback) callback.apply(this, [json]);
  743. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  744. },
  745. _newItemSelected: function(data, selector, item){
  746. return new MWF.xApplication.Selector.Person.ItemSelected(data, selector, item)
  747. },
  748. _listItemByPinyin: function(callback, failure, key){
  749. this.orgAction.listPersonByPinyin(function(json){
  750. if (callback) callback.apply(this, [json]);
  751. }.bind(this), failure, key);
  752. },
  753. _newItem: function(data, selector, container){
  754. return new MWF.xApplication.Selector.Person.Item(data, selector, container);
  755. },
  756. _newItemSearch: function(data, selector, container){
  757. return this._newItem(data, selector, container);
  758. },
  759. _listItemNext: function(last, count, callback){
  760. this.orgAction.listPersonNext(last, count, function(json){
  761. if (callback) callback.apply(this, [json]);
  762. }.bind(this));
  763. },
  764. _scrollEvent: function(y){
  765. if (!this.options.groups.length && !this.options.roles.length){
  766. var scrollSize = this.itemAreaScrollNode.getScrollSize();
  767. var clientSize = this.itemAreaScrollNode.getSize();
  768. var scrollHeight = scrollSize.y-clientSize.y;
  769. if (y+30>scrollHeight) {
  770. if (!this.isItemLoaded) this.loadSelectItems();
  771. }
  772. }
  773. }
  774. });
  775. MWF.xApplication.Selector.Person.Item = new Class({
  776. initialize: function(data, selector, container, level){
  777. this.data = data;
  778. this.selector = selector;
  779. this.container = container;
  780. this.isSelected = false;
  781. this.level = (level) ? level.toInt() : 1;
  782. this.load();
  783. },
  784. _getShowName: function(){
  785. return this.data.name+"("+this.data.employee+")";
  786. },
  787. _getTtiteText: function(){
  788. return this.data.name+"("+this.data.employee+")";
  789. },
  790. _setIcon: function(){
  791. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  792. },
  793. load: function(){
  794. this.node = new Element("div", {
  795. "styles": this.selector.css.selectorItem
  796. }).inject(this.container);
  797. this.levelNode = new Element("div", {
  798. "styles": this.selector.css.selectorItemLevelNode
  799. }).inject(this.node);
  800. var indent = this.level*10;
  801. this.levelNode.setStyle("width", ""+indent+"px");
  802. this.iconNode = new Element("div", {
  803. "styles": this.selector.css.selectorItemIconNode
  804. }).inject(this.node);
  805. this._setIcon();
  806. this.actionNode = new Element("div", {
  807. "styles": this.selector.css.selectorItemActionNode
  808. }).inject(this.node);
  809. this.textNode = new Element("div", {
  810. "styles": this.selector.css.selectorItemTextNode,
  811. "text": this._getShowName(),
  812. "title": this._getTtiteText()
  813. }).inject(this.node);
  814. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  815. this.textNode.setStyle("margin-left", ""+m+"px");
  816. this.loadSubItem();
  817. this.setEvent();
  818. this.check();
  819. },
  820. loadSubItem: function(){},
  821. check: function(){
  822. if (this.selector.options.count.toInt()===1){
  823. this.checkSelectedSingle();
  824. }else{
  825. this.checkSelected();
  826. }
  827. },
  828. checkSelectedSingle: function(){
  829. var selectedItem = this.selector.options.values.filter(function(item, index){
  830. if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
  831. if (typeOf(item)==="string") return this.data.distinguishedName === item;
  832. return false;
  833. }.bind(this));
  834. if (selectedItem.length){
  835. this.selectedSingle();
  836. }
  837. },
  838. checkSelected: function(){
  839. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  840. return item.data.distinguishedName === this.data.distinguishedName;
  841. }.bind(this));
  842. if (selectedItem.length){
  843. //selectedItem[0].item = this;
  844. selectedItem[0].addItem(this);
  845. this.selectedItem = selectedItem[0];
  846. this.setSelected();
  847. }
  848. },
  849. setSelected: function(){
  850. this.isSelected = true;
  851. this.node.setStyles(this.selector.css.selectorItem_selected);
  852. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  853. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  854. },
  855. setEvent: function(){
  856. this.node.addEvents({
  857. "mouseover": function(){
  858. this.overItem();
  859. }.bind(this),
  860. "mouseout": function(){
  861. this.outItem();
  862. }.bind(this),
  863. "click": function(){
  864. this.clickItem();
  865. }.bind(this)
  866. });
  867. },
  868. clickItem: function(){
  869. if (this.selector.options.count.toInt()===1){
  870. this.selectedSingle();
  871. }else{
  872. if (this.isSelected){
  873. this.unSelected();
  874. }else{
  875. this.selected();
  876. }
  877. }
  878. },
  879. overItem: function(){
  880. if (!this.isSelected){
  881. this.node.setStyles(this.selector.css.selectorItem_over);
  882. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  883. }
  884. },
  885. outItem: function(){
  886. if (!this.isSelected){
  887. this.node.setStyles(this.selector.css.selectorItem);
  888. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  889. }
  890. },
  891. selectedSingle: function(){
  892. if (!this.isSelected){
  893. if (this.selector.currentItem) this.selector.currentItem.unSelectedSingle();
  894. this.getData(function(){
  895. this.selector.currentItem = this;
  896. this.isSelected = true;
  897. this.selector.selectedItems.push(this);
  898. this.node.setStyles(this.selector.css.selectorItem_selected);
  899. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  900. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  901. }.bind(this));
  902. }else {
  903. this.unSelectedSingle();
  904. }
  905. },
  906. getData: function(callback){
  907. if (callback) callback();
  908. },
  909. unSelectedSingle: function(){
  910. this.selector.currentItem = null;
  911. this.isSelected = false;
  912. this.selector.selectedItems.erase(this);
  913. this.node.setStyles(this.selector.css.selectorItem);
  914. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  915. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  916. },
  917. selected: function(){
  918. if ((this.selector.options.count.toInt()===0) || (this.selector.selectedItems.length+1)<=this.selector.options.count){
  919. this.isSelected = true;
  920. this.node.setStyles(this.selector.css.selectorItem_selected);
  921. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  922. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  923. this.selectedItem = this.selector._newItemSelected(this.data, this.selector, this);
  924. this.selectedItem.check();
  925. this.selector.selectedItems.push(this.selectedItem);
  926. }else{
  927. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+this.selector.options.count+"个选项", this.selector.node);
  928. }
  929. },
  930. unSelected: function(){
  931. this.isSelected = false;
  932. this.node.setStyles(this.selector.css.selectorItem);
  933. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  934. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  935. if (this.selectedItem){
  936. this.selector.selectedItems.erase(this.selectedItem);
  937. this.selectedItem.items.each(function(item){
  938. if (item != this){
  939. item.isSelected = false;
  940. item.node.setStyles(this.selector.css.selectorItem);
  941. item.textNode.setStyles(this.selector.css.selectorItemTextNode);
  942. item.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  943. }
  944. }.bind(this));
  945. this.selectedItem.destroy();
  946. this.selectedItem = null;
  947. }
  948. }
  949. });
  950. MWF.xApplication.Selector.Person.ItemSelected = new Class({
  951. Extends: MWF.xApplication.Selector.Person.Item,
  952. initialize: function(data, selector, item){
  953. this.data = data;
  954. this.selector = selector;
  955. this.container = this.selector.selectedNode;
  956. this.isSelected = false;
  957. this.items = [];
  958. if (item) this.items.push(item);
  959. this.level = 0;
  960. this.getData(function(){
  961. this.load();
  962. }.bind(this));
  963. },
  964. getData: function(callback){
  965. if (callback) callback();
  966. },
  967. clickItem: function(){
  968. if (this.items.length){
  969. this.items.each(function(item){
  970. item.unSelected();
  971. });
  972. }else{
  973. //this.item.selectedItem = null;
  974. //this.item.isSelected = false;
  975. this.destroy();
  976. this.selector.selectedItems.erase(this);
  977. }
  978. },
  979. overItem: function(){
  980. if (!this.isSelected){
  981. this.node.setStyles(this.selector.css.selectorItem_over);
  982. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  983. }
  984. },
  985. addItem: function(item){
  986. if (this.items.indexOf(item)===-1) this.items.push(item);
  987. },
  988. check: function(){
  989. if (this.selector.items.length){
  990. var items = this.selector.items.filter(function(item, index){
  991. return item.data.distinguishedName === this.data.distinguishedName;
  992. }.bind(this));
  993. this.items = items;
  994. if (items.length){
  995. items.each(function(item){
  996. item.selectedItem = this;
  997. item.setSelected();
  998. }.bind(this));
  999. }
  1000. }
  1001. },
  1002. destroy: function(){
  1003. this.node.destroy();
  1004. delete this;
  1005. }
  1006. });
  1007. MWF.xApplication.Selector.Person.ItemCategory = new Class({
  1008. Extends: MWF.xApplication.Selector.Person.Item,
  1009. initialize: function(data, selector, container, level){
  1010. this.data = data;
  1011. this.selector = selector;
  1012. this.container = container;
  1013. this.isSelected = false;
  1014. this.level = (level) ? level.toInt() : 1;
  1015. this.load();
  1016. },
  1017. createNode: function(){
  1018. this.node = new Element("div", {
  1019. "styles": this.selector.css.selectorItemCategory
  1020. }).inject(this.container);
  1021. },
  1022. load: function(){
  1023. this.createNode();
  1024. this.levelNode = new Element("div", {
  1025. "styles": this.selector.css.selectorItemLevelNode
  1026. }).inject(this.node);
  1027. var indent = this.level*10;
  1028. this.levelNode.setStyle("width", ""+indent+"px");
  1029. this.iconNode = new Element("div", {
  1030. "styles": this.selector.css.selectorItemIconNode
  1031. }).inject(this.node);
  1032. this._setIcon();
  1033. this.actionNode = new Element("div", {
  1034. "styles": (this.selector.options.expand) ? this.selector.css.selectorItemCategoryActionNode_expand : this.selector.css.selectorItemCategoryActionNode_collapse
  1035. }).inject(this.node);
  1036. this.textNode = new Element("div", {
  1037. "styles": this.selector.css.selectorItemCategoryTextNode,
  1038. "text": this._getShowName()
  1039. }).inject(this.node);
  1040. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  1041. this.textNode.setStyle("margin-left", ""+m+"px");
  1042. this.children = new Element("div", {
  1043. "styles": this.selector.css.selectorItemCategoryChildrenNode
  1044. }).inject(this.node, "after");
  1045. if (!this.selector.options.expand) this.children.setStyle("display", "none");
  1046. var subIdList = this.selector._getChildrenItemIds(this.data);
  1047. if (subIdList){
  1048. var count = subIdList.length;
  1049. this.childrenHeight = count*29;
  1050. this.children.setStyle("height", ""+this.childrenHeight+"px");
  1051. }
  1052. if (!this._hasChild()){
  1053. this.actionNode.setStyle("background", "transparent");
  1054. this.textNode.setStyle("color", "#777");
  1055. }
  1056. this.setEvent();
  1057. this.check();
  1058. this.afterLoad();
  1059. },
  1060. afterLoad: function(){
  1061. if (this.level===1) this.clickItem();
  1062. },
  1063. clickItem: function(){
  1064. if (this._hasChild()){
  1065. if (!this.fx){
  1066. this.fx = new Fx.Tween(this.children, {
  1067. "duration": 200
  1068. // "transition": Fx.Transitions.Cubic.easeIn
  1069. });
  1070. };
  1071. if (!this.fx.isRunning()){
  1072. var display = this.children.getStyle("display");
  1073. if (display === "none"){
  1074. this.children.setStyles({
  1075. "display": "block",
  1076. "height": "0px"
  1077. });
  1078. this.fx.start("height", "0px", ""+this.childrenHeight+"px");
  1079. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  1080. }else{
  1081. if (!this.childrenHeight) this.childrenHeight = this.children.getStyle("height").toFloat();
  1082. this.fx.start("height", ""+this.childrenHeight+"px", "0px").chain(function(){
  1083. this.children.setStyles({
  1084. "display": "none",
  1085. "height": "0px"
  1086. });
  1087. }.bind(this));
  1088. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  1089. }
  1090. }
  1091. }
  1092. },
  1093. overItem: function(){
  1094. //if (!this.isSelected){
  1095. // this.node.setStyles(this.selector.css.selectorItem_over);
  1096. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  1097. //}
  1098. },
  1099. outItem: function(){
  1100. //if (!this.isSelected){
  1101. // this.node.setStyles(this.selector.css.selectorItem);
  1102. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1103. //}
  1104. },
  1105. _hasChild: function(){
  1106. var subIdList = this.selector._getChildrenItemIds(this.data);
  1107. if (subIdList) if (subIdList.length) return true;
  1108. return false;
  1109. }
  1110. });
  1111. MWF.xApplication.Selector.Person.ItemGroupCategory = new Class({
  1112. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  1113. _getShowName: function(){
  1114. return this.data.name;
  1115. },
  1116. _setIcon: function(){
  1117. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/groupicon.png)");
  1118. }
  1119. });
  1120. MWF.xApplication.Selector.Person.ItemRoleCategory = new Class({
  1121. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  1122. _getShowName: function(){
  1123. return this.data.name;
  1124. },
  1125. _setIcon: function(){
  1126. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/roleicon.png)");
  1127. }
  1128. });
  1129. MWF.xApplication.Selector.Person.Filter = new Class({
  1130. Implements: [Options, Events],
  1131. options: {
  1132. "style": "default",
  1133. "groups": [],
  1134. "roles": [],
  1135. },
  1136. initialize: function(value, options){
  1137. this.setOptions(options);
  1138. this.value = value;
  1139. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1140. },
  1141. filter: function(value, callback){
  1142. this.value = value;
  1143. var key = this.value;
  1144. if (this.options.groups.length || this.options.roles.length) key = {"key": key, "groupList": this.options.groupList, "roleList": this.options.roleList};
  1145. this.orgAction.listPersonByKey(function(json){
  1146. data = json.data;
  1147. if (callback) callback(data)
  1148. }.bind(this), null, key);
  1149. }
  1150. });