MWF.xDesktop.requireApp("Template", "MTooltips", null, false); MWF.xDesktop.requireApp("Org", "$Explorer", null, false); MWF.xApplication.Org.RoleExplorer = new Class({ Extends: MWF.xApplication.Org.$Explorer, Implements: [Options, Events], options: { "style": "default", "lp": { }, "creator": false }, _loadLp: function(){ this.options.lp = { "elementLoaded": this.app.lp.roleLoaded, "search": this.app.lp.search, "searchText": this.app.lp.searchText, "elementSave": this.app.lp.roleSave, "deleteElements": this.app.lp.deleteRoles, "deleteElementsCancel": this.app.lp.deleteElementsCancel, "deleteElementsTitle": this.app.lp.deleteRolesTitle, "deleteElementsConfirm": this.app.lp.deletePersonsConfirm, "elementBaseText": this.app.lp.roleBaseText, "elementName": this.app.lp.roleName, "noSignature": this.app.lp.noSignature, "edit": this.app.lp.edit, "cancel": this.app.lp.cancel, "save": this.app.lp.save, "add": this.app.lp.add } }, _listElementNext: function(lastid, count, callback){ this.actions.listRoleNext(lastid || "(0)", count, function(json){ if (callback) callback.apply(this, [json]); }.bind(this)); }, _newElement: function(data, explorer){ return new MWF.xApplication.Org.RoleExplorer.Role(data, explorer, this.isEditor); }, _listElementByKey: function(callback, failure, key){ this.actions.listRoleByKey(function(json){ if (callback) callback.apply(this, [json]); }.bind(this), failure, key); }, _getAddElementData: function(){ return { "personList": [], "groupList": [], "description": "", "unique": "", "orderNumber": "", "id": "", "name": "", "control": { "allowEdit": true, "allowDelete": true } }; }, loadToolbar: function(){ if (this._isActionManager()){ this.isEditor = true; this.addTopElementNode = new Element("div", {"styles": this.css.addTopGroupNode}).inject(this.toolbarNode); this.addTopElementNode.addEvent("click", function(){ this.addTopElement(); }.bind(this)); } this.createSearchNode(); this.loadPingyinArea(); }, _isActionManager: function(){ debugger; return (MWF.AC.isOrganizationManager() || MWF.AC.isRoleManager() || MWF.AC.isSecurityManager()); } }); MWF.xApplication.Org.RoleExplorer.Role = new Class({ Extends: MWF.xApplication.Org.$Explorer.Item, showItemProperty: function(){ this.content = new MWF.xApplication.Org.RoleExplorer.RoleContent(this); }, addActions: function(){ if (this.isEditor){ if (this.data.id && !this.data.isSystemRole){ if (this.data.control.allowDelete){ if (!this.deleteNode){ this.deleteNode = new Element("div.o2icon-delete", {"styles": this.style.actionDeleteNode}).inject(this.actionNode); this.deleteNode.addEvent("click", function(e){ if (!this.notDelete){ if (!this.deleteSelected){ this.setDelete(); }else{ this.setUndelete(); } } e.stopPropagation(); }.bind(this)); if (this.explorer.currentItem===this){ if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected); } } } } } }, "delete": function(success, failure){ this.explorer.actions.deleteRole(this.data.id, function(){ this.destroy(); if (success) success(); }.bind(this), function(xhr, text, error){ var errorText = error; if (xhr) errorText = xhr.responseText; MWF.xDesktop.notice("error", {x: "right", y:"top"}, "request json error: "+errorText); if (failure) failure(); }); }, _getIcon: function(){ return "../x_component_Org/$Explorer/default/icon/role.png"; } }); MWF.xApplication.Org.RoleExplorer.RoleContent = new Class({ Extends: MWF.xApplication.Org.$Explorer.ItemContent, _getData: function(callback){ if (this.item.data.id){ this.explorer.actions.getRole(function(json){ this.data = json.data; this.item.data = json.data; if (callback) callback(); }.bind(this), null, this.item.data.id); }else{ this.data = this.item.data; if (callback) callback(); } }, _showItemPropertyTitle: function(){ this.titleInfor = new MWF.xApplication.Org.RoleExplorer.RoleContent.TitleInfor(this); //this.baseInfor = new MWF.xApplication.Org.BaseInfor(this); }, _showItemPropertyBottom: function(){ this.bottomInfor = new MWF.xApplication.Org.RoleExplorer.RoleContent.BottomInfor(this); }, _loadTabs: function(){ this.baseContentNode = new Element("div", {"styles": this.item.style.tabContentNode}); this.basePage = this.propertyTab.addTab(this.baseContentNode, this.explorer.app.lp.roleBaseText); this.personMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode}); this.personMemberPage = this.propertyTab.addTab(this.personMemberContentNode, this.explorer.app.lp.rolePersonMembers); this.groupMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode}); this.groupMemberPage = this.propertyTab.addTab(this.groupMemberContentNode, this.explorer.app.lp.roleGroupMembers); }, _loadContent: function(){ this._listBaseInfor(); this.loadListCount(); var _self = this; this.personMemberList = this._listMembers("personList", "woPersonList", this.personMemberContentNode, [{ "getHtml": function(){ var src = _self.explorer.actions.getPersonIcon(this.id); return "
"; }, "set": function(){} }, "name", "employee", "mobile", "mail", { "getHtml": function(){ return ""; }, "events": { "click": function(){ _self.explorer.openPerson(this.data, this.td); } } }], [ {"style": "width: 30px", "text": ""}, {"style": "width: 20%", "text": this.explorer.app.lp.personName}, {"style": "", "text": this.explorer.app.lp.personEmployee}, {"style": "", "text": this.explorer.app.lp.personMobile}, {"style": "", "text": this.explorer.app.lp.personMail}, {"style": "width: 30px", "text": ""} ], this.addPersonMember.bind(this), "personCountNode", this.explorer.app.lp.deletePersonMemeberTitle, this.explorer.app.lp.deletePersonMemeber); this.groupMemberList = this._listMembers("groupList", "woGroupList", this.groupMemberContentNode, ["name", "distinguishedName", "description", { "getHtml": function(){ return ""; }, "events": { "click": function(){ _self.explorer.openGroup(this.data, this.td); } } }], [ {"style": "width: 20%", "text": this.explorer.app.lp.groupName}, {"style": "width: 40%", "text": this.explorer.app.lp.groupDn}, {"style": "", "text": this.explorer.app.lp.groupDescription}, {"style": "width: 30px", "text": ""} ], this.addGroupMember.bind(this), "groupCountNode", this.explorer.app.lp.deleteGroupMemeberTitle, this.explorer.app.lp.deleteGroupMemeber); }, loadListCount: function(){ var personCount = this.data.personList.length; if (personCount){ if (this.personCountNode){ this.personCountNode.set("text", personCount); }else{ this.personCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": personCount}).inject(this.personMemberPage.tabNode); } }else{ if (this.personCountNode) this.personCountNode.destroy(); } var groupCount = this.data.groupList.length; if (groupCount){ if (this.groupCountNode){ this.groupCountNode.set("text", groupCount); }else{ this.groupCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": groupCount}).inject(this.groupMemberPage.tabNode); } }else{ if (this.groupCountNode) this.groupCountNode.destroy(); } }, _listBaseInfor: function(){ this.baseInfor = new MWF.xApplication.Org.RoleExplorer.RoleContent.BaseInfor(this); }, _listMembers: function(list, woList, node, attr, titles, addItemFun, countNode, deleteTitle, deleteText){ var memberList = new MWF.xApplication.Org.List(node, this, { "action": this.data.control.allowEdit, "canEdit": false, "deleteItemTitle": deleteTitle, "deleteItemText": deleteText, "data": { "person": this.data.id, "name": "", "unique": "", "orderNumber": "", "attributeList": [] }, "attr": attr, "onQueryDelete": function(){ this.saveCloneData = Object.clone(this.data); }.bind(this), "onDelete": function(continueDelete){ this.explorer.actions.saveRole(this.saveCloneData, function(json){ this.data[list] = this.saveCloneData[list]; this.data[woList] = this.saveCloneData[woList]; this.data.id = json.data.id; this.saveCloneData = null; delete this.saveCloneData; }.bind(this), function(xhr, text, error){ continueDelete = false; this.explorer.app.notice((JSON.decode(xhr.responseText).message.trim() || "request json error"), "error"); }.bind(this), false); }.bind(this), "onPostDelete": function(delCount){ if (this[countNode]){ var count = this[countNode].get("text").toInt()-delCount; this[countNode].set("text", count); } }.bind(this) }); memberList.addItem = addItemFun; memberList.load(titles); if (this.data[woList] && this.data[woList].length){ this.data[woList].each(function(d){ this.addListItem(memberList, d, list, woList); // var item = memberList.push(d); // item["delete"] = function(callback){ // debugger; // _self.saveCloneData[list].erase(this.data.id); // _self.saveCloneData[woList] = _self.saveCloneData[woList].filter(function(a){ // return (this.data.id !== a.id); // }.bind(this)); // if (callback) callback(); // }; }.bind(this)); } return memberList; }, addListItem: function(memberList, data, list, woList){ var _self = this; var item = memberList.push(data); item["delete"] = function(callback){ _self.saveCloneData[list].erase(this.data.id); _self.saveCloneData[woList] = _self.saveCloneData[woList].filter(function(a){ return (this.data.id !== a.id); }.bind(this)); if (callback) callback(); }; }, checkSaveBaseInfor: function(callback){ if (!this.data.id){ if (this.baseInfor){ if (this.baseInfor.mode==="edit") this.baseInfor.save(function(){ if (callback) callback(); }.bind(this)); } }else{ if (callback) callback(); } }, addPersonMember: function(){ this.checkSaveBaseInfor(function(){ MWF.xDesktop.requireApp("Selector", "Person", function(){ var selector = new MWF.xApplication.Selector.Person(this.explorer.app.content,{ "values": this.data.personList, "onComplete": function(items){ var ids = []; var persons = []; items.each(function(item){ ids.push(item.data.id); persons.push(item.data); }); this.data.personList = ids; this.data.woPersonList = persons; this._saveElement(this.data, function(){ this.personMemberList.clear(); this.data.woPersonList.each(function(d){ this.addListItem(this.personMemberList, d, "personList", "woPersonList"); }.bind(this)); this.loadListCount(); }.bind(this)); }.bind(this) }); selector.load(); }.bind(this)); }.bind(this)); }, addGroupMember: function(){ this.checkSaveBaseInfor(function(){ MWF.xDesktop.requireApp("Selector", "Group", function(){ var selector = new MWF.xApplication.Selector.Group(this.explorer.app.content,{ "values": this.data.groupList, "onComplete": function(items){ var ids = []; var groups = []; items.each(function(item){ ids.push(item.data.id); groups.push(item.data); }); this.data.groupList = ids; this.data.woGroupList = groups; this._saveElement(this.data, function(){ this.groupMemberList.clear(); this.data.woGroupList.each(function(d){ this.addListItem(this.groupMemberList, d, "groupList", "woGroupList"); }.bind(this)); this.loadListCount(); }.bind(this)); }.bind(this) }); selector.load(); }.bind(this)); }.bind(this)); }, _saveElement: function(data, success, failure){ this.explorer.actions.saveRole(data, function(json){ Object.merge(this.data, data); if (this.data.id){ this.data.id = json.data.id; this.item.refresh(); if (success) success(); }else{ this.explorer.actions.getRole(function(json){ this.data = json.data; this.item.refresh(); if (success) success(); }.bind(this), null, json.data.id); } }.bind(this), function(xhr, text, error){ if (failure) failure(xhr, text, error); }.bind(this)); } }); MWF.xApplication.Org.RoleExplorer.RoleContent.TitleInfor = new Class({ Extends: MWF.xApplication.Org.$Explorer.ItemContent.TitleInfor, _getStyle: function(){ var css = Object.clone(this.item.style.person); return Object.merge(css, this.item.style.role); }, _getIcon: function(){ return "../x_component_Org/$Explorer/default/icon/role70.png"; }, setBackground: function(){ this.titleBgNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/group_bg_bg.png)"); this.titleNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/group_bg.png)"); }, loadRightInfor: function(){ //var text = this.data.name+((this.data.unique) ? "("+this.data.unique+")" : ""); var text = this.data.name; if (!this.nameNode) this.nameNode = new Element("div", {"styles": this.style.titleInforNameNode}).inject(this.titleInforRightNode); if (!this.signatureNode) this.signatureNode = new Element("div", {"styles": this.style.titleInforSignatureNode}).inject(this.titleInforRightNode); this.nameNode.set("text", text); this.signatureNode.set("text", (this.data.distinguishedName || "" )); } }); MWF.xApplication.Org.RoleExplorer.RoleContent.BottomInfor = new Class({ Extends: MWF.xApplication.Org.$Explorer.ItemContent.BottomInfor, addInforList: function(){ var text = this.explorer.app.lp.roleReadDn.replace(/{dn}/g, (this.data.distinguishedName || " ")); this.addInfor(text); text = this.explorer.app.lp.roleReadCreate.replace(/{date}/g, (this.data.createTime || " ")); text = text.replace(/{date2}/g, (this.data.updateTime || " ")); this.addInfor(text); } }); MWF.xApplication.Org.RoleExplorer.RoleContent.BaseInfor = new Class({ initialize: function(content){ this.content = content; this.item = content.item; this.data = this.content.data; this.explorer = this.item.explorer; this.contentNode = this.content.baseContentNode; this.style = this.item.style.person; this.mode = "read"; this.load(); }, load: function(){ this.node = new Element("div", {"styles": this.style.baseContentNode}).inject(this.contentNode); this.editContentNode = new Element("div", {"styles": this.style.baseEditNode}).inject(this.node); this.editContentNode.set("html", this.getContentHtml()); this.editContentNode.getElement(".infor_name").set("text", this.data.name || ""); this.editContentNode.getElement(".infor_unique").set("text", this.data.unique || ""); this.editContentNode.getElement(".infor_description").set("text", this.data.description || ""); this.editContentNode.getElements("td.inforTitle").setStyles(this.style.baseInforTitleNode); this.editContentNode.getElements("td.inforContent").setStyles(this.style.baseInforContentNode); this.editContentNode.getElements("td.inforAction").setStyles(this.style.baseInforActionNode); this.loadAction(); }, getContentHtml: function(){ var html = ""+this.explorer.app.lp.roleName+": | " + " | "+this.explorer.app.lp.roleUnique+": | |
"+this.explorer.app.lp.roleDescription+": | "; html += " | ||