MWF.xApplication.Selector = MWF.xApplication.Selector || {}; MWF.xDesktop.requireApp("Selector", "Person", null, false); MWF.xApplication.Selector.Identity = new Class({ Extends: MWF.xApplication.Selector.Person, options: { "style": "default", "count": 0, "title": MWF.xApplication.Selector.LP.selectIdentity, "units": [], "values": [], "dutys": [], "zIndex": 1000, "expand": false, "noUnit" : false, "include" : [], //增加的可选项 "exclude" : [], //排除的可选项 "resultType" : "", //可以设置成个人,那么结果返回个人 "expandSubEnable" : true, //是否允许展开下一层, "selectAllEnable" : true, //分类是否允许全选下一层 "selectType" : "identity" }, loadSelectItems: function(addToNext){ debugger; var afterLoadSelectItemFun = this.afterLoadSelectItem.bind(this); if( this.options.resultType === "person" ){ if( this.titleTextNode ){ this.titleTextNode.set("text", MWF.xApplication.Selector.LP.selectPerson ); }else{ this.options.title = MWF.xApplication.Selector.LP.selectPerson; } } if(this.options.noUnit){ this.loadInclude(afterLoadSelectItemFun); }else if (this.options.units.length){ var loadUnitSuccess = function () { this.unitLoaded = true; if( this.includeLoaded ){ afterLoadSelectItemFun(); } }.bind(this); var loadUnitFailure = loadUnitSuccess; this.loadInclude( function () { this.includeLoaded = true; if( this.unitLoaded ){ afterLoadSelectItemFun(); } }.bind(this)); var unitList = []; for( var i=0 ; i 0 ){ o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({"personList":keys}, function (json) { json.data.each( function ( p ){ if(object[ p.id ])object[ p.id ].data.woPerson = p; }.bind(this)); _selectAllFun(); }) }else{ _selectAllFun(); } }, clickItem: function( callback ){ if (this._hasChild() && !this.loading){ var firstLoaded = !this.loaded; this.loading = true; this.loadSub(function(){ this.loading = false; if( firstLoaded ){ if( !this.selector.isFlatCategory ){ this.children.setStyles({"display": "block", "height": "auto"}); this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand); this.isExpand = true; } // this.checkSelectAll(); }else{ var display = this.children.getStyle("display"); if (display === "none"){ this.children.setStyles({"display": "block", "height": "auto"}); this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_expand); this.isExpand = true; }else{ this.children.setStyles({"display": "none", "height": "0px"}); this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse); this.isExpand = false; } } if(callback)callback(); }.bind(this)); } }, loadSub: function(callback){ if (!this.loaded){ if (this.selector.options.dutys && this.selector.options.dutys.length){ var ids = []; var object = {}; this.selector.options.dutys.each(function(duty){ this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){ if (json.data && json.data.length){ ids = ids.concat(json.data); } }.bind(this), null, false); ids.each(function(idSubData){ if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) { var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this); this.selector.items.push(item); if(this.subItems)this.subItems.push( item ); object[ idSubData.id || idSubData.distinguishedName ] = true; } }.bind(this)); }.bind(this)); if( this.selector.options.expandSubEnable ){ this.selector.orgAction.listSubUnitDirect(function(json){ json.data.each(function(subData){ if( !this.selector.isExcluded( subData ) ) { var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this); this.subCategorys.push( category ); } }.bind(this)); this.loaded = true; if(callback)callback(); }.bind(this), null, this.data.distinguishedName); }else{ this.loaded = true; if(callback)callback(); } }else{ this.selector.orgAction.listIdentityWithUnit(function(idJson){ idJson.data.each(function(idSubData){ if( !this.selector.isExcluded( idSubData ) ) { var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this); this.selector.items.push(item); if(this.subItems)this.subItems.push( item ); } }.bind(this)); if( this.selector.options.expandSubEnable ){ this.selector.orgAction.listSubUnitDirect(function(json){ json.data.each(function(subData){ if( !this.selector.isExcluded( subData ) ) { var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this); this.subCategorys.push( category ); } }.bind(this)); this.loaded = true; if (callback) callback(); }.bind(this), null, this.data.distinguishedName); }else{ this.loaded = true; if (callback) callback(); } }.bind(this), null, this.data.distinguishedName); } }else{ if (callback) callback( ); } }, _hasChild: function(){ var uCount = (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0; var iCount = (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0; return uCount + iCount; }, _hasChildCategory: function(){ return (this.data.subDirectUnitCount) ? this.data.subDirectUnitCount : 0; }, _hasChildItem: function(){ return (this.data.subDirectIdentityCount) ? this.data.subDirectIdentityCount : 0; }, //for flat category start clickFlatCategoryItem: function( callback, hidden ){ if (this._hasChildItem()){ var firstLoaded = !this.itemLoaded; this.loadItemChildren(function(){ if( hidden ){ //alert("hidden") this.children.setStyles({"display": "none", "height": "0px"}); this.node.setStyles( this.selector.css.flatCategoryItemNode ); this.isExpand = false; }else if( firstLoaded ){ this.children.setStyles({"display": "block", "height": "auto"}); this.node.setStyles( this.selector.css.flatCategoryItemNode_selected ); this.isExpand = true; }else{ var display = this.children.getStyle("display"); if (display === "none"){ this.children.setStyles({"display": "block", "height": "auto"}); this.node.setStyles( this.selector.css.flatCategoryItemNode_selected ); this.isExpand = true; }else{ this.children.setStyles({"display": "none", "height": "0px"}); this.node.setStyles( this.selector.css.flatCategoryItemNode ); this.isExpand = false; } } if(callback)callback(); }.bind(this)); } }, loadCategoryChildren: function(callback){ if (!this.categoryLoaded){ if( this.selector.options.expandSubEnable ){ this.selector.orgAction.listSubUnitDirect(function(json){ json.data.each(function(subData){ if( !this.selector.isExcluded( subData ) ) { var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this); this.subCategorys.push( category ); } }.bind(this)); this.categoryLoaded = true; if (callback) callback(); }.bind(this), null, this.data.distinguishedName); }else{ if (callback) callback(); } }else{ if (callback) callback( ); } }, loadItemChildren: function(callback){ if (!this.itemLoaded){ if (this.selector.options.dutys && this.selector.options.dutys.length){ var ids = []; var object = {}; this.selector.options.dutys.each(function(duty){ this.selector.orgAction.listIdentityWidthUnitWithDutyName(this.data.distinguishedName, duty, function(json){ if (json.data && json.data.length){ ids = ids.concat(json.data); } }.bind(this), null, false); ids.each(function(idSubData){ if( !this.selector.isExcluded( idSubData ) && !object[ idSubData.id || idSubData.distinguishedName ]) { var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this); this.selector.items.push(item); if(this.subItems)this.subItems.push( item ); object[ idSubData.id || idSubData.distinguishedName ] = true; } this.itemLoaded = true; }.bind(this)); }.bind(this)); if (callback) callback(); }else{ this.selector.orgAction.listIdentityWithUnit(function(idJson){ idJson.data.each(function(idSubData){ if( !this.selector.isExcluded( idSubData ) ) { var item = this.selector._newItem(idSubData, this.selector, this.children, this.level + 1, this); this.selector.items.push(item); if(this.subItems)this.subItems.push( item ); } this.itemLoaded = true; }.bind(this)); if (callback) callback(); }.bind(this), null, this.data.distinguishedName); } }else{ if (callback) callback( ); } } //for flat category end }); MWF.xApplication.Selector.Identity.ItemUnitCategory = new Class({ Extends: MWF.xApplication.Selector.Identity.ItemCategory }); MWF.xApplication.Selector.Identity.ItemGroupCategory = new Class({ Extends: MWF.xApplication.Selector.Identity.ItemCategory, createNode: function(){ this.node = new Element("div", { "styles": this.selector.css.selectorItemCategory }).inject(this.container); }, _setIcon: function(){ var style = this.selector.options.style; this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/groupicon.png)"); }, loadSub: function(callback){ if (!this.loaded){ debugger; var personContainer, identityContainer, groupContainer, unitContainer; if( this.data.personList )personContainer = new Element("div").inject( this.children ); if( this.data.identityList )identityContainer = new Element("div").inject( this.children ); if( this.data.groupList )groupContainer = new Element("div").inject( this.children ); if( this.data.unitList )unitContainer = new Element("div").inject( this.children ); var personLoadedCount = 0; var identityLoadedCount = 0; var unitLoadedCount = 0; var groupLoadedCount = 0; var checkCallback = function( type, count ){ var addCount = count || 1; if( !this.selector.options.expandSubEnable ){ if( type === "person" )personLoadedCount += addCount; if( type === "identity" )identityLoadedCount += addCount; if( (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) && (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount) ){ this.loaded = true; if (callback) callback(); } }else{ if( type === "person" )personLoadedCount += addCount; if( type === "identity" )identityLoadedCount += addCount; if( type === "unit" )unitLoadedCount += addCount; if( type === "group" )groupLoadedCount += addCount; if( ( !this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount ) && ( !this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount )&& ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) && ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){ this.loaded = true; if (callback) callback(); } } }.bind(this); checkCallback(); if( this.data.identityList && this.data.identityList.length > 0 ){ if( this.selector.options.resultType === "person" ) { //根据身份id批量获取人员对象 o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({ identityList : this.data.identityList }, function (json) { this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this); checkCallback("identity", this.data.identityList.length ) }.bind(this), function () { checkCallback("identity", this.data.identityList.length ) }.bind(this)) }else{ //根据身份id批量获取身份对象 o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({ identityList : this.data.identityList }, function (json) { this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this); checkCallback("identity", this.data.identityList.length ) }.bind(this), function () { checkCallback("identity", this.data.identityList.length ) }.bind(this)) } } if( this.data.personList && this.data.personList.length > 0 ){ if( this.selector.options.resultType === "person" ) { //根据人员d批量获取人员对象 o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({ personList : this.data.personList }, function (json) { this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this); checkCallback("person", this.data.personList.length ) }.bind(this), function () { checkCallback("person", this.data.personList.length ) }.bind(this)) }else{ //根据人员id批量获取身份对象 o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({ personList : this.data.personList }, function (json) { this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this); checkCallback("person", this.data.personList.length ) }.bind(this), function () { checkCallback("person", this.data.personList.length ) }.bind(this)) } } // ( this.data.personList || [] ).each( function(p){ // if( this.selector.options.resultType === "person" ){ // this.selector.orgAction.getPerson(function (json) { // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this ); // checkCallback("person"); // }.bind(this), function(){ checkCallback("person") }, p ); // }else{ // this.selector.orgAction.listIdentityByPerson(function(json){ // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this); // checkCallback("person") // }.bind(this), function(){ checkCallback("person") }, p ); // } // }.bind(this)); //list 服务不能获取下级数量 // if( this.selector.options.expandSubEnable ){ // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({ // unitList : this.data.unitList // }, function (json) { // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this); // checkCallback("unit", this.data.unitList.length ) // }.bind(this), function () { // checkCallback("unit", this.data.unitList.length ) // }.bind(this)) // // // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({ // groupList : this.data.groupList // }, function (json) { // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this); // checkCallback("group", this.data.groupList.length ) // }.bind(this), function () { // checkCallback("group", this.data.groupList.length ) // }.bind(this)) // } if( this.selector.options.expandSubEnable ){ ( this.data.unitList || [] ).each( function(u){ this.selector.orgAction.getUnit(function (json) { this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this); checkCallback("unit"); }.bind(this), function(){ checkCallback("unit") }, u ); }.bind(this)); ( this.data.groupList || [] ).each( function(g){ this.selector.orgAction.getGroup(function (json) { this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this); checkCallback("group"); }.bind(this), function(){ checkCallback("group") }, g ); }.bind(this)); } }else{ if (callback) callback( ); } }, loadCategoryChildren: function(callback){ if (!this.categoryLoaded){ var groupContainer, unitContainer; if( this.data.groupList )groupContainer = new Element("div").inject( this.children ); if( this.data.unitList )unitContainer = new Element("div").inject( this.children ); var unitLoadedCount = 0; var groupLoadedCount = 0; var checkCallback = function( type, count ){ var addCount = count || 1; if( !this.selector.options.expandSubEnable ){ this.categoryLoaded = true; }else{ if( type === "unit" )unitLoadedCount += addCount; if( type === "group" )groupLoadedCount += addCount; if( ( !this.data.unitList || this.data.unitList.length === 0 || this.data.unitList.length == unitLoadedCount ) && ( !this.data.groupList || this.data.groupList.length === 0 || this.data.groupList.length == groupLoadedCount ) ){ this.categoryLoaded = true; if (callback) callback(); } } }.bind(this); checkCallback(); //list 服务不能获取下级数量 // if( this.selector.options.expandSubEnable ){ // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({ // unitList : this.data.unitList // }, function (json) { // this.selector.includeObject.loadUnitItem( json, this.children, this.level + 1, this); // checkCallback("unit", this.data.unitList.length ) // }.bind(this), function () { // checkCallback("unit", this.data.unitList.length ) // }.bind(this)) // // // o2.Actions.load("x_organization_assemble_express").GroupAction.listObject({ // groupList : this.data.groupList // }, function (json) { // this.selector.includeObject.loadGroupItem(json, this.children, this.level + 1, this); // checkCallback("group", this.data.groupList.length ) // }.bind(this), function () { // checkCallback("group", this.data.groupList.length ) // }.bind(this)) // } if( this.selector.options.expandSubEnable ){ ( this.data.unitList || [] ).each( function(u){ this.selector.orgAction.getUnit(function (json) { this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this); checkCallback("unit"); }.bind(this), function(){ checkCallback("unit") }, u ); }.bind(this)); ( this.data.groupList || [] ).each( function(g){ this.selector.orgAction.getGroup(function (json) { this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this); checkCallback("group"); }.bind(this), function(){ checkCallback("group") }, g ); }.bind(this)); } }else{ if (callback) callback( ); } }, loadItemChildren: function(callback){ if (!this.itemLoaded){ var personContainer, identityContainer; if( this.data.personList )personContainer = new Element("div").inject( this.children ); if( this.data.identityList )identityContainer = new Element("div").inject( this.children ); var personLoadedCount = 0; var identityLoadedCount = 0; var checkCallback = function( type, count ){ var addCount = count || 1; if( type === "person" )personLoadedCount += addCount; if( type === "identity" )identityLoadedCount += addCount; if( (!this.data.personList || this.data.personList.length === 0 || this.data.personList.length == personLoadedCount) && (!this.data.identityList || this.data.identityList.length === 0 || this.data.identityList.length == identityLoadedCount) ){ this.itemLoaded = true; if (callback) callback(); } }.bind(this); checkCallback(); if( this.data.identityList && this.data.identityList.length > 0 ){ if( this.selector.options.resultType === "person" ) { //根据身份id批量获取人员对象 o2.Actions.load("x_organization_assemble_express").PersonAction.listWithIdentityObject({ identityList : this.data.identityList }, function (json) { this.selector.includeObject.loadPersonItem( json, identityContainer, this.level + 1, this); checkCallback("identity", this.data.identityList.length ) }.bind(this), function () { checkCallback("identity", this.data.identityList.length ) }.bind(this)) }else{ //根据身份id批量获取身份对象 o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({ identityList : this.data.identityList }, function (json) { this.selector.includeObject.loadIdentityItem( json, identityContainer, this.level + 1, this); checkCallback("identity", this.data.identityList.length ) }.bind(this), function () { checkCallback("identity", this.data.identityList.length ) }.bind(this)) } } if( this.data.personList && this.data.personList.length > 0 ){ if( this.selector.options.resultType === "person" ) { //根据人员d批量获取人员对象 o2.Actions.load("x_organization_assemble_express").PersonAction.listObject({ personList : this.data.personList }, function (json) { this.selector.includeObject.loadPersonItem( json, personContainer, this.level + 1, this); checkCallback("person", this.data.personList.length ) }.bind(this), function () { checkCallback("person", this.data.personList.length ) }.bind(this)) }else{ //根据人员id批量获取身份对象 o2.Actions.load("x_organization_assemble_express").IdentityAction.listWithPersonObject({ personList : this.data.personList }, function (json) { this.selector.includeObject.loadIdentityItem( json, personContainer, this.level + 1, this); checkCallback("person", this.data.personList.length ) }.bind(this), function () { checkCallback("person", this.data.personList.length ) }.bind(this)) } } // ( this.data.personList || [] ).each( function(p){ // if( this.selector.options.resultType === "person" ){ // this.selector.orgAction.getPerson(function (json) { // this.selector.includeObject.loadPersonItem(json, this.children, this.level + 1, this ); // checkCallback("person"); // }.bind(this), function(){ checkCallback("person") }, p ); // }else{ // this.selector.orgAction.listIdentityByPerson(function(json){ // this.selector.includeObject.loadIdentityItem(json, this.children, this.level + 1, this); // checkCallback("person") // }.bind(this), function(){ checkCallback("person") }, p ); // } // }.bind(this)); }else{ if (callback) callback( ); } }, _hasChild: function(){ var uCount = (this.data.unitList) ? this.data.unitList.length : 0; var gCount = (this.data.groupList) ? this.data.groupList.length : 0; var pCount = (this.data.personList) ? this.data.personList.length : 0; var iCount = (this.data.identityList) ? this.data.identityList.length : 0; return uCount + gCount + pCount + iCount; }, _hasChildCategory: function(){ var uCount = (this.data.unitList) ? this.data.unitList.length : 0; var gCount = (this.data.groupList) ? this.data.groupList.length : 0; return uCount + gCount; }, _hasChildItem: function(){ var pCount = (this.data.personList) ? this.data.personList.length : 0; var iCount = (this.data.identityList) ? this.data.identityList.length : 0; return pCount + iCount; } }); MWF.xApplication.Selector.Identity.ItemRoleCategory = new Class({ Extends: MWF.xApplication.Selector.Person.ItemCategory, _getShowName: function(){ return this.data.name; }, _setIcon: function(){ var style = this.selector.options.style; this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/roleicon.png)"); } }); MWF.xApplication.Selector.Identity.Include = new Class({ Implements: [Options, Events], options: { "include" : [], //增加的可选项 "resultType" : "", //可以设置成个人,那么结果返回个人 "expandSubEnable" : true //是否允许展开下一层 }, initialize: function(selector, itemAreaNode, options){ this.setOptions(options); this.selector = selector; this.itemAreaNode = $(itemAreaNode); this.orgAction = MWF.Actions.get("x_organization_assemble_control"); }, load : function( callback ){ if( !this.options.include || this.options.include.length === 0 ){ this.fireEvent("afterLoad"); if(callback)callback(); return; } var count = 0; var checkCallback = function () { count++; if( count === this.options.include.length ){ this.fireEvent("afterLoad"); if(callback)callback(); } }.bind(this); this.includeAreaNode = new Element( "div.includeAreaNode").inject( this.itemAreaNode, "top" ); if( this.selector.isFlatCategory ){ this.flatCategoryAreaNode = new Element( "div.includeFlatCategoryAreaNode").inject( this.selector.flatCategoryNode, "top" ); } //this.includeIdentityAreaNode = new Element( "div").inject( this.includeAreaNode ); //this.includePersonAreaNode = new Element( "div").inject( this.includeAreaNode ); //this.includeUnitAreaNode = new Element( "div").inject( this.includeAreaNode ); //this.includeGroupAreaNode = new Element( "div").inject( this.includeAreaNode ); this.options.include.each( function( d ){ var container = new Element("div").inject( this.includeAreaNode ); var flatCategoryContainer; if( this.flatCategoryAreaNode ){ flatCategoryContainer = new Element("div").inject( this.flatCategoryAreaNode ); } if (typeOf(d)==="string"){ var arr = d.split("@"); var flag = arr[ arr.length - 1].toLowerCase(); if( flag === "u" ){ this.orgAction.listUnitByKey(function(json){ this.loadUnitItem(json, container, null, null, flatCategoryContainer); checkCallback(); }.bind(this), checkCallback, d); }else if( flag === "i" ) { this.orgAction.listIdentityByKey(function (json) { this.loadIdentityItem(json, container, null, null, true ); checkCallback(); }.bind(this), checkCallback, d); }else if( flag === "g" ){ this.orgAction.listGroupByKey(function(json){ this.loadGroupItem( json , container, null, null, flatCategoryContainer); checkCallback(); }.bind(this), checkCallback, d); }else if( flag === "p" ){ if( this.options.resultType === "person" ){ this.orgAction.getPerson(function (json){ this.loadPersonItem( json , container, null, null, true); checkCallback(); }.bind(this), checkCallback, d); }else{ this.orgAction.listIdentityByPerson(function(json){ this.loadIdentityItem(json, container , null, null, true); checkCallback(); }.bind(this), checkCallback, d); } }else{ if( this.options.resultType === "person" ){ this.orgAction.listPersonByKey(function (json) { this.loadPersonItem( json , container, null, null, true); checkCallback(); }.bind(this), checkCallback, d); }else{ this.orgAction.listIdentityByKey(function(json){ this.loadIdentityItem(json, container, null, null, true); checkCallback(); }.bind(this), checkCallback, d); } } }else{ var arr = d.distinguishedName.split("@"); var flag = arr[ arr.length - 1].toLowerCase(); if( flag === "u" ) { this.orgAction.getUnit(function (json) { this.loadUnitItem(json, container, null, null, flatCategoryContainer); checkCallback(); }.bind(this), checkCallback, d.distinguishedName); }else if( flag === "i" ){ this.orgAction.getIdentity(function (json) { this.loadIdentityItem(json, container, null, null, true); checkCallback(); }.bind(this), checkCallback, d.distinguishedName); }else if( flag === "g" ){ this.orgAction.getGroup(function(json){ this.loadGroupItem( json , container, null, null, flatCategoryContainer); checkCallback(); }.bind(this), checkCallback, d.distinguishedName, null, null, true); }else if( flag === "p" ){ if( this.options.resultType === "person" ){ this.orgAction.getPerson(function (json) { this.loadPersonItem(json, container, null, null, true); checkCallback(); }.bind(this), checkCallback, d.distinguishedName); }else{ this.orgAction.listIdentityByPerson(function(json){ this.loadIdentityItem(json, container, null, null, true); checkCallback(); }.bind(this), checkCallback, d.distinguishedName); } }else{ if( this.options.resultType === "person" ){ this.orgAction.getPerson(function (json) { this.loadPersonItem(json, container, null, null, true); checkCallback(); }.bind(this), checkCallback, d.distinguishedName); }else{ this.orgAction.getIdentity(function (json) { this.loadIdentityItem(json, container, null, null, true); checkCallback(); }.bind(this), checkCallback, d.distinguishedName); } } //var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode); } }.bind(this)) }, loadPersonItem : function( json, container, level, category, isIncludedPerson ){ if( !json.data )return; var array = typeOf( json.data ) === "array" ? json.data : [json.data]; array.each(function(data){ if( !this.selector.isExcluded( data ) ) { if(!this.includePerson)this.includePerson = []; if(isIncludedPerson)this.includePerson.push( data.distinguishedName ); if(!this.includePersonObject)this.includePersonObject = []; if(isIncludedPerson)this.includePersonObject.push( data ); var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category); this.selector.items.push(item); if( category && category.subItems ){ category.subItems.push( item ); } } }.bind(this)); }, loadIdentityItem : function( json, container, level, category, isIncludedIdentity ){ if( !json.data )return; var array = typeOf( json.data ) === "array" ? json.data : [json.data]; array.each(function(data){ if( !this.selector.isExcluded( data ) ) { if(!this.includeIdentity)this.includeIdentity = []; if(isIncludedIdentity)this.includeIdentity.push( data.distinguishedName ); if(!this.includeIdentityObject)this.includeIdentityObject = []; if(isIncludedIdentity)this.includeIdentityObject.push( data ); var item = this.selector._newItem(data, this.selector, container || this.includeAreaNode, level || 1, category); this.selector.items.push(item); if( category && category.subItems ){ category.subItems.push( item ); } } }.bind(this)); }, loadUnitItem : function( json, container, level, parentCategory, flatCategoryContainer ){ if( !json.data )return; var array = typeOf( json.data ) === "array" ? json.data : [json.data]; array.each(function(data){ if( !this.selector.isExcluded( data ) ) { if(!this.includeUnit)this.includeUnit = []; this.includeUnit.push( data.distinguishedName ); var category; if( flatCategoryContainer ){ category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory, true); category.nodeContainer = flatCategoryContainer; category.load(); }else{ category = this.selector._newItemCategory("ItemUnitCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory); } if( parentCategory && parentCategory.subCategorys ){ parentCategory.subCategorys.push( category ) }else if(this.selector.subCategorys){ this.selector.subCategorys.push( category ) } } }.bind(this)); }, loadGroupItem : function( json, container, level, parentCategory, flatCategoryContainer ){ if( !json.data )return; var array = typeOf( json.data ) === "array" ? json.data : [json.data]; array.each(function(data){ if( !this.selector.isExcluded( data ) ) { if(!this.includeGroup)this.includeGroup = []; this.includeGroup.push( data.distinguishedName ); var category; if( flatCategoryContainer ){ category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory, true); category.nodeContainer = flatCategoryContainer; category.load(); }else{ category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory) } if( parentCategory && parentCategory.subCategorys ){ parentCategory.subCategorys.push( category ) }else if(this.selector.subCategorys){ this.selector.subCategorys.push( category ) } } }.bind(this)); }, listByFilter : function( type, key, callback ){ var arr1 = this.listByFilterPerson(key) || []; this.listByFilterUnitAndGroup( type, key, function(arr2){ this.listByFilterGroup( type, key, function(arr3){ if (callback) callback( arr1.concat( arr2 || [] ).concat( arr3 || [] ) ); }.bind(this)) }.bind(this)) }, listByFilterPerson : function( key ){ var identitys = []; var persons = []; var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase(); if( this.includeIdentityObject && this.includeIdentityObject.length ){ identitys = this.includeIdentityObject.filter( function(id) { return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1; }) } if( this.includePersonObject && this.includePersonObject.length ){ persons = this.includePersonObject.filter( function(id) { return ( id.pinyin || "" ).indexOf(keyString) > -1 || (id.pinyinInitial || "").indexOf(keyString) > -1 || (id.distinguishedName || "").indexOf(keyString) > -1; }) } return identitys.concat( persons); }, listByFilterGroup : function( type, key, callback ){ //根据关键字获取群组内的人员,再转成身份 var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase(); if( this.includeGroup && this.includeGroup.length ){ var keyObject = { "key" : keyString, "groupList" : this.includeGroup }; this.orgAction[ type === "pinyin" ? "listPersonByPinyin" : "listPersonByKey" ](function(json){ if( this.options.resultType === "person" ){ if (callback) callback( json.data ); }else{ var personList = (json.data || []).map( function(d){ return d.id }); o2.Actions.get("x_organization_assemble_express").listIdentityWithPerson( { "personList" : personList }, function(js){ if (callback) callback(js.data); }.bind(this), function(){ if (callback) callback(); }.bind(this)) } }.bind(this), function(){ if (callback) callback(); }.bind(this), keyObject); }else{ if (callback) callback(); } }, listByFilterUnitAndGroup : function( type, key, callback ){ //根据关键字获取组织和群组内的身份 var keyString = typeOf( key )==="string" ? key.toLowerCase() : key.key.toLowerCase(); if ( this.includeUnit && this.includeUnit.length ){ key = this.getUnitFilterKey( key, this.includeUnit, this.includeGroup ); this.orgAction.listIdentityByKey(function(json){ if (callback) callback(json.data); }.bind(this), function(){ if (callback) callback(); }, key); }else{ if (callback) callback(); } }, getUnitFilterKey : function( key, unitObject, groupObject ){ var unitObjects = unitObject || []; var units = []; unitObjects.each(function(u){ if (typeOf(u)==="string"){ units.push(u); } if (typeOf(u)==="object"){ units.push(u.distinguishedName); } }); var groupObjects = groupObject || []; var groups = []; groupObjects.each(function(g){ if (typeOf(g)==="string"){ groups.push(g); } if (typeOf(g)==="object"){ groups.push(g.distinguishedName); } }); if( !units.length && !groups.length ){ return key; }else{ var result = { "key": key }; if( units.length )result.unitList = units; if( groups.length )result.groupList = groups; return result; } // return units.length ? {"key": key, "unitList": units, "groupList" : groups} : key; } }); MWF.xApplication.Selector.Identity.Filter = new Class({ Implements: [Options, Events], options: { "style": "default", "units": [], "resultType" : "" //可以设置成个人,那么结果返回个人 }, initialize: function(value, options){ this.setOptions(options); this.value = value; this.orgAction = MWF.Actions.get("x_organization_assemble_control"); }, filter: function(value, callback){ this.value = value; var key = this.value; if (this.options.units.length){ var units = []; this.options.units.each(function(u){ if (typeOf(u)==="string"){ units.push(u); } if (typeOf(u)==="object"){ units.push(u.distinguishedName); } }); key = {"key": this.value, "unitList": units}; } var data = null; this.orgAction.listIdentityByKey(function(json){ data = json.data; if (callback) callback(data) }.bind(this), null, key); } });