Explorer.js 31 KB

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