GroupExplorer.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. this._listBaseInfor();
  124. this.loadListCount();
  125. var _self = this;
  126. this.personMemberList = this._listMembers("personList", "woPersonList", this.personMemberContentNode, [{
  127. "get": function(){
  128. var src = _self.explorer.actions.getPersonIcon(this.id);
  129. return "<div style='width:24px; height:24px;''><img style='width:24px; height:24px; border-radius:12px; border: 0' src='"+src+"'/></div>";
  130. },
  131. "set": function(){}
  132. }, "name", "employee", "mobile", "mail", {
  133. "get": function(){
  134. return "<div style='width:24px; height:24px; cursor: pointer; background:url(/x_component_Org/$Explorer/"+
  135. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  136. },
  137. "events": {
  138. "click": function(){
  139. _self.explorer.openPerson(this.data, this.td);
  140. }
  141. }
  142. }], [
  143. {"style": "width: 30px", "text": ""},
  144. {"style": "width: 20%", "text": this.explorer.app.lp.personName},
  145. {"style": "", "text": this.explorer.app.lp.personEmployee},
  146. {"style": "", "text": this.explorer.app.lp.personMobile},
  147. {"style": "", "text": this.explorer.app.lp.personMail},
  148. {"style": "width: 30px", "text": ""}
  149. ], this.addPersonMember.bind(this), "personCountNode", this.explorer.app.lp.deletePersonMemeberTitle, this.explorer.app.lp.deletePersonMemeber);
  150. this.groupMemberList = this._listMembers("groupList", "woGroupList", this.groupMemberContentNode, ["name", "distinguishedName", "description", {
  151. "get": function(){
  152. return "<div style='width:24px; height:24px; cursor: pointer; background:url(/x_component_Org/$Explorer/"+
  153. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  154. },
  155. "events": {
  156. "click": function(){
  157. _self.explorer.openGroup(this.data, this.td);
  158. }
  159. }
  160. }], [
  161. {"style": "width: 20%", "text": this.explorer.app.lp.groupName},
  162. {"style": "width: 40%", "text": this.explorer.app.lp.groupDn},
  163. {"style": "", "text": this.explorer.app.lp.groupDescription},
  164. {"style": "width: 30px", "text": ""}
  165. ], this.addGroupMember.bind(this), "groupCountNode", this.explorer.app.lp.deleteGroupMemeberTitle, this.explorer.app.lp.deleteGroupMemeber);
  166. this.unitMemberList = this._listMembers("unitList", "woUnitList", this.unitMemberContentNode, ["name", "levelName", "typeList", {
  167. "get": function(){
  168. return "<div style='width:24px; height:24px; cursor: pointer; background:url(/x_component_Org/$Explorer/"+
  169. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  170. },
  171. "events": {
  172. "click": function(){
  173. _self.explorer.openUnit(this.data, this.td);
  174. }
  175. }
  176. }], [
  177. {"style": "width: 20%", "text": this.explorer.app.lp.unitName},
  178. {"style": "width: 40%", "text": this.explorer.app.lp.unitLevelName},
  179. {"style": "", "text": this.explorer.app.lp.unitTypeList},
  180. {"style": "width: 30px", "text": ""}
  181. ], this.addUnitMember.bind(this), "unitCountNode", this.explorer.app.lp.deleteUnitMemeberTitle, this.explorer.app.lp.deleteUnitMemeber);
  182. },
  183. loadListCount: function(){
  184. var personCount = this.data.personList.length;
  185. if (personCount){
  186. if (this.personCountNode){
  187. this.personCountNode.set("text", personCount);
  188. }else{
  189. this.personCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": personCount}).inject(this.personMemberPage.tabNode);
  190. }
  191. }else{
  192. if (this.personCountNode) this.personCountNode.destroy();
  193. }
  194. var groupCount = this.data.groupList.length;
  195. if (groupCount){
  196. if (this.groupCountNode){
  197. this.groupCountNode.set("text", groupCount);
  198. }else{
  199. this.groupCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": groupCount}).inject(this.groupMemberPage.tabNode);
  200. }
  201. }else{
  202. if (this.groupCountNode) this.groupCountNode.destroy();
  203. }
  204. var unitCount = this.data.unitList.length;
  205. if (unitCount){
  206. if (this.unitCountNode){
  207. this.unitCountNode.set("text", unitCount);
  208. }else{
  209. this.unitCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": unitCount}).inject(this.unitMemberPage.tabNode);
  210. }
  211. }else{
  212. if (this.unitCountNode) this.unitCountNode.destroy();
  213. }
  214. },
  215. _listBaseInfor: function(){
  216. this.baseInfor = new MWF.xApplication.Org.GroupExplorer.GroupContent.BaseInfor(this);
  217. },
  218. _listMembers: function(list, woList, node, attr, titles, addItemFun, countNode, deleteTitle, deleteText){
  219. var memberList = new MWF.xApplication.Org.List(node, this, {
  220. "action": this.data.control.allowEdit,
  221. "canEdit": false,
  222. "deleteItemTitle": deleteTitle,
  223. "deleteItemText": deleteText,
  224. "data": {
  225. "person": this.data.id,
  226. "name": "",
  227. "unique": "",
  228. "orderNumber": "",
  229. "attributeList": []
  230. },
  231. "attr": attr,
  232. "onQueryDelete": function(){
  233. this.saveCloneData = Object.clone(this.data);
  234. }.bind(this),
  235. "onDelete": function(continueDelete){
  236. this.explorer.actions.saveGroup(this.saveCloneData, function(json){
  237. this.data[list] = this.saveCloneData[list];
  238. this.data[woList] = this.saveCloneData[woList];
  239. this.data.id = json.data.id;
  240. this.saveCloneData = null;
  241. delete this.saveCloneData;
  242. }.bind(this), function(xhr, text, error){
  243. continueDelete = false;
  244. this.explorer.app.notice((JSON.decode(xhr.responseText).message.trim() || "request json error"), "error");
  245. }.bind(this), false);
  246. }.bind(this),
  247. "onPostDelete": function(delCount){
  248. if (this[countNode]){
  249. var count = this[countNode].get("text").toInt()-delCount;
  250. this[countNode].set("text", count);
  251. }
  252. }.bind(this)
  253. });
  254. memberList.addItem = addItemFun;
  255. memberList.load(titles);
  256. var _self = this;
  257. if (this.data[woList] && this.data[woList].length){
  258. this.data[woList].each(function(d){
  259. var item = memberList.push(d);
  260. item["delete"] = function(callback){
  261. _self.saveCloneData[list].erase(this.data.id);
  262. _self.saveCloneData[woList] = _self.saveCloneData[woList].filter(function(a){
  263. return (this.data.id !== a.id);
  264. }.bind(this));
  265. if (callback) callback();
  266. };
  267. }.bind(this));
  268. }
  269. return memberList;
  270. },
  271. addListItem: function(memberList, data, list, woList){
  272. var _self = this;
  273. var item = memberList.push(data);
  274. item["delete"] = function(callback){
  275. _self.saveCloneData[list].erase(this.data.id);
  276. _self.saveCloneData[woList] = _self.saveCloneData[woList].filter(function(a){
  277. return (this.data.id !== a.id);
  278. }.bind(this));
  279. if (callback) callback();
  280. };
  281. },
  282. checkSaveBaseInfor: function(callback){
  283. if (!this.data.id){
  284. if (this.baseInfor){
  285. if (this.baseInfor.mode==="edit") this.baseInfor.save(function(){
  286. if (callback) callback();
  287. }.bind(this));
  288. }
  289. }else{
  290. if (callback) callback();
  291. }
  292. },
  293. addPersonMember: function(){
  294. this.checkSaveBaseInfor(function(){
  295. MWF.xDesktop.requireApp("Selector", "Person", function(){
  296. var selector = new MWF.xApplication.Selector.Person(this.explorer.app.content,{
  297. "values": this.data.personList,
  298. "onComplete": function(items){
  299. var ids = [];
  300. var persons = [];
  301. items.each(function(item){
  302. ids.push(item.data.id);
  303. persons.push(item.data);
  304. });
  305. this.data.personList = ids;
  306. this.data.woPersonList = persons;
  307. this._saveElement(this.data, function(){
  308. this.personMemberList.clear();
  309. this.data.woPersonList.each(function(d){
  310. this.addListItem(this.personMemberList, d, "personList", "woPersonList");
  311. }.bind(this));
  312. }.bind(this));
  313. }.bind(this)
  314. });
  315. selector.load();
  316. }.bind(this));
  317. }.bind(this));
  318. },
  319. addGroupMember: function(){
  320. this.checkSaveBaseInfor(function(){
  321. MWF.xDesktop.requireApp("Selector", "Group", function(){
  322. var selector = new MWF.xApplication.Selector.Group(this.explorer.app.content,{
  323. "values": this.data.groupList,
  324. "onComplete": function(items){
  325. var ids = [];
  326. var groups = [];
  327. items.each(function(item){
  328. ids.push(item.data.id);
  329. groups.push(item.data);
  330. });
  331. this.data.groupList = ids;
  332. this.data.woGroupList = groups;
  333. this._saveElement(this.data, function(){
  334. this.groupMemberList.clear();
  335. this.data.woGroupList.each(function(d){
  336. this.addListItem(this.groupMemberList, d, "groupList", "woGroupList");
  337. }.bind(this));
  338. }.bind(this));
  339. }.bind(this)
  340. });
  341. selector.load();
  342. }.bind(this));
  343. }.bind(this));
  344. },
  345. addUnitMember: function(){
  346. this.checkSaveBaseInfor(function(){
  347. MWF.xDesktop.requireApp("Selector", "Unit", function(){
  348. var selector = new MWF.xApplication.Selector.Unit(this.explorer.app.content,{
  349. "values": this.data.unitList,
  350. "onComplete": function(items){
  351. var ids = [];
  352. var groups = [];
  353. items.each(function(item){
  354. ids.push(item.data.id);
  355. groups.push(item.data);
  356. });
  357. this.data.unitList = ids;
  358. this.data.woUnitList = groups;
  359. this._saveElement(this.data, function(){
  360. this.unitMemberList.clear();
  361. this.data.woUnitList.each(function(d){
  362. this.addListItem(this.unitMemberList, d, "unitList", "woUnitList");
  363. }.bind(this));
  364. }.bind(this));
  365. }.bind(this)
  366. });
  367. selector.load();
  368. }.bind(this));
  369. }.bind(this));
  370. },
  371. _saveElement: function(data, success, failure){
  372. this.explorer.actions.saveGroup(data, function(json){
  373. Object.merge(this.data, data);
  374. if (this.data.id){
  375. this.data.id = json.data.id;
  376. this.item.refresh();
  377. if (success) success();
  378. }else{
  379. this.explorer.actions.getGroup(function(json){
  380. this.data = json.data;
  381. this.item.refresh();
  382. if (success) success();
  383. }.bind(this), null, json.data.id);
  384. }
  385. }.bind(this), function(xhr, text, error){
  386. if (failure) failure(xhr, text, error);
  387. }.bind(this));
  388. }
  389. });
  390. MWF.xApplication.Org.GroupExplorer.GroupContent.TitleInfor = new Class({
  391. Extends: MWF.xApplication.Org.RoleExplorer.RoleContent.TitleInfor,
  392. _getIcon: function(){
  393. return "/x_component_Org/$Explorer/default/icon/group70.png";
  394. }
  395. });
  396. MWF.xApplication.Org.GroupExplorer.GroupContent.BottomInfor = new Class({
  397. Extends: MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor,
  398. addInforList: function(){
  399. var text = this.explorer.app.lp.groupReadDn.replace(/{dn}/g, (this.data.distinguishedName || " "));
  400. this.addInfor(text);
  401. text = this.explorer.app.lp.groupReadCreate.replace(/{date}/g, (this.data.createTime || " "));
  402. text = text.replace(/{date2}/g, (this.data.updateTime || " "));
  403. this.addInfor(text);
  404. }
  405. });
  406. MWF.xApplication.Org.GroupExplorer.GroupContent.BaseInfor = new Class({
  407. Extends: MWF.xApplication.Org.RoleExplorer.RoleContent.BaseInfor,
  408. getContentHtml: function(){
  409. var html = "<table width='100%' cellpadding='3px' cellspacing='5px'>";
  410. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.groupName+":</td><td class='inforContent'>"+(this.data.name || "")+"</td>" +
  411. "<td class='inforTitle'>"+this.explorer.app.lp.groupUnique+":</td><td class='inforContent'>"+(this.data.unique || "")+"</td></tr>";
  412. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.groupDescription+":</td><td colspan='3' class='inforContent'>"+(this.data.description || "")+"</td>";
  413. html += "<tr><td colspan='4' class='inforAction'></td></tr>";
  414. //this.baseInforRightNode.set("html", html);
  415. return html;
  416. },
  417. loadAction: function(){
  418. //this.explorer.app.lp.edit
  419. var actionAreas = this.editContentNode.getElements("td");
  420. var actionArea = actionAreas[actionAreas.length-1];
  421. if (this.data.control.allowEdit){
  422. this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea);
  423. this.editNode = new Element("div", {"styles": this.style.actionEditNode, "text": this.explorer.app.lp.editGroup}).inject(this.baseInforEditActionAreaNode);
  424. this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.saveGroup}).inject(this.baseInforEditActionAreaNode);
  425. this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode);
  426. this.editNode.setStyle("display", "block");
  427. this.editNode.addEvent("click", this.edit.bind(this));
  428. this.saveNode.addEvent("click", this.save.bind(this));
  429. this.cancelNode.addEvent("click", this.cancel.bind(this));
  430. }else{
  431. }
  432. },
  433. save: function(){
  434. if (!this.nameInputNode.get("value")){
  435. this.explorer.app.notice(this.explorer.app.lp.inputGroupInfor, "error", this.explorer.propertyContentNode);
  436. return false;
  437. }
  438. //this.data.genderType = gender;
  439. if (!this.uniqueInputNode.get("value")) this.data.unique = this.nameInputNode.get("value");
  440. this.content.propertyContentScrollNode.mask({
  441. "style": {
  442. "opacity": 0.7,
  443. "background-color": "#999"
  444. }
  445. });
  446. this.saveGroup(function(){
  447. this.cancel();
  448. this.content.propertyContentScrollNode.unmask();
  449. }.bind(this), function(xhr, text, error){
  450. this.explorer.app.notice((JSON.decode(xhr.responseText).message.trim() || "request json error"), "error");
  451. this.content.propertyContentScrollNode.unmask();
  452. }.bind(this));
  453. },
  454. saveGroup: function(callback, cancel){
  455. var data = Object.clone(this.data);
  456. data.name = this.nameInputNode.get("value");
  457. data.unique = this.uniqueInputNode.get("value");
  458. data.description = this.descriptionInputNode.get("value");
  459. this.explorer.actions.saveGroup(data, function(json){
  460. Object.merge(this.data, data);
  461. if (this.data.id){
  462. this.data.id = json.data.id;
  463. this.item.refresh();
  464. if (callback) callback();
  465. }else{
  466. this.explorer.actions.getGroup(function(json){
  467. this.data = Object.merge(this.data, json.data);
  468. this.item.data = this.data;
  469. this.item.refresh();
  470. if (callback) callback();
  471. }.bind(this), null, json.data.id);
  472. }
  473. }.bind(this), function(xhr, text, error){
  474. if (cancel) cancel(xhr, text, error);
  475. }.bind(this));
  476. },
  477. destroy: function(){
  478. this.node.empty();
  479. this.node.destroy();
  480. MWF.release(this);
  481. }
  482. });