GroupExplorer.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147
  1. MWF.xApplication.Organization.GroupExplorer = new Class({
  2. Extends: MWF.widget.Common,
  3. Implements: [Options, Events],
  4. options: {
  5. "style": "default",
  6. "lp": {
  7. },
  8. "creator": false
  9. },
  10. _loadPath: function(){
  11. this.path = "/x_component_Organization/$GroupExplorer/";
  12. this.cssPath = "/x_component_Organization/$GroupExplorer/"+this.options.style+"/css.wcss";
  13. },
  14. _loadLp: function(){
  15. this.options.lp = {
  16. "elementLoaded": this.app.lp.groupLoaded,
  17. "search": this.app.lp.search,
  18. "searchText": this.app.lp.searchText,
  19. "elementSave": this.app.lp.groupSave,
  20. "deleteElements": this.app.lp.deleteGroups,
  21. "deleteElementsTitle": this.app.lp.deleteGroupsTitle,
  22. "deleteElementsConfirm": this.app.lp.deleteGroupsConfirm,
  23. "elementBaseText": this.app.lp.groupBaseText,
  24. "elementName": this.app.lp.groupName,
  25. "edit": this.app.lp.edit,
  26. "cancel": this.app.lp.cancel,
  27. "save": this.app.lp.save,
  28. "add": this.app.lp.add,
  29. "inputElementName": this.app.lp.inputGroupName,
  30. "elementMemberPersonText": this.app.lp.groupMemberPersonText,
  31. "personEmployee": this.app.lp.personEmployee,
  32. "personDisplay": this.app.lp.personDisplay,
  33. "personMail": this.app.lp.personMail,
  34. "personPhone": this.app.lp.personPhone,
  35. "deletePersonMemberTitle": this.app.lp.deletePersonMemberTitle,
  36. "deletePersonMember": this.app.lp.deletePersonMember,
  37. "elementMemberGroupText": this.app.lp.groupMemberGroupText,
  38. "groupDescription": this.app.lp.groupDescription,
  39. "groupName": this.app.lp.groupName,
  40. "deleteGroupMemberTitle": this.app.lp.deleteGroupMemberTitle,
  41. "deleteGroupMember": this.app.lp.deleteGroupMember
  42. }
  43. },
  44. initialize: function(node, actions, options){
  45. this.setOptions(options);
  46. this._loadPath();
  47. this._loadCss();
  48. this.actions = actions;
  49. this.node = $(node);
  50. this.loaddingElement = false;
  51. this.elements = [];
  52. this.isElementLoaded = false;
  53. this.loadElementQueue = 0;
  54. this.deleteElements = [];
  55. },
  56. clear: function(){
  57. this.loaddingElement = false;
  58. this.isElementLoaded = false;
  59. this.loadElementQueue = 0;
  60. this.chartNode.empty();
  61. },
  62. load: function(){
  63. this._loadLp();
  64. this.loadLayout();
  65. this.loadChart();
  66. },
  67. loadLayout: function(){
  68. this.chartAreaNode = new Element("div", {"styles": this.css.chartAreaNode}).inject(this.node);
  69. this.propertyAreaNode = new Element("div", {"styles": this.css.propertyAreaNode}).inject(this.node);
  70. this.resizeBarNode = new Element("div", {"styles": this.css.resizeBarNode}).inject(this.propertyAreaNode);
  71. this.propertyNode = new Element("div", {"styles": this.css.propertyNode}).inject(this.propertyAreaNode);
  72. this.propertyTitleNode = new Element("div", {"styles": this.css.propertyTitleNode}).inject(this.propertyNode);
  73. this.propertyContentNode = new Element("div", {"styles": this.css.propertyContentNode}).inject(this.propertyNode);
  74. this.loadToolbar();
  75. this.chartScrollNode = new Element("div", {"styles": this.css.chartScrollNode}).inject(this.chartAreaNode);
  76. this.chartNode = new Element("div", {"styles": this.css.chartNode}).inject(this.chartScrollNode);
  77. this.resizePropertyContentNode();
  78. this.app.addEvent("resize", function(){this.resizePropertyContentNode();}.bind(this));
  79. MWF.require("MWF.widget.ScrollBar", function(){
  80. var _self = this;
  81. new MWF.widget.ScrollBar(this.chartScrollNode, {
  82. "style":"xApp_Organization_Explorer",
  83. "where": "before",
  84. "distance": 100,
  85. "friction": 4,
  86. "axis": {"x": false, "y": true},
  87. "onScroll": function(y){
  88. var scrollSize = _self.chartScrollNode.getScrollSize();
  89. var clientSize = _self.chartScrollNode.getSize();
  90. var scrollHeight = scrollSize.y-clientSize.y;
  91. if (y+200>scrollHeight) {
  92. if (!_self.isElementLoaded) _self.loadElements();
  93. }
  94. }
  95. });
  96. new MWF.widget.ScrollBar(this.propertyContentNode, {
  97. "style":"xApp_Organization_Explorer", "where": "before", "distance": 100, "friction": 4, "axis": {"x": false, "y": true}
  98. });
  99. }.bind(this));
  100. this.propertyResize = new Drag(this.resizeBarNode,{
  101. "snap": 1,
  102. "onStart": function(el, e){
  103. var x = e.event.clientX;
  104. var y = e.event.clientY;
  105. el.store("position", {"x": x, "y": y});
  106. var size = this.chartAreaNode.getSize();
  107. el.store("initialWidth", size.x);
  108. }.bind(this),
  109. "onDrag": function(el, e){
  110. var x = e.event.clientX;
  111. // var y = e.event.y;
  112. var bodySize = this.node.getSize();
  113. var position = el.retrieve("position");
  114. var initialWidth = el.retrieve("initialWidth").toFloat();
  115. var dx = position.x.toFloat()-x.toFloat();
  116. var width = initialWidth-dx;
  117. if (width> bodySize.x/1.5) width = bodySize.x/1.5;
  118. if (width<400) width = 400;
  119. this.chartAreaNode.setStyle("width", width+1);
  120. this.propertyAreaNode.setStyle("margin-left", width);
  121. }.bind(this)
  122. });
  123. },
  124. getPageNodeCount: function(){
  125. var size = this.chartScrollNode.getSize();
  126. count = (size.y/46).toInt()+5;
  127. return count;
  128. },
  129. getLastLoadedElementId: function(){
  130. return (this.elements.length) ? this.elements[this.elements.length-1].data.id : "";
  131. },
  132. loadChart: function(){
  133. this.loadElements();
  134. this.app.addEvent("resize", function(){
  135. if (this.elements.length<this.getPageNodeCount()){
  136. this.loadElements(true);
  137. }
  138. }.bind(this));
  139. },
  140. loadElements: function(addToNext){
  141. if (!this.isElementLoaded){
  142. if (!this.loaddingElement){
  143. this.loaddingElement = true;
  144. var count = this.getPageNodeCount();
  145. this._listElementNext(this.getLastLoadedElementId(), count, function(json){
  146. if (json.data.length){
  147. this.loadChartContent(json.data);
  148. this.loaddingElement = false;
  149. if (json.data.length<count){
  150. this.isElementLoaded = true;
  151. this.app.notice(this.options.lp.elementLoaded, "ok", this.chartScrollNode, {"x": "center", "y": "bottom"});
  152. }else{
  153. if (this.loadElementQueue>0){
  154. this.loadElementQueue--;
  155. this.loadElements();
  156. }
  157. }
  158. }else{
  159. if (!this.elements.length){
  160. this.setNoGroupNoticeArea();
  161. }else{
  162. this.app.notice(this.options.lp.elementLoaded, "ok", this.chartScrollNode, {"x": "center", "y": "bottom"});
  163. }
  164. this.isElementLoaded = true;
  165. this.loaddingElement = false;
  166. }
  167. }.bind(this));
  168. }else{
  169. if (addToNext) this.loadElementQueue++;
  170. }
  171. }
  172. },
  173. setNoGroupNoticeArea: function(){},
  174. loadChartContent: function(data){
  175. data.each(function(itemData){
  176. var item = this._newElement(itemData, this);
  177. this.elements.push(item);
  178. item.load();
  179. }.bind(this));
  180. },
  181. resizePropertyContentNode: function(){
  182. var size = this.node.getSize();
  183. var tSize = this.propertyTitleNode.getSize();
  184. var mtt = this.propertyTitleNode.getStyle("margin-top").toFloat();
  185. var mbt = this.propertyTitleNode.getStyle("margin-bottom").toFloat();
  186. var mtc = this.propertyContentNode.getStyle("margin-top").toFloat();
  187. var mbc = this.propertyContentNode.getStyle("margin-bottom").toFloat();
  188. var height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  189. this.propertyContentNode.setStyle("height", height);
  190. tSize = this.toolbarNode.getSize();
  191. mtt = this.toolbarNode.getStyle("margin-top").toFloat();
  192. mbt = this.toolbarNode.getStyle("margin-bottom").toFloat();
  193. mtc = this.toolbarNode.getStyle("margin-top").toFloat();
  194. mbc = this.toolbarNode.getStyle("margin-bottom").toFloat();
  195. height = size.y-tSize.y-mtt-mbt-mtc-mbc;
  196. this.chartScrollNode.setStyle("height", height);
  197. },
  198. loadToolbar: function(){
  199. this.toolbarNode = new Element("div", {"styles": this.css.toolbarNode}).inject(this.chartAreaNode);
  200. if (MWF.AC.isGroupCreator()){
  201. this.isEditor = true;
  202. this.addTopElementNode = new Element("div", {"styles": this.css.addTopGroupNode}).inject(this.toolbarNode);
  203. this.addTopElementNode.addEvent("click", function(){
  204. this.addTopElement();
  205. }.bind(this));
  206. }
  207. this.createSearchNode();
  208. },
  209. createSearchNode: function(){
  210. this.searchNode = new Element("div", {"styles": this.css.searchNode}).inject(this.toolbarNode);
  211. this.searchButtonNode = new Element("div", {
  212. "styles": this.css.searchButtonNode,
  213. "title": this.options.lp.search
  214. }).inject(this.searchNode);
  215. this.searchButtonNode.addEvent("click", function(){
  216. this.searchOrg();
  217. }.bind(this));
  218. this.searchInputAreaNode = new Element("div", {
  219. "styles": this.css.searchInputAreaNode
  220. }).inject(this.searchNode);
  221. this.searchInputBoxNode = new Element("div", {
  222. "styles": this.css.searchInputBoxNode
  223. }).inject(this.searchInputAreaNode);
  224. this.searchInputNode = new Element("input", {
  225. "type": "text",
  226. "value": this.options.lp.searchText,
  227. "styles": this.css.searchInputNode,
  228. "x-webkit-speech": "1"
  229. }).inject(this.searchInputBoxNode);
  230. var _self = this;
  231. this.searchInputNode.addEvents({
  232. "focus": function(){
  233. if (this.value==_self.options.lp.searchText) this.set("value", "");
  234. },
  235. "blur": function(){if (!this.value) this.set("value", _self.options.lp.searchText);},
  236. "keydown": function(e){
  237. if (e.code==13){
  238. this.searchOrg();
  239. e.preventDefault();
  240. }
  241. }.bind(this),
  242. "selectstart": function(e){
  243. e.preventDefault();
  244. },
  245. "change": function(){
  246. var key = this.searchInputNode.get("value");
  247. if (!key || key==this.options.lp.searchText) {
  248. if (this.currentItem){
  249. if (this.currentItem.unSelected()){
  250. this.clear();
  251. this.loadElements();
  252. }else{
  253. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  254. }
  255. }
  256. }
  257. }.bind(this)
  258. });
  259. this.searchButtonNode.addEvent("click", function(){this.searchOrg();}.bind(this));
  260. },
  261. searchOrg: function(){
  262. var key = this.searchInputNode.get("value");
  263. if (key){
  264. if (key!=this.options.lp.searchText){
  265. var isSearchElement = true;
  266. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  267. if (isSearchElement){
  268. this._listElementByKey(function(json){
  269. if (this.currentItem) this.currentItem.unSelected();
  270. this.clear();
  271. json.data.each(function(itemData){
  272. var item = this._newElement(itemData, this);
  273. item.load();
  274. }.bind(this));
  275. }.bind(this), null, key);
  276. }else{
  277. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  278. }
  279. }else{
  280. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  281. if (isSearchElement){
  282. this.clear();
  283. this.loadElements();
  284. }else{
  285. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  286. }
  287. }
  288. }else{
  289. if (this.currentItem) isSearchElement = this.currentItem.unSelected();
  290. if (isSearchElement){
  291. this.clear();
  292. this.loadElements();
  293. }else{
  294. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  295. }
  296. }
  297. },
  298. addTopElement: function(){
  299. var isNewElement = true;
  300. if (this.currentItem) isNewElement = this.currentItem.unSelected();
  301. if (isNewElement){
  302. var newElementData = this._getAddElementData();
  303. var item = this._newElement(newElementData, this);
  304. item.load();
  305. item.selected();
  306. item.editBaseInfor();
  307. (new Fx.Scroll(this.chartScrollNode)).toElementCenter(item.node);
  308. }else{
  309. this.app.notice(this.options.lp.elementSave, "error", this.propertyContentNode);
  310. }
  311. },
  312. checkDeleteElements: function(){
  313. if (this.deleteElements.length){
  314. if (!this.deleteElementsNode){
  315. this.deleteElementsNode = new Element("div", {
  316. "styles": this.css.deleteGroupsNode,
  317. "text": this.options.lp.deleteElements
  318. }).inject(this.node);
  319. this.deleteElementsNode.position({
  320. relativeTo: this.chartScrollNode,
  321. position: "centerTop",
  322. edge: "centerTop"
  323. });
  324. this.deleteElementsNode.addEvent("click", function(e){
  325. this.deleteSelectedElements(e);
  326. }.bind(this));
  327. }
  328. }else{
  329. if (this.deleteElementsNode){
  330. this.deleteElementsNode.destroy();
  331. this.deleteElementsNode = null;
  332. delete this.deleteElementsNode;
  333. }
  334. }
  335. },
  336. deleteSelectedElements: function(e){
  337. var _self = this;
  338. this.app.confirm("infor", e, this.options.lp.deleteElementsTitle, this.options.lp.deleteElementsConfirm, 300, 120, function(){
  339. var deleted = [];
  340. var doCount = 0;
  341. var readyCount = _self.deleteElements.length;
  342. var errorText = "";
  343. var complete = function(){
  344. if (doCount == readyCount){
  345. if (errorText){
  346. _self.app.notice(errorText, "error", _self.propertyContentNode, {x: "left", y:"top"});
  347. }
  348. }
  349. }
  350. _self.deleteElements.each(function(group){
  351. group["delete"](function(){
  352. deleted.push(group);
  353. doCount++;
  354. if (_self.deleteElements.length==doCount){
  355. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  356. return !deleted.contains(item);
  357. });
  358. _self.checkDeleteElements();
  359. }
  360. complete();
  361. }, function(error){
  362. errorText = (errorText) ? errorText+"<br/><br/>"+error : error;
  363. doCount++;
  364. if (_self.deleteElements.length==doCount){
  365. _self.deleteElements = _self.deleteElements.filter(function(item, index){
  366. return !deleted.contains(item);
  367. });
  368. _self.checkDeleteElements();
  369. }
  370. complete();
  371. });
  372. });
  373. this.close();
  374. }, function(){
  375. this.close();
  376. });
  377. },
  378. _listElementNext: function(lastid, count, callback){
  379. this.actions.listGroupNext(lastid, count, function(json){
  380. if (callback) callback.apply(this, [json]);
  381. }.bind(this));
  382. },
  383. _newElement: function(data, explorer){
  384. return new MWF.xApplication.Organization.GroupExplorer.Group(data, explorer, this.isEditor);
  385. },
  386. _listElementByKey: function(callback, failure, key){
  387. this.actions.listGroupByKey(function(json){
  388. if (callback) callback.apply(this, [json]);
  389. }.bind(this), failure, key);
  390. },
  391. _getAddElementData: function(){
  392. return {
  393. "personList": [],
  394. "groupList": [],
  395. "id": "",
  396. "name": ""
  397. };
  398. }
  399. });
  400. MWF.xApplication.Organization.GroupExplorer.Group = new Class({
  401. initialize: function(data, explorer, isEditor){
  402. this.data = data;
  403. if (this.data.personList) this.data.personList = data.personList.filter(function(item){return item;});
  404. if (this.data.groupList) this.data.groupList = data.groupList.filter(function(item){return item;});
  405. this.explorer = explorer;
  406. this.chartNode = this.explorer.chartNode;
  407. this.initStyle();
  408. this.selectedPersons = [];
  409. this.selectedGroups = [];
  410. this.isEdit = false;
  411. this.isEditor = isEditor;
  412. this.deleteSelected = false;
  413. },
  414. initStyle: function(){
  415. this.style = this.explorer.css.groupItem;
  416. },
  417. load: function(){
  418. this.node = new Element("div", {"styles": this.style.node}).inject(this.chartNode);
  419. this.contentNode = new Element("div", {"styles": this.style.contentNode}).inject(this.node);
  420. this.childNode = new Element("div", {"styles": this.style.childNode}).inject(this.node);
  421. this.flagNode = new Element("div", {"styles": this.style.flagNode}).inject(this.contentNode);
  422. this.iconNode = new Element("div", {"styles": this.style.iconNode}).inject(this.contentNode);
  423. this.actionNode = new Element("div", {"styles": this.style.actionNode}).inject(this.contentNode);
  424. this.textNode = new Element("div", {"styles": this.style.textNode}).inject(this.contentNode);
  425. this.textNode.set({
  426. "text": this.data.name
  427. });
  428. this.setNewItem();
  429. this.node.inject(this.chartNode);
  430. this.addActions();
  431. this.setEvent();
  432. },
  433. setNewItem: function(){
  434. if (!this.created){
  435. if (!this.data.id){
  436. this.created = false;
  437. this.contentNode.setStyles(this.style.contentNodeNew);
  438. }else {
  439. this.created = true;
  440. this.contentNode.setStyles(this.style.contentNode);
  441. }
  442. }
  443. },
  444. addActions: function(){
  445. if (this.isEditor){
  446. if (MWF.AC.isGroupCreator()){
  447. this.deleteNode = new Element("div", {"styles": this.style.actionDeleteNode}).inject(this.actionNode);
  448. // this.addNode = new Element("div", {"styles": this.style.actionAddNode}).inject(this.actionNode);
  449. this.deleteNode.addEvent("click", function(e){
  450. if (!this.deleteSelected){
  451. this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  452. this.contentNode.setStyles(this.style.contentNode_selected);
  453. this.explorer.deleteElements.push(this);
  454. this.deleteSelected = true;
  455. this.explorer.checkDeleteElements();
  456. }else{
  457. this.deleteNode.setStyles(this.style.actionDeleteNode);
  458. this.contentNode.setStyles(this.style.contentNode);
  459. this.explorer.deleteElements.erase(this);
  460. this.deleteSelected = false;
  461. this.explorer.checkDeleteElements();
  462. }
  463. e.stopPropagation();
  464. }.bind(this));
  465. }
  466. }
  467. },
  468. setEvent: function(){
  469. this.contentNode.addEvents({
  470. "mouseover": function(e){
  471. if (this.explorer.currentItem!=this){
  472. this.flagNode.setStyles(this.style.flagNodeOver);
  473. }
  474. if (!this.deleteSelected) if (this.data.id) this.actionNode.fade("in");
  475. }.bind(this),
  476. "mouseout": function(e){
  477. if (this.explorer.currentItem!=this){
  478. this.flagNode.setStyles(this.style.flagNode);
  479. }
  480. if (!this.deleteSelected) if (this.data.id) this.actionNode.fade("out");
  481. }.bind(this),
  482. "click": function(e){
  483. if (this.explorer.currentItem){
  484. if (this.explorer.currentItem.unSelected()){
  485. this.selected();
  486. }else{
  487. this.explorer.app.notice(this.explorer.options.lp.elementSave, "error", this.propertyContentNode);
  488. }
  489. }else{
  490. this.selected();
  491. }
  492. }.bind(this)
  493. });
  494. },
  495. selected: function(){
  496. this.explorer.currentItem = this;
  497. this.flagNode.setStyles(this.style.flagNodeSelected);
  498. this.showItemProperty();
  499. },
  500. unSelected: function(){
  501. if (this.isEdit) return false;
  502. this.explorer.currentItem = null;
  503. this.flagNode.setStyles(this.style.flagNode);
  504. this.clearItemProperty();
  505. return true;
  506. },
  507. showItemProperty: function(){
  508. this.explorer.propertyTitleNode.set("text", this.data.name);
  509. this.showItemPropertyBase();
  510. this.showItemPropertyPerson();
  511. this.showItemPropertyGroup();
  512. // this.showItemPropertyBase();
  513. // this.showItemPropertyDuty();
  514. // this.showItemPropertyAttribute();
  515. },
  516. clearItemProperty: function(){
  517. this.explorer.propertyTitleNode.empty();
  518. this.explorer.propertyContentNode.empty();
  519. },
  520. showItemPropertyBase: function(){
  521. this.propertyBaseNode = new Element("div", {
  522. "styles": this.style.propertyInforNode
  523. }).inject(this.explorer.propertyContentNode);
  524. this.baseActionNode = new Element("div", {
  525. "styles": this.style.propertyInforActionNode
  526. }).inject(this.propertyBaseNode);
  527. this.propertyBaseTextNode = new Element("div", {
  528. "styles": this.style.propertyInforTextNode,
  529. "text": this.explorer.options.lp.elementBaseText
  530. }).inject(this.propertyBaseNode);
  531. if (this.isEditor) this.createEditBaseNode();
  532. this.propertyBaseContentNode = new Element("div", {
  533. "styles": this.style.propertyInforContentNode
  534. }).inject(this.propertyBaseNode);
  535. var html = "<table cellspacing='0' cellpadding='0' border='0' width='95%' align='center'>";
  536. html += "<tr><td class='formTitle'>"+this.explorer.options.lp.elementName+"</td><td id='formGroupName'></td></tr>";
  537. html += "</table>";
  538. this.propertyBaseContentNode.set("html", html);
  539. this.propertyBaseContentNode.getElements("td.formTitle").setStyles(this.style.propertyBaseContentTdTitle);
  540. this.elementNameInput = new MWF.xApplication.Organization.GroupExplorer.Input(this.propertyBaseContentNode.getElement("#formGroupName"), this.data.name, this.explorer.css.formInput);
  541. },
  542. createEditBaseNode: function(){
  543. if (MWF.AC.isGroupCreator()){
  544. this.editBaseNode = new Element("button", {
  545. "styles": this.style.editBaseNode,
  546. "text": this.explorer.options.lp.edit,
  547. "events": {"click": this.editBaseInfor.bind(this)}
  548. }).inject(this.baseActionNode);
  549. }
  550. },
  551. createCancelBaseNode: function(){
  552. this.cancelBaseNode = new Element("button", {
  553. "styles": this.style.cancelBaseNode,
  554. "text": this.explorer.options.lp.cancel,
  555. "events": {"click": this.cancelBaseInfor.bind(this)}
  556. }).inject(this.baseActionNode);
  557. },
  558. createSaveBaseNode: function(){
  559. this.saveBaseNode = new Element("button", {
  560. "styles": this.style.saveBaseNode,
  561. "text": this.explorer.options.lp.save,
  562. "events": {"click": this.saveBaseInfor.bind(this)}
  563. }).inject(this.baseActionNode);
  564. },
  565. editBaseInfor: function(){
  566. this.baseActionNode.empty();
  567. this.editBaseNode = null;
  568. this.createCancelBaseNode();
  569. this.createSaveBaseNode();
  570. this.editMode();
  571. },
  572. cancelBaseInfor: function(){
  573. if (this.data.name){
  574. this.baseActionNode.empty();
  575. this.cancelBaseNode = null;
  576. this.saveBaseNode = null;
  577. this.createEditBaseNode();
  578. this.readMode();
  579. }else{
  580. this.destroy();
  581. }
  582. },
  583. saveBaseInfor: function(callback){
  584. if (!this.elementNameInput.input.get("value")){
  585. this.explorer.app.notice(this.explorer.options.lp.inputElementName, "error", this.explorer.propertyContentNode);
  586. return false;
  587. }
  588. this.propertyBaseNode.mask({
  589. "style": {
  590. "opacity": 0.7,
  591. "background-color": "#999"
  592. }
  593. });
  594. this.save(function(){
  595. this.baseActionNode.empty();
  596. this.cancelBaseNode = null;
  597. this.saveBaseNode = null;
  598. this.createEditBaseNode();
  599. this.readMode();
  600. this.setNewItem();
  601. this.propertyBaseNode.unmask();
  602. if (callback) callback();
  603. }.bind(this), function(xhr, text, error){
  604. var errorText = error;
  605. if (xhr) errorText = xhr.responseText;
  606. this.explorer.app.notice("request json error: "+errorText, "error");
  607. this.propertyBaseNode.unmask();
  608. }.bind(this));
  609. },
  610. editMode: function(){
  611. this.elementNameInput.editMode();
  612. this.isEdit = true;
  613. },
  614. readMode: function(){
  615. this.elementNameInput.readMode();
  616. this.isEdit = false;
  617. },
  618. save: function(callback, cancel){
  619. this.data.name = this.elementNameInput.input.get("value");
  620. this._saveElement(this.data, function(json){
  621. this.data.id = json.data.id;
  622. this.textNode.set("text", this.data.name);
  623. this.elementNameInput.save();
  624. if (callback) callback();
  625. }.bind(this), function(xhr, text, error){
  626. if (cancel) cancel(xhr, text, error);
  627. }.bind(this));
  628. },
  629. showItemPropertyPerson: function(){
  630. this.propertyPersonNode = new Element("div", {
  631. "styles": this.style.propertyInforNode
  632. }).inject(this.explorer.propertyContentNode);
  633. this.personActionNode = new Element("div", {
  634. "styles": this.style.propertyInforActionNode
  635. }).inject(this.propertyPersonNode);
  636. this.propertyPersonTextNode = new Element("div", {
  637. "styles": this.style.propertyInforTextNode,
  638. "text": this.explorer.options.lp.elementMemberPersonText
  639. }).inject(this.propertyPersonNode);
  640. // this.createEditBaseNode();
  641. this.propertyPersonContentNode = new Element("div", {
  642. "styles": this.style.propertyInforContentNode
  643. }).inject(this.propertyPersonNode);
  644. if (this.isEditor){
  645. if (MWF.AC.isGroupCreator()){
  646. this.createDeletePersonNode();
  647. this.createAddPersonNode();
  648. }
  649. }
  650. this.listPerson();
  651. },
  652. createAddPersonNode: function(){
  653. this.addPersonNode = new Element("button", {
  654. "styles": this.style.addActionNode,
  655. "text": this.explorer.options.lp.add,
  656. "events": {"click": this.addPerson.bind(this)}
  657. }).inject(this.personActionNode);
  658. },
  659. createDeletePersonNode: function(){
  660. this.deletePersonNode = new Element("button", {
  661. "styles": this.style.deleteActionNode_desable,
  662. "text": this.explorer.app.lp["delete"],
  663. "disable": true
  664. }).inject(this.personActionNode);
  665. },
  666. checkSaveBaseInfor: function(callback){
  667. if (!this.created){
  668. this.saveBaseInfor(function(){
  669. if (callback) callback();
  670. }.bind(this));
  671. }else{
  672. if (callback) callback();
  673. }
  674. },
  675. addPerson: function(){
  676. this.checkSaveBaseInfor(function(){
  677. MWF.xDesktop.requireApp("Organization", "Selector.Person", function(){
  678. var selector = new MWF.xApplication.Organization.Selector.Person(this.explorer.app.content,{
  679. "values": this.data.personList,
  680. "onComplete": function(items){
  681. var ids = [];
  682. items.each(function(item){
  683. ids.push(item.data.id);
  684. });
  685. this.data.personList = ids;
  686. this._saveElement(this.data, function(){
  687. this.listPerson();
  688. }.bind(this));
  689. }.bind(this)
  690. });
  691. selector.load();
  692. }.bind(this));
  693. }.bind(this));
  694. },
  695. listPerson: function(){
  696. var html = "<table cellspacing='0' cellpadding='5' border='0' width='95%' align='center' style='line-height:normal'>";
  697. html += "<tr><th style='width:20px'></th>";
  698. html += "<th style='border-right: 1px solid #FFF'>"+this.explorer.options.lp.personEmployee+"</th>";
  699. html += "<th style='border-right: 1px solid #FFF'>"+this.explorer.options.lp.personDisplay+"</th>";
  700. html += "<th style='border-right: 1px solid #FFF'>"+this.explorer.options.lp.personMail+"</th>";
  701. html += "<th>"+this.explorer.options.lp.personPhone+"</th></tr>";
  702. html += "</table>";
  703. this.propertyPersonContentNode.set("html", html);
  704. this.propertyPersonContentNode.getElements("th").setStyles(this.style.propertyContentTdTitle);
  705. this.data.personList.each(function(id){
  706. this.explorer.actions.getPerson(function(json){
  707. new MWF.xApplication.Organization.GroupExplorer.PersonMember(this.propertyPersonContentNode.getElement("table").getFirst(), json.data, this, this.explorer.css.map);
  708. }.bind(this), null, id, false);
  709. }.bind(this));
  710. // this.explorer.actions.listCompanyDuty(function(json){
  711. // json.data.each(function(item){
  712. // new MWF.xApplication.Organization.CompanyDuty(this.propertyDutyContentNode.getElement("table").getFirst(), item, this, this.explorer.css.map);
  713. // }.bind(this));
  714. // }.bind(this), null, this.data.id);
  715. },
  716. checkDeletePersonAction: function(){
  717. if (this.selectedPersons.length){
  718. if (this.deletePersonNode.get("disable")){
  719. this.deletePersonNode.set({
  720. "styles": this.style.deleteActionNode
  721. });
  722. this.deletePersonNode.removeProperty("disable");
  723. this.deletePersonNode.addEvent("click", function(e){this.deletePerson(e);}.bind(this));
  724. }
  725. }else{
  726. if (!this.deletePersonNode.get("disable")){
  727. this.deletePersonNode.set({
  728. "styles": this.style.deleteActionNode_desable,
  729. "disable": true
  730. });
  731. this.deletePersonNode.removeEvents("click");
  732. }
  733. }
  734. },
  735. deletePerson: function(e){
  736. var _self = this;
  737. this.explorer.app.confirm("infor", e, this.explorer.options.lp.deletePersonMemberTitle, this.explorer.options.lp.deletePersonMember, 300, 120, function(){
  738. var deleteIds = [];
  739. _self.selectedPersons.each(function(item){
  740. this.data.personList = this.data.personList.erase(item.data.id);
  741. }.bind(_self));
  742. _self._saveElement(_self.data, function(){
  743. this.listPerson();
  744. }.bind(_self));
  745. this.close();
  746. }, function(){
  747. this.close();
  748. });
  749. },
  750. showItemPropertyGroup: function(){
  751. this.propertyGroupNode = new Element("div", {
  752. "styles": this.style.propertyInforNode
  753. }).inject(this.explorer.propertyContentNode);
  754. this.groupActionNode = new Element("div", {
  755. "styles": this.style.propertyInforActionNode
  756. }).inject(this.propertyGroupNode);
  757. this.propertyGroupTextNode = new Element("div", {
  758. "styles": this.style.propertyInforTextNode,
  759. "text": this.explorer.options.lp.elementMemberGroupText
  760. }).inject(this.propertyGroupNode);
  761. // this.createEditBaseNode();
  762. this.propertyGroupContentNode = new Element("div", {
  763. "styles": this.style.propertyInforContentNode
  764. }).inject(this.propertyGroupNode);
  765. if (this.isEditor) {
  766. if (MWF.AC.isGroupCreator()){
  767. this.createDeleteGroupNode();
  768. this.createAddGroupNode();
  769. }
  770. }
  771. this.listGroup();
  772. },
  773. createAddGroupNode: function(){
  774. this.addGroupNode = new Element("button", {
  775. "styles": this.style.addActionNode,
  776. "text": this.explorer.options.lp.add,
  777. "events": {"click": this.addGroup.bind(this)}
  778. }).inject(this.groupActionNode);
  779. },
  780. createDeleteGroupNode: function(){
  781. this.deleteGroupNode = new Element("button", {
  782. "styles": this.style.deleteActionNode_desable,
  783. "text": this.explorer.app.lp["delete"],
  784. "disable": true
  785. }).inject(this.groupActionNode);
  786. },
  787. addGroup: function(){
  788. this.checkSaveBaseInfor(function(){
  789. MWF.xDesktop.requireApp("Organization", "Selector.Group", function(){
  790. var selector = new MWF.xApplication.Organization.Selector.Group(this.explorer.app.content,{
  791. "values": this.data.groupList,
  792. "onComplete": function(items){
  793. var ids = [];
  794. items.each(function(item){
  795. ids.push(item.data.id);
  796. });
  797. this.data.groupList = ids;
  798. this._saveElement(this.data, function(){
  799. this.listGroup();
  800. }.bind(this));
  801. }.bind(this)
  802. });
  803. selector.load();
  804. }.bind(this));
  805. }.bind(this));
  806. },
  807. listGroup: function(){
  808. var html = "<table cellspacing='0' cellpadding='5' border='0' width='95%' align='center' style='line-height:normal'>";
  809. html += "<tr><th style='width:20px'></th>";
  810. html += "<th style='width:25%; border-right: 1px solid #FFF'>"+this.explorer.options.lp.groupName+"</th>";
  811. html += "<th style='border-right: 1px solid #FFF'>"+this.explorer.options.lp.groupDescription+"</th>";
  812. html += "</table>";
  813. this.propertyGroupContentNode.set("html", html);
  814. this.propertyGroupContentNode.getElements("th").setStyles(this.style.propertyContentTdTitle);
  815. this.data.groupList.each(function(id){
  816. this.explorer.actions.getGroup(function(json){
  817. new MWF.xApplication.Organization.GroupExplorer.GroupMember(this.propertyGroupContentNode.getElement("table").getFirst(), json.data, this, this.explorer.css.map);
  818. }.bind(this), null, id);
  819. }.bind(this));
  820. // this.explorer.actions.listCompanyDuty(function(json){
  821. // json.data.each(function(item){
  822. // new MWF.xApplication.Organization.CompanyDuty(this.propertyDutyContentNode.getElement("table").getFirst(), item, this, this.explorer.css.map);
  823. // }.bind(this));
  824. // }.bind(this), null, this.data.id);
  825. },
  826. checkDeleteGroupAction: function(){
  827. if (this.selectedGroups.length){
  828. if (this.deleteGroupNode.get("disable")){
  829. this.deleteGroupNode.set({
  830. "styles": this.style.deleteActionNode
  831. });
  832. this.deleteGroupNode.removeProperty("disable");
  833. this.deleteGroupNode.addEvent("click", function(e){this.deleteGroupMember(e);}.bind(this));
  834. }
  835. }else{
  836. if (!this.deleteGroupNode.get("disable")){
  837. this.deleteGroupNode.set({
  838. "styles": this.style.deleteActionNode_desable,
  839. "disable": true
  840. });
  841. this.deleteGroupNode.removeEvents("click");
  842. }
  843. }
  844. },
  845. destroy: function(){
  846. this.explorer.currentItem = null;
  847. this.clearItemProperty();
  848. this.node.destroy();
  849. delete this;
  850. },
  851. "delete": function(success, failure){
  852. this._deleteElement(this.data.id, function(){
  853. this.destroy();
  854. if (success) success();
  855. }.bind(this), function(xhr, text, error){
  856. var errorText = error;
  857. if (xhr) errorText = xhr.responseText;
  858. // this.explorer.app.notice(errorText, "error", this.explorer.propertyContentNode, {x: "left", y:"top"});
  859. if (failure) failure(errorText);
  860. }.bind(this));
  861. },
  862. deleteGroupMember: function(e){
  863. var _self = this;
  864. this.explorer.app.confirm("infor", e, this.explorer.options.lp.deleteGroupMemberTitle, this.explorer.options.lp.deleteGroupMember, 300, 120, function(){
  865. var deleteIds = [];
  866. _self.selectedGroups.each(function(item){
  867. this.data.groupList = this.data.groupList.erase(item.data.id);
  868. }.bind(_self));
  869. _self._saveElement(_self.data, function(){
  870. this.listGroup();
  871. }.bind(_self));
  872. this.close();
  873. }, function(){
  874. this.close();
  875. });
  876. },
  877. _saveElement: function(data, success, failure){
  878. this.explorer.actions.saveGroup(data, success, failure);
  879. },
  880. _deleteElement: function(id, success, failure){
  881. var errorText = "";
  882. var deleteFlag = true;
  883. this.explorer.actions.listRoleByGroup(function(json){
  884. if (json.data.length){
  885. deleteFlag = false;
  886. var name = "";
  887. json.data.each(function(data){name = (name) ? name+", "+data.name : data.name;});
  888. errorText = "“"+this.data.name+"”"+this.explorer.app.lp.deleteGroupError_InRole+"“"+name+"”";
  889. }
  890. }.bind(this), null, id,false);
  891. this.explorer.actions.listSupGroupDirect(function(json){
  892. if (json.data.length){
  893. deleteFlag = false;
  894. var name = "";
  895. json.data.each(function(data){name = (name) ? name+", "+data.name : data.name;});
  896. errorText = (errorText) ? errorText+"<br/>"+"“"+this.data.name+"”"+this.explorer.app.lp.deleteGroupError_InGroup+"“"+name+"”" : this.explorer.app.lp.deleteGroupError_InGroup+"“"+name+"”";
  897. }
  898. }.bind(this), null, id,false);
  899. if (deleteFlag){
  900. this.explorer.actions.deleteGroup(id, success, failure);
  901. }else{
  902. if (failure) failure(null, null, errorText);
  903. };
  904. }
  905. });
  906. MWF.xApplication.Organization.GroupExplorer.PersonMember = new Class({
  907. initialize: function(container, data, item, style){
  908. this.container = $(container);
  909. this.data = data;
  910. this.style = style;
  911. this.item = item;
  912. this.selected = false;
  913. this.load();
  914. },
  915. load: function(){
  916. this.node = new Element("tr", {
  917. "styles": this.style.contentNode
  918. }).inject(this.container);
  919. this.selectNode = new Element("td", {
  920. "styles": this.style.selectNode
  921. }).inject(this.node);
  922. this.employeeNode = new Element("td", {
  923. "styles": this.style.valueNode,
  924. "text": this.data.employee || ""
  925. }).inject(this.node);
  926. this.displayNode = new Element("td", {
  927. "styles": this.style.valueNode,
  928. "text": this.data.display
  929. }).inject(this.node);
  930. this.mailNode = new Element("td", {
  931. "styles": this.style.valueNode,
  932. "text": this.data.mail || ""
  933. }).inject(this.node);
  934. this.phoneNode = new Element("td", {
  935. "styles": this.style.valueNode,
  936. "text": this.data.mobile || ""
  937. }).inject(this.node);
  938. this.setEvent();
  939. },
  940. setEvent: function(){
  941. this.selectNode.addEvent("click", function(){
  942. this.selectNodeClick();
  943. }.bind(this));
  944. },
  945. selectNodeClick: function(){
  946. if (!this.selected){
  947. this.selected = true;
  948. this.selectNode.setStyles(this.style.selectNode_selected);
  949. this.node.setStyles(this.style.contentNode_selected);
  950. this.item.selectedPersons.push(this);
  951. this.item.checkDeletePersonAction();
  952. }else{
  953. this.selected = false;
  954. this.selectNode.setStyles(this.style.selectNode);
  955. this.node.setStyles(this.style.contentNode);
  956. this.item.selectedPersons.erase(this);
  957. this.item.checkDeletePersonAction();
  958. }
  959. }
  960. });
  961. MWF.xApplication.Organization.GroupExplorer.GroupMember = new Class({
  962. initialize: function(container, data, item, style){
  963. this.container = $(container);
  964. this.data = data;
  965. this.style = style;
  966. this.item = item;
  967. this.selected = false;
  968. this.load();
  969. },
  970. load: function(){
  971. this.node = new Element("tr", {
  972. "styles": this.style.contentNode
  973. }).inject(this.container);
  974. this.selectNode = new Element("td", {
  975. "styles": this.style.selectNode
  976. }).inject(this.node);
  977. this.nameNode = new Element("td", {
  978. "styles": this.style.valueNode,
  979. "text": this.data.name || ""
  980. }).inject(this.node);
  981. this.descriptionNode = new Element("td", {
  982. "styles": this.style.valueNode,
  983. "text": this.data.description || ""
  984. }).inject(this.node);
  985. this.setEvent();
  986. },
  987. setEvent: function(){
  988. this.selectNode.addEvent("click", function(){
  989. this.selectNodeClick();
  990. }.bind(this));
  991. },
  992. selectNodeClick: function(){
  993. if (!this.selected){
  994. this.selected = true;
  995. this.selectNode.setStyles(this.style.selectNode_selected);
  996. this.node.setStyles(this.style.contentNode_selected);
  997. this.item.selectedGroups.push(this);
  998. this.item.checkDeleteGroupAction();
  999. }else{
  1000. this.selected = false;
  1001. this.selectNode.setStyles(this.style.selectNode);
  1002. this.node.setStyles(this.style.contentNode);
  1003. this.item.selectedGroups.erase(this);
  1004. this.item.checkDeleteGroupAction();
  1005. }
  1006. }
  1007. });
  1008. MWF.xApplication.Organization.GroupExplorer.Input = new Class({
  1009. Implements: [Events],
  1010. initialize: function(node, value, style, display){
  1011. this.node = $(node);
  1012. this.value = value || "";
  1013. this.style = style;
  1014. this.display = display;
  1015. this.load();
  1016. },
  1017. load: function(){
  1018. this.content = new Element("div", {
  1019. "styles": this.style.content,
  1020. "text": (this.display=="none") ? "***" : this.value
  1021. }).inject(this.node);
  1022. },
  1023. editMode: function(){
  1024. this.content.empty();
  1025. this.input = new Element("input",{
  1026. "styles": this.style.input,
  1027. "value": this.value
  1028. }).inject(this.content);
  1029. this.input.addEvents({
  1030. "focus": function(){
  1031. this.input.setStyles(this.style.input_focus);
  1032. }.bind(this),
  1033. "blur": function(){
  1034. this.input.setStyles(this.style.input);
  1035. }.bind(this)
  1036. });
  1037. },
  1038. readMode: function(){
  1039. this.content.empty();
  1040. this.input = null;
  1041. this.content.set("text", this.value);
  1042. if (this.display=="none") this.content.set("text", "***");
  1043. },
  1044. save: function(){
  1045. if (this.input) this.value = this.input.get("value");
  1046. return this.value;
  1047. }
  1048. });