Person.js 40 KB

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