RoleExplorer.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625
  1. MWF.xDesktop.requireApp("Template", "MTooltips", null, false);
  2. MWF.xDesktop.requireApp("Org", "$Explorer", null, false);
  3. MWF.xApplication.Org.RoleExplorer = new Class({
  4. Extends: MWF.xApplication.Org.$Explorer,
  5. Implements: [Options, Events],
  6. options: {
  7. "style": "default",
  8. "lp": {
  9. },
  10. "creator": false
  11. },
  12. _loadLp: function(){
  13. this.options.lp = {
  14. "elementLoaded": this.app.lp.roleLoaded,
  15. "search": this.app.lp.search,
  16. "searchText": this.app.lp.searchText,
  17. "elementSave": this.app.lp.roleSave,
  18. "deleteElements": this.app.lp.deleteRoles,
  19. "deleteElementsCancel": this.app.lp.deleteElementsCancel,
  20. "deleteElementsTitle": this.app.lp.deleteRolesTitle,
  21. "deleteElementsConfirm": this.app.lp.deletePersonsConfirm,
  22. "elementBaseText": this.app.lp.roleBaseText,
  23. "elementName": this.app.lp.roleName,
  24. "noSignature": this.app.lp.noSignature,
  25. "edit": this.app.lp.edit,
  26. "cancel": this.app.lp.cancel,
  27. "save": this.app.lp.save,
  28. "add": this.app.lp.add
  29. }
  30. },
  31. _listElementNext: function(lastid, count, callback){
  32. this.actions.listRoleNext(lastid || "(0)", count, function(json){
  33. if (callback) callback.apply(this, [json]);
  34. }.bind(this));
  35. },
  36. _newElement: function(data, explorer){
  37. return new MWF.xApplication.Org.RoleExplorer.Role(data, explorer, this.isEditor);
  38. },
  39. _listElementByKey: function(callback, failure, key){
  40. this.actions.listRoleByKey(function(json){
  41. if (callback) callback.apply(this, [json]);
  42. }.bind(this), failure, key);
  43. },
  44. _getAddElementData: function(){
  45. return {
  46. "personList": [],
  47. "groupList": [],
  48. "description": "",
  49. "unique": "",
  50. "orderNumber": "",
  51. "id": "",
  52. "name": "",
  53. "control": {
  54. "allowEdit": true,
  55. "allowDelete": true
  56. }
  57. };
  58. },
  59. loadToolbar: function(){
  60. if (this._isActionManager()){
  61. this.isEditor = true;
  62. this.addTopElementNode = new Element("div", {"styles": this.css.addTopGroupNode}).inject(this.toolbarNode);
  63. this.addTopElementNode.addEvent("click", function(){
  64. this.addTopElement();
  65. }.bind(this));
  66. }
  67. this.createSearchNode();
  68. this.loadPingyinArea();
  69. },
  70. _isActionManager: function(){
  71. debugger;
  72. return (MWF.AC.isOrganizationManager() || MWF.AC.isRoleManager() || MWF.AC.isSecurityManager());
  73. }
  74. });
  75. MWF.xApplication.Org.RoleExplorer.Role = new Class({
  76. Extends: MWF.xApplication.Org.$Explorer.Item,
  77. showItemProperty: function(){
  78. this.content = new MWF.xApplication.Org.RoleExplorer.RoleContent(this);
  79. },
  80. addActions: function(){
  81. if (this.isEditor){
  82. if (this.data.id && !this.data.isSystemRole){
  83. if (this.data.control.allowDelete){
  84. if (!this.deleteNode){
  85. this.deleteNode = new Element("div.o2icon-delete", {"styles": this.style.actionDeleteNode}).inject(this.actionNode);
  86. this.deleteNode.addEvent("click", function(e){
  87. if (!this.notDelete){
  88. if (!this.deleteSelected){
  89. this.setDelete();
  90. }else{
  91. this.setUndelete();
  92. }
  93. }
  94. e.stopPropagation();
  95. }.bind(this));
  96. if (this.explorer.currentItem===this){
  97. if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected);
  98. }
  99. }
  100. }
  101. }
  102. }
  103. },
  104. "delete": function(success, failure){
  105. this.explorer.actions.deleteRole(this.data.id, function(){
  106. this.destroy();
  107. if (success) success();
  108. }.bind(this), function(xhr, text, error){
  109. var errorText = error;
  110. if (xhr) errorText = xhr.responseText;
  111. MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText);
  112. if (failure) failure();
  113. });
  114. },
  115. _getIcon: function(){
  116. return "../x_component_Org/$Explorer/default/icon/role.png";
  117. }
  118. });
  119. MWF.xApplication.Org.RoleExplorer.RoleContent = new Class({
  120. Extends: MWF.xApplication.Org.$Explorer.ItemContent,
  121. _getData: function(callback){
  122. if (this.item.data.id){
  123. this.explorer.actions.getRole(function(json){
  124. this.data = json.data;
  125. this.item.data = json.data;
  126. if (callback) callback();
  127. }.bind(this), null, this.item.data.id);
  128. }else{
  129. this.data = this.item.data;
  130. if (callback) callback();
  131. }
  132. },
  133. _showItemPropertyTitle: function(){
  134. this.titleInfor = new MWF.xApplication.Org.RoleExplorer.RoleContent.TitleInfor(this);
  135. //this.baseInfor = new MWF.xApplication.Org.BaseInfor(this);
  136. },
  137. _showItemPropertyBottom: function(){
  138. this.bottomInfor = new MWF.xApplication.Org.RoleExplorer.RoleContent.BottomInfor(this);
  139. },
  140. _loadTabs: function(){
  141. this.baseContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  142. this.basePage = this.propertyTab.addTab(this.baseContentNode, this.explorer.app.lp.roleBaseText);
  143. this.personMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  144. this.personMemberPage = this.propertyTab.addTab(this.personMemberContentNode, this.explorer.app.lp.rolePersonMembers);
  145. this.groupMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode});
  146. this.groupMemberPage = this.propertyTab.addTab(this.groupMemberContentNode, this.explorer.app.lp.roleGroupMembers);
  147. },
  148. _loadContent: function(){
  149. this._listBaseInfor();
  150. this.loadListCount();
  151. var _self = this;
  152. this.personMemberList = this._listMembers("personList", "woPersonList", this.personMemberContentNode, [{
  153. "getHtml": function(){
  154. var src = _self.explorer.actions.getPersonIcon(this.id);
  155. return "<div style='width:24px; height:24px;''><img style='width:24px; height:24px; border-radius:12px; border: 0' src='"+src+"'/></div>";
  156. },
  157. "set": function(){}
  158. }, "name", "employee", "mobile", "mail", {
  159. "getHtml": function(){
  160. return "<div style='width:24px; height:24px; cursor: pointer; background:url(../x_component_Org/$Explorer/"+
  161. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  162. },
  163. "events": {
  164. "click": function(){
  165. _self.explorer.openPerson(this.data, this.td);
  166. }
  167. }
  168. }], [
  169. {"style": "width: 30px", "text": ""},
  170. {"style": "width: 20%", "text": this.explorer.app.lp.personName},
  171. {"style": "", "text": this.explorer.app.lp.personEmployee},
  172. {"style": "", "text": this.explorer.app.lp.personMobile},
  173. {"style": "", "text": this.explorer.app.lp.personMail},
  174. {"style": "width: 30px", "text": ""}
  175. ], this.addPersonMember.bind(this), "personCountNode", this.explorer.app.lp.deletePersonMemeberTitle, this.explorer.app.lp.deletePersonMemeber);
  176. this.groupMemberList = this._listMembers("groupList", "woGroupList", this.groupMemberContentNode, ["name", "distinguishedName", "description", {
  177. "getHtml": function(){
  178. return "<div style='width:24px; height:24px; cursor: pointer; background:url(../x_component_Org/$Explorer/"+
  179. _self.explorer.app.options.style+"/icon/open.png) center center no-repeat'></div>";
  180. },
  181. "events": {
  182. "click": function(){
  183. _self.explorer.openGroup(this.data, this.td);
  184. }
  185. }
  186. }], [
  187. {"style": "width: 20%", "text": this.explorer.app.lp.groupName},
  188. {"style": "width: 40%", "text": this.explorer.app.lp.groupDn},
  189. {"style": "", "text": this.explorer.app.lp.groupDescription},
  190. {"style": "width: 30px", "text": ""}
  191. ], this.addGroupMember.bind(this), "groupCountNode", this.explorer.app.lp.deleteGroupMemeberTitle, this.explorer.app.lp.deleteGroupMemeber);
  192. },
  193. loadListCount: function(){
  194. var personCount = this.data.personList.length;
  195. if (personCount){
  196. if (this.personCountNode){
  197. this.personCountNode.set("text", personCount);
  198. }else{
  199. this.personCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": personCount}).inject(this.personMemberPage.tabNode);
  200. }
  201. }else{
  202. if (this.personCountNode) this.personCountNode.destroy();
  203. }
  204. var groupCount = this.data.groupList.length;
  205. if (groupCount){
  206. if (this.groupCountNode){
  207. this.groupCountNode.set("text", groupCount);
  208. }else{
  209. this.groupCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": groupCount}).inject(this.groupMemberPage.tabNode);
  210. }
  211. }else{
  212. if (this.groupCountNode) this.groupCountNode.destroy();
  213. }
  214. },
  215. _listBaseInfor: function(){
  216. this.baseInfor = new MWF.xApplication.Org.RoleExplorer.RoleContent.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.saveRole(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. if (this.data[woList] && this.data[woList].length){
  257. this.data[woList].each(function(d){
  258. this.addListItem(memberList, d, list, woList);
  259. // var item = memberList.push(d);
  260. // item["delete"] = function(callback){
  261. // debugger;
  262. // _self.saveCloneData[list].erase(this.data.id);
  263. // _self.saveCloneData[woList] = _self.saveCloneData[woList].filter(function(a){
  264. // return (this.data.id !== a.id);
  265. // }.bind(this));
  266. // if (callback) callback();
  267. // };
  268. }.bind(this));
  269. }
  270. return memberList;
  271. },
  272. addListItem: function(memberList, data, list, woList){
  273. var _self = this;
  274. var item = memberList.push(data);
  275. item["delete"] = function(callback){
  276. _self.saveCloneData[list].erase(this.data.id);
  277. _self.saveCloneData[woList] = _self.saveCloneData[woList].filter(function(a){
  278. return (this.data.id !== a.id);
  279. }.bind(this));
  280. if (callback) callback();
  281. };
  282. },
  283. checkSaveBaseInfor: function(callback){
  284. if (!this.data.id){
  285. if (this.baseInfor){
  286. if (this.baseInfor.mode==="edit") this.baseInfor.save(function(){
  287. if (callback) callback();
  288. }.bind(this));
  289. }
  290. }else{
  291. if (callback) callback();
  292. }
  293. },
  294. addPersonMember: function(){
  295. this.checkSaveBaseInfor(function(){
  296. MWF.xDesktop.requireApp("Selector", "Person", function(){
  297. var selector = new MWF.xApplication.Selector.Person(this.explorer.app.content,{
  298. "values": this.data.personList,
  299. "onComplete": function(items){
  300. var ids = [];
  301. var persons = [];
  302. items.each(function(item){
  303. ids.push(item.data.id);
  304. persons.push(item.data);
  305. });
  306. this.data.personList = ids;
  307. this.data.woPersonList = persons;
  308. this._saveElement(this.data, function(){
  309. this.personMemberList.clear();
  310. this.data.woPersonList.each(function(d){
  311. this.addListItem(this.personMemberList, d, "personList", "woPersonList");
  312. }.bind(this));
  313. this.loadListCount();
  314. }.bind(this));
  315. }.bind(this)
  316. });
  317. selector.load();
  318. }.bind(this));
  319. }.bind(this));
  320. },
  321. addGroupMember: function(){
  322. this.checkSaveBaseInfor(function(){
  323. MWF.xDesktop.requireApp("Selector", "Group", function(){
  324. var selector = new MWF.xApplication.Selector.Group(this.explorer.app.content,{
  325. "values": this.data.groupList,
  326. "onComplete": function(items){
  327. var ids = [];
  328. var groups = [];
  329. items.each(function(item){
  330. ids.push(item.data.id);
  331. groups.push(item.data);
  332. });
  333. this.data.groupList = ids;
  334. this.data.woGroupList = groups;
  335. this._saveElement(this.data, function(){
  336. this.groupMemberList.clear();
  337. this.data.woGroupList.each(function(d){
  338. this.addListItem(this.groupMemberList, d, "groupList", "woGroupList");
  339. }.bind(this));
  340. this.loadListCount();
  341. }.bind(this));
  342. }.bind(this)
  343. });
  344. selector.load();
  345. }.bind(this));
  346. }.bind(this));
  347. },
  348. _saveElement: function(data, success, failure){
  349. this.explorer.actions.saveRole(data, function(json){
  350. Object.merge(this.data, data);
  351. if (this.data.id){
  352. this.data.id = json.data.id;
  353. this.item.refresh();
  354. if (success) success();
  355. }else{
  356. this.explorer.actions.getRole(function(json){
  357. this.data = json.data;
  358. this.item.refresh();
  359. if (success) success();
  360. }.bind(this), null, json.data.id);
  361. }
  362. }.bind(this), function(xhr, text, error){
  363. if (failure) failure(xhr, text, error);
  364. }.bind(this));
  365. }
  366. });
  367. MWF.xApplication.Org.RoleExplorer.RoleContent.TitleInfor = new Class({
  368. Extends: MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor,
  369. _getStyle: function(){
  370. var css = Object.clone(this.item.style.person);
  371. return Object.merge(css, this.item.style.role);
  372. },
  373. _getIcon: function(){
  374. return "../x_component_Org/$Explorer/default/icon/role70.png";
  375. },
  376. setBackground: function(){
  377. this.titleBgNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/group_bg_bg.png)");
  378. this.titleNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/group_bg.png)");
  379. },
  380. loadRightInfor: function(){
  381. //var text = this.data.name+((this.data.unique) ? "("+this.data.unique+")" : "");
  382. var text = this.data.name;
  383. if (!this.nameNode) this.nameNode = new Element("div", {"styles": this.style.titleInforNameNode}).inject(this.titleInforRightNode);
  384. if (!this.signatureNode) this.signatureNode = new Element("div", {"styles": this.style.titleInforSignatureNode}).inject(this.titleInforRightNode);
  385. this.nameNode.set("text", text);
  386. this.signatureNode.set("text", (this.data.distinguishedName || "" ));
  387. }
  388. });
  389. MWF.xApplication.Org.RoleExplorer.RoleContent.BottomInfor = new Class({
  390. Extends: MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor,
  391. addInforList: function(){
  392. var text = this.explorer.app.lp.roleReadDn.replace(/{dn}/g, (this.data.distinguishedName || " "));
  393. this.addInfor(text);
  394. text = this.explorer.app.lp.roleReadCreate.replace(/{date}/g, (this.data.createTime || " "));
  395. text = text.replace(/{date2}/g, (this.data.updateTime || " "));
  396. this.addInfor(text);
  397. }
  398. });
  399. MWF.xApplication.Org.RoleExplorer.RoleContent.BaseInfor = new Class({
  400. initialize: function(content){
  401. this.content = content;
  402. this.item = content.item;
  403. this.data = this.content.data;
  404. this.explorer = this.item.explorer;
  405. this.contentNode = this.content.baseContentNode;
  406. this.style = this.item.style.person;
  407. this.mode = "read";
  408. this.load();
  409. },
  410. load: function(){
  411. this.node = new Element("div", {"styles": this.style.baseContentNode}).inject(this.contentNode);
  412. this.editContentNode = new Element("div", {"styles": this.style.baseEditNode}).inject(this.node);
  413. this.editContentNode.set("html", this.getContentHtml());
  414. this.editContentNode.getElement(".infor_name").set("text", this.data.name || "");
  415. this.editContentNode.getElement(".infor_unique").set("text", this.data.unique || "");
  416. this.editContentNode.getElement(".infor_description").set("text", this.data.description || "");
  417. this.editContentNode.getElements("td.inforTitle").setStyles(this.style.baseInforTitleNode);
  418. this.editContentNode.getElements("td.inforContent").setStyles(this.style.baseInforContentNode);
  419. this.editContentNode.getElements("td.inforAction").setStyles(this.style.baseInforActionNode);
  420. this.loadAction();
  421. },
  422. getContentHtml: function(){
  423. var html = "<table width='100%' cellpadding='3px' cellspacing='5px'>";
  424. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.roleName+":</td><td class='inforContent infor_name'></td>" +
  425. "<td class='inforTitle'>"+this.explorer.app.lp.roleUnique+":</td><td class='inforContent infor_unique'></td></tr>";
  426. html += "<tr><td class='inforTitle'>"+this.explorer.app.lp.roleDescription+":</td><td colspan='3' class='inforContent infor_description'></td>";
  427. html += "<tr><td colspan='4' class='inforAction'></td></tr>";
  428. //this.baseInforRightNode.set("html", html);
  429. return html;
  430. },
  431. loadAction: function(){
  432. //this.explorer.app.lp.edit
  433. var actionAreas = this.editContentNode.getElements("td");
  434. var actionArea = actionAreas[actionAreas.length-1];
  435. if (this.data.control.allowEdit){
  436. this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea);
  437. if( this.data.isSystemRole ) {
  438. this.editNode = new Element("div");
  439. this.saveNode = new Element("div");
  440. this.cancelNode = new Element("div");
  441. }else{
  442. this.editNode = new Element("div", {"styles": this.style.actionEditNode, "text": this.explorer.app.lp.editRole}).inject(this.baseInforEditActionAreaNode);
  443. this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.saveRole}).inject(this.baseInforEditActionAreaNode);
  444. this.saveNode.addClass("mainColor_bg");
  445. this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode);
  446. this.editNode.setStyle("display", "block");
  447. this.editNode.addEvent("click", this.edit.bind(this));
  448. this.saveNode.addEvent("click", function(){this.save();}.bind(this));
  449. this.cancelNode.addEvent("click", this.cancel.bind(this));
  450. }
  451. }else{
  452. }
  453. },
  454. edit: function(){
  455. var tdContents = this.editContentNode.getElements("td.inforContent");
  456. tdContents[0].setStyles(this.style.baseInforContentNode_edit).empty();
  457. this.nameInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[0]);
  458. this.nameInputNode.set("value", (this.data.name));
  459. tdContents[1].setStyles(this.style.baseInforContentNode_edit).empty();
  460. this.uniqueInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[1]);
  461. this.uniqueInputNode.set("value", (this.data.unique));
  462. if( this.data.id ){
  463. this.tooltip = new MWF.xApplication.Org.RoleExplorer.RoleContent.UniqueTooltip(this.explorer.app.content, tdContents[1], this.explorer.app, {}, {
  464. axis : "y",
  465. position : {
  466. x : "right"
  467. },
  468. hiddenDelay : 300,
  469. displayDelay : 300
  470. });
  471. }
  472. tdContents[2].setStyles(this.style.baseInforContentNode_edit).empty();
  473. this.descriptionInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[2]);
  474. this.descriptionInputNode.set("value", (this.data.description));
  475. var _self = this;
  476. this.editContentNode.getElements("input").addEvents({
  477. "focus": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_focus);}},
  478. "blur": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_blur);}}
  479. });
  480. this.mode = "edit";
  481. this.editNode.setStyle("display", "none");
  482. this.saveNode.setStyle("display", "block");
  483. this.cancelNode.setStyle("display", "block");
  484. },
  485. save: function(callback){
  486. if (!this.nameInputNode.get("value")){
  487. this.explorer.app.notice(this.explorer.app.lp.inputRoleInfor, "error", this.explorer.propertyContentNode);
  488. return false;
  489. }
  490. //this.data.genderType = gender;
  491. if (!this.uniqueInputNode.get("value")) this.data.unique = this.nameInputNode.get("value");
  492. this.content.propertyContentScrollNode.mask({
  493. "style": {
  494. "opacity": 0.7,
  495. "background-color": "#999"
  496. }
  497. });
  498. this.saveRole(function(){
  499. this.cancel();
  500. this.content.propertyContentScrollNode.unmask();
  501. if (callback) callback();
  502. }.bind(this), function(xhr, text, error){
  503. this.explorer.app.notice((JSON.decode(xhr.responseText).message.trim() || "request json error"), "error");
  504. this.content.propertyContentScrollNode.unmask();
  505. }.bind(this));
  506. },
  507. saveRole: function(callback, cancel){
  508. var data = Object.clone(this.data);
  509. data.name = this.nameInputNode.get("value");
  510. data.unique = this.uniqueInputNode.get("value");
  511. data.description = this.descriptionInputNode.get("value");
  512. this.explorer.actions.saveRole(data, function(json){
  513. Object.merge(this.data, data);
  514. if (this.data.id){
  515. this.data.id = json.data.id;
  516. this.item.refresh();
  517. if (callback) callback();
  518. }else{
  519. this.explorer.actions.getRole(function(json){
  520. this.data = Object.merge(this.data, json.data);
  521. this.item.data = this.data;
  522. this.item.refresh();
  523. if (callback) callback();
  524. }.bind(this), null, json.data.id);
  525. }
  526. }.bind(this), function(xhr, text, error){
  527. if (cancel) cancel(xhr, text, error);
  528. }.bind(this));
  529. },
  530. cancel: function(){
  531. if (this.data.id){
  532. var tdContents = this.editContentNode.getElements("td.inforContent");
  533. tdContents[0].setStyles(this.style.baseInforContentNode).set("text", this.data.name || "");
  534. tdContents[1].setStyles(this.style.baseInforContentNode).set("text", this.data.unique || "");
  535. tdContents[2].setStyles(this.style.baseInforContentNode).set("text", this.data.description || "");
  536. this.mode = "read";
  537. this.editNode.setStyle("display", "block");
  538. this.saveNode.setStyle("display", "none");
  539. this.cancelNode.setStyle("display", "none");
  540. }else{
  541. this.item.destroy();
  542. }
  543. if( this.tooltip ){
  544. this.tooltip.destroy();
  545. this.tooltip = null;
  546. }
  547. },
  548. // getGenderType: function(){
  549. // var text = "";
  550. // if (this.data.genderType){
  551. // switch (this.data.genderType) {
  552. // case "m":
  553. // text = this.explorer.app.lp.man;
  554. // break;
  555. // case "f":
  556. // text = this.explorer.app.lp.female;
  557. // break;
  558. // default:
  559. // text = this.explorer.app.lp.other;
  560. // }
  561. // }
  562. // return text;
  563. // },
  564. destroy: function(){
  565. if( this.tooltip ){
  566. this.tooltip.destroy();
  567. this.tooltip = null;
  568. }
  569. this.node.empty();
  570. this.node.destroy();
  571. MWF.release(this);
  572. }
  573. // _getIcon: function(){
  574. // var src = "data:image/png;base64,"+this.data.icon;
  575. // if (!this.data.icon){
  576. // if (this.data.genderType==="f"){
  577. // src = "../x_component_Org/$Explorer/default/icon/female.png"
  578. // }else{
  579. // src = "../x_component_Org/$Explorer/default/icon/man.png"
  580. // }
  581. // }
  582. // return src;
  583. // }
  584. });
  585. MWF.xApplication.Org.RoleExplorer.RoleContent.UniqueTooltip = new Class({
  586. Extends: MTooltips,
  587. _getHtml : function(){
  588. var html =
  589. "<div item='containr' style='line-height:24px;'><div style='font-size: 14px;color:red;float:left; '>"+ this.lp.roleUniqueModifyNote +"</div></div>";
  590. return html;
  591. }
  592. });