MWF.require("MWF.widget.O2Identity", null, false); MWF.xDesktop.requireApp("Org", "$Explorer", null, false); MWF.xDesktop.requireApp("Template", "MTooltips", null, false); MWF.xApplication.Org.UnitExplorer = new Class({ Extends: MWF.xApplication.Org.$Explorer, Implements: [Options, Events], options: { "style": "default", "lp": { }, "creator": false }, _loadLp: function(){ this.options.lp = { "search": this.app.lp.search, "searchText": this.app.lp.searchText, "elementSave": this.app.lp.organizationSave, "deleteElements": this.app.lp.deleteOrganization, "deleteElementsCancel": this.app.lp.deleteElementsCancel, "deleteElementsTitle": this.app.lp.deleteOrganizationTitle, "deleteElementsConfirm": this.app.lp.deleteOrganizationSubConfirm, "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 } }, loadElements: function(addToNext){ if (!this.isElementLoaded){ if (!this.loaddingElement){ this.loaddingElement = true; this._listElementNext(function(json){ if (json.data.length){ this.loadListContent(json.data); }else{ if (!this.elements.length){ this.setNoElementNoticeArea(); } } this.loadElementQueue = 0; this.isElementLoaded = true; this.loaddingElement = false; }.bind(this)); }else{ if (addToNext) this.loadElementQueue++; } } }, loadListContent: function(data){ data.each(function(itemData, i){ var item = this._newElement(itemData, this, i); this.elements.push(item); item.load(); if (this.elements.length===1){ item.selected(); if (!item.isExpand) item.expand(); } }.bind(this)); }, _listElementNext: function(callback){ if (MWF.AC.isOrganizationManager() || MWF.AC.isSecurityManager()){ this.actions.listTopUnit(function(json){ if (callback) callback.apply(this, [json]); }.bind(this)); }else{ if (layout.session.user.identityList.length){ var json = {"data": []}; var unitNames = []; layout.session.user.identityList.each(function(id){ var idFlag = (id.distinguishedName || id.id || id.unique || id.name); o2.Actions.get("x_organization_assemble_express").getUnitWithIdentityAndLevel({"identity": idFlag, "level": 1}, function(o){ if (o.data){ this.actions.getUnit(o.data.distinguishedName, function(u){ if (unitNames.indexOf(u.data.distinguishedName)==-1){ unitNames.push(u.data.distinguishedName); json.data.push(u.data); } }.bind(this),null, false); } }.bind(this), null, false); }.bind(this)); if (callback) callback.apply(this, [json]); } } }, _newElement: function(data, explorer){ return new MWF.xApplication.Org.UnitExplorer.Unit(data, explorer, this.isEditor, 0); }, _listElementByKey: function(callback, failure, key){ this.actions.listUnitByKey(function(json){ if (callback) callback.apply(this, [json]); }.bind(this), failure, key); }, _getAddElementData: function(){ return { "name": "", "unique": "", "typeList": ["company"], "description": "", "shortName": "", "superior": "", "orderNumber": "", "controllerList": [], "control": { "allowEdit": true, "allowDelete": true }, "woSubDirectIdentityList": [], "woUnitAttributeList": [], "woUnitDutyList": [] }; }, deleteSelectedElements: function(e){ var _self = this; this.app.confirm("infor", e, this.options.lp.deleteElementsTitle, {"html": this.options.lp.deleteElementsConfirm}, 500, 260, function(){ var deleted = []; var doCount = 0; var readyCount = _self.deleteElements.length; var errorText = ""; var complete; complete = function () { if (doCount === readyCount) { if (errorText) { _self.app.notice(errorText, "error", _self.propertyContentNode, {x: "left", y: "top"}); } } }; _self.deleteElements.each(function(element){ element["delete"](function(){ deleted.push(element); doCount++; if (_self.deleteElements.length===doCount){ _self.deleteElements = _self.deleteElements.filter(function (item) { return !deleted.contains(item); }); _self.checkDeleteElements(); } complete(); }, function(error){ errorText = (errorText) ? errorText+"

"+error : error; doCount++; if (_self.deleteElements.length !== doCount) { } else { _self.deleteElements = _self.deleteElements.filter(function (item) { return !deleted.contains(item); }); _self.checkDeleteElements(); } complete(); }); }); this.close(); }, function(){ this.close(); }); } }); MWF.xApplication.Org.UnitExplorer.Unit = new Class({ Extends: MWF.xApplication.Org.$Explorer.Item, initialize: function(data, explorer, isEditor, i, listNode, parent){ this.i = i; this.level = i; this.parent = parent; this.data = data; this.explorer = explorer; this.listNode = listNode || this.explorer.listNode; this.propertyContentNode = this.explorer.propertyContentNode; this.initStyle(); this.selectedAttributes = []; this.isEdit = false; this.isEditor = isEditor; this.deleteSelected = false; this.subUnits = []; }, refresh: function(){ this._loadTextNode(); if (this.content){ if (this.content.titleInfor) this.content.titleInfor.refresh(); if (this.content.bottomInfor) this.content.bottomInfor.refresh(); } this.addActions(); }, initStyle: function(){ var css = Object.clone(this.explorer.css.item); this.style = Object.merge(css, this.explorer.css.unitItem); }, _loadTextNode: function(){ this.textNode.set({"text": this.data.name+((this.data.subDirectUnitCount) ? " ("+(this.data.subDirectUnitCount)+")" : "")}); }, load: function(){ this.node = new Element("div", {"styles": this.style.node}).inject(this.listNode); this.contentNode = new Element("div", {"styles": this.style.contentNode}).inject(this.node); var left = (10*this.level); this.contentNode.setStyle("padding-left", ""+left+"px"); if ((this.level%2)===1){ this.node.setStyle("background-color", "#ffffff"); this.contentNode.setStyle("background-color", "#ffffff"); } this.childNode = new Element("div", {"styles": this.style.childNode}).inject(this.node); this.toggleIconNode = new Element("div", {"styles": this.style.unitToggleIconNode}).inject(this.contentNode); this.setToggleIconNode(); this.setToggleAction(); this.iconNode = new Element("div", {"styles": this.style.unitIconNode}).inject(this.contentNode); var src = this._getIcon(); this.iconNode.setStyle("background-image", "url("+src+")"); this.actionNode = new Element("div", {"styles": this.style.actionNode}).inject(this.contentNode); this.textNode = new Element("div", {"styles": this.style.unitTextNode}).inject(this.contentNode); this._loadTextNode(); this.setNewItem(); this.node.inject(this.listNode); this.addActions(); this.setEvent(); }, addActions: function(){ //if (this.isEditor){ if (this.data.id){ 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.data.control.allowEdit){ if (!this.addNode){ this.addNode = new Element("div.o2icon-add", {"styles": this.style.actionAddNode}).inject(this.actionNode); this.addNode.addEvent("click", function(e){ if (!this.notDelete){ this.addSubUnit(); } e.stopPropagation(); }.bind(this)); } } if (this.explorer.currentItem===this){ if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected); if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected); } } // } }, addSubUnit: function(){ this.expand(function(){ var isNewElement = true; if (this.explorer.currentItem) isNewElement = this.explorer.currentItem.unSelected(); if (isNewElement){ var newElementData = this.explorer._getAddElementData(); newElementData.superior = this.data.id; var item = new MWF.xApplication.Org.UnitExplorer.Unit(newElementData, this.explorer, this.isEditor, this.level+1, this.childNode, this); item.load(); item.selected(); item.editBaseInfor(); (new Fx.Scroll(this.explorer.listScrollNode)).toElementCenter(item.node); }else{ this.app.notice(this.explorer.options.lp.elementSave, "error", this.explorer.propertyContentNode); } }.bind(this)); }, setDeleteFromP: function(){ this.notDelete = true; this.subUnits.each(function(unit){ unit.setDeleteFromP(); }); this.deleteNode.setStyles(this.style.actionDeleteNode_delete); this.contentNode.setStyles(this.style.contentNode_delete); this.textNode.setStyles(this.style.unitTextNode); //this.explorer.deleteElements.push(this); this.deleteSelected = true; this.explorer.checkDeleteElements(this); }, setDelete: function(){ //this.actionNode.fade("in"); this.subUnits.each(function(unit){ unit.setDeleteFromP(); }); this.deleteNode.setStyles(this.style.actionDeleteNode_delete); if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_delete); this.contentNode.setStyles(this.style.contentNode_delete); this.contentNode.removeClass("mainColor_bg"); this.textNode.setStyles(this.style.unitTextNode); this.explorer.deleteElements.push(this); this.deleteSelected = true; this.deleteNode.removeClass("o2icon-delete").addClass("o2icon-off"); this.explorer.checkDeleteElements(this); }, setUndelete: function(){ //this.actionNode.fade("out"); this.notDelete = false; this.subUnits.each(function(unit){ unit.setUndelete(); }); if (this.explorer.currentItem!==this){ if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode); if (this.addNode) this.addNode.setStyles(this.style.actionAddNode); this.contentNode.setStyles(this.style.contentNode); this.contentNode.removeClass("mainColor_bg"); this.textNode.setStyles(this.style.unitTextNode); }else{ this.contentNode.setStyles(this.style.contentNode_selected); this.contentNode.addClass("mainColor_bg"); this.textNode.setStyles(this.style.textNode_selected); this.actionNode.setStyles(this.style.actionNode_selected); if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected); if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected); if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected); } this.deleteNode.removeClass("o2icon-off").addClass("o2icon-delete"); this.explorer.deleteElements.erase(this); this.deleteSelected = false; this.explorer.checkDeleteElements(this); }, setToggleIconNode: function(){ if (this.data.subDirectUnitCount>0){ var toggle_on = (this.explorer.currentItem===this) ? "toggle_current_on" : "toggle_on"; var toggle_off = (this.explorer.currentItem===this) ? "toggle_current_off" : "toggle_off"; if (this.isExpand){ this.toggleIconNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/"+toggle_on+".png)"); }else{ this.toggleIconNode.setStyle("background-image", "url(../x_component_Org/$Explorer/"+this.explorer.app.options.style+"/icon/"+toggle_off+".png)"); } }else{ this.toggleIconNode.setStyle("background-image", ""); } }, setToggleAction: function(){ this.toggleIconNode.addEvent("click", function(e){ this.expandOrCollapse(); e.stopPropagation(); }.bind(this)); }, expandOrCollapse: function(){ if (this.isExpand){ this.collapse(); }else{ this.expand(); } }, listSubUnit: function(callback){ this.node.mask(); this.explorer.actions.listSubUnitDirect(function(json){ if (json.data.length){ json.data.each(function(itemData){ var item = new MWF.xApplication.Org.UnitExplorer.Unit(itemData, this.explorer, this.isEditor, this.level+1, this.childNode, this); this.explorer.elements.push(item); item.load(); this.subUnits.push(item); }.bind(this)); } this.isLoadSub = true; this.node.unmask(); if (callback) callback(); }.bind(this), null, this.data.id); }, expand: function(callback){ this.childNode.setStyle("display", "block"); this.isExpand = true; this.setToggleIconNode(); if (!this.isLoadSub){ this.listSubUnit(callback); }else{ if (callback) callback(); } }, collapse: function(){ this.childNode.setStyle("display", "none"); this.isExpand = false; this.setToggleIconNode(); }, unSelected: function(){ if (this.content.baseInfor.mode==="edit") return false; this.explorer.currentItem = null; this.contentNode.setStyles(this.style.contentNode); this.textNode.setStyles(this.style.unitTextNode); this.actionNode.setStyles(this.style.actionNode); if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode); if (this.addNode) this.addNode.setStyles(this.style.actionAddNode); if (this.deleteNode)this.deleteNode.removeClass("mainColor_color"); if (this.addNode)this.addNode.removeClass("mainColor_color"); this.iconNode.setStyle("background-image", "url("+this._getIcon()+")"); this.contentNode.removeClass("mainColor_bg"); this.contentNode.removeClass("mainColor_bg_opacity"); this.setToggleIconNode(); this.clearItemProperty(); return true; }, selected: function(){ this.explorer.currentItem = this; this.contentNode.setStyles(this.style.contentNode_selected); this.textNode.setStyles(this.style.textNode_selected); this.actionNode.setStyles(this.style.actionNode_selected); if (this.deleteNode) this.deleteNode.setStyles(this.style.actionDeleteNode_selected); if (this.addNode) this.addNode.setStyles(this.style.actionAddNode_selected); if (this.deleteNode)this.deleteNode.removeClass("mainColor_color"); if (this.addNode)this.addNode.removeClass("mainColor_color"); this.iconNode.setStyle("background-image", "url("+this._getIcon()+")"); this.contentNode.addClass("mainColor_bg"); this.contentNode.removeClass("mainColor_bg_opacity"); this.setToggleIconNode(); this.showItemProperty(); }, showItemProperty: function(){ this.content = new MWF.xApplication.Org.UnitExplorer.UnitContent(this); }, "delete": function(success, failure){ this.explorer.actions.deleteUnit(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 (this.explorer.currentItem===this) ? "../x_component_Org/$Explorer/default/icon/unit_current.png" : "../x_component_Org/$Explorer/default/icon/unit.png"; }, _isActionManager: function(){ return (MWF.AC.isOrganizationManager() || MWF.AC.isUnitManager()); } }); MWF.xApplication.Org.UnitExplorer.UnitContent = new Class({ Extends: MWF.xApplication.Org.$Explorer.ItemContent, _getData: function(callback){ if (this.item.data.id){ this.explorer.actions.getUnit(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.UnitExplorer.UnitContent.TitleInfor(this); }, _showItemPropertyBottom: function(){ this.bottomInfor = new MWF.xApplication.Org.UnitExplorer.UnitContent.BottomInfor(this); }, loadItemPropertyTab: function(callback){ this.propertyTabContainerNode = new Element("div", {"styles": this.item.style.tabTitleNode}).inject(this.propertyContentNode, "top"); MWF.require("MWF.widget.Tab", function(){ this.propertyTab = new MWF.widget.Tab(this.propertyContentNode, {"style": "unit", "useMainColor":true}); this.propertyTab.load(); this.propertyTab.tabNodeContainer.inject(this.propertyTabContainerNode); if (callback) callback(); }.bind(this)); }, _loadTabs: function(){ this.baseContentNode = new Element("div", {"styles": this.item.style.tabContentNode}); this.basePage = this.propertyTab.addTab(this.baseContentNode, this.explorer.app.lp.unitBaseText); this.personMemberContentNode = new Element("div", {"styles": this.item.style.tabContentNode}); this.personMemberPage = this.propertyTab.addTab(this.personMemberContentNode, this.explorer.app.lp.unitPersonMembers); this.dutyContentNode = new Element("div", {"styles": this.item.style.tabContentNode}); this.dutyPage = this.propertyTab.addTab(this.dutyContentNode, this.explorer.app.lp.unitDutys); if (this.data.control.allowEdit){ this.attributeContentNode = new Element("div", {"styles": this.item.style.tabContentNode}); this.attributePage = this.propertyTab.addTab(this.attributeContentNode, this.explorer.app.lp.unitAttribute); } }, _loadContent: function(){ this._listBaseInfor(); this.loadListCount(); this._listIdentityMembers(); this._listDutys(); if (this.data.control.allowEdit) this._listAttributes(); //var _self = this; // this.personMemberList = this._listMembers("personList", "woSubDirectIdentityList", this.personMemberContentNode, [{ // "get": function(){ // var src = _self.explorer.actions.getPersonIcon(this.person); // return "
"; // }, // "set": function(){} // }, "name", "employee", "mobile", "mail"], [ // {"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} // ], this.addPersonMember.bind(this), "personCountNode"); // // this.groupMemberList = this._listMembers("groupList", "woGroupList", this.groupMemberContentNode, ["name", "distinguishedName", "description"], [ // {"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} // ], this.addGroupMember.bind(this), "groupCountNode"); }, loadListCount: function(){ var identityCount = this.data.woSubDirectIdentityList.length; if (identityCount){ if (this.identityCountNode){ this.identityCountNode.set("text", identityCount); }else{ this.identityCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": identityCount}).inject(this.personMemberPage.tabNode); } }else{ if (this.identityCountNode) this.identityCountNode.destroy(); } var dutyCount = this.data.woUnitDutyList.length; if (dutyCount){ if (this.dutyCountNode){ this.dutyCountNode.set("text", dutyCount); }else{ this.dutyCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": dutyCount}).inject(this.dutyPage.tabNode); } }else{ if (this.dutyCountNode) this.dutyCountNode.destroy(); } if (this.data.control.allowEdit){ var attributeCount = this.data.woUnitAttributeList.length; if (attributeCount){ if (this.attributeCountNode){ this.attributeCountNode.set("text", attributeCount); }else{ this.attributeCountNode = new Element("div", {"styles": this.item.style.tabCountNode, "text": attributeCount}).inject(this.attributePage.tabNode); } }else{ if (this.attributeCountNode) this.attributeCountNode.destroy(); } } }, _listBaseInfor: function(){ this.baseInfor = new MWF.xApplication.Org.UnitExplorer.UnitContent.BaseInfor(this); }, getDutyActionPermission: function(){ if( MWF.AC.isManager() )return true; if( MWF.AC.isSecurityManager() )return true; if( MWF.AC.isSystemManager() )return false; return this.data.control.allowEdit; }, _listDutys: function(){ var _self = this; this.dutyList = new MWF.xApplication.Org.List(this.dutyContentNode, this, { "action": _self.getDutyActionPermission(), "saveAction": "saveUnitduty", "deleteAction": "deleteUnitduty", "data": { "description":"", "name": "", "unique": "", "unit": this.data.id, "orderNumber": "", "identityList": [], "woIdentityList": [] }, "attr": ["name", "description", { "get": function(){ //var html = ""; // this.woIdentityList.each(function(identity){ // html+="
"+identity.name+"
" // }.bind(this)); return ""; }, "events": { "init": function(){ //var divs = this.td.getElements("div"); var contentNode = this.td; if (this.item.list.options.action){ var actionDiv = new Element("div", {"styles": _self.item.style.dutyIdentityAction}).inject(this.td); contentNode = new Element("div", {"styles": _self.item.style.dutyIdentityContent}).inject(this.td); actionDiv.addEvent("click", function(){ _self.editDutyIdentity(this.data, contentNode); }.bind(this)); } var _dutyData = this.data; this.data.woIdentityList.each(function(identity, i){ new MWF.widget.O2Identity(identity, contentNode, { "lazy" : true, "canRemove": _self.data.control.allowEdit, "onRemove": function(O2Identity, e){ _self.deleteDutyIdentity(_dutyData, e, O2Identity); } }) }.bind(this)); }, "click": function(){ //_self.explorer.openGroup(this.data, this.td); } } }], "onPostSave": function(item, id){ if (!item.data.id){ item.data.id = id; this.data.woUnitDutyList.push(item.data); } this.loadListCount(); }.bind(this), "onPostDelete": function(delCount){ if (this.dutyCountNode){ var count = this.dutyCountNode.get("text").toInt()-delCount; this.dutyCountNode.set("text", count); } }.bind(this), }); //this.dutyList.addItem = function(){this.addDuty();}; this.dutyList.load([ {"style": "width: 20%", "text": this.explorer.app.lp.dutyName}, {"style": "", "text": this.explorer.app.lp.description}, {"style": "width: 50%", "text": this.explorer.app.lp.dutyMembers} ]); this.data.woUnitDutyList.each(function(item){ //this.attributes.push(new MWF.xApplication.Org.PersonExplorer.PersonAttribute(this.attributeTabContentNode.getElement("table").getFirst(), item, this, this.explorer.css.list)); this.dutyList.push(item); }.bind(this)); }, editDutyIdentity: function(dutyData, contentNode){ var _self = this; MWF.xDesktop.requireApp("Selector", "Identity", function(){ var selector = new MWF.xApplication.Selector.Identity(this.explorer.app.content,{ "values": dutyData.identityList, "onComplete": function(items){ var woIdentityList = []; var identityList = []; var dData = Object.clone(dutyData); items.each(function(item, i){ woIdentityList.push(item.data); identityList.push(item.data.id); }.bind(this)); dData.identityList = identityList; dData.woIdentityList = woIdentityList; _self.saveDuty(dData, function () { contentNode.empty(); items.each(function(item, i){ new MWF.widget.O2Identity(item.data, contentNode, { "canRemove": true, "onRemove": function(O2Identity, e){ _self.deleteDutyIdentity(dutyData, e, O2Identity); } }) }.bind(this)); dutyData.identityList = identityList; dutyData.woIdentityList = woIdentityList; }.bind(this)); }.bind(this) }); selector.load(); }.bind(this)); }, deleteDutyIdentity: function(dutyData, e, O2Identity){ var _self = this; var text = this.explorer.app.lp.deleteDutyIdentity.replace(/{duty}/g, dutyData.name); text = text.replace(/{identity}/g, O2Identity.data.name); this.explorer.app.confirm("warn", e, this.explorer.app.lp.deleteDutyIdentityTitle, text, "360", "170", function(){ dutyData.identityList.erase(O2Identity.data.id); dutyData.woIdentityList = dutyData.woIdentityList.filter(function(a){ return (O2Identity.data.id !== a.id); }); _self.saveDuty(dutyData, function(){ O2Identity.destroy(); }); this.close(); }, function(){ this.close(); }); }, saveDuty: function(data, callback){ this.propertyContentScrollNode.mask({ "style": { "opacity": 0.7, "background-color": "#999" } }); this.explorer.actions.saveUnitduty(data, function(){ this.propertyContentScrollNode.unmask(); if (callback) callback(); }.bind(this), function(xhr, text, error){ var errorText = error; if (xhr) errorText = xhr.responseText; this.explorer.app.notice("request json error: "+errorText, "error"); this.propertyContentScrollNode.unmask(); }.bind(this)); }, _listAttributes: function(){ this.attributeList = new MWF.xApplication.Org.List(this.attributeContentNode, this, { "action": this.data.control.allowEdit, "saveAction": "saveUnitattribute", "deleteAction": "deleteUnitattribute", "data": { "description":"", "name": "", "unique": "", "unit": this.data.id, "orderNumber": "", "attributeList": [] }, "attr": ["name", { "get": function(){return this.attributeList.join(",")}, "set": function(value){this.attributeList = value.split(/,\s*/g)} }, "description"], "onPostSave": function(item, id){ if (!item.data.id){ item.data.id = id; this.data.woUnitAttributeList.push(item.data); } this.loadListCount(); }.bind(this), "onPostDelete": function(delCount){ if (this.attributeCountNode){ var count = this.attributeCountNode.get("text").toInt()-delCount; this.attributeCountNode.set("text", count); } }.bind(this), }); this.attributeList.load([ {"style": "width: 20%", "text": this.explorer.app.lp.attributeName}, {"style": "width: 45%", "text": this.explorer.app.lp.attributeValue}, {"style": "", "text": this.explorer.app.lp.description} ]); this.data.woUnitAttributeList.each(function(item){ //this.attributes.push(new MWF.xApplication.Org.PersonExplorer.PersonAttribute(this.attributeTabContentNode.getElement("table").getFirst(), item, this, this.explorer.css.list)); this.attributeList.push(item); }.bind(this)); }, getIdentityActionPermission: function(){ if( MWF.AC.isManager() )return true; if( MWF.AC.isSecurityManager() )return true; if( MWF.AC.isSystemManager() )return false; return this.data.control.allowEdit; }, getIdentitySortActionPermission: function(){ if( MWF.AC.isManager() )return true; if( MWF.AC.isSecurityManager() )return false; if( MWF.AC.isSystemManager() )return false; return this.data.control.allowEdit; }, _listIdentityMembers: function(){ var _self = this; if(this.identityMemberList){ this.identityMemberList.clear(); } this.personMemberContentNode.empty(); this.identityMemberList = new MWF.xApplication.Org.List(this.personMemberContentNode, this, { "action": _self.getIdentityActionPermission(), "canEdit": false, "deleteAction": "deleteIdentity", "deleteItemTitle": this.explorer.app.lp.deleteIdentityMemeberTitle, "deleteItemText": this.explorer.app.lp.deleteIdentityMemeber, "data": {}, "attr": [{ "getHtml": function(){ var src = _self.explorer.actions.getPersonIcon(this.woPerson.id); return "
"; }, "set": function(){} }, { "get": function(){return this.woPerson.name} }, { "get": function(){return this.woPerson.employee} }, { "get": function(){return this.woPerson.mobile} }, { "get": function(){return this.woPerson.mail} }, { "getHtml": function(){ return "
"; }, "events": { "click": function(){ _self.explorer.openPerson(this.data.woPerson, this.td); } } }, { "getHtml": function(){ if(_self.getIdentityActionPermission()){ return "
"; }else{ return "
" } }, "events": { "selectstart": function(e){e.stopPropagation(); e.preventDefault();return false;}, "touchstart": function(e){if(_self.getIdentityActionPermission())_self.startOrder(this.item, this.td, e)}, "mousedown": function(e){if(_self.getIdentityActionPermission())_self.startOrder(this.item, this.td, e)} } }], "onPostDelete": function(delCount){ if (this.identityCountNode){ var count = this.identityCountNode.get("text").toInt()-delCount; this.identityCountNode.set("text", count); } }.bind(this), "onPostLoadAction": function () { debugger; if( _self.getIdentitySortActionPermission() ){ this.sortAction = new Element("div", {"styles": this.css.sortActionNode, "text": _self.explorer.app.lp.sortByPinYin}).inject(this.actionNode); this.sortAction.addEvent("click", function (e) { _self.sortByPinYin(e) }) this.sortByManualAction = new Element("div", {"styles": this.css.sortActionNode, "text": _self.explorer.app.lp.sortByManual}).inject(this.actionNode); this.sortByManualAction.addEvent("click", function (e) { _self.sortByManual(e) }) } } }); this.identityMemberList.addItem = this.addPersonMember.bind(this); this.identityMemberList.load([ {"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: 100px", "text": ""}, {"style": "width: 100px", "text": ""} ]); this.data.woSubDirectIdentityList.each(function(id){ var item = this.identityMemberList.push(id); }.bind(this)); }, sortByManual: function(){ var _self = this; if(this.identityMemberList)this.identityMemberList.clear(); this.identityMemberList = null; this.personMemberContentNode.empty(); this.identitySortList = new MWF.xApplication.Org.List(this.personMemberContentNode, this, { "action": false, "canEdit": false, "attr": [{ "getHtml": function(){ var src = _self.explorer.actions.getPersonIcon(this.woPerson.id); return "
"; }, "set": function(){} }, { "get": function(){return this.woPerson.name} }, { "get": function(){return this.woPerson.employee} }, { "get": function(){return this.woPerson.mobile} }, { "get": function(){return this.woPerson.mail} }, { "getHtml": function(){ return ""; } }] }); this.identitySortList.loadAction = function(){ this.actionAreaNode = new Element("div", {"styles": this.css.actionAreaNode}).inject(this.contentNode, "top"); this.actionNode = new Element("div", {"styles": this.css.actionNode}).inject(this.actionAreaNode); this.sortCancelAction = new Element("div", {"styles": this.css.cancelActionNode, "text": _self.explorer.app.lp.cancel}).inject(this.actionNode); this.sortCancelAction.addEvent("click", function (e) { _self._listIdentityMembers(e) }) this.sortOkAction = new Element("div", {"styles": this.css.okActionNode, "text": _self.explorer.app.lp.ok}).inject(this.actionNode); this.sortOkAction.addEvent("click", function (e) { var pList = []; _self.identitySortList.items.each(function(item){ item.data.orderNumber = item.tr.tr.getElement(".orderNumber").get("value").toInt(); var p = o2.Actions.load("x_organization_assemble_control").IdentityAction.edit(item.data.id, item.data); pList.push(p); }) Promise.all(pList).then(function () { _self.data.woSubDirectIdentityList.sort(function(a, b){ return a.orderNumber - b.orderNumber; }) _self._listIdentityMembers(e) }) }) }; this.identitySortList.load([ {"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": "", "text": this.explorer.app.lp.orderNumber} ]); this.data.woSubDirectIdentityList.each(function(id){ var item = this.identitySortList.push(id); }.bind(this)); }, sortByPinYin : function(e){ var _self = this; this.explorer.app.confirm("infor", e, this.explorer.app.lp.sortByPinYin, {"html": this.explorer.app.lp.sortByPinYinConfirmContent}, 300, 180, function(){ debugger; var list = _self.data.woSubDirectIdentityList; list.sort( function(a, b){ return a.name.localeCompare(b.name); }); for( var i=0; i"; if (this.data.control.allowEdit || o2.AC.isSecurityManager()) html += ""+this.explorer.app.lp.unitUnique+":"; html += ""+this.explorer.app.lp.unitTypeList+":" + ""+this.explorer.app.lp.unitShortName+":"; // html += ""+this.explorer.app.lp.unitLevel+":"+this.data.level+"" + // ""+this.explorer.app.lp.unitLevelName+":"+(this.data.levelName || "")+""; html += ""+this.explorer.app.lp.unitDescription+":"; if (this.data.control.allowEdit || o2.AC.isSecurityManager()){ html += ""+this.explorer.app.lp.unitControllerList+":" + ""+this.explorer.app.lp.unitSuperUnit+":"; html += ""+this.explorer.app.lp.orderNumber+":"; } html += ""; //this.baseInforRightNode.set("html", html); return html; }, loadAction: function(){ //this.explorer.app.lp.edit var actionAreas = this.editContentNode.getElements("td"); var actionArea = actionAreas[actionAreas.length-1]; if (this.data.control.allowEdit){ this.baseInforEditActionAreaNode = new Element("div", {"styles": this.style.baseInforEditActionAreaNode}).inject(actionArea); this.editNode = new Element("div", {"styles": this.style.actionEditNode, "text": this.explorer.app.lp.editUnit}).inject(this.baseInforEditActionAreaNode); this.saveNode = new Element("div", {"styles": this.style.actionSaveNode, "text": this.explorer.app.lp.saveUnit}).inject(this.baseInforEditActionAreaNode); this.saveNode.addClass("mainColor_bg"); this.cancelNode = new Element("div", {"styles": this.style.actionCancelNode, "text": this.explorer.app.lp.cancel}).inject(this.baseInforEditActionAreaNode); this.editNode.setStyle("display", "block"); this.editNode.addEvent("click", this.edit.bind(this)); this.saveNode.addEvent("click", this.save.bind(this)); this.cancelNode.addEvent("click", this.cancel.bind(this)); }else{ } }, edit: function(){ var tdContents = this.editContentNode.getElements("td.inforContent"); tdContents[0].setStyles(this.style.baseInforContentNode_edit).empty(); this.nameInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[0]); this.nameInputNode.set("value", (this.data.name)); tdContents[1].setStyles(this.style.baseInforContentNode_edit).empty(); this.uniqueInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[1]); this.uniqueInputNode.set("value", (this.data.unique)); if( this.data.id ){ this.tooltip = new MWF.xApplication.Org.UnitExplorer.UnitContent.UniqueTooltip(this.explorer.app.content, tdContents[1], this.explorer.app, {}, { axis : "y", position : { x : "right" }, hiddenDelay : 300, displayDelay : 300 }); } tdContents[2].setStyles(this.style.baseInforContentNode_edit).empty(); this.typeListInputNode = new Element("input", {"styles": this.style.inputNode_type}).inject(tdContents[2]); this.typeListInputNode.set("value", ((this.data.typeList.length) ? this.data.typeList.join(", "): "")); this.loadUnitTypeSelect(); tdContents[3].setStyles(this.style.baseInforContentNode_edit).empty(); this.shortNameInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[3]); this.shortNameInputNode.set("value", (this.data.shortName || "")); tdContents[4].setStyles(this.style.baseInforContentNode_edit).empty(); this.descriptionInputNode = new Element("input", {"styles": this.style.inputNode}).inject(tdContents[4]); this.descriptionInputNode.set("value", (this.data.description || "")); tdContents[5].setStyles(this.style.baseInforContentNode_edit).empty(); this.controllerListInputNode = new Element("div", {"styles": this.style.inputNode_person}).inject(tdContents[5]); tdContents[6].setStyles(this.style.baseInforContentNode_edit).empty(); this.superUnitInputNode = new Element("div", {"styles": this.style.inputNode_person}).inject(tdContents[6]); tdContents[7].setStyles(this.style.baseInforContentNode_edit).empty(); this.orderNumberInputNode = new Element("input", {"styles": this.style.inputNode, "type":"number"}).inject(tdContents[7]); this.orderNumberInputNode.set("value", (this.data.orderNumber || "")); //this.controllerListInputNode.set("value", ((this.data.controllerList) ? this.data.controllerList.join(", ") : "")); if (this.data.superior) new MWF.widget.O2Unit({"name": this.data.superior}, this.superUnitInputNode, {"style": "xform"}); this.superUnitInputNode.addEvent("click", function(){ MWF.xDesktop.requireApp("Selector", "package", function(){ var options = { "type": "unit", "values": [this.data.superior] || [], "count": 1, "onComplete": function(items){ this.superUnitInputNode.empty(); this.data.oldSuperior = this.data.superior; if (items.length){ this.data.superior = items[0].data.id; new MWF.widget.O2Unit({"name": this.data.superior}, this.superUnitInputNode, {"style": "xform"}) }else{ this.data.superior = ""; } }.bind(this) }; var selector = new MWF.O2Selector(this.explorer.app.content, options); }.bind(this)); }.bind(this)); if (this.data.controllerList){ this.data.controllerList.each(function(id){ new MWF.widget.O2Person({"name": id}, this.controllerListInputNode, {"style": "xform"}); }.bind(this)); } this.controllerListInputNode.addEvent("click", function(){ MWF.xDesktop.requireApp("Selector", "package", function(){ var options = { "type": "person", "values": this.data.controllerList || [], "count": 0, "onComplete": function(items){ this.data.oldControllerList = this.data.controllerList; var controllerList = []; this.controllerListInputNode.empty(); items.each(function(item){ controllerList.push(item.data.id); new MWF.widget.O2Person(item.data, this.controllerListInputNode, {"style": "xform"}); }.bind(this)); this.data.controllerList = controllerList; }.bind(this) }; var selector = new MWF.O2Selector(this.explorer.app.content, options); }.bind(this)); }.bind(this)); var _self = this; this.editContentNode.getElements("input").addEvents({ "focus": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_focus);}}, "blur": function(){if (this.get("type").toLowerCase()==="text"){this.setStyles(_self.style.inputNode_blur);}} }); this.mode = "edit"; this.editNode.setStyle("display", "none"); this.saveNode.setStyle("display", "block"); this.cancelNode.setStyle("display", "block"); }, loadUnitTypeSelect: function(){ if (this.typeListInputNode){ this.typeListInputNode.addEvents({ "blur": function(){this.hideTypeSelectNode();}.bind(this), "click": function(){this.showTypeSelectNode();}.bind(this), "focus": function(){this.showTypeSelectNode();}.bind(this) }); } }, hideTypeSelectNode: function(){ if (this.typeSelectNode) this.typeSelectNode.destroy(); this.typeSelectNode = null; }, showTypeSelectNode: function(){ if (!this.typeSelectNode){ this.typeSelectNode = new Element("div", {"styles": this.style.typeSelectNode}).inject(this.typeListInputNode, "after"); var size = this.typeListInputNode.getSize(); var width = size.x-3; this.typeSelectNode.setStyle("width", ""+width+"px"); this.typeSelectNode.position({ "relativeTo": this.typeListInputNode, "position": 'bottomLeft', "edge": 'upperLeft', "offset": {"x": 1, "y": -3} }); this.explorer.actions.listUnitType(function(json){ var count = json.data.valueList.length; var height = (count*30); this.typeSelectNode.setStyle("height", ""+height+"px"); json.data.valueList.each(function(t, i){ this.createTypeSelectItem(t, i); }.bind(this)); }.bind(this)); } }, createTypeSelectItem: function(text, i){ var typeSelectItemNode = new Element("div", {"styles": this.style.typeSelectItemNode}).inject(this.typeSelectNode); if ((i % 2)===0) typeSelectItemNode.setStyle("background", "#f4f9ff"); var iconNode = new Element("div", {"styles": this.style.typeSelectItemIconNode}).inject(typeSelectItemNode); var textNode = new Element("div", {"styles": this.style.typeSelectItemTextNode}).inject(typeSelectItemNode); textNode.set("text", text); var _self = this; typeSelectItemNode.addEvents({ "mouseover": function(){this.setStyle("background-color", "#fef5e7");}, "mouseout": function(){this.setStyle("background", "#ffffff"); if ((i % 2)===0) this.setStyle("background", "#f4f9ff");}, "mousedown": function(){ _self.typeListInputNode.set("value", this.get("text")); } }); }, save: function(){ var tdContents = this.editContentNode.getElements("td.inforContent"); if (!this.nameInputNode.get("value") || !this.uniqueInputNode.get("value")){ this.explorer.app.notice(this.explorer.app.lp.inputUnitInfor, "error", this.explorer.propertyContentNode); return false; } //this.data.genderType = gender; //if (!this.uniqueInputNode.get("value")) this.data.unique = this.employeeInputNode.get("value"); this.content.propertyContentScrollNode.mask({ "style": { "opacity": 0.7, "background-color": "#999" } }); this.saveUnit(function(){ this.cancel( null,true ); this.content.propertyContentScrollNode.unmask(); }.bind(this), function(xhr, text, error){ var errorText = error; if (xhr) errorText = xhr.responseText; this.explorer.app.notice("request json error: "+errorText, "error"); this.content.propertyContentScrollNode.unmask(); }.bind(this)); }, saveUnit: function(callback, cancel){ var data = Object.clone(this.data); data.name = this.nameInputNode.get("value"); data.unique = this.uniqueInputNode.get("value"); data.typeList = (this.typeListInputNode.get("value")) ? this.typeListInputNode.get("value").split(/,\s*/g) : []; data.shortName = this.shortNameInputNode.get("value"); data.description = this.descriptionInputNode.get("value"); data.orderNumber = this.orderNumberInputNode.get("value"); delete data.oldSuperior; delete data.oldControllerList; //data.controllerList = (this.controllerListInputNode.get("value")) ? this.controllerListInputNode.get("value").split(/,\s*/g) : []; this.explorer.actions.saveUnit(data, function(json){ Object.merge(this.data, data); if (this.data.id){ this.data.id = json.data.id; this.item.refresh(); if (callback) callback(); }else{ this.explorer.actions.getUnit(function(json){ this.data = Object.merge(this.data, json.data); this.item.data = this.data; this.item.refresh(); if (this.item.parent) this.item.parent.subUnits.push(this.item); if (callback) callback(); }.bind(this), null, json.data.id); } }.bind(this), function(xhr, text, error){ if (cancel) cancel(xhr, text, error); }.bind(this)); }, cancel: function( ev, flag ){ if (this.data.id){ var tdContents = this.editContentNode.getElements("td.inforContent"); tdContents[0].setStyles(this.style.baseInforContentNode).set("text", this.data.name || ""); tdContents[1].setStyles(this.style.baseInforContentNode).set("text", this.data.unique || ""); tdContents[2].setStyles(this.style.baseInforContentNode).set("text", ((this.data.typeList.length) ? this.data.typeList.join(", "): "")); tdContents[3].setStyles(this.style.baseInforContentNode).set("text", this.data.shortName || ""); tdContents[4].setStyles(this.style.baseInforContentNode).set("text", this.data.description || ""); //tdContents[5].setStyles(this.style.baseInforContentNode).set("text", ((this.data.controllerList.length) ? this.data.controllerList.join(", "): "")); tdContents[5].setStyles(this.style.baseInforContentNode).empty(); tdContents[6].setStyles(this.style.baseInforContentNode).empty(); tdContents[7].setStyles(this.style.baseInforContentNode).set("text", this.data.orderNumber || ""); if( !flag ){ if (this.data.oldSuperior) this.data.superior = this.data.oldSuperior; if (this.data.oldControllerList) this.data.controllerList = this.data.oldControllerList; } delete this.data.oldSuperior; delete this.data.oldControllerList; if (this.data.superior) new MWF.widget.O2Unit({"name": this.data.superior}, tdContents[6], {"style": "xform"}); if (this.data.controllerList){ this.data.controllerList.each(function(id){ new MWF.widget.O2Person({"name": id}, tdContents[5], {"style": "xform"}); }.bind(this)); } this.mode = "read"; this.editNode.setStyle("display", "block"); this.saveNode.setStyle("display", "none"); this.cancelNode.setStyle("display", "none"); }else{ this.item.destroy(); } if( this.tooltip ){ this.tooltip.destroy(); this.tooltip = null; } }, destroy: function(){ if( this.tooltip ){ this.tooltip.destroy(); this.tooltip = null; } this.node.empty(); this.node.destroy(); MWF.release(this); } }); MWF.xApplication.Org.UnitExplorer.UnitContent.UniqueTooltip = new Class({ Extends: MTooltips, _getHtml : function(){ var html = "
"+ this.lp.unitUniqueModifyNote +"
"; return html; } });