Person.js 47 KB

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