Person.js 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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. this.loadSelectNode();
  213. if (this.options.count.toInt()!==1) this.loadSelectedNode();
  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. this.loadSelectedNodeScroll();
  435. },
  436. loadSelectedNodeScroll: function(){
  437. MWF.require("MWF.widget.ScrollBar", function(){
  438. var _self = this;
  439. new MWF.widget.ScrollBar(this.selectedScrollNode, {
  440. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  441. });
  442. }.bind(this));
  443. },
  444. loadSelectedNodeMobile: function(){
  445. this.selectedScrollNode = new Element("div", {
  446. "styles": this.css.selectedScrollNode
  447. }).inject(this.contentNode);
  448. this.selectedNode = new Element("div", {
  449. "styles": this.css.selectedNode
  450. }).inject(this.selectedScrollNode);
  451. this.setSelectedItem();
  452. MWF.require("MWF.widget.ScrollBar", function(){
  453. var _self = this;
  454. new MWF.widget.ScrollBar(this.selectedScrollNode, {
  455. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4,"axis": {"x": false, "y": true}
  456. });
  457. }.bind(this));
  458. this.selectedScrollNode.setStyle("display", "none");
  459. },
  460. setSelectedItem: function(){
  461. if (this.options.values.length){
  462. this.options.values.each(function(v, i){
  463. if (typeOf(v)==="object"){
  464. this.selectedItems.push(this._newItemSelected(v, this, null));
  465. }else{
  466. this._getItem(function(json){
  467. this.options.values[i] = json.data;
  468. this.selectedItems.push(this._newItemSelected(json.data, this, null));
  469. }.bind(this), null, v, false);
  470. }
  471. // this._getItem(function(json){
  472. // this.selectedItems.push(this._newItemSelected(json.data, this, null));
  473. // }.bind(this), null, v, false);
  474. }.bind(this));
  475. }
  476. },
  477. loadLetters: function(){
  478. var _self = this;
  479. 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"];
  480. if (layout.mobile){
  481. var size = this.container.getSize();
  482. var w = (layout.mobile) ? (size.x-18)/13 : (size.x-20-4-18)/13;
  483. //letterNode.setStyle("width", ""+w+"px");
  484. this.css.letterNode.width = ""+w+"px";
  485. this.css.letterNode_over.width = ""+w+"px";
  486. }
  487. letters.each(function(l){
  488. var letterNode = new Element("div", {
  489. "styles": this.css.letterNode,
  490. "text": l
  491. }).inject(this.letterAreaNode);
  492. if (layout.mobile){
  493. letterNode.addEvents({
  494. "click": function(){
  495. _self.listPersonByPinyin(this);
  496. }
  497. });
  498. }else{
  499. letterNode.addEvents({
  500. "mouseover": function(e){
  501. e.target.setStyles(this.css.letterNode_over);
  502. var showNode = new Element("div", {
  503. "styles": this.css.letterShowNode,
  504. "text": e.target.get("text")
  505. }).inject(this.selectNode);
  506. showNode.position({
  507. relativeTo: this.itemAreaScrollNode,
  508. position: "center",
  509. edge: "center"
  510. });
  511. e.target.store("showNode", showNode);
  512. }.bind(this),
  513. "mouseout": function(e){
  514. var showNode = e.target.retrieve("showNode");
  515. showNode.destroy();
  516. e.target.setStyles(this.css.letterNode);
  517. }.bind(this),
  518. "click": function(){
  519. _self.listPersonByPinyin(this);
  520. }
  521. });
  522. }
  523. }.bind(this));
  524. },
  525. listPersonByPinyin: function(node){
  526. this.searchInput.focus();
  527. var pinyin = this.searchInput.get("value");
  528. pinyin = pinyin+node.get("text");
  529. this.searchInput.set("value", pinyin);
  530. if (!this.options.groups.length && !this.options.roles.length){
  531. if (pinyin){
  532. this._listItemByPinyin(function(json){
  533. this.initSearchArea(true);
  534. json.data.each(function(data){
  535. // var flag = true;
  536. // if (this.options.departments){
  537. // if (this.options.departments.length){
  538. // if (this.options.departments.indexOf(data.departmentName)==-1) flag = false;
  539. // }
  540. // }
  541. // if (this.options.companys){
  542. // if (this.options.companys.length){
  543. // if (this.options.companys.indexOf(data.company)==-1) flag = false;
  544. // }
  545. // }
  546. if( !this.isExcluded( data ) ) {
  547. this._newItemSearch(data, this, this.itemSearchAreaNode);
  548. }
  549. //this._newItem(data, this, this.itemSearchAreaNode);
  550. //this._newItem(data, this, this.itemSearchAreaNode);
  551. }.bind(this));
  552. }.bind(this), null, pinyin.toLowerCase());
  553. }
  554. }else{
  555. if (pinyin){
  556. this.initSearchArea(true);
  557. this.searchInItems(pinyin);
  558. }else{
  559. this.initSearchArea(false);
  560. }
  561. }
  562. },
  563. initLoadSelectItems: function(){
  564. this.loaddingItems = false;
  565. this.isItemLoaded = false;
  566. this.loadItemsQueue = 0;
  567. this.initSearchArea(false);
  568. },
  569. //loadSelectItems: function(addToNext){
  570. // if (!this.isItemLoaded){
  571. // if (!this.loaddingItems){
  572. // this.loaddingItems = true;
  573. // var count = 20;
  574. // this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  575. // if (json.data.length){
  576. // json.data.each(function(data){
  577. // var item = this._newItem(data, this, this.itemAreaNode);
  578. // this.items.push(item);
  579. // }.bind(this));
  580. // this.loaddingItems = false;
  581. //
  582. // if (json.data.length<count){
  583. // this.isItemLoaded = true;
  584. // }else{
  585. // if (this.loadItemsQueue>0){
  586. // this.loadItemsQueue--;
  587. // this.loadSelectItems();
  588. // }
  589. // }
  590. // }else{
  591. // this.isItemLoaded = true;
  592. // this.loaddingItems = false;
  593. // }
  594. // }.bind(this));
  595. // }else{
  596. // if (addToNext) this.loadItemsQueue++;
  597. // }
  598. // }
  599. //},
  600. loadSelectItems: function(addToNext, lastExcludeCount ){
  601. //lastExcludeCount 参数:表示本次加载是为了补足上次load的时候被排除的数量
  602. if (!this.isItemLoaded){
  603. if (!this.loaddingItems){
  604. this.loaddingItems = true;
  605. var count = 20;
  606. this._listItemNext(this.getLastLoadedItemId(), count, function(json){
  607. if (json.data.length){
  608. var excludedCount = 0;
  609. json.data.each(function(data, i){
  610. if( this.isExcluded( data ) ){
  611. excludedCount++;
  612. if( i+1 === count )this.tailExcludeItemId = data.distinguishedName
  613. }else{
  614. var item = this._newItem(data, this, this.itemAreaNode);
  615. this.items.push(item);
  616. if( i+1 === count )this.tailExcludeItemId = null;
  617. }
  618. }.bind(this));
  619. this.loaddingItems = false;
  620. if( lastExcludeCount ){ //如果是因为上次load的时候被排除而加载的
  621. if( count - lastExcludeCount - excludedCount < 0 ){ //如果本次load的数量还不够补足排除的数量,需要再次load
  622. excludedCount = lastExcludeCount + excludedCount - count; //把不足的数量作为再次load的参数
  623. this.loadItemsQueue++
  624. }
  625. }else if( excludedCount > 0 ){ //把排除的数量作为再次load的参数
  626. this.loadItemsQueue++
  627. }
  628. if (json.data.length<count){
  629. this.isItemLoaded = true;
  630. }else{
  631. if (this.loadItemsQueue>0){
  632. this.loadItemsQueue--;
  633. this.loadSelectItems( addToNext, excludedCount );
  634. }
  635. }
  636. }else{
  637. this.isItemLoaded = true;
  638. this.loaddingItems = false;
  639. }
  640. }.bind(this));
  641. }else{
  642. if (addToNext) this.loadItemsQueue++;
  643. }
  644. }
  645. },
  646. getLastLoadedItemId: function(){
  647. if( this.tailExcludeItemId )return this.tailExcludeItemId;
  648. return (this.items.length) ? this.items[this.items.length-1].data.distinguishedName : "(0)";
  649. },
  650. //loadSelectItemsByCondition: function(){
  651. // this.options.groups.each(function(group){
  652. //
  653. // this.orgAction.listGroupByKey(function(json){
  654. // if (json.data.length){
  655. // var groupData = json.data[0];
  656. // var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  657. // this._getChildrenItemIds(groupData).each(function(id){
  658. // this._getItem(function(json){
  659. // var item = this._newItem(json.data, this, category.children);
  660. // this.items.push(item);
  661. // }.bind(this), null, id);
  662. // }.bind(this));
  663. // }
  664. // }.bind(this), null, group);
  665. // }.bind(this));
  666. //
  667. // this.options.roles.each(function(role){
  668. // this.orgAction.listRoleByKey(function(json){
  669. // if (json.data.length){
  670. // var roleData = json.data[0];
  671. // var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  672. // this._getChildrenItemIds(roleData).each(function(id){
  673. // this._getItem(function(json){
  674. // var item = this._newItem(json.data, this, category.children);
  675. // this.items.push(item);
  676. // }.bind(this), null, id)
  677. // }.bind(this));
  678. // }
  679. // }.bind(this), null, role);
  680. // }.bind(this));
  681. //},
  682. loadSelectItemsByCondition: function(){
  683. this.options.groups.each(function(group){
  684. this.orgAction.listGroupByKey(function(json){
  685. if (json.data.length){
  686. var groupData = json.data[0];
  687. var category = this._newItemCategory("ItemGroupCategory", groupData, this, this.itemAreaNode);
  688. this._getChildrenItemIds(groupData).each(function(id){
  689. this._getItem(function(json){
  690. if( !this.isExcluded( json.data ) ) {
  691. var item = this._newItem(json.data, this, category.children);
  692. this.items.push(item);
  693. }
  694. }.bind(this), null, id);
  695. }.bind(this));
  696. }
  697. }.bind(this), null, group);
  698. }.bind(this));
  699. this.options.roles.each(function(role){
  700. this.orgAction.listRoleByKey(function(json){
  701. if (json.data.length){
  702. var roleData = json.data[0];
  703. var category = this._newItemCategory("ItemRoleCategory", roleData, this, this.itemAreaNode);
  704. this._getChildrenItemIds(roleData).each(function(id){
  705. this._getItem(function(json){
  706. if( !this.isExcluded( json.data ) ) {
  707. var item = this._newItem(json.data, this, category.children);
  708. this.items.push(item);
  709. }
  710. }.bind(this), null, id)
  711. }.bind(this));
  712. }
  713. }.bind(this), null, role);
  714. }.bind(this));
  715. },
  716. isExcluded : function( d ){
  717. if( this.options.exclude.length === 0 )return false;
  718. if( !this.excludeFlagMap ){
  719. this.excludeFlagMap = {};
  720. this.options.exclude.each( function( e ){
  721. if( !e )return;
  722. this.excludeFlagMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.id || e.unique || e.employee || e.levelName) ] = true;
  723. }.bind(this));
  724. }
  725. var map = this.excludeFlagMap;
  726. return ( d.distinguishedName && map[ d.distinguishedName ] ) ||
  727. ( d.id && map[ d.id ] ) ||
  728. ( d.unique && map[ d.unique ] ) ||
  729. ( d.employee && map[ d.employee ] ) ||
  730. ( d.levelName && map[ d.levelName ] );
  731. },
  732. _getChildrenItemIds: function(data){
  733. return data.personList;
  734. },
  735. _newItemCategory: function(type, data, selector, item){
  736. return new MWF.xApplication.Selector.Person[type](data, selector, item)
  737. },
  738. _listItemByKey: function(callback, failure, key){
  739. this.orgAction.listPersonByKey(function(json){
  740. if (callback) callback.apply(this, [json]);
  741. }.bind(this), failure, key);
  742. },
  743. _getItem: function(callback, failure, id, async){
  744. this.orgAction.getPerson(function(json){
  745. if (callback) callback.apply(this, [json]);
  746. }.bind(this), failure, ((typeOf(id)==="string") ? id : id.distinguishedName), async);
  747. },
  748. _newItemSelected: function(data, selector, item){
  749. return new MWF.xApplication.Selector.Person.ItemSelected(data, selector, item)
  750. },
  751. _listItemByPinyin: function(callback, failure, key){
  752. this.orgAction.listPersonByPinyin(function(json){
  753. if (callback) callback.apply(this, [json]);
  754. }.bind(this), failure, key);
  755. },
  756. _newItem: function(data, selector, container){
  757. return new MWF.xApplication.Selector.Person.Item(data, selector, container);
  758. },
  759. _newItemSearch: function(data, selector, container){
  760. return this._newItem(data, selector, container);
  761. },
  762. _listItemNext: function(last, count, callback){
  763. this.orgAction.listPersonNext(last, count, function(json){
  764. if (callback) callback.apply(this, [json]);
  765. }.bind(this));
  766. },
  767. _scrollEvent: function(y){
  768. if (!this.options.groups.length && !this.options.roles.length){
  769. var scrollSize = this.itemAreaScrollNode.getScrollSize();
  770. var clientSize = this.itemAreaScrollNode.getSize();
  771. var scrollHeight = scrollSize.y-clientSize.y;
  772. if (y+30>scrollHeight) {
  773. if (!this.isItemLoaded) this.loadSelectItems();
  774. }
  775. }
  776. }
  777. });
  778. MWF.xApplication.Selector.Person.Item = new Class({
  779. initialize: function(data, selector, container, level){
  780. this.data = data;
  781. this.selector = selector;
  782. this.container = container;
  783. this.isSelected = false;
  784. this.level = (level) ? level.toInt() : 1;
  785. this.load();
  786. },
  787. _getShowName: function(){
  788. return this.data.name+"("+this.data.employee+")";
  789. },
  790. _getTtiteText: function(){
  791. return this.data.name+"("+this.data.employee+")";
  792. },
  793. _setIcon: function(){
  794. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/personicon.png)");
  795. },
  796. load: function(){
  797. this.node = new Element("div", {
  798. "styles": this.selector.css.selectorItem
  799. }).inject(this.container);
  800. this.levelNode = new Element("div", {
  801. "styles": this.selector.css.selectorItemLevelNode
  802. }).inject(this.node);
  803. var indent = this.level*10;
  804. this.levelNode.setStyle("width", ""+indent+"px");
  805. this.iconNode = new Element("div", {
  806. "styles": this.selector.css.selectorItemIconNode
  807. }).inject(this.node);
  808. this._setIcon();
  809. this.actionNode = new Element("div", {
  810. "styles": this.selector.css.selectorItemActionNode
  811. }).inject(this.node);
  812. this.textNode = new Element("div", {
  813. "styles": this.selector.css.selectorItemTextNode,
  814. "text": this._getShowName(),
  815. "title": this._getTtiteText()
  816. }).inject(this.node);
  817. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  818. this.textNode.setStyle("margin-left", ""+m+"px");
  819. this.loadSubItem();
  820. this.setEvent();
  821. this.check();
  822. },
  823. loadSubItem: function(){},
  824. check: function(){
  825. if (this.selector.options.count.toInt()===1){
  826. this.checkSelectedSingle();
  827. }else{
  828. this.checkSelected();
  829. }
  830. },
  831. checkSelectedSingle: function(){
  832. var selectedItem = this.selector.options.values.filter(function(item, index){
  833. if (typeOf(item)==="object") return this.data.distinguishedName === item.distinguishedName;
  834. if (typeOf(item)==="string") return this.data.distinguishedName === item;
  835. return false;
  836. }.bind(this));
  837. if (selectedItem.length){
  838. this.selectedSingle();
  839. }
  840. },
  841. checkSelected: function(){
  842. var selectedItem = this.selector.selectedItems.filter(function(item, index){
  843. return item.data.distinguishedName === this.data.distinguishedName;
  844. }.bind(this));
  845. if (selectedItem.length){
  846. //selectedItem[0].item = this;
  847. selectedItem[0].addItem(this);
  848. this.selectedItem = selectedItem[0];
  849. this.setSelected();
  850. }
  851. },
  852. setSelected: function(){
  853. this.isSelected = true;
  854. this.node.setStyles(this.selector.css.selectorItem_selected);
  855. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  856. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  857. },
  858. setEvent: function(){
  859. this.node.addEvents({
  860. "mouseover": function(){
  861. this.overItem();
  862. }.bind(this),
  863. "mouseout": function(){
  864. this.outItem();
  865. }.bind(this),
  866. "click": function(){
  867. this.clickItem();
  868. }.bind(this)
  869. });
  870. },
  871. clickItem: function(){
  872. if (this.selector.options.count.toInt()===1){
  873. this.selectedSingle();
  874. }else{
  875. if (this.isSelected){
  876. this.unSelected();
  877. }else{
  878. this.selected();
  879. }
  880. }
  881. },
  882. overItem: function(){
  883. if (!this.isSelected){
  884. this.node.setStyles(this.selector.css.selectorItem_over);
  885. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  886. }
  887. },
  888. outItem: function(){
  889. if (!this.isSelected){
  890. this.node.setStyles(this.selector.css.selectorItem);
  891. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  892. }
  893. },
  894. selectedSingle: function(){
  895. if (!this.isSelected){
  896. if (this.selector.currentItem) this.selector.currentItem.unSelectedSingle();
  897. this.getData(function(){
  898. this.selector.currentItem = this;
  899. this.isSelected = true;
  900. this.selector.selectedItems.push(this);
  901. this.node.setStyles(this.selector.css.selectorItem_selected);
  902. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  903. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  904. }.bind(this));
  905. }else {
  906. this.unSelectedSingle();
  907. }
  908. },
  909. getData: function(callback){
  910. if (callback) callback();
  911. },
  912. unSelectedSingle: function(){
  913. this.selector.currentItem = null;
  914. this.isSelected = false;
  915. this.selector.selectedItems.erase(this);
  916. this.node.setStyles(this.selector.css.selectorItem);
  917. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  918. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  919. },
  920. selected: function(){
  921. if ((this.selector.options.count.toInt()===0) || (this.selector.selectedItems.length+1)<=this.selector.options.count){
  922. this.isSelected = true;
  923. this.node.setStyles(this.selector.css.selectorItem_selected);
  924. this.textNode.setStyles(this.selector.css.selectorItemTextNode_selected);
  925. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected);
  926. this.selectedItem = this.selector._newItemSelected(this.data, this.selector, this);
  927. this.selectedItem.check();
  928. this.selector.selectedItems.push(this.selectedItem);
  929. }else{
  930. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "最多可选择"+this.selector.options.count+"个选项", this.selector.node);
  931. }
  932. },
  933. unSelected: function(){
  934. this.isSelected = false;
  935. this.node.setStyles(this.selector.css.selectorItem);
  936. this.textNode.setStyles(this.selector.css.selectorItemTextNode);
  937. this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  938. if (this.selectedItem){
  939. this.selector.selectedItems.erase(this.selectedItem);
  940. this.selectedItem.items.each(function(item){
  941. if (item != this){
  942. item.isSelected = false;
  943. item.node.setStyles(this.selector.css.selectorItem);
  944. item.textNode.setStyles(this.selector.css.selectorItemTextNode);
  945. item.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  946. }
  947. }.bind(this));
  948. this.selectedItem.destroy();
  949. this.selectedItem = null;
  950. }
  951. }
  952. });
  953. MWF.xApplication.Selector.Person.ItemSelected = new Class({
  954. Extends: MWF.xApplication.Selector.Person.Item,
  955. initialize: function(data, selector, item){
  956. this.data = data;
  957. this.selector = selector;
  958. this.container = this.selector.selectedNode;
  959. this.isSelected = false;
  960. this.items = [];
  961. if (item) this.items.push(item);
  962. this.level = 0;
  963. this.getData(function(){
  964. this.load();
  965. }.bind(this));
  966. },
  967. getData: function(callback){
  968. if (callback) callback();
  969. },
  970. clickItem: function(){
  971. if (this.items.length){
  972. this.items.each(function(item){
  973. item.unSelected();
  974. });
  975. }else{
  976. //this.item.selectedItem = null;
  977. //this.item.isSelected = false;
  978. this.destroy();
  979. this.selector.selectedItems.erase(this);
  980. }
  981. },
  982. overItem: function(){
  983. if (!this.isSelected){
  984. this.node.setStyles(this.selector.css.selectorItem_over);
  985. this.actionNode.setStyles(this.selector.css.selectorItemActionNode_selected_over);
  986. }
  987. },
  988. addItem: function(item){
  989. if (this.items.indexOf(item)===-1) this.items.push(item);
  990. },
  991. check: function(){
  992. if (this.selector.items.length){
  993. var items = this.selector.items.filter(function(item, index){
  994. return item.data.distinguishedName === this.data.distinguishedName;
  995. }.bind(this));
  996. this.items = items;
  997. if (items.length){
  998. items.each(function(item){
  999. item.selectedItem = this;
  1000. item.setSelected();
  1001. }.bind(this));
  1002. }
  1003. }
  1004. },
  1005. destroy: function(){
  1006. this.node.destroy();
  1007. delete this;
  1008. }
  1009. });
  1010. MWF.xApplication.Selector.Person.ItemCategory = new Class({
  1011. Extends: MWF.xApplication.Selector.Person.Item,
  1012. initialize: function(data, selector, container, level){
  1013. this.data = data;
  1014. this.selector = selector;
  1015. this.container = container;
  1016. this.isSelected = false;
  1017. this.level = (level) ? level.toInt() : 1;
  1018. this.load();
  1019. },
  1020. createNode: function(){
  1021. this.node = new Element("div", {
  1022. "styles": this.selector.css.selectorItemCategory
  1023. }).inject(this.container);
  1024. },
  1025. load: function(){
  1026. this.createNode();
  1027. this.levelNode = new Element("div", {
  1028. "styles": this.selector.css.selectorItemLevelNode
  1029. }).inject(this.node);
  1030. var indent = this.level*10;
  1031. this.levelNode.setStyle("width", ""+indent+"px");
  1032. this.iconNode = new Element("div", {
  1033. "styles": this.selector.css.selectorItemIconNode
  1034. }).inject(this.node);
  1035. this._setIcon();
  1036. this.actionNode = new Element("div", {
  1037. "styles": (this.selector.options.expand) ? this.selector.css.selectorItemCategoryActionNode_expand : this.selector.css.selectorItemCategoryActionNode_collapse
  1038. }).inject(this.node);
  1039. this.textNode = new Element("div", {
  1040. "styles": this.selector.css.selectorItemCategoryTextNode,
  1041. "text": this._getShowName()
  1042. }).inject(this.node);
  1043. var m = this.textNode.getStyle("margin-left").toFloat()+indent;
  1044. this.textNode.setStyle("margin-left", ""+m+"px");
  1045. this.children = new Element("div", {
  1046. "styles": this.selector.css.selectorItemCategoryChildrenNode
  1047. }).inject(this.node, "after");
  1048. if (!this.selector.options.expand) this.children.setStyle("display", "none");
  1049. var subIdList = this.selector._getChildrenItemIds(this.data);
  1050. if (subIdList){
  1051. var count = subIdList.length;
  1052. this.childrenHeight = count*29;
  1053. this.children.setStyle("height", ""+this.childrenHeight+"px");
  1054. }
  1055. if (!this._hasChild()){
  1056. this.actionNode.setStyle("background", "transparent");
  1057. this.textNode.setStyle("color", "#777");
  1058. }
  1059. this.setEvent();
  1060. this.check();
  1061. this.afterLoad();
  1062. },
  1063. afterLoad: function(){
  1064. if (this.level===1) this.clickItem();
  1065. },
  1066. clickItem: function(){
  1067. if (this._hasChild()){
  1068. if (!this.fx){
  1069. this.fx = new Fx.Tween(this.children, {
  1070. "duration": 200
  1071. // "transition": Fx.Transitions.Cubic.easeIn
  1072. });
  1073. };
  1074. if (!this.fx.isRunning()){
  1075. var display = this.children.getStyle("display");
  1076. if (display === "none"){
  1077. this.children.setStyles({
  1078. "display": "block",
  1079. "height": "0px"
  1080. });
  1081. this.fx.start("height", "0px", ""+this.childrenHeight+"px");
  1082. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand);
  1083. }else{
  1084. if (!this.childrenHeight) this.childrenHeight = this.children.getStyle("height").toFloat();
  1085. this.fx.start("height", ""+this.childrenHeight+"px", "0px").chain(function(){
  1086. this.children.setStyles({
  1087. "display": "none",
  1088. "height": "0px"
  1089. });
  1090. }.bind(this));
  1091. this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse);
  1092. }
  1093. }
  1094. }
  1095. },
  1096. overItem: function(){
  1097. //if (!this.isSelected){
  1098. // this.node.setStyles(this.selector.css.selectorItem_over);
  1099. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode_over);
  1100. //}
  1101. },
  1102. outItem: function(){
  1103. //if (!this.isSelected){
  1104. // this.node.setStyles(this.selector.css.selectorItem);
  1105. // this.actionNode.setStyles(this.selector.css.selectorItemActionNode);
  1106. //}
  1107. },
  1108. _hasChild: function(){
  1109. var subIdList = this.selector._getChildrenItemIds(this.data);
  1110. if (subIdList) if (subIdList.length) return true;
  1111. return false;
  1112. }
  1113. });
  1114. MWF.xApplication.Selector.Person.ItemGroupCategory = new Class({
  1115. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  1116. _getShowName: function(){
  1117. return this.data.name;
  1118. },
  1119. _setIcon: function(){
  1120. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/groupicon.png)");
  1121. }
  1122. });
  1123. MWF.xApplication.Selector.Person.ItemRoleCategory = new Class({
  1124. Extends: MWF.xApplication.Selector.Person.ItemCategory,
  1125. _getShowName: function(){
  1126. return this.data.name;
  1127. },
  1128. _setIcon: function(){
  1129. this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/default/icon/roleicon.png)");
  1130. }
  1131. });
  1132. MWF.xApplication.Selector.Person.Filter = new Class({
  1133. Implements: [Options, Events],
  1134. options: {
  1135. "style": "default",
  1136. "groups": [],
  1137. "roles": [],
  1138. },
  1139. initialize: function(value, options){
  1140. this.setOptions(options);
  1141. this.value = value;
  1142. this.orgAction = MWF.Actions.get("x_organization_assemble_control");
  1143. },
  1144. filter: function(value, callback){
  1145. this.value = value;
  1146. var key = this.value;
  1147. if (this.options.groups.length || this.options.roles.length) key = {"key": key, "groupList": this.options.groupList, "roleList": this.options.roleList};
  1148. this.orgAction.listPersonByKey(function(json){
  1149. data = json.data;
  1150. if (callback) callback(data)
  1151. }.bind(this), null, key);
  1152. }
  1153. });