Person.js 32 KB

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