GroupExplorer.js 22 KB

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