GroupExplorer.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  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. "description": "",
  48. "unique": "",
  49. "orderNumber": "",
  50. "id": "",
  51. "name": "",
  52. "control": {
  53. "allowEdit": true,
  54. "allowDelete": true
  55. }
  56. };
  57. },
  58. _isActionManager: function() {
  59. return (MWF.AC.isOrganizationManager() || MWF.AC.isGroupManager());
  60. }
  61. });
  62. MWF.xApplication.Org.GroupExplorer.Group = new Class({
  63. Extends: MWF.xApplication.Org.$Explorer.Item,
  64. showItemProperty: function(){
  65. this.content = new MWF.xApplication.Org.GroupExplorer.GroupContent(this);
  66. },
  67. "delete": function(success, failure){
  68. this.explorer.actions.deleteGroup(this.data.id, function(){
  69. this.destroy();
  70. if (success) success();
  71. }.bind(this), function(xhr, text, error){
  72. var errorText = error;
  73. if (xhr) errorText = xhr.responseText;
  74. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  75. if (failure) failure();
  76. });
  77. },
  78. _getIcon: function(){
  79. return "/x_component_Org/$Explorer/default/icon/group.png";
  80. }
  81. });
  82. MWF.xApplication.Org.GroupExplorer.GroupContent = new Class({
  83. Extends: MWF.xApplication.Org.$Explorer.ItemContent,
  84. _getData: function(callback){
  85. if (this.item.data.id){
  86. this.explorer.actions.getGroup(function(json){
  87. this.data = json.data;
  88. this.item.data = json.data;
  89. if (callback) callback();
  90. }.bind(this), null, this.item.data.id);
  91. }else{
  92. this.data = this.item.data;
  93. if (callback) callback();
  94. }
  95. },
  96. _showItemPropertyTitle: function(){
  97. this.titleInfor = new MWF.xApplication.Org.GroupExplorer.GroupContent.TitleInfor(this);
  98. },
  99. _showItemPropertyBottom: function(){
  100. this.bottomInfor = new MWF.xApplication.Org.GroupExplorer.GroupContent.BottomInfor(this);
  101. },
  102. _loadTabs: function(){
  103. this.baseContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  104. this.basePage = this.propertyTab.addTab(this.baseContentNode, this.explorer.app.lp.groupBaseText);
  105. this.personMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  106. this.personMemberPage = this.propertyTab.addTab(this.personMemberContentNode, this.explorer.app.lp.groupMemberPersonText);
  107. this.groupMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  108. this.groupMemberPage = this.propertyTab.addTab(this.groupMemberContentNode, this.explorer.app.lp.groupMemberGroupText);
  109. },
  110. _loadContent: function(){
  111. this._listBaseInfor();
  112. this.loadListCount();
  113. var _self = this;
  114. this.personMemberList = this._listMembers("personList", "woPersonList", this.personMemberContentNode, [{
  115. "get": function(){
  116. var src = _self.explorer.actions.getPersonIcon(this.id);
  117. return "<div style='width:24px; height:24px;''><img style='width:24px; height:24px; border-radius:12px; border: 0' src='"+src+"'/></div>";
  118. },
  119. "set": function(){}
  120. }, "name", "employee", "mobile", "mail", {
  121. "get": function(){
  122. return "<div style='width:24px; height:24px; cursor: pointer; background:url(/x_component_Org/$Explorer/"+
  123. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  124. },
  125. "events": {
  126. "click": function(){
  127. _self.explorer.openPerson(this.data, this.td);
  128. }
  129. }
  130. }], [
  131. {"style": "width: 30px", "text": ""},
  132. {"style": "width: 20%", "text": this.explorer.app.lp.personName},
  133. {"style": "", "text": this.explorer.app.lp.personEmployee},
  134. {"style": "", "text": this.explorer.app.lp.personMobile},
  135. {"style": "", "text": this.explorer.app.lp.personMail},
  136. {"style": "width: 30px", "text": ""}
  137. ], this.addPersonMember.bind(this), "personCountNode", this.explorer.app.lp.deletePersonMemeberTitle, this.explorer.app.lp.deletePersonMemeber);
  138. this.groupMemberList = this._listMembers("groupList", "woGroupList", this.groupMemberContentNode, ["name", "distinguishedName", "description", {
  139. "get": function(){
  140. return "<div style='width:24px; height:24px; cursor: pointer; background:url(/x_component_Org/$Explorer/"+
  141. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  142. },
  143. "events": {
  144. "click": function(){
  145. _self.explorer.openGroup(this.data, this.td);
  146. }
  147. }
  148. }], [
  149. {"style": "width: 20%", "text": this.explorer.app.lp.groupName},
  150. {"style": "width: 40%", "text": this.explorer.app.lp.groupDn},
  151. {"style": "", "text": this.explorer.app.lp.groupDescription},
  152. {"style": "width: 30px", "text": ""}
  153. ], this.addGroupMember.bind(this), "groupCountNode", this.explorer.app.lp.deleteGroupMemeberTitle, this.explorer.app.lp.deleteGroupMemeber);
  154. },
  155. loadListCount: function(){
  156. var personCount = this.data.personList.length;
  157. if (personCount){
  158. if (this.personCountNode){
  159. this.personCountNode.set("text", personCount);
  160. }else{
  161. this.personCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": personCount}).inject(this.personMemberPage.tabNode);
  162. }
  163. }else{
  164. if (this.personCountNode) this.personCountNode.destroy();
  165. }
  166. var groupCount = this.data.groupList.length;
  167. if (groupCount){
  168. if (this.groupCountNode){
  169. this.groupCountNode.set("text", groupCount);
  170. }else{
  171. this.groupCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": groupCount}).inject(this.groupMemberPage.tabNode);
  172. }
  173. }else{
  174. if (this.groupCountNode) this.groupCountNode.destroy();
  175. }
  176. },
  177. _listBaseInfor: function(){
  178. this.baseInfor = new MWF.xApplication.Org.GroupExplorer.GroupContent.BaseInfor(this);
  179. },
  180. _listMembers: function(list, woList, node, attr, titles, addItemFun, countNode, deleteTitle, deleteText){
  181. var memberList = new MWF.xApplication.Org.List(node, this, {
  182. "action": this.data.control.allowEdit,
  183. "canEdit": false,
  184. "deleteItemTitle": deleteTitle,
  185. "deleteItemText": deleteText,
  186. "data": {
  187. "person": this.data.id,
  188. "name": "",
  189. "unique": "",
  190. "orderNumber": "",
  191. "attributeList": []
  192. },
  193. "attr": attr,
  194. "onQueryDelete": function(){
  195. this.saveCloneData = Object.clone(this.data);
  196. }.bind(this),
  197. "onDelete": function(continueDelete){
  198. this.explorer.actions.saveGroup(this.saveCloneData, function(json){
  199. this.data[list] = this.saveCloneData[list];
  200. this.data[woList] = this.saveCloneData[woList];
  201. this.data.id = json.data.id;
  202. this.saveCloneData = null;
  203. delete this.saveCloneData;
  204. }.bind(this), function(xhr, text, error){
  205. continueDelete = false;
  206. this.explorer.app.notice((JSON.decode(xhr.responseText).message.trim() || "request json error"), "error");
  207. }.bind(this), false);
  208. }.bind(this),
  209. "onPostDelete": function(delCount){
  210. if (this[countNode]){
  211. var count = this[countNode].get("text").toInt()-delCount;
  212. this[countNode].set("text", count);
  213. }
  214. }.bind(this)
  215. });
  216. memberList.addItem = addItemFun;
  217. memberList.load(titles);
  218. var _self = this;
  219. if (this.data[woList] && this.data[woList].length){
  220. this.data[woList].each(function(d){
  221. var item = memberList.push(d);
  222. item["delete"] = function(callback){
  223. _self.saveCloneData[list].erase(this.data.id);
  224. _self.saveCloneData[woList] = _self.saveCloneData[woList].filter(function(a){
  225. return (this.data.id !== a.id);
  226. }.bind(this));
  227. if (callback) callback();
  228. };
  229. }.bind(this));
  230. }
  231. return memberList;
  232. },
  233. addListItem: function(memberList, data, list, woList){
  234. var _self = this;
  235. var item = memberList.push(data);
  236. item["delete"] = function(callback){
  237. _self.saveCloneData[list].erase(this.data.id);
  238. _self.saveCloneData[woList] = _self.saveCloneData[woList].filter(function(a){
  239. return (this.data.id !== a.id);
  240. }.bind(this));
  241. if (callback) callback();
  242. };
  243. },
  244. checkSaveBaseInfor: function(callback){
  245. if (!this.data.id){
  246. if (this.baseInfor){
  247. if (this.baseInfor.mode==="edit") this.baseInfor.save(function(){
  248. if (callback) callback();
  249. }.bind(this));
  250. }
  251. }else{
  252. if (callback) callback();
  253. }
  254. },
  255. addPersonMember: function(){
  256. this.checkSaveBaseInfor(function(){
  257. MWF.xDesktop.requireApp("Selector", "Person", function(){
  258. var selector = new MWF.xApplication.Selector.Person(this.explorer.app.content,{
  259. "values": this.data.personList,
  260. "onComplete": function(items){
  261. var ids = [];
  262. var persons = [];
  263. items.each(function(item){
  264. ids.push(item.data.id);
  265. persons.push(item.data);
  266. });
  267. this.data.personList = ids;
  268. this.data.woPersonList = persons;
  269. this._saveElement(this.data, function(){
  270. this.personMemberList.clear();
  271. this.data.woPersonList.each(function(d){
  272. this.addListItem(this.personMemberList, d, "personList", "woPersonList");
  273. }.bind(this));
  274. }.bind(this));
  275. }.bind(this)
  276. });
  277. selector.load();
  278. }.bind(this));
  279. }.bind(this));
  280. },
  281. addGroupMember: function(){
  282. this.checkSaveBaseInfor(function(){
  283. MWF.xDesktop.requireApp("Selector", "Group", function(){
  284. var selector = new MWF.xApplication.Selector.Group(this.explorer.app.content,{
  285. "values": this.data.groupList,
  286. "onComplete": function(items){
  287. var ids = [];
  288. var groups = [];
  289. items.each(function(item){
  290. ids.push(item.data.id);
  291. groups.push(item.data);
  292. });
  293. this.data.groupList = ids;
  294. this.data.woGroupList = groups;
  295. this._saveElement(this.data, function(){
  296. this.groupMemberList.clear();
  297. this.data.woGroupList.each(function(d){
  298. this.addListItem(this.groupMemberList, d, "groupList", "woGroupList");
  299. }.bind(this));
  300. }.bind(this));
  301. }.bind(this)
  302. });
  303. selector.load();
  304. }.bind(this));
  305. }.bind(this));
  306. },
  307. _saveElement: function(data, success, failure){
  308. this.explorer.actions.saveGroup(data, function(json){
  309. Object.merge(this.data, data);
  310. if (this.data.id){
  311. this.data.id = json.data.id;
  312. this.item.refresh();
  313. if (success) success();
  314. }else{
  315. this.explorer.actions.getGroup(function(json){
  316. this.data = json.data;
  317. this.item.refresh();
  318. if (success) success();
  319. }.bind(this), null, json.data.id);
  320. }
  321. }.bind(this), function(xhr, text, error){
  322. if (failure) failure(xhr, text, error);
  323. }.bind(this));
  324. }
  325. });
  326. MWF.xApplication.Org.GroupExplorer.GroupContent.TitleInfor = new Class({
  327. Extends: MWF.xApplication.Org.RoleExplorer.RoleContent.TitleInfor,
  328. _getIcon: function(){
  329. return "/x_component_Org/$Explorer/default/icon/group70.png";
  330. }
  331. });
  332. MWF.xApplication.Org.GroupExplorer.GroupContent.BottomInfor = new Class({
  333. Extends: MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor,
  334. addInforList: function(){
  335. var text = this.explorer.app.lp.groupReadDn.replace(/{dn}/g, (this.data.distinguishedName || " "));
  336. this.addInfor(text);
  337. text = this.explorer.app.lp.groupReadCreate.replace(/{date}/g, (this.data.createTime || " "));
  338. text = text.replace(/{date2}/g, (this.data.updateTime || " "));
  339. this.addInfor(text);
  340. }
  341. });
  342. MWF.xApplication.Org.GroupExplorer.GroupContent.BaseInfor = new Class({
  343. Extends: MWF.xApplication.Org.RoleExplorer.RoleContent.BaseInfor,
  344. getContentHtml: function(){
  345. var html = "<table width='100%' cellpadding='3px' cellspacing='5px'>";
  346. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.groupName+":</td><td class='inforContent'>"+(this.data.name || "")+"</td>" +
  347. "<td class='inforTitle'>"+this.explorer.app.lp.groupUnique+":</td><td class='inforContent'>"+(this.data.unique || "")+"</td></tr>";
  348. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.groupDescription+":</td><td colspan='3' class='inforContent'>"+(this.data.description || "")+"</td>";
  349. html += "<tr><td colspan='4' class='inforAction'></td></tr>";
  350. //this.baseInforRightNode.set("html", html);
  351. return html;
  352. },
  353. loadAction: function(){
  354. //this.explorer.app.lp.edit
  355. var actionAreas = this.editContentNode.getElements("td");
  356. var actionArea = actionAreas[actionAreas.length-1];
  357. if (this.data.control.allowEdit){
  358. this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea);
  359. this.editNode = new Element("div", {"styles": this.style.actionEditNode, "text": this.explorer.app.lp.editGroup}).inject(this.baseInforEditActionAreaNode);
  360. this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.saveGroup}).inject(this.baseInforEditActionAreaNode);
  361. this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode);
  362. this.editNode.setStyle("display", "block");
  363. this.editNode.addEvent("click", this.edit.bind(this));
  364. this.saveNode.addEvent("click", this.save.bind(this));
  365. this.cancelNode.addEvent("click", this.cancel.bind(this));
  366. }else{
  367. }
  368. },
  369. save: function(){
  370. if (!this.nameInputNode.get("value")){
  371. this.explorer.app.notice(this.explorer.app.lp.inputGroupInfor, "error", this.explorer.propertyContentNode);
  372. return false;
  373. }
  374. //this.data.genderType = gender;
  375. if (!this.uniqueInputNode.get("value")) this.data.unique = this.nameInputNode.get("value");
  376. this.content.propertyContentScrollNode.mask({
  377. "style": {
  378. "opacity": 0.7,
  379. "background-color": "#999"
  380. }
  381. });
  382. this.saveGroup(function(){
  383. this.cancel();
  384. this.content.propertyContentScrollNode.unmask();
  385. }.bind(this), function(xhr, text, error){
  386. this.explorer.app.notice((JSON.decode(xhr.responseText).message.trim() || "request json error"), "error");
  387. this.content.propertyContentScrollNode.unmask();
  388. }.bind(this));
  389. },
  390. saveGroup: function(callback, cancel){
  391. var data = Object.clone(this.data);
  392. data.name = this.nameInputNode.get("value");
  393. data.unique = this.uniqueInputNode.get("value");
  394. data.description = this.descriptionInputNode.get("value");
  395. this.explorer.actions.saveGroup(data, function(json){
  396. Object.merge(this.data, data);
  397. if (this.data.id){
  398. this.data.id = json.data.id;
  399. this.item.refresh();
  400. if (callback) callback();
  401. }else{
  402. this.explorer.actions.getGroup(function(json){
  403. this.data = Object.merge(this.data, json.data);
  404. this.item.data = this.data;
  405. this.item.refresh();
  406. if (callback) callback();
  407. }.bind(this), null, json.data.id);
  408. }
  409. }.bind(this), function(xhr, text, error){
  410. if (cancel) cancel(xhr, text, error);
  411. }.bind(this));
  412. },
  413. destroy: function(){
  414. this.node.empty();
  415. this.node.destroy();
  416. MWF.release(this);
  417. }
  418. });