GroupExplorer.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. MWF.xDesktop.requireApp("Org", "RoleExplorer", null, false);
  2. MWF.xApplication.Org.GroupExplorer = new Class({
  3. Extends: MWF.xApplication.Org.$Explorer,
  4. Implements: [Options, Events],
  5. options: {
  6. "style": "default",
  7. "lp": {
  8. },
  9. "creator": false
  10. },
  11. _loadLp: function(){
  12. this.options.lp = {
  13. "elementLoaded": this.app.lp.groupLoaded,
  14. "search": this.app.lp.search,
  15. "searchText": this.app.lp.searchText,
  16. "elementSave": this.app.lp.groupSave,
  17. "deleteElements": this.app.lp.deleteGroups,
  18. "deleteElementsCancel": this.app.lp.deleteElementsCancel,
  19. "deleteElementsTitle": this.app.lp.deleteGroupsTitle,
  20. "deleteElementsConfirm": this.app.lp.deleteGroupsConfirm,
  21. "elementBaseText": this.app.lp.groupBaseText,
  22. "elementName": this.app.lp.groupName,
  23. "noSignature": this.app.lp.noSignature,
  24. "edit": this.app.lp.edit,
  25. "cancel": this.app.lp.cancel,
  26. "save": this.app.lp.save,
  27. "add": this.app.lp.add
  28. }
  29. },
  30. _listElementNext: function(lastid, count, callback){
  31. this.actions.listGroupNext(lastid || "(0)", count, function(json){
  32. if (callback) callback.apply(this, [json]);
  33. }.bind(this));
  34. },
  35. _newElement: function(data, explorer){
  36. return new MWF.xApplication.Org.GroupExplorer.Group(data, explorer, this.isEditor);
  37. },
  38. _listElementByKey: function(callback, failure, key){
  39. this.actions.listGroupByKey(function(json){
  40. if (callback) callback.apply(this, [json]);
  41. }.bind(this), failure, key);
  42. },
  43. _getAddElementData: function(){
  44. return {
  45. "personList": [],
  46. "groupList": [],
  47. "unitList": [],
  48. "description": "",
  49. "unique": "",
  50. "orderNumber": "",
  51. "id": "",
  52. "name": "",
  53. "control": {
  54. "allowEdit": true,
  55. "allowDelete": true
  56. }
  57. };
  58. },
  59. _isActionManager: function() {
  60. return (MWF.AC.isOrganizationManager() || MWF.AC.isGroupManager());
  61. }
  62. });
  63. MWF.xApplication.Org.GroupExplorer.Group = new Class({
  64. Extends: MWF.xApplication.Org.$Explorer.Item,
  65. showItemProperty: function(){
  66. this.content = new MWF.xApplication.Org.GroupExplorer.GroupContent(this);
  67. },
  68. "delete": function(success, failure){
  69. this.explorer.actions.deleteGroup(this.data.id, function(){
  70. this.destroy();
  71. if (success) success();
  72. }.bind(this), function(xhr, text, error){
  73. var errorText = error;
  74. if (xhr) errorText = xhr.responseText;
  75. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  76. if (failure) failure();
  77. });
  78. },
  79. _getIcon: function(){
  80. return "/x_component_Org/$Explorer/default/icon/group.png";
  81. }
  82. });
  83. MWF.xApplication.Org.GroupExplorer.GroupContent = new Class({
  84. Extends: MWF.xApplication.Org.$Explorer.ItemContent,
  85. _getData: function(callback){
  86. if (this.item.data.id){
  87. this.explorer.actions.getGroup(function(json){
  88. this.data = json.data;
  89. this.item.data = json.data;
  90. if (callback) callback();
  91. }.bind(this), null, this.item.data.id);
  92. }else{
  93. this.data = this.item.data;
  94. if (callback) callback();
  95. }
  96. },
  97. _showItemPropertyTitle: function(){
  98. this.titleInfor = new MWF.xApplication.Org.GroupExplorer.GroupContent.TitleInfor(this);
  99. },
  100. _showItemPropertyBottom: function(){
  101. this.bottomInfor = new MWF.xApplication.Org.GroupExplorer.GroupContent.BottomInfor(this);
  102. },
  103. loadItemPropertyTab: function(callback){
  104. this.propertyTabContainerNode = new Element("div", {"styles": this.item.style.tabTitleNode}).inject(this.propertyContentNode, "top");
  105. MWF.require("MWF.widget.Tab", function(){
  106. this.propertyTab = new MWF.widget.Tab(this.propertyContentNode, {"style": "unit"});
  107. this.propertyTab.load();
  108. this.propertyTab.tabNodeContainer.inject(this.propertyTabContainerNode);
  109. if (callback) callback();
  110. }.bind(this));
  111. },
  112. _loadTabs: function(){
  113. this.baseContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  114. this.basePage = this.propertyTab.addTab(this.baseContentNode, this.explorer.app.lp.groupBaseText);
  115. this.personMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  116. this.personMemberPage = this.propertyTab.addTab(this.personMemberContentNode, this.explorer.app.lp.groupMemberPersonText);
  117. this.groupMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  118. this.groupMemberPage = this.propertyTab.addTab(this.groupMemberContentNode, this.explorer.app.lp.groupMemberGroupText);
  119. this.unitMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  120. this.unitMemberPage = this.propertyTab.addTab(this.unitMemberContentNode, this.explorer.app.lp.unitMemberGroupText);
  121. },
  122. _loadContent: function(){
  123. debugger;
  124. this._listBaseInfor();
  125. this.loadListCount();
  126. var _self = this;
  127. this.personMemberList = this._listMembers("personList", "woPersonList", this.personMemberContentNode, [{
  128. "getHtml": function(){
  129. var src = _self.explorer.actions.getPersonIcon(this.id);
  130. return "<div style='width:24px; height:24px;''><img style='width:24px; height:24px; border-radius:12px; border: 0' src='"+src+"'/></div>";
  131. },
  132. "set": function(){}
  133. }, "name", "employee", "mobile", "mail", {
  134. "getHtml": function(){
  135. return "<div style='width:24px; height:24px; cursor: pointer; background:url(/x_component_Org/$Explorer/"+
  136. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  137. },
  138. "events": {
  139. "click": function(){
  140. _self.explorer.openPerson(this.data, this.td);
  141. }
  142. }
  143. }], [
  144. {"style": "width: 30px", "text": ""},
  145. {"style": "width: 20%", "text": this.explorer.app.lp.personName},
  146. {"style": "", "text": this.explorer.app.lp.personEmployee},
  147. {"style": "", "text": this.explorer.app.lp.personMobile},
  148. {"style": "", "text": this.explorer.app.lp.personMail},
  149. {"style": "width: 30px", "text": ""}
  150. ], this.addPersonMember.bind(this), "personCountNode", this.explorer.app.lp.deletePersonMemeberTitle, this.explorer.app.lp.deletePersonMemeber);
  151. this.groupMemberList = this._listMembers("groupList", "woGroupList", this.groupMemberContentNode, ["name", "distinguishedName", //"description",
  152. {
  153. "getHtml": function(){
  154. return "<div style='width:24px; height:24px; cursor: pointer; background:url(/x_component_Org/$Explorer/"+
  155. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  156. },
  157. "events": {
  158. "click": function(){
  159. _self.explorer.openGroup(this.data, this.td);
  160. }
  161. }
  162. }
  163. ], [
  164. {"style": "width: 20%", "text": this.explorer.app.lp.groupName},
  165. {"style": "width: 40%", "text": this.explorer.app.lp.groupDn},
  166. //{"style": "", "text": this.explorer.app.lp.groupDescription},
  167. {"style": "width: 30px", "text": ""}
  168. ], this.addGroupMember.bind(this), "groupCountNode", this.explorer.app.lp.deleteGroupMemeberTitle, this.explorer.app.lp.deleteGroupMemeber);
  169. this.unitMemberList = this._listMembers("unitList", "woUnitList", this.unitMemberContentNode, ["name", "levelName", //"typeList",
  170. {
  171. "getHtml": function(){
  172. return "<div style='width:24px; height:24px; cursor: pointer; background:url(/x_component_Org/$Explorer/"+
  173. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  174. },
  175. "events": {
  176. "click": function(){
  177. _self.explorer.openUnit(this.data, this.td);
  178. }
  179. }
  180. }], [
  181. {"style": "width: 20%", "text": this.explorer.app.lp.unitName},
  182. {"style": "width: 40%", "text": this.explorer.app.lp.unitLevelName},
  183. //{"style": "", "text": this.explorer.app.lp.unitTypeList},
  184. {"style": "width: 30px", "text": ""}
  185. ], this.addUnitMember.bind(this), "unitCountNode", this.explorer.app.lp.deleteUnitMemeberTitle, this.explorer.app.lp.deleteUnitMemeber);
  186. },
  187. loadListCount: function(){
  188. var personCount = this.data.personList.length;
  189. if (personCount){
  190. if (this.personCountNode){
  191. this.personCountNode.set("text", personCount);
  192. }else{
  193. this.personCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": personCount}).inject(this.personMemberPage.tabNode);
  194. }
  195. }else{
  196. if (this.personCountNode) this.personCountNode.destroy();
  197. }
  198. var groupCount = this.data.groupList.length;
  199. if (groupCount){
  200. if (this.groupCountNode){
  201. this.groupCountNode.set("text", groupCount);
  202. }else{
  203. this.groupCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": groupCount}).inject(this.groupMemberPage.tabNode);
  204. }
  205. }else{
  206. if (this.groupCountNode) this.groupCountNode.destroy();
  207. }
  208. var unitCount = this.data.unitList.length;
  209. if (unitCount){
  210. if (this.unitCountNode){
  211. this.unitCountNode.set("text", unitCount);
  212. }else{
  213. this.unitCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": unitCount}).inject(this.unitMemberPage.tabNode);
  214. }
  215. }else{
  216. if (this.unitCountNode) this.unitCountNode.destroy();
  217. }
  218. },
  219. _listBaseInfor: function(){
  220. this.baseInfor = new MWF.xApplication.Org.GroupExplorer.GroupContent.BaseInfor(this);
  221. },
  222. _listMembers: function(list, woList, node, attr, titles, addItemFun, countNode, deleteTitle, deleteText){
  223. var memberList = new MWF.xApplication.Org.List(node, this, {
  224. "action": this.data.control.allowEdit,
  225. "canEdit": false,
  226. "deleteItemTitle": deleteTitle,
  227. "deleteItemText": deleteText,
  228. "data": {
  229. "person": this.data.id,
  230. "name": "",
  231. "unique": "",
  232. "orderNumber": "",
  233. "attributeList": []
  234. },
  235. "attr": attr,
  236. "onQueryDelete": function(){
  237. this.saveCloneData = Object.clone(this.data);
  238. }.bind(this),
  239. "onDelete": function(continueDelete){
  240. this.explorer.actions.saveGroup(this.saveCloneData, function(json){
  241. this.data[list] = this.saveCloneData[list];
  242. this.data[woList] = this.saveCloneData[woList];
  243. this.data.id = json.data.id;
  244. this.saveCloneData = null;
  245. delete this.saveCloneData;
  246. }.bind(this), function(xhr, text, error){
  247. continueDelete = false;
  248. this.explorer.app.notice((JSON.decode(xhr.responseText).message.trim() || "request json error"), "error");
  249. }.bind(this), false);
  250. }.bind(this),
  251. "onPostDelete": function(delCount){
  252. if (this[countNode]){
  253. var count = this[countNode].get("text").toInt()-delCount;
  254. this[countNode].set("text", count);
  255. }
  256. }.bind(this)
  257. });
  258. memberList.addItem = addItemFun;
  259. memberList.load(titles);
  260. var _self = this;
  261. if (this.data[woList] && this.data[woList].length){
  262. this.data[woList].each(function(d){
  263. var item = memberList.push(d);
  264. item["delete"] = function(callback){
  265. _self.saveCloneData[list].erase(this.data.id);
  266. _self.saveCloneData[woList] = _self.saveCloneData[woList].filter(function(a){
  267. return (this.data.id !== a.id);
  268. }.bind(this));
  269. if (callback) callback();
  270. };
  271. }.bind(this));
  272. }
  273. return memberList;
  274. },
  275. addListItem: function(memberList, data, list, woList){
  276. var _self = this;
  277. var item = memberList.push(data);
  278. item["delete"] = function(callback){
  279. _self.saveCloneData[list].erase(this.data.id);
  280. _self.saveCloneData[woList] = _self.saveCloneData[woList].filter(function(a){
  281. return (this.data.id !== a.id);
  282. }.bind(this));
  283. if (callback) callback();
  284. };
  285. },
  286. checkSaveBaseInfor: function(callback){
  287. if (!this.data.id){
  288. if (this.baseInfor){
  289. if (this.baseInfor.mode==="edit") this.baseInfor.save(function(){
  290. if (callback) callback();
  291. }.bind(this));
  292. }
  293. }else{
  294. if (callback) callback();
  295. }
  296. },
  297. addPersonMember: function(){
  298. this.checkSaveBaseInfor(function(){
  299. MWF.xDesktop.requireApp("Selector", "Person", function(){
  300. var selector = new MWF.xApplication.Selector.Person(this.explorer.app.content,{
  301. "values": this.data.personList,
  302. "onComplete": function(items){
  303. var ids = [];
  304. var persons = [];
  305. items.each(function(item){
  306. ids.push(item.data.id);
  307. persons.push(item.data);
  308. });
  309. this.data.personList = ids;
  310. this.data.woPersonList = persons;
  311. this._saveElement(this.data, function(){
  312. this.personMemberList.clear();
  313. this.data.woPersonList.each(function(d){
  314. this.addListItem(this.personMemberList, d, "personList", "woPersonList");
  315. }.bind(this));
  316. }.bind(this));
  317. }.bind(this)
  318. });
  319. selector.load();
  320. }.bind(this));
  321. }.bind(this));
  322. },
  323. addGroupMember: function(){
  324. this.checkSaveBaseInfor(function(){
  325. MWF.xDesktop.requireApp("Selector", "Group", function(){
  326. var selector = new MWF.xApplication.Selector.Group(this.explorer.app.content,{
  327. "values": this.data.groupList,
  328. "onComplete": function(items){
  329. var ids = [];
  330. var groups = [];
  331. items.each(function(item){
  332. ids.push(item.data.id);
  333. groups.push(item.data);
  334. });
  335. this.data.groupList = ids;
  336. this.data.woGroupList = groups;
  337. this._saveElement(this.data, function(){
  338. this.groupMemberList.clear();
  339. this.data.woGroupList.each(function(d){
  340. this.addListItem(this.groupMemberList, d, "groupList", "woGroupList");
  341. }.bind(this));
  342. }.bind(this));
  343. }.bind(this)
  344. });
  345. selector.load();
  346. }.bind(this));
  347. }.bind(this));
  348. },
  349. addUnitMember: function(){
  350. this.checkSaveBaseInfor(function(){
  351. MWF.xDesktop.requireApp("Selector", "Unit", function(){
  352. var selector = new MWF.xApplication.Selector.Unit(this.explorer.app.content,{
  353. "values": this.data.unitList,
  354. "onComplete": function(items){
  355. var ids = [];
  356. var groups = [];
  357. items.each(function(item){
  358. ids.push(item.data.id);
  359. groups.push(item.data);
  360. });
  361. this.data.unitList = ids;
  362. this.data.woUnitList = groups;
  363. this._saveElement(this.data, function(){
  364. this.unitMemberList.clear();
  365. this.data.woUnitList.each(function(d){
  366. this.addListItem(this.unitMemberList, d, "unitList", "woUnitList");
  367. }.bind(this));
  368. }.bind(this));
  369. }.bind(this)
  370. });
  371. selector.load();
  372. }.bind(this));
  373. }.bind(this));
  374. },
  375. _saveElement: function(data, success, failure){
  376. this.explorer.actions.saveGroup(data, function(json){
  377. Object.merge(this.data, data);
  378. if (this.data.id){
  379. this.data.id = json.data.id;
  380. this.item.refresh();
  381. if (success) success();
  382. }else{
  383. this.explorer.actions.getGroup(function(json){
  384. this.data = json.data;
  385. this.item.refresh();
  386. if (success) success();
  387. }.bind(this), null, json.data.id);
  388. }
  389. }.bind(this), function(xhr, text, error){
  390. if (failure) failure(xhr, text, error);
  391. }.bind(this));
  392. }
  393. });
  394. MWF.xApplication.Org.GroupExplorer.GroupContent.TitleInfor = new Class({
  395. Extends: MWF.xApplication.Org.RoleExplorer.RoleContent.TitleInfor,
  396. _getIcon: function(){
  397. return "/x_component_Org/$Explorer/default/icon/group70.png";
  398. }
  399. });
  400. MWF.xApplication.Org.GroupExplorer.GroupContent.BottomInfor = new Class({
  401. Extends: MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor,
  402. addInforList: function(){
  403. var text = this.explorer.app.lp.groupReadDn.replace(/{dn}/g, (this.data.distinguishedName || " "));
  404. this.addInfor(text);
  405. text = this.explorer.app.lp.groupReadCreate.replace(/{date}/g, (this.data.createTime || " "));
  406. text = text.replace(/{date2}/g, (this.data.updateTime || " "));
  407. this.addInfor(text);
  408. }
  409. });
  410. MWF.xApplication.Org.GroupExplorer.GroupContent.BaseInfor = new Class({
  411. Extends: MWF.xApplication.Org.RoleExplorer.RoleContent.BaseInfor,
  412. getContentHtml: function(){
  413. var html = "<table width='100%' cellpadding='3px' cellspacing='5px'>";
  414. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.groupName+":</td><td class='inforContent infor_name'></td>" +
  415. "<td class='inforTitle'>"+this.explorer.app.lp.groupUnique+":</td><td class='inforContent infor_unique'></td></tr>";
  416. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.groupDescription+":</td><td colspan='3' class='inforContent infor_description'></td>";
  417. html += "<tr><td colspan='4' class='inforAction'></td></tr>";
  418. //this.baseInforRightNode.set("html", html);
  419. return html;
  420. },
  421. loadAction: function(){
  422. //this.explorer.app.lp.edit
  423. var actionAreas = this.editContentNode.getElements("td");
  424. var actionArea = actionAreas[actionAreas.length-1];
  425. if (this.data.control.allowEdit){
  426. this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea);
  427. this.editNode = new Element("div", {"styles": this.style.actionEditNode, "text": this.explorer.app.lp.editGroup}).inject(this.baseInforEditActionAreaNode);
  428. this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.saveGroup}).inject(this.baseInforEditActionAreaNode);
  429. this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode);
  430. this.editNode.setStyle("display", "block");
  431. this.editNode.addEvent("click", this.edit.bind(this));
  432. this.saveNode.addEvent("click", this.save.bind(this));
  433. this.cancelNode.addEvent("click", this.cancel.bind(this));
  434. }else{
  435. }
  436. },
  437. save: function(){
  438. if (!this.nameInputNode.get("value")){
  439. this.explorer.app.notice(this.explorer.app.lp.inputGroupInfor, "error", this.explorer.propertyContentNode);
  440. return false;
  441. }
  442. //this.data.genderType = gender;
  443. if (!this.uniqueInputNode.get("value")) this.data.unique = this.nameInputNode.get("value");
  444. this.content.propertyContentScrollNode.mask({
  445. "style": {
  446. "opacity": 0.7,
  447. "background-color": "#999"
  448. }
  449. });
  450. this.saveGroup(function(){
  451. this.cancel();
  452. this.content.propertyContentScrollNode.unmask();
  453. }.bind(this), function(xhr, text, error){
  454. this.explorer.app.notice((JSON.decode(xhr.responseText).message.trim() || "request json error"), "error");
  455. this.content.propertyContentScrollNode.unmask();
  456. }.bind(this));
  457. },
  458. saveGroup: function(callback, cancel){
  459. var data = Object.clone(this.data);
  460. data.name = this.nameInputNode.get("value");
  461. data.unique = this.uniqueInputNode.get("value");
  462. data.description = this.descriptionInputNode.get("value");
  463. this.explorer.actions.saveGroup(data, function(json){
  464. Object.merge(this.data, data);
  465. if (this.data.id){
  466. this.data.id = json.data.id;
  467. this.item.refresh();
  468. if (callback) callback();
  469. }else{
  470. this.explorer.actions.getGroup(function(json){
  471. this.data = Object.merge(this.data, json.data);
  472. this.item.data = this.data;
  473. this.item.refresh();
  474. if (callback) callback();
  475. }.bind(this), null, json.data.id);
  476. }
  477. }.bind(this), function(xhr, text, error){
  478. if (cancel) cancel(xhr, text, error);
  479. }.bind(this));
  480. },
  481. destroy: function(){
  482. this.node.empty();
  483. this.node.destroy();
  484. MWF.release(this);
  485. }
  486. });