diff --git a/o2web/source/x_component_Selector/Identity.js b/o2web/source/x_component_Selector/Identity.js index 02f68df2c7e83aa93de8264369527cd75411cfd1..b7ff281ee91e81639530018956bf591ca0d5015f 100644 --- a/o2web/source/x_component_Selector/Identity.js +++ b/o2web/source/x_component_Selector/Identity.js @@ -30,101 +30,12 @@ MWF.xApplication.Selector.Identity = new Class({ this.afterLoadSelectItem(); return; } - if( this.className === "Identity" && (this.options.isCheckStatus || this.options.showSelectedCount )) { - var unitList = []; - var groupList = []; - - var parseInclude = function () { - if (this.options.include.length > 0) { - this.options.include.each(function (d) { - var dn = typeOf(d) === "string" ? d : d.distinguishedName; - var flag = dn.split("@").getLast().toLowerCase(); - if (flag === "u") { - unitList.push(dn); - } else if (flag === "g") { - groupList.push(dn) - } - }) - } - }.bind(this); - - var load = function () { - - var unitLoaded, groupLoaded, selectedIdentityLoaded, excludeIdentityLoaded; - var unitTree, groupTree; - this.unitExcludedIdentityCount = {}; - this.groupExcludedIdentityCount = {}; - this.unitSelectedIdentityCount = {}; - this.groupSelectedIdentityCount = {}; - - var caculate = function () { - if (unitLoaded && groupLoaded && selectedIdentityLoaded && excludeIdentityLoaded) { - this.caculateNestedSubCount(unitTree, groupTree, function () { - debugger; - this._loadSelectItems() - }.bind(this)) - - } - }.bind(this); - - this.getIdentityCountMap(this.options.values, groupList && groupList.length > 0, function (result) { - this.unitSelectedIdentityCount = result.unitMap; - this.groupSelectedIdentityCount = result.groupMap; - selectedIdentityLoaded = true; - caculate(); - }.bind(this)); - - this.getIdentityCountMap(this.options.exclude, groupList && groupList.length > 0, function (result) { - this.unitExcludedIdentityCount = result.unitMap; - this.groupExcludedIdentityCount = result.groupMap; - excludeIdentityLoaded = true; - caculate(); - }.bind(this)); + this._loadSelectItems(); - if (unitList && unitList.length > 0) { - o2.Actions.load("x_organization_assemble_express").UnitAction.listWithUnitTree({"unitList": unitList}, function (json) { - unitTree = json.data; - unitLoaded = true; - caculate(); - }.bind(this)) - } else { - unitLoaded = true; - caculate(); - } - - if (groupList && groupList.length > 0) { - o2.Actions.load("x_organization_assemble_express").GroupAction.listWithGroupTree({"groupList": groupList}, function (json) { - groupTree = json.data; - groupLoaded = true; - caculate(); - }.bind(this)) - } else { - groupLoaded = true; - caculate(); - } - }.bind(this); - - if (this.options.noUnit) { - parseInclude(); - load(); - } else if (this.options.units.length) { - parseInclude(); - this.options.units.each(function (u) { - unitList.push(typeOf(u) === "string" ? u : (u.distinguishedName || u.id || u.unique || u.levelName)) - }.bind(this)); - load(); - } else { - this.orgAction.listTopUnit(function (json) { - this.topUnitObj = json.data; - this.topUnitObj.each(function (u) { - unitList.push(u.distinguishedName) - }.bind(this)); - load(); - }.bind(this)) - } - }else{ - this._loadSelectItems() + if( this.isCheckStatusOrCount() ) { + this.loadingCount = "wait"; + this.loadCount(); } }, _loadSelectItems: function(addToNext){ @@ -169,76 +80,20 @@ MWF.xApplication.Selector.Identity = new Class({ json.data.each( function(data){ var category = this._newItemCategory("ItemUnitCategory", data, this, this.itemAreaNode ); this.subCategorys.push(category); + this.subCategoryMap[data.levelName] = category; }.bind(this)); } loadUnitSuccess(); }.bind(this), loadUnitFailure ); - // var unitLoaded = 0; - // - // var loadUnitSuccess = function () { - // unitLoaded++; - // if( unitLoaded === this.options.units.length ){ - // this.unitLoaded = true; - // if( this.includeLoaded ){ - // afterLoadSelectItemFun(); - // } - // } - // }.bind(this); - // var loadUnitFailure = loadUnitSuccess; - // - // this.loadInclude( function () { - // this.includeLoaded = true; - // if( this.unitLoaded ){ - // afterLoadSelectItemFun(); - // } - // }.bind(this)); - // this.options.units.each(function(unit){ - // - // var container = new Element("div").inject( this.itemAreaNode ); - // - // if (typeOf(unit)==="string"){ - // this.orgAction.getUnit(unit, function(json){ - // if (json.data){ - // var category = this._newItemCategory("ItemUnitCategory", json.data, this, container); - // this.subCategorys.push( category ); - // } - // loadUnitSuccess(); - // }.bind(this), function(){ - // this.orgAction.listUnitByKey(function(json){ - // if (json.data.length){ - // json.data.each(function(data){ - // var category = this._newItemCategory("ItemUnitCategory", data, this, container); - // this.subCategorys.push( category ); - // }.bind(this)) - // } - // loadUnitSuccess(); - // }.bind(this), loadUnitFailure, unit); - // }.bind(this)); - // }else{ - // this.orgAction.getUnit(function(json){ - // if (json.data){ - // var category = this._newItemCategory("ItemUnitCategory", json.data, this, container); - // this.subCategorys.push( category ); - // } - // loadUnitSuccess(); - // }.bind(this), loadUnitFailure, unit.distinguishedName); - // } - // - // }.bind(this)); }else{ - // this.loadInclude( function () { - // this.includeLoaded = true; - // if( this.unitLoaded ){ - // afterLoadSelectItemFun(); - // } - // }.bind(this)); var load = function ( topUnit ) { topUnit.each(function(data){ if( !this.isExcluded( data ) ){ var category = this._newItemCategory("ItemUnitCategory", data, this, this.itemAreaNode); this.subCategorys.push( category ); + this.subCategoryMap[data.levelName] = category; } }.bind(this)); @@ -257,7 +112,6 @@ MWF.xApplication.Selector.Identity = new Class({ } } }, - loadInclude: function(afterLoadFun) { if (!this.includeObject){ this.includeObject = new MWF.xApplication.Selector.Identity.Include(this, this.itemAreaNode, { @@ -379,63 +233,141 @@ MWF.xApplication.Selector.Identity = new Class({ return units.length ? keyObj : key; }, - //_listItemNext: function(last, count, callback){ - // this.action.listRoleNext(last, count, function(json){ - // if (callback) callback.apply(this, [json]); - // }.bind(this)); - //} - getIdentityAllLevelName : function(identityList, byGroup, callback){ - var result = { - unitMap : {}, - groupMap : {} - }; - this.listIndetityObject( identityList, function ( list, map ) { - list.each( function (id) { - if(id.unitLevelName){ - result.unitMap[ id.unitLevelName ] = ( result.unitMap[ id.unitLevelName ] || 0 )+1; - } - }.bind(this)); - if( byGroup ) { - this.listLevelNameGroupMap(list, function ( levelNameGroupMap ) { - for( var key in levelNameGroupMap ){ - var group = levelNameGroupMap[key] - var identityCount = group["identityList"].length; - if(identityCount)result.groupMap[key] = identityCount; + loadCount: function(){ + + var unitList = []; + var groupList = []; + + var parseInclude = function () { + if (this.options.include.length > 0) { + this.options.include.each(function (d) { + var dn = typeOf(d) === "string" ? d : d.distinguishedName; + var flag = dn.split("@").getLast().toLowerCase(); + if (flag === "u") { + unitList.push(dn); + } else if (flag === "g") { + groupList.push(dn) } - if( callback )callback( result ); + }) + } + }.bind(this); + + var check = function () { + this.loadingCount = "ready"; + this.checkCountAndStatus(); + this.loadingCount = "done"; + }.bind(this); + + if (this.options.noUnit) { + parseInclude(); + this._loadUnitAndGroupCount(unitList, groupList, check); + } else if (this.options.units.length) { + parseInclude(); + this.options.units.each(function (u) { + unitList.push(typeOf(u) === "string" ? u : (u.distinguishedName || u.id || u.unique || u.levelName)) + }.bind(this)); + this._loadUnitAndGroupCount(unitList, groupList, check); + } else { + this.orgAction.listTopUnit(function (json) { + this.topUnitObj = json.data; + this.topUnitObj.each(function (u) { + unitList.push(u.distinguishedName) }.bind(this)); - }else{ - if( callback )callback( result ); + this._loadUnitAndGroupCount(unitList, groupList, check); + }.bind(this)) + } + }, + _loadUnitAndGroupCount: function(unitList, groupList, callback){ + + if( !this.groupLevelNameListMap )this.groupLevelNameListMap = {}; + if( !this.groupAllLevelNameListMap )this.groupAllLevelNameListMap = {}; + + this.hasGroupCategory = groupList && groupList.length > 0; + + var unitLoaded, groupLoaded, selectedIdentityLoaded, excludeIdentityLoaded; + var unitTree, groupTree; + this.unitExcludedIdentityCount = {}; + this.groupExcludedIdentityCount = {}; + this.unitSelectedIdentityCount = {}; + this.groupSelectedIdentityCount = {}; + + var caculate = function () { + if (unitLoaded && groupLoaded && selectedIdentityLoaded && excludeIdentityLoaded) { + this.caculateNestedSubCount(unitTree, groupTree, function () { + + if(callback)callback(); + + }.bind(this)) + } + }.bind(this); + + this.getIdentityCountMap(this.options.values, groupList && groupList.length > 0, function (result) { + this.unitSelectedIdentityCount = result.unitMap; + this.groupSelectedIdentityCount = result.groupMap; + selectedIdentityLoaded = true; + caculate(); }.bind(this)); + + this.getIdentityCountMap(this.options.exclude, groupList && groupList.length > 0, function (result) { + this.unitExcludedIdentityCount = result.unitMap; + this.groupExcludedIdentityCount = result.groupMap; + excludeIdentityLoaded = true; + caculate(); + }.bind(this)); + + if (unitList && unitList.length > 0) { + o2.Actions.load("x_organization_assemble_express").UnitAction.listWithUnitTree({"unitList": unitList}, function (json) { + unitTree = json.data; + unitLoaded = true; + caculate(); + }.bind(this)) + } else { + unitLoaded = true; + caculate(); + } + + if (groupList && groupList.length > 0) { + o2.Actions.load("x_organization_assemble_express").GroupAction.listWithGroupTree({"groupList": groupList}, function (json) { + groupTree = json.data; + groupLoaded = true; + caculate(); + }.bind(this)) + } else { + groupLoaded = true; + caculate(); + } }, getIdentityCountMap : function( identityList, byGroup, callback ){ var result = { unitMap : {}, groupMap : {} }; - this.listIndetityObject( identityList, function ( list, map ) { - list.each( function (id) { - if(id.unitLevelName){ - result.unitMap[ id.unitLevelName ] = ( result.unitMap[ id.unitLevelName ] || 0 )+1; - } - }.bind(this)); - if( byGroup ) { - this.listLevelNameGroupMap(list, function ( levelNameGroupMap ) { - for( var key in levelNameGroupMap ){ - var group = levelNameGroupMap[key] - var identityCount = group["identityList"].length; - if(identityCount)result.groupMap[key] = identityCount; + if( byGroup ){ + this.listIdentityObjectWithGroup( identityList, function ( identityObjectList, groupLevelNameList ) { + identityObjectList.each(function (id) { + if (id && id.unitLevelName) { + result.unitMap[id.unitLevelName] = (result.unitMap[id.unitLevelName] || 0) + 1; } - if( callback )callback( result ); }.bind(this)); - }else{ + groupLevelNameList.each(function(g){ + result.groupMap[g] = (result.groupMap[g] || 0) + 1; + }) if( callback )callback( result ); - } - }.bind(this)); + }) + }else{ + this.listIndentityObjectWithoutGroup( identityList, function ( identityObjectList ) { + identityObjectList.each(function (id) { + if (id && id.unitLevelName) { + result.unitMap[id.unitLevelName] = (result.unitMap[id.unitLevelName] || 0) + 1; + } + }.bind(this)); + if( callback )callback( result ); + }) + } }, - listIndetityObject : function( identityList, callback ){ + listIndentityObjectWithoutGroup : function( identityList, callback ){ var list = []; identityList.each( function (d) { if( typeOf( d ) === "object"){ @@ -448,55 +380,45 @@ MWF.xApplication.Selector.Identity = new Class({ o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({ identityList : list }, function (json) { var map = {}; json.data.each( function (d) { map[ d.matchKey ] = d; }); - var result = []; + var identityObjectList = []; identityList.each( function (d) { var key = typeOf( d ) === "object" ? ( d.distinguishedName || d.id || d.unique ) : d; - result.push( map[key] ? map[key] : d ); + identityObjectList.push( map[key] ? map[key] : d ); }); - if( callback )callback( result, map ); + if( callback )callback( identityObjectList ); }.bind(this)) }else{ - if( callback )callback( identityList, {} ); + if( callback )callback( identityList ); } }, - listLevelNameGroupMap : function(identityList, callback, referenceFlag, recursiveOrgFlag){ - var list = identityList.map( function (d) { return d.distinguishedName; }).clean(); - if( list.length > 0 ){ - o2.Actions.load("x_organization_assemble_express").GroupAction.listWithIdentityObject( { - recursiveGroupFlag : true, identityList : list, referenceFlag : !!referenceFlag, recursiveOrgFlag : !!recursiveOrgFlag - }, function (json) { - var map = {}; - var groupList = json.data; - groupList.each( function (d) { map[ d.distinguishedName ] = d; }); - groupList.each( function (d) { - d.identityList = d.identityList.filter( function (id) { return list.contains(id) }); - d.groupObjectList = []; - d.groupList.each( function (g) { if(map[g])d.groupObjectList.push( map[g] ) }) - }); - - var groupIdentityMap = {}; - var fun = function ( group, parentName ) { - var levelName = parentName ? ( parentName + "/" + group.name ) : group.name; - groupIdentityMap[ levelName ] = group; - group.groupObjectList.each( function( g ){ - fun( g, levelName ); - }) - }; - - groupList.each( function (d) { fun(d) }); - - if( callback )callback( groupIdentityMap ); - }.bind(this)) - }else{ - if( callback )callback({}); + listIdentityObjectWithGroup: function(identityList, callback){ + if( identityList.length === 0 ){ + if( callback )callback( [], [] ); + return; } + var list = identityList.map( function (d) { + return typeOf( d ) === "object" ? (d.distinguishedName || d.id || d.unique ) : d; + }); + o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({ + identityList : list, referenceFlag: true, recursiveFlag: true + }, function (json) { + var groupLevelNameList = []; + json.data.each(function (d) { + d.woGroupList.each(function (group) { + if(group.identityList.contains(d.id)){ + groupLevelNameList = groupLevelNameList.concat(this.caculateGroupLevelName(group, false)); + } + }.bind(this)); + }.bind(this)); + if (callback) callback(json.data, groupLevelNameList); + }.bind(this)) }, - - caculateNestedSubCount : function(unitTree, groupTree, callback){ + caculateNestedSubCount: function(unitTree, groupTree, callback){ if( !this.allUnitObject )this.allUnitObject = {}; if( !this.allGroupObject )this.allGroupObject = {}; if( !this.allGroupObjectByDn )this.allGroupObjectByDn = {}; + if( !this.allGrounUnitObject )this.allGrounUnitObject = {}; if( groupTree && groupTree.length ){ groupTree.each( function ( tree ) { @@ -524,6 +446,12 @@ MWF.xApplication.Selector.Identity = new Class({ caculateGroupNestedCount : function( tree, parentLevelName ){ if( this.isExcluded( tree ) )return; var groupLevelName = parentLevelName ? ( parentLevelName + "/" + tree.distinguishedName.split("@")[0] ) : tree.distinguishedName.split("@")[0]; + + if(!this.allGrounUnitObject[groupLevelName]){ + this.allGrounUnitObject[groupLevelName] = tree; + tree.groupUnitLevelName = groupLevelName; + } + if(!this.allGroupObject[ groupLevelName ]){ this.allGroupObject[ groupLevelName ] = tree; }else{ @@ -568,6 +496,12 @@ MWF.xApplication.Selector.Identity = new Class({ if( this.isExcluded( tree ) )return; var count; var selectedCount; + + if(!this.allGrounUnitObject[groupLevelName+"/"+tree.levelName]){ + this.allGrounUnitObject[groupLevelName+"/"+tree.levelName] = tree; + tree.groupUnitLevelName = groupLevelName+"/"+tree.levelName; + } + if(!this.allUnitObject[ tree.levelName ]){ this.allUnitObject[ tree.levelName ] = tree; count = tree.subDirectIdentityCount; @@ -583,7 +517,7 @@ MWF.xApplication.Selector.Identity = new Class({ return; }else{ count = this.allUnitObject[ tree.levelName ].subNestedIdentityCount || 0; - count = this.allUnitObject[ tree.levelName ].selectedNestedIdentityCount || 0; + selectedCount = this.allUnitObject[ tree.levelName ].selectedNestedIdentityCount || 0; } if( groupLevelName ){ @@ -617,6 +551,118 @@ MWF.xApplication.Selector.Identity = new Class({ this.caculateUnitNestedCount( unit, groupLevelName ) }.bind(this)) } + }, + + getIdentityParentLevelNameList: function(itemData, callback){ + if( this.hasGroupCategory ){ + if( !itemData.parentLevelNameList ){ + o2.Actions.load("x_organization_assemble_express").IdentityAction.listObject({ + identityList : [itemData.distinguishedName], referenceFlag: true, recursiveFlag:true + }, function (json) { + json.data.each( function (d) { + var list = []; + var listWithIdentity = []; //身份直接所在群组 + + d.woGroupList.each(function (group) { + var gList = this.caculateGroupLevelName(group); + list = list.concat( gList ); + if(group.identityList.contains(d.id))listWithIdentity = listWithIdentity.concat(gList); + }.bind(this)); + + var resultList = [itemData.unitLevelName]; + if( this.allGrounUnitObject ){ + list.each(function(lName){ + if( this.allGrounUnitObject[ lName +"/"+ itemData.unitLevelName ] ){ + resultList.push(lName +"/"+ itemData.unitLevelName); + if( listWithIdentity.contains(lName) )resultList.push(lName); + }else if( this.allGrounUnitObject[ lName ] ){ + resultList.push(lName); + } + }.bind(this)); + }else{ //数量树没有加载完成的时候 ???可能有问题 + list.each(function(lName){ + var level1Name = lName.split("/")[0]; + if( this.subCategoryMap[ level1Name ] ){ + resultList.push(lName +"/"+ itemData.unitLevelName); + resultList.push(lName ); + } + }.bind(this)); + } + itemData.parentLevelNameList = resultList; + if( callback )callback(resultList); + }.bind(this)) + }.bind(this)) + }else{ + if( callback )callback(itemData.parentLevelNameList); + } + }else{ + if( callback )callback([itemData.unitLevelName]); + } + }, + //通过身份信息获取的group + caculateGroupLevelName: function(g, flag){ + var levelNameMap = flag ? this.groupAllLevelNameListMap : this.groupLevelNameListMap; + if( levelNameMap[g.distinguishedName] ){ + return levelNameMap[g.distinguishedName]; + } + + var levelNameList = [g.name]; + var map = {}; + map[g.id] = g; + g.woSupGroupList.each(function(group){ map[group.id] = group; }); + + var nest = function( supGroupName, groupList ){ + groupList.each(function(subGroupId){ + if( map[subGroupId] ){ + var groupLevelName = supGroupName+"/"+map[subGroupId].name; + if(flag || map[subGroupId].name === g.name )levelNameList.push( groupLevelName ); + nest(groupLevelName, map[subGroupId].groupList || []); + } + }) + }; + + g.woSupGroupList.each(function(group){ + if(flag)levelNameList.push(group.name); + nest( group.name, group.groupList ) + }); + + levelNameList = levelNameList.unique(); + levelNameMap[g.distinguishedName] = levelNameList; + return levelNameList; + }, + addSelectedCount: function( itemOrItemSelected, count ){ + this._addSelectedCount(itemOrItemSelected, count); + }, + _addSelectedCount: function( itemOrItemSelected, count ){ + var itemData = itemOrItemSelected.data; + this.getIdentityParentLevelNameList(itemData, function (parentLevelNameList) { + parentLevelNameList.each(function(parentLevelName){ + if(!parentLevelName)return; + var list = parentLevelName.split("/"); + var nameList = []; + var subCategoryMapList = [this.subCategoryMap]; + for (var j = 0; j < list.length; j++) { + nameList.push(list[j]); + var name = nameList.join("/"); + var maplist = []; + subCategoryMapList.each(function(subCategoryMap){ + if ( subCategoryMap[name] ) { + var category = subCategoryMap[name]; + category._addSelectedCount(count); + maplist.push( category.subCategoryMap ) ; + } + }); + subCategoryMapList = subCategoryMapList.concat(maplist); + + if( this.loadingCount === "done" ){ + var obj = this.allUnitObject[name]; + if (obj) { + obj.selectedNestedIdentityCount = obj.selectedNestedIdentityCount + count; + } + } + } + }.bind(this)); + }.bind(this)) } }); @@ -705,10 +751,8 @@ MWF.xApplication.Selector.Identity.Item = new Class({ this.selectedItem = selectedItem[0]; this.setSelected(); - var flag = this.selector.options.selectAllRange === "all" || - ( this.selector.selectType == "identity" && ( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus )); - if( flag ){ - if(this.category && this.category._addSelectedCount )this.category._addSelectedCount( 1, true ); + if( this.selector.options.selectAllRange === "all" && !this.selector.isCheckStatusOrCount() ){ + if(this.category && this.category._addSelectAllSelectedCount )this.category._addSelectAllSelectedCount( 1, true ); } } } @@ -785,9 +829,10 @@ MWF.xApplication.Selector.Identity.ItemSelected = new Class({ this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/personicon.png)"); }, check: function(){ + var items; if (this.selector.items.length){ var isPerson = this.selector.options.resultType === "person"; - var items = this.selector.items.filter(function(item, index){ + items = this.selector.items.filter(function(item, index){ if( isPerson ){ return (item.data.person && item.data.person === this.data.id) || ( item.data.id && item.data.id === this.data.person) || @@ -801,14 +846,21 @@ MWF.xApplication.Selector.Identity.ItemSelected = new Class({ items.each(function(item){ item.selectedItem = this; item.setSelected(); - var flag = this.selector.options.selectAllRange === "all" || - ( this.selector.selectType == "identity" && ( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ) ); - if( flag ){ - if(item.category && item.category._addSelectedCount )item.category._addSelectedCount( 1, true ); + + if( this.selector.options.selectAllRange === "all" && !this.selector.isCheckStatusOrCount() ){ + if(item.category && item.category._addSelectAllSelectedCount )item.category._addSelectAllSelectedCount( 1, true ); } + }.bind(this)); } } + + if( !this.isFromValues ){ + if( this.selector.isCheckStatusOrCount() ){ + this.selector.addSelectedCount(this, 1, items||[]); + } + } + if( this.afterCheck )this.afterCheck(); } }); @@ -821,48 +873,33 @@ MWF.xApplication.Selector.Identity.ItemCategory = new Class({ "title" : this._getTtiteText() }).inject(this.container); }, - _addSelectedCount : function( count, nested ){ - var c = ( this._getSelectedCount() || 0 ) + count; + _addSelectAllSelectedCount : function( count, nested ){ + var c = ( this._getSelectAllSelectedCount() || 0 ) + count; this.selectedCount = c; - this.checkCountAndStatus( c ); - if( nested && this.category && this.category._addSelectedCount ){ - this.category._addSelectedCount(count, nested); + this._checkCountAndStatus( c ); + if( nested && this.category && this.category._addSelectAllSelectedCount ){ + this.category._addSelectAllSelectedCount(count, nested); } }, - checkCountAndStatus: function( count ){ - if( this.selector.options.showSelectedCount ){ - this.selectedCountNode.set("text", count ? "(" + count + ")" : "" ); - } - if( this.selector.options.isCheckStatus && this.selectAllNode ){ - var total = this._getTotalCount(); - if( total ){ - var styles; - if( count >= total ){ - styles = this.selector.css.selectorItemCategoryActionNode_selectAll_selected; - this.isSelectedSome = false; - this.isSelectedAll = true; - }else if( count > 0 ){ - styles = this.selector.css.selectorItemCategoryActionNode_selectsome_selected; - this.isSelectedSome = true; - this.isSelectedAll = false; - }else{ - styles = this.selector.css.selectorItemCategoryActionNode_selectAll; - this.isSelectedSome = false; - this.isSelectedAll = false; - } - this.selectAllNode.setStyles( styles ); - } - }else if( count === 0 && this.selector.options.selectAllRange === "all" && this.selectAllNode ){ - styles = this.selector.css.selectorItemCategoryActionNode_selectAll; - this.isSelectedSome = false; - this.isSelectedAll = false; - this.selectAllNode.setStyles( styles ); + _getSelectAllSelectedCount: function(){ + if( typeOf(this.selectedCount) === "number" ){ + return this.selectedCount; + }else{ + return 0; } + }, - // if( !this.selectedCountNode1 ){ - // this.selectedCountNode1 = new Element("span").inject(this.textNode); - // } - // this.selectedCountNode1.set("text",count); + _addSelectedCount : function( count, nested ){ //增加数字并向上回溯 + if( this.selector.loadingCount === "done" ){ + var c = ( this._getSelectedCount() || 0 ) + count; + this.selectedCount = c; + this._checkCountAndStatus( c ); + }else{ + this.selectedCount_wait = (this.selectedCount_wait || 0) + count; + } + if( nested && this.category && this.category._addSelectedCount ){ + this.category._addSelectedCount(count, nested); + } }, _getShowName: function(){ // if( this._getTotalCount && this._getSelectedCount ){ @@ -882,15 +919,15 @@ MWF.xApplication.Selector.Identity.ItemCategory = new Class({ if( !this.selector.allUnitObject )return 0; var unit = this.selector.allUnitObject[this.data.levelName]; var count = unit ? unit.selectedNestedIdentityCount : 0; - this.selectedCount = count; - return count; + this.selectedCount = count + (this.selectedCount_wait || 0); + this.selectedCount_wait = 0; + return this.selectedCount; }, _setIcon: function(){ var style = this.selector.options.style; this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/companyicon.png)"); }, _beforeSelectAll : function( _selectAllFun ){ - debugger; if( this.selector.options.ignorePerson || ( this.selector.options.storeRange === "simple" && this.selector.options.resultType !== "person") ){ _selectAllFun(); return; @@ -1003,38 +1040,40 @@ MWF.xApplication.Selector.Identity.ItemCategory = new Class({ // } // }else{ - var loadSubUnit = function () { - if( this.selector.options.expandSubEnable && !this.categoryLoaded ){ - 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( true ); - }.bind(this), null, this.data.distinguishedName); - }else{ - this.loaded = true; - if (callback) callback( true ); - } - }.bind(this); - - if( !this.itemLoaded ){ - 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 ); + var loadSubUnit = function () { + if( this.selector.options.expandSubEnable && !this.categoryLoaded ){ + this.selector.orgAction.listSubUnitDirect(function(json){ + json.data.each(function(subData){ + if( !this.selector.isExcluded( subData ) ) { + if( subData && this.data.parentLevelName)subData.parentLevelName = this.data.parentLevelName +"/" + subData.name; + var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this); + this.subCategorys.push( category ); + this.subCategoryMap[subData.parentLevelName || subData.levelName] = category; } }.bind(this)); - loadSubUnit(); + this.loaded = true; + if (callback) callback( true ); }.bind(this), null, this.data.distinguishedName); }else{ - loadSubUnit(); + this.loaded = true; + if (callback) callback( true ); } + }.bind(this); + + if( !this.itemLoaded ){ + 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)); + loadSubUnit(); + }.bind(this), null, this.data.distinguishedName); + }else{ + loadSubUnit(); + } // } }else{ @@ -1054,9 +1093,10 @@ MWF.xApplication.Selector.Identity.ItemCategory = new Class({ }, afterLoad: function(){ if (this.level===1) this.clickItem(); - if( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ){ - var count = this._getSelectedCount(); - this.checkCountAndStatus( count ); + if( this.selector.isCheckStatusOrCount() ) { + if (this.selector.loadingCount === "done"){ + this.checkCountAndStatus(); + } } }, @@ -1096,8 +1136,10 @@ MWF.xApplication.Selector.Identity.ItemCategory = new Class({ this.selector.orgAction.listSubUnitDirect(function(json){ json.data.each(function(subData){ if( !this.selector.isExcluded( subData ) ) { + if( subData && this.data.parentLevelName)subData.parentLevelName = this.data.parentLevelName +"/" + subData.name; var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this); this.subCategorys.push( category ); + this.subCategoryMap[subData.parentLevelName || subData.levelName] = category; } }.bind(this)); this.categoryLoaded = true; @@ -1134,17 +1176,17 @@ MWF.xApplication.Selector.Identity.ItemCategory = new Class({ // }.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); + 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( ); @@ -1309,9 +1351,11 @@ MWF.xApplication.Selector.Identity.ItemGroupCategory = new Class({ // }.bind(this)) // } + if( this.selector.options.expandSubEnable ){ ( this.data.unitList || [] ).each( function(u){ this.selector.orgAction.getUnit(function (json) { + if( json.data && this.data.parentLevelName)json.data.parentLevelName = this.data.parentLevelName +"/" + json.data.levelName; this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this); checkCallback("unit"); }.bind(this), function(){ checkCallback("unit") }, u ); @@ -1319,6 +1363,7 @@ MWF.xApplication.Selector.Identity.ItemGroupCategory = new Class({ ( this.data.groupList || [] ).each( function(g){ this.selector.orgAction.getGroup(function (json) { + if( json.data && this.data.parentLevelName)json.data.parentLevelName = this.data.parentLevelName +"/" + json.data.name; this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this); checkCallback("group"); }.bind(this), function(){ checkCallback("group") }, g ); @@ -1380,6 +1425,7 @@ MWF.xApplication.Selector.Identity.ItemGroupCategory = new Class({ if( this.selector.options.expandSubEnable ){ ( this.data.unitList || [] ).each( function(u){ this.selector.orgAction.getUnit(function (json) { + if( json.data && this.data.parentLevelName)json.data.parentLevelName = this.data.parentLevelName +"/" + json.data.levelName; this.selector.includeObject.loadUnitItem(json, unitContainer, this.level + 1, this); checkCallback("unit"); }.bind(this), function(){ checkCallback("unit") }, u ); @@ -1387,6 +1433,7 @@ MWF.xApplication.Selector.Identity.ItemGroupCategory = new Class({ ( this.data.groupList || [] ).each( function(g){ this.selector.orgAction.getGroup(function (json) { + if( json.data && this.data.parentLevelName)json.data.parentLevelName = this.data.parentLevelName +"/" + json.data.name; this.selector.includeObject.loadGroupItem(json, groupContainer, this.level + 1, this); checkCallback("group"); }.bind(this), function(){ checkCallback("group") }, g ); @@ -1565,6 +1612,7 @@ MWF.xApplication.Selector.Identity.Include = new Class({ flatCategoryContainer = new Element("div").inject( this.flatCategoryAreaNode ); } + if (typeOf(d)==="string"){ var arr = d.split("@"); var flag = arr[ arr.length - 1].toLowerCase(); @@ -1580,6 +1628,7 @@ MWF.xApplication.Selector.Identity.Include = new Class({ }.bind(this), checkCallback, d); }else if( flag === "g" ){ this.orgAction.listGroupByKey(function(json){ + json.data.each(function(d){ d.parentLevelName = d.name; }); this.loadGroupItem( json , container, null, null, flatCategoryContainer); checkCallback(); }.bind(this), checkCallback, d); @@ -1623,6 +1672,7 @@ MWF.xApplication.Selector.Identity.Include = new Class({ }.bind(this), checkCallback, d.distinguishedName); }else if( flag === "g" ){ this.orgAction.getGroup(function(json){ + json.data.each(function(d){ d.parentLevelName = d.name; }); this.loadGroupItem( json , container, null, null, flatCategoryContainer); checkCallback(); }.bind(this), checkCallback, d.distinguishedName, null, null, true); @@ -1717,9 +1767,11 @@ MWF.xApplication.Selector.Identity.Include = new Class({ container || this.includeAreaNode, level, parentCategory); } if( parentCategory && parentCategory.subCategorys ){ - parentCategory.subCategorys.push( category ) + parentCategory.subCategorys.push( category ); + if(parentCategory.subCategoryMap)parentCategory.subCategoryMap[data.parentLevelName || data.levelName] = category; }else if(this.selector.subCategorys){ - this.selector.subCategorys.push( category ) + this.selector.subCategorys.push( category ); + this.selector.subCategoryMap[data.parentLevelName || data.levelName] = category; } } }.bind(this)); @@ -1740,9 +1792,11 @@ MWF.xApplication.Selector.Identity.Include = new Class({ category = this.selector._newItemCategory("ItemGroupCategory", data, this.selector, container || this.includeAreaNode, level, parentCategory) } if( parentCategory && parentCategory.subCategorys ){ - parentCategory.subCategorys.push( category ) + parentCategory.subCategorys.push( category ); + if(parentCategory.subCategoryMap)parentCategory.subCategoryMap[data.parentLevelName || data.name] = category; }else if(this.selector.subCategorys){ - this.selector.subCategorys.push( category ) + this.selector.subCategorys.push( category ); + this.selector.subCategoryMap[data.parentLevelName || data.name] = category; } } }.bind(this)); diff --git a/o2web/source/x_component_Selector/IdentityWidthDuty.js b/o2web/source/x_component_Selector/IdentityWidthDuty.js index 0d3be6e7c1b9b62929a03eccc918ab3ac20e98e6..5e2ccaf239d0666bac4c3fda95f7a99f15b6059c 100644 --- a/o2web/source/x_component_Selector/IdentityWidthDuty.js +++ b/o2web/source/x_component_Selector/IdentityWidthDuty.js @@ -1,7 +1,7 @@ MWF.xApplication.Selector = MWF.xApplication.Selector || {}; MWF.xDesktop.requireApp("Selector", "Identity", null, false); MWF.xApplication.Selector.IdentityWidthDuty = new Class({ - Extends: MWF.xApplication.Selector.Identity, + Extends: MWF.xApplication.Selector.Identity, options: { "style": "default", "count": 0, @@ -23,10 +23,12 @@ MWF.xApplication.Selector.IdentityWidthDuty = new Class({ this.setOptions({"title": MWF.xApplication.Selector.LP.selectIdentity}); }, _init : function(){ - this.selectType = "identity"; - this.className = "IdentityWidthDuty" + this.selectType = "identity"; + this.className = "IdentityWidthDuty" }, loadSelectItems: function(addToNext){ + this.loadingCountDuty = "wait"; + this.allUnitObjectWithDuty = {}; var afterLoadSelectItemFun = this.afterLoadSelectItem.bind(this); if( this.options.disabled ){ this.afterLoadSelectItem(); @@ -61,10 +63,15 @@ MWF.xApplication.Selector.IdentityWidthDuty = new Class({ }.bind(this)); var loadDuty = function () { + if( this.isCheckStatusOrCount() ){ + this.loadingCountDuty = "ready"; + this.checkLoadingCount(); + } this.options.dutys.each(function(duty){ var data = {"name": duty, "id":duty}; var category = this._newItemCategory("ItemCategory",data, this, this.itemAreaNode); this.subCategorys.push(category); + this.allUnitObjectWithDuty[data.name] = category; loadDutySuccess(); }.bind(this)); }.bind(this); @@ -136,6 +143,11 @@ MWF.xApplication.Selector.IdentityWidthDuty = new Class({ } } } + + if( this.isCheckStatusOrCount() ) { + this.loadingCountInclude = "wait"; + this.loadIncludeCount(); + } }, search: function(){ @@ -209,7 +221,75 @@ MWF.xApplication.Selector.IdentityWidthDuty = new Class({ }, _newItemSearch: function(data, selector, container, level){ return new MWF.xApplication.Selector.IdentityWidthDuty.SearchItem(data, selector, container, level); - } + }, + uniqueIdentityList: function(list){ + var items = [], map = {}; + (list||[]).each(function(d) { + if (d.distinguishedName || d.unique) { + if ((!d.distinguishedName || !map[d.distinguishedName]) && (!d.unique || !map[d.unique])) { + items.push(d); + map[d.distinguishedName] = true; + map[d.unique] = true; + } + } else { + items.push(d); + } + }) + return items; + }, + loadIncludeCount: function(){ + + var unitList = []; + var groupList = []; + + if (this.options.include.length > 0) { + this.options.include.each(function (d) { + var dn = typeOf(d) === "string" ? d : d.distinguishedName; + var flag = dn.split("@").getLast().toLowerCase(); + if (flag === "u") { + unitList.push(dn); + } else if (flag === "g") { + groupList.push(dn) + } + }) + } + + if(unitList.length || groupList.length){ + this._loadUnitAndGroupCount(unitList, groupList, function () { + this.loadingCountInclude = "ready"; + this.checkLoadingCount(); + }.bind(this)); + }else{ + this.loadingCountInclude = "ignore"; + this.checkLoadingCount(); + } + }, + checkLoadingCount: function(){ + if(this.loadingCountDuty === "ready" && this.loadingCountInclude === "ready"){ + this.checkCountAndStatus(); + this.loadingCount = "done"; + }else if(this.loadingCountDuty === "ready" && this.loadingCountInclude === "ignore"){ + this.loadingCount = "done"; + } + }, + addSelectedCount: function( itemOrItemSelected, count, items ){ + if( this.loadingCountInclude === "ignore" ){ + this._addSelectedCountWithDuty(itemOrItemSelected, count, items); + }else{ + this._addSelectedCountWithDuty(itemOrItemSelected, count, items); + this._addSelectedCount(itemOrItemSelected, count); + } + + }, + _addSelectedCountWithDuty: function( itemOrItemSelected, count, items ){ + var itemData = itemOrItemSelected.data; + debugger; + items.each(function(item){ + if(item.category && item.category._addSelectedCount && item.category.className === "ItemCategory"){ + item.category._addSelectedCount( count ); + } + }.bind(this)); + }, //_listItemNext: function(last, count, callback){ // this.action.listRoleNext(last, count, function(json){ // if (callback) callback.apply(this, [json]); @@ -217,7 +297,7 @@ MWF.xApplication.Selector.IdentityWidthDuty = new Class({ //} }); MWF.xApplication.Selector.IdentityWidthDuty.Item = new Class({ - Extends: MWF.xApplication.Selector.Identity.Item, + Extends: MWF.xApplication.Selector.Identity.Item, _getShowName: function(){ return this.data.name; }, @@ -237,7 +317,7 @@ MWF.xApplication.Selector.IdentityWidthDuty.SearchItem = new Class({ }); MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected = new Class({ - Extends: MWF.xApplication.Selector.Identity.ItemSelected, + Extends: MWF.xApplication.Selector.Identity.ItemSelected, _getShowName: function(){ return this.data.name+((this.data.unitLevelName) ? "("+this.data.unitLevelName+")" : ""); }, @@ -253,6 +333,7 @@ MWF.xApplication.Selector.IdentityWidthDuty.ItemSelected = new Class({ MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory = new Class({ Extends: MWF.xApplication.Selector.Identity.ItemCategory, createNode: function(){ + this.className = "ItemCategory"; this.node = new Element("div", { "styles": this.selector.css.selectorItemCategory_department, "title" : this._getTtiteText() @@ -265,9 +346,16 @@ MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory = new Class({ var style = this.selector.options.style; this.iconNode.setStyle("background-image", "url("+"../x_component_Selector/$Selector/"+style+"/icon/companyicon.png)"); }, - _addSelectedCount : function(){ + _addSelectAllSelectedCount: function(){ var count = this._getSelectedCount(); - this.checkCountAndStatus(count); + this._checkCountAndStatus(count); + }, + + _addSelectedCount : function(){ + if( this.selector.loadingCount === "done" ){ + var count = this._getSelectedCount(); + this._checkCountAndStatus(count); + } }, _getTotalCount : function(){ return this.subItems.length; @@ -279,9 +367,12 @@ MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory = new Class({ loadSub : function(callback){ this._loadSub( function( firstLoad ) { if(firstLoad){ - if( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus ){ - var count = this._getSelectedCount(); - this.checkCountAndStatus(count); + if( this.selector.isCheckStatusOrCount() ){ + // var count = this._getSelectedCount(); + // this.checkCountAndStatus(count); + if( this.selector.loadingCount === "done" ){ + this.checkCountAndStatus(); + } } } if(callback)callback(); @@ -299,7 +390,8 @@ MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory = new Class({ }; MWF.Actions.get("x_organization_assemble_express").getDuty(data, function(json){ - json.data.each(function(idSubData){ + var list = this.selector.uniqueIdentityList(json.data); + list.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); @@ -316,82 +408,83 @@ MWF.xApplication.Selector.IdentityWidthDuty.ItemCategory = new Class({ }.bind(this), null, false); - // if (this.selector.options.units.length){ - // var action = MWF.Actions.get("x_organization_assemble_express"); - // var data = {"name":this.data.name, "unit":""}; - // var count = this.selector.options.units.length; - // var i = 0; - // - // if (this.selector.options.expandSubEnable) { - // this.selector.options.units.each(function(u){ - // var unitName = ""; - // if (typeOf(u)==="string"){ - // unitName = u; - // }else{ - // unitName = u.distinguishedName || u.unique || u.id || u.levelName - // } - // if (unitName){ - // var unitNames; - // action.listUnitNameSubNested({"unitList": [unitName]}, function(json){ - // unitNames = json.data.unitList; - // }.bind(this), null, false); - // - // unitNames.push(unitName); - // if (unitNames && unitNames.length){ - // data.unitList = unitNames; - // action.getDuty(data, function(json){ - // json.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)); - // }.bind(this), null, false); - // } - // } - // - // i++; - // if (i>=count){ - // if (!this.loaded) { - // this.loaded = true; - // this.loadingsub = false; - // this.itemLoaded = true; - // if (callback) callback(); - // } - // } - // }.bind(this)); - // }else{ - // this.selector.options.units.each(function(u){ - // if (typeOf(u)==="string"){ - // data.unit = u; - // }else{ - // data.unit = u.distinguishedName || u.unique || u.id || u.levelName - // } - // action.getDuty(data, function(json){ - // json.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)); - // i++; - // if (i>=count){ - // if (!this.loaded) { - // this.loaded = true; - // this.loadingsub = false; - // this.itemLoaded = true; - // if (callback) callback(); - // } - // } - // }.bind(this)); - // }.bind(this)); - // } + // if (this.selector.options.units.length){ + // var action = MWF.Actions.get("x_organization_assemble_express"); + // var data = {"name":this.data.name, "unit":""}; + // var count = this.selector.options.units.length; + // var i = 0; + // + // if (this.selector.options.expandSubEnable) { + // this.selector.options.units.each(function(u){ + // var unitName = ""; + // if (typeOf(u)==="string"){ + // unitName = u; + // }else{ + // unitName = u.distinguishedName || u.unique || u.id || u.levelName + // } + // if (unitName){ + // var unitNames; + // action.listUnitNameSubNested({"unitList": [unitName]}, function(json){ + // unitNames = json.data.unitList; + // }.bind(this), null, false); + // + // unitNames.push(unitName); + // if (unitNames && unitNames.length){ + // data.unitList = unitNames; + // action.getDuty(data, function(json){ + // json.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)); + // }.bind(this), null, false); + // } + // } + // + // i++; + // if (i>=count){ + // if (!this.loaded) { + // this.loaded = true; + // this.loadingsub = false; + // this.itemLoaded = true; + // if (callback) callback(); + // } + // } + // }.bind(this)); + // }else{ + // this.selector.options.units.each(function(u){ + // if (typeOf(u)==="string"){ + // data.unit = u; + // }else{ + // data.unit = u.distinguishedName || u.unique || u.id || u.levelName + // } + // action.getDuty(data, function(json){ + // json.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)); + // i++; + // if (i>=count){ + // if (!this.loaded) { + // this.loaded = true; + // this.loadingsub = false; + // this.itemLoaded = true; + // if (callback) callback(); + // } + // } + // }.bind(this)); + // }.bind(this)); + // } }else{ this.selector.orgAction.listIdentityWithDuty(function(json){ - json.data.each(function(idSubData){ + var list = this.selector.uniqueIdentityList(json.data); + list.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); @@ -433,7 +526,8 @@ MWF.xApplication.Selector.IdentityWidthDuty.ItemUnitCategory = new Class({ if (!this.loaded){ this.selector.orgAction.listIdentityWithUnit(function(idJson){ if( !this.itemLoaded ){ - idJson.data.each(function(idSubData){ + var list = this.selector.uniqueIdentityList(idJson.data); + list.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); @@ -452,8 +546,10 @@ MWF.xApplication.Selector.IdentityWidthDuty.ItemUnitCategory = new Class({ this.selector.orgAction.listSubUnitDirect(function(json){ json.data.each(function(subData){ if( !this.selector.isExcluded( subData ) ) { + if( subData && this.data.parentLevelName)subData.parentLevelName = this.data.parentLevelName +"/" + subData.name; var category = this.selector._newItemCategory("ItemUnitCategory", subData, this.selector, this.children, this.level + 1, this); this.subCategorys.push( category ); + this.subCategoryMap[subData.parentLevelName || subData.levelName] = category; } }.bind(this)); this.loaded = true; @@ -491,7 +587,8 @@ MWF.xApplication.Selector.IdentityWidthDuty.ItemUnitCategory = new Class({ loadItemChildren: function(callback){ if (!this.itemLoaded){ this.selector.orgAction.listIdentityWithUnit(function(idJson){ - idJson.data.each(function(idSubData){ + var list = this.selector.uniqueIdentityList(idJson.data); + list.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); diff --git a/o2web/source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js b/o2web/source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js index 664dc2da7b157a3986f70f00d9f6dd8b3279587e..64895fea8613cac9a28cb20098640569628e2f6b 100644 --- a/o2web/source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js +++ b/o2web/source/x_component_Selector/IdentityWidthDutyCategoryByUnit.js @@ -28,74 +28,6 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({ this.selectType = "identity"; this.className = "IdentityWidthDutyCategoryByUnit"; }, - // loadSelectItems: function (addToNext) { - // //根据组织分类展现职务 - // 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.disabled) { - // this.afterLoadSelectItem(); - // return; - // } - // - // if (this.options.dutys.length) { - // this.loadInclude(function () { - // this.includeLoaded = true; - // if (this.dutyLoaded) { - // this.afterLoadSelectItem(); - // } - // }.bind(this)); - // if (this.options.units.length) { - // - // var units = []; - // for (var i = 0; i < this.options.units.length; i++) { - // var unit = this.options.units[i]; - // if (typeOf(unit) === "string") { - // units.push(unit) - // } else { - // units.push(unit.distinguishedName || unit.unique || unit.id || unit.levelName) - // } - // } - // this.unitStringList = units; - // - // var getAllIdentity = function (unitList) { - // o2.Actions.load("x_organization_assemble_express").UnitDutyAction.listIdentityWithUnitWithNameObject({ - // nameList: this.options.dutys, - // unitList: unitList - // }, function (json) { - // this._loadSelectItems(json.data) - // }.bind(this)) - // }.bind(this); - // - // if (this.options.expandSubEnable) { - // o2.Actions.load("x_organization_assemble_express").UnitAction.listWithUnitSubNested({ - // unitList: units - // }, function (json) { - // getAllIdentity(units.combine(json.data ? json.data.unitList : [])); - // }.bind(this)) - // } else { - // getAllIdentity(units); - // } - // } else { - // var identityList = []; - // var count = 0; - // this.options.dutys.each(function (d) { - // this.orgAction.listIdentityWithDuty(function (json) { - // count++; - // identityList = identityList.combine(json.data); - // if (this.options.dutys.length === count) this._loadSelectItems(identityList); - // }.bind(this), function () { - // count++; - // if (this.options.dutys.length === count) this._loadSelectItems(identityList); - // }.bind(this), d); - // }.bind(this)); - // } - // } - // }, getUnitUniqueFormDn : function(dn){ if(!dn)return ""; var arr = dn.split("@"); @@ -139,40 +71,54 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({ this.unitStringList = units; this.unitUniqueList = unitUniques; + this.loadingCountDuty = "wait"; + o2.Actions.load("x_organization_assemble_express").UnitDutyAction.listIdentityWithUnitWithNameObject({ nameList: this.options.dutys, unitList: units, recursiveUnit : !!this.options.expandSubEnable }, function (json) { this.allIdentityData = json.data; + + this.setUnitLevelNameMap(); //如果需要检查状态,创建身份-所在组织层次名对应关系 + // this.setUnitLevelNameMapInValues(); //如果需要检查状态,创建已选值身份-所在组织层次名对应关系 + this._loadSelectItems(json.data) }.bind(this)) }else{ this.afterLoadSelectItem(); } + + if( this.isCheckStatusOrCount() ) { + this.loadingCountInclude = "wait"; + this.loadIncludeCount(); + } }, _loadSelectItems: function (identityList) { //this.listAllIdentityInUnitObject( identityList ); - var unitTree = this.listNestedUnitByIdentity(identityList); - this.dataTree = unitTree; - this.uniqueIdentity(unitTree); - if (this.options.dutyUnitLevelBy === "duty") { - this.level1Container = []; - if (this.options.units && this.options.units.length) { - this.options.units.each( function (unit ,i) { - var div = new Element("div").inject(this.itemAreaNode); - this.level1Container.push(div); - }.bind(this)) + this.listNestedUnitByIdentity(identityList, function (unitTree) { + this.dataTree = unitTree; + this.uniqueIdentity(unitTree); + this.loadingCountDuty = "ready"; + this.checkLoadingCount(); + if (this.options.dutyUnitLevelBy === "duty") { + this.level1Container = []; + if (this.options.units && this.options.units.length) { + this.options.units.each( function (unit ,i) { + var div = new Element("div").inject(this.itemAreaNode); + this.level1Container.push(div); + }.bind(this)) + } + this._loadSelectItemsByDutyUnit(unitTree); + } else { + this._loadSelectItemsByIdentityUnit(unitTree); } - this._loadSelectItemsByDutyUnit(unitTree); - } else { - this._loadSelectItemsByIdentityUnit(unitTree); - } - this.dutyLoaded = true; - if (this.includeLoaded) { - this.afterLoadSelectItem(); - } + this.dutyLoaded = true; + if (this.includeLoaded) { + this.afterLoadSelectItem(); + } + }.bind(this)); }, _loadSelectItemsByIdentityUnit: function (unitTree) { if (!unitTree.unitList) return; @@ -182,6 +128,9 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({ // if( !this.isExcluded( unit ) ) { var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode); this.subCategorys.push(category); + + var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName"; + this.subCategoryMapWithDuty[unit.matchLevelName || unit.levelName] = category; // } } }, @@ -226,6 +175,7 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({ } var category = this._newItemCategory("ItemCategory", unit, this, container); this.subCategorys.push(category); + this.subCategoryMapWithDuty[unit.matchLevelName || unit.levelName] = category; // } } else { this._loadSelectItemsByDutyUnit(unit); @@ -274,24 +224,6 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({ } return flag; }, - // listAllIdentityInUnitObject: function () { - // var unitArray = []; - // for (var i = 0; i < identityList.length; i++) { - // unitArray.push(identityList[i].unit || identityList[i].unitLevelName); - // } - // o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({ - // unitList: unitArray - // }, function (json) { - // this.allIdentityInUnitObject = {}; - // json.data.each(function (u) { - // this.allIdentityInUnitObject[u.levelName] = u; - // }.bind(this)); - // if (callback) callback(); - // }.bind(this), null, false) - // }, - getUnitOrderNumber: function (unit) { - return this.allIdentityInUnitObject[unit.levelName].orderNumber; - }, listAllUnitObject: function (identityList, callback) { var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName"; var unitArray = []; @@ -311,18 +243,19 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({ o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({ unitList: unitArray }, function (json) { - this.allUnitObject = {}; + this.allUnitObjectWithDuty = {}; json.data.each(function (u) { - this.allUnitObject[u.levelName] = u; + this.allUnitObjectWithDuty[u.levelName] = u; }.bind(this)); if (callback) callback(); - }.bind(this), null, false) + }.bind(this)) }, - listNestedUnitByIdentity: function (identityList) { - this.listAllUnitObject(identityList); - return this._listNestedUnitByIdentity(identityList); + listNestedUnitByIdentity: function (identityList, callback) { + this.listAllUnitObject(identityList, function () { + this._listNestedUnitByIdentity(identityList, callback); + }.bind(this)); }, - _listNestedUnitByIdentity: function (identityList) { + _listNestedUnitByIdentity: function (identityList, callback) { debugger; //identityList = Array.unique(identityList); var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName"; @@ -341,7 +274,7 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({ nameList.push(unitLevelNameList[j]); var name = nameList.join("/"); - if (this.isExcluded(this.allUnitObject[name] || {})) { + if (this.isExcluded(this.allUnitObjectWithDuty[name] || {})) { flag = false; break; } @@ -357,20 +290,20 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({ } if (!found) { // var obj = {}; - var obj = this.allUnitObject[name] || {}; + var obj = this.allUnitObjectWithDuty[name] || {}; obj.matchLevelName = name; tree.unitList.push(obj); tree = obj; } // if( !tree.distinguishedName ){ - // tree = Object.merge( tree, this.allUnitObject[name] ); + // tree = Object.merge( tree, this.allUnitObjectWithDuty[name] ); // } if (!tree.identityList) tree.identityList = []; } if (flag) tree.identityList.push(identityList[i]); } - return unitTree; + if(callback)callback(unitTree); }, uniqueIdentity: function (tree) { @@ -406,7 +339,6 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({ if (!isExist(tree.identityList[i], i)){ identityList.push(tree.identityList[i]); }else if( this.options.identitySortBy !== "identityNumber" ){ - debugger; var index = getIndex(tree.identityList[i]); if( index > -1 ){ var identity = tree.identityList[index]; @@ -424,15 +356,22 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({ } tree.identityList = identityList; - if (this.options.isCheckStatus) { + if (this.isCheckStatusOrCount()) { var names = (tree.matchLevelName || tree.levelName || "").split("/"); var nameList = []; + + var selectedCount = 0; + tree.identityList.each(function (id) { + if( this.isInValues(id) )selectedCount++; + }.bind(this)); + for (var i = 0; i < names.length; i++) { nameList.push(names[i]); var name = nameList.join("/"); - var obj = this.allUnitObject[name]; + var obj = this.allUnitObjectWithDuty[name]; if (obj) { obj.subNestedIdentityCount = (obj.subNestedIdentityCount || 0) + identityList.length; + obj.selectedNestedIdentityCount = (obj.selectedNestedIdentityCount || 0) + selectedCount; } } } @@ -564,7 +503,121 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit = new Class({ }, _newItemSearch: function (data, selector, container, level) { return new MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.SearchItem(data, selector, container, level); - } + }, + setUnitLevelNameMap: function(){ + var map = this.unitLevelNameMap = {}; + if (this.isCheckStatusOrCount() && this.allIdentityData.length > 0) { + var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName"; + this.allIdentityData.each(function(id) { + if (!map[id.distinguishedName]) { + map[id.distinguishedName] = [id[key]]; + }else if( !map[id.distinguishedName].contains(id[key]) ){ + map[id.distinguishedName].push(id[key]); + } + }) + } + }, + getUnitLevelNameFormMap: function(id){ + return (this.unitLevelNameMap && this.unitLevelNameMap[id.distinguishedName]) || []; + }, + addSelectedCount: function( itemOrItemSelected, count ){ + if( this.loadingCountInclude === "ignore" ){ + this._addSelectedCountWithDuty(itemOrItemSelected, count); + }else{ + this._addSelectedCountWithDuty(itemOrItemSelected, count); + this._addSelectedCount(itemOrItemSelected, count); + } + + }, + _addSelectedCountWithDuty: function( itemOrItemSelected, count ){ + var itemData = itemOrItemSelected.data; + var unitlevelNameList = this.getUnitLevelNameFormMap(itemData); + unitlevelNameList.each(function (levelName) { + var subCategoryMap = this.subCategoryMapWithDuty; + var list = levelName.split("/"); + var nameList = []; + for (var j = 0; j < list.length; j++) { + nameList.push(list[j]); + var name = nameList.join("/"); + if ( subCategoryMap[name] ) { + var category = subCategoryMap[name]; + category._addSelectedCount(count); + subCategoryMap = category.subCategoryMapWithDuty; + } + + var obj = this.allUnitObjectWithDuty[name]; + if (obj) { + obj.selectedNestedIdentityCount = obj.selectedNestedIdentityCount + count; + } + } + }.bind(this)); + }, + + + // setUnitLevelNameMapInValues: function(){ //取消选择的时候用 + // var map = this.unitLevelNameMapInValues = {}; + // if (this.isCheckStatusOrCount() && this.options.values.length > 0) { + // var vMap = {}; + // this.options.values.each( function( e ){ + // if( !e )return; + // vMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.unique || e.levelName) ] = true; + // }.bind(this)); + // + // var key = this.options.dutyUnitLevelBy === "duty" ? "matchUnitLevelName" : "unitLevelName"; + // this.allIdentityData.each(function(id) { + // if (vMap[id.distinguishedName]) { + // if (!map[id.distinguishedName]) { + // map[id.distinguishedName] = [id[key]]; + // }else if( !map[id.distinguishedName].contains(id[key]) ){ + // map[id.distinguishedName].push(id[key]); + // } + // }else if (vMap[id.unique]) { + // if (!map[id.unique]) { + // map[id.unique] = [id[key]]; + // }else if( !map[id.unique].contains(id[key]) ){ + // map[id.unique].push(id[key]); + // } + // }else if (vMap[id.levelName]) { + // if (!map[id.levelName]) { + // map[id.levelName] = [id[key]]; + // }else if( !map[id.levelName].contains(id[key]) ){ + // map[id.levelName].push(id[key]); + // } + // } + // }) + // } + // }, + // getUnitLevelNameFormValueMap: function(id){ + // var map = this.unitLevelNameMapInValues; + // var list = []; + // if( map[id.distinguishedName] )list = list.concat(map[id.distinguishedName]); + // if( map[id.unique] )list = list.concat(map[id.unique]); + // if( map[id.levelName] )list = list.concat(map[id.levelName]); + // return list; + // }, + // checkCountAndStatusByUnselectItem: function( itemData ){ + // debugger; + // var unitlevelNameList = this.getUnitLevelNameFormValueMap(itemData); + // unitlevelNameList.each(function (levelName) { + // var subCategoryMap = this.subCategoryMap; + // var list = levelName.split("/"); + // var nameList = []; + // for (var j = 0; j < list.length; j++) { + // nameList.push(list[j]); + // var name = nameList.join("/"); + // if ( subCategoryMap[name] ) { + // var category = subCategoryMap[name]; + // category._addSelectedCount(-1); + // subCategoryMap = category.subCategoryMap; + // } + // + // var obj = this.allUnitObjectWithDuty[name]; + // if (obj) { + // obj.selectedNestedIdentityCount = obj.selectedNestedIdentityCount - 1; + // } + // } + // }.bind(this)); + // } //_listItemNext: function(last, count, callback){ // this.action.listRoleNext(last, count, function(json){ // if (callback) callback.apply(this, [json]); @@ -587,24 +640,17 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemCategory = new Cla _getShowName: function () { return this.data.name; }, - _addSelectedCount: function (count, nested) { + _addSelectAllSelectedCount: function (count, nested) { debugger; - var c = (this._getSelectedCount() || 0) + count; + var c = (this._getSelectAllSelectedCount() || 0) + count; this.selectedCount = c; - this.checkCountAndStatus(c); + this._checkCountAndStatus(c); - if (nested && this.category && this.category._addSelectedCount) { - this.category._addSelectedCount(count, nested); + if (nested && this.category && this.category._addSelectAllSelectedCount) { + this.category._addSelectAllSelectedCount(count, nested); } }, - // _getSelectedCount : function(){ - // var list = this.subItems.filter( function (item) { return item.isSelected; }); - // return list.length; - // }, - _getTotalCount: function () { - return this.data.subNestedIdentityCount; - }, - _getSelectedCount: function () { + _getSelectAllSelectedCount: function () { debugger; if (typeOf(this.selectedCount) === "number") { return this.selectedCount; @@ -612,8 +658,33 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemCategory = new Cla return 0; } }, - _checkStatus: function () { + + _addSelectedCount: function (count, nested) { + if( this.selector.loadingCount === "done" ){ + var c = (this._getSelectedCount() || 0) + count; + this.selectedCount = c; + this._checkCountAndStatus(c); + }else{ + this.selectedCount_wait = (this.selectedCount_wait || 0) + count; + } + + if (nested && this.category && this.category._addSelectedCount) { + this.category._addSelectedCount(count, nested); + } + }, + _getTotalCount: function () { + return this.data.subNestedIdentityCount; + }, + _getSelectedCount : function(){ + if( typeOf(this.selectedCount) === "number" )return this.selectedCount; + if( !this.selector.allUnitObjectWithDuty )return 0; + var levelName = this.data.matchLevelName || this.data.levelName; + var unit = this.selector.allUnitObjectWithDuty[levelName]; + var count = unit ? unit.selectedNestedIdentityCount : 0; + this.selectedCount = count + (this.selectedCount_wait || 0); + this.selectedCount_wait = 0; + return this.selectedCount; }, isExisted: function (d) { if (!d) return true; @@ -647,7 +718,6 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemCategory = new Cla return (a.orderNumber || 9999999) - (b.orderNumber || 9999999); }); }else{ - debugger; var getOrderNumber = function (d) { var orderNumber = "999"; if( d.matchUnitDutyName ){ @@ -670,7 +740,7 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemCategory = new Cla }); return array.min(); }else{ - return getOrderNumber(d); + return getOrderNumber(d); } }.bind(this); @@ -681,21 +751,12 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemCategory = new Cla }, loadSub: function (callback) { this._loadSub(function (firstLoad) { - if (firstLoad && (this.selector.options.showSelectedCount || this.selector.options.isCheckStatus)) { - var count = 0; - this.subCategorys.each(function (category) { - var l = category.subItems.filter(function (item) { - return item.isSelected; - }); - count = count + l.length; - }); + if (firstLoad && this.selector.isCheckStatusOrCount()) { - var list = this.subItems.filter(function (item) { - return item.isSelected; - }); - this.selectedCount = count + list.length; + if (this.selector.loadingCount === "done"){ + this.checkCountAndStatus(); + } - this.checkCountAndStatus(this.selectedCount); } if (callback) callback(); }.bind(this)) @@ -731,6 +792,7 @@ MWF.xApplication.Selector.IdentityWidthDutyCategoryByUnit.ItemCategory = new Cla // if( !this.selector.isExcluded( subData ) ) { var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level + 1, this); this.subCategorys.push(category); + this.subCategoryMapWithDuty[subData.matchLevelName || subData.levelName] = category; // category.loadSub() // } }.bind(this)); diff --git a/o2web/source/x_component_Selector/Person.js b/o2web/source/x_component_Selector/Person.js index 5f563db84c5a99ebdcb42be3953a181d5e49d616..cd528b7a9d13a01d4846de2478c9368f4c7eb43b 100644 --- a/o2web/source/x_component_Selector/Person.js +++ b/o2web/source/x_component_Selector/Person.js @@ -13,7 +13,6 @@ MWF.xApplication.Selector.Person = new Class({ "roles": [], "values": [], "exclude" : [], - "exclude" : [], "zIndex": 1000, "expand": true, "embedded" : false, //是否嵌入在其他容器中 @@ -93,10 +92,15 @@ MWF.xApplication.Selector.Person = new Class({ this.subCategorys = []; //直接的分类 this.subItems = []; //直接的选择项 + this.subCategoryMap = {}; + this.subCategoryMapWithDuty = {}; + if( !this.options.values ){ this.options.values = []; } + this.availableStatusTypes = ["identity","custom"]; + this._init(); }, _init : function(){ @@ -1104,10 +1108,12 @@ MWF.xApplication.Selector.Person = new Class({ if (this.options.values.length){ this.options.values.each(function(v, i){ if (typeOf(v)==="object"){ + v.isFromValues = true; this.selectedItems.push(this._newItemSelected(v, this, null)); }else{ this._getItem(function(json){ this.options.values[i] = json.data; + json.data.isFromValues = true; this.selectedItems.push(this._newItemSelected(json.data, this, null)); }.bind(this), null, v, false); } @@ -1372,6 +1378,22 @@ MWF.xApplication.Selector.Person = new Class({ }.bind(this), null, role); }.bind(this)); }, + isInValues: function(d){ + if( this.options.values.length === 0 )return false; + if( !this.valueFlagMap ){ + this.valueFlagMap = {}; + this.options.values.each( function( e ){ + if( !e )return; + this.valueFlagMap[ typeOf( e ) === "string" ? e : ( e.distinguishedName || e.id || e.unique || e.employee || e.levelName) ] = true; + }.bind(this)); + } + var map = this.valueFlagMap; + return ( d.distinguishedName && map[ d.distinguishedName ] ) || + ( d.id && map[ d.id ] ) || + ( d.unique && map[ d.unique ] ) || + ( d.employee && map[ d.employee ] ) || + ( d.levelName && map[ d.levelName ] ); + }, isExcluded : function( d ){ if( this.options.exclude.length === 0 )return false; if( !this.excludeFlagMap ){ @@ -1555,8 +1577,6 @@ MWF.xApplication.Selector.Person = new Class({ }, setSize : function(){ - debugger; - if( !this.options.width && !this.options.height )return; var getOffsetX = function(node){ @@ -1761,6 +1781,39 @@ MWF.xApplication.Selector.Person = new Class({ } return subCategoryListNode; + }, + isCheckStatusOrCount: function(){ + if( this.isCheckStatusFlag )return this.isCheckStatusFlag === "y"; + if( this.availableStatusTypes.contains(this.selectType) && + ( this.options.count.toInt() !== 1) && (this.options.resultType !== "person") && + ( this.options.showSelectedCount || this.options.isCheckStatus ) ){ + + if( this.selectType === "unit" ){ + if( this.options.expandSubEnable ){ + this.isCheckStatusFlag = "y"; + return true; + }else{ + this.isCheckStatusFlag = "n"; + return false; + } + }else{ + this.isCheckStatusFlag = "y"; + return true; + } + }else{ + this.isCheckStatusFlag = "n"; + return false; + } + }, + checkCountAndStatus: function(){ + if( this.subCategorys && this.subCategorys.length ){ + this.subCategorys.each(function (category) { + if(category.checkCountAndStatus)category.checkCountAndStatus(true); + }) + } + }, + addSelectedCount: function( itemOrItemSelected, count ){ + } //checkClickFlatCategoryItem : function(categoryItemNode, itemNodeContainer){ // if( !this.flatCategorySeqObj_current ){ @@ -1827,6 +1880,8 @@ MWF.xApplication.Selector.Person.Item = new Class({ this.category = category; this.subItems = []; this.subCategorys = []; + this.subCategoryMap = {}; + this.subCategoryMapWithDuty = {}; if(!delay)this.load(); }, _getShowName: function(){ @@ -1975,7 +2030,7 @@ MWF.xApplication.Selector.Person.Item = new Class({ // this.selectedSingle( checkValid ); // }else{ if (this.isSelected){ - this.unSelected( checkValid ); + this.unSelected( checkValid); }else{ this.selected( checkValid ); } @@ -2139,17 +2194,28 @@ MWF.xApplication.Selector.Person.Item = new Class({ }.bind(this)) } + + var countItems = []; if (this.selectedItem){ this.selector.selectedItems.erase(this.selectedItem); - this.selectedItem.items.each(function(item){ - if( item.isSelected || ( item === this && isSelected ) ){ - var flag = this.selector.options.selectAllRange === "all" || - ( this.selector.selectType == "identity" && ( this.selector.options.showSelectedCount || this.selector.options.isCheckStatus )); - if( flag ){ - if(item.category && item.category._addSelectedCount )item.category._addSelectedCount( -1, true ); + debugger; + + if( this.selector.isCheckStatusOrCount()){ + this.selectedItem.items.each(function(item){ + if( item.isSelected || ( item === this && isSelected ) ){ + countItems.push(item); } - } + }.bind(this)); + }else if( this.selector.options.selectAllRange === "all" ){ + this.selectedItem.items.each(function(item) { + if (item.isSelected || (item === this && isSelected)) { + if (item.category && item.category._addSelectAllSelectedCount) item.category._addSelectAllSelectedCount(-1, true); + } + }.bind(this)) + } + + this.selectedItem.items.each(function(item){ if (item != this){ item.isSelected = false; @@ -2168,6 +2234,11 @@ MWF.xApplication.Selector.Person.Item = new Class({ this.selectedItem.destroy(); this.selectedItem = null; } + + if( this.selector.isCheckStatusOrCount()){ + this.selector.addSelectedCount( this, -1, countItems ); + } + this.selector.fireEvent("unselectItem",[this]); if( checkValid )this.selector.fireEvent("valid", [this.selector, this]); if(callback)callback(); @@ -2202,6 +2273,11 @@ MWF.xApplication.Selector.Person.ItemSelected = new Class({ }).inject(this.container); this.node.setStyle("display","none"); + if(this.data.isFromValues){ + this.isFromValues = true; + this.data.isFromValues = false; + } + this.getData(function(){ this.node.setStyle("display",""); this.load(); @@ -2223,13 +2299,30 @@ MWF.xApplication.Selector.Person.ItemSelected = new Class({ }, clickItem: function( callback, checkValid ){ if (this.items.length){ + var items = [], map = {}; this.items.each(function(item){ + if( item.data.distinguishedName || item.data.unique ){ + if( (!item.data.distinguishedName || !map[item.data.distinguishedName]) && ( !item.data.unique || !map[item.data.unique])){ + items.push(item); + map[item.data.distinguishedName] = true; + map[item.data.unique] = true; + } + }else{ + items.push(item); + } + }); + items.each(function(item){ item.unSelected( checkValid ); }); if( checkValid )this.selector.fireEvent("valid", [this.selector, this]) }else{ //this.item.selectedItem = null; //this.item.isSelected = false; + + if( this.selector.isCheckStatusOrCount()){ + this.selector.addSelectedCount( this, -1, [] ); + } + this.destroy(); this.selector.selectedItems.erase(this); if( checkValid )this.selector.fireEvent("valid", [this.selector, this]) @@ -2320,6 +2413,8 @@ MWF.xApplication.Selector.Person.ItemCategory = new Class({ this.category = parentCategory; this.subItems = []; this.subCategorys = []; + this.subCategoryMap = {}; + this.subCategoryMapWithDuty = {}; if(!delay)this.load(); }, load : function(){ @@ -2500,7 +2595,7 @@ MWF.xApplication.Selector.Person.ItemCategory = new Class({ var m = this.textNode.getStyle("margin-left").toFloat()+indent; this.textNode.setStyle("margin-left", ""+m+"px"); - if( this.selector.options.showSelectedCount && this.selector.selectType == "identity" ){ + if( this.selector.options.showSelectedCount && this.selector.availableStatusTypes.contains(this.selector.selectType) ){ this.selectedCountNode = new Element("span").inject(this.textNode); } @@ -2650,7 +2745,7 @@ MWF.xApplication.Selector.Person.ItemCategory = new Class({ var styles = this.selector.css.selectorItemCategoryActionNode_selectAll_selected; - if( this.selector.options.isCheckStatus && this.selector.selectType === "identity" ){ + if( this.selector.options.isCheckStatus && this.selector.availableStatusTypes.contains(this.selector.selectType) ){ if( this._getSelectedCount() < this._getTotalCount() ){ styles = this.selector.css.selectorItemCategoryActionNode_selectsome_selected; } @@ -2829,8 +2924,62 @@ MWF.xApplication.Selector.Person.ItemCategory = new Class({ }else{ return this.data.name; } + }, + checkCountAndStatus: function( nestedSub ){ + var count = this._getSelectedCount(); + this._checkCountAndStatus(count); + if( nestedSub && this.subCategorys && this.subCategorys.length){ + this.subCategorys.each(function(category){ + if( category.checkCountAndStatus )category.checkCountAndStatus(nestedSub); + }.bind(this)) + } + }, + _checkCountAndStatus: function( count ){ + if( this.selector.isCheckStatusOrCount() ){ + if(this.selectedCountNode){ + if( this.selector.options.showSelectedCount && this.selector.options.showAllCount ){ + var totalCount = this._getTotalCount(); + if(count || totalCount)this.selectedCountNode.set("text", (count||0)+"/"+ (totalCount||0)); + }else if(this.selector.options.showSelectedCount){ + this.selectedCountNode.set("text", count ? "(" + count + ")" : "" ); + }else if(this.selector.options.showAllCount){ + var totalCount = this._getTotalCount(); + this.selectedCountNode.set("text", totalCount ? "(" + totalCount + ")" : "" ); + } + } + if( this.selector.options.isCheckStatus && this.selectAllNode ){ + var total = this._getTotalCount(); + if( total ){ + var styles; + if( count >= total ){ + styles = this.selector.css.selectorItemCategoryActionNode_selectAll_selected; + this.isSelectedSome = false; + this.isSelectedAll = true; + }else if( count > 0 ){ + styles = this.selector.css.selectorItemCategoryActionNode_selectsome_selected; + this.isSelectedSome = true; + this.isSelectedAll = false; + }else{ + styles = this.selector.css.selectorItemCategoryActionNode_selectAll; + this.isSelectedSome = false; + this.isSelectedAll = false; + } + this.selectAllNode.setStyles( styles ); + } + } + }else if( count === 0 && this.selector.options.selectAllRange === "all" && this.selectAllNode ){ + styles = this.selector.css.selectorItemCategoryActionNode_selectAll; + this.isSelectedSome = false; + this.isSelectedAll = false; + this.selectAllNode.setStyles( styles ); + } + + // if( !this.selectedCountNode1 ){ + // this.selectedCountNode1 = new Element("span").inject(this.textNode); + // } + // this.selectedCountNode1.set("text",count); } -}); +}) MWF.xApplication.Selector.Person.ItemGroupCategory = new Class({ Extends: MWF.xApplication.Selector.Person.ItemCategory, diff --git a/o2web/source/x_component_Selector/Unit.js b/o2web/source/x_component_Selector/Unit.js index 7844f0f3e715bb884cd9c9a14a01b490051f6d1d..7e78e8059a8332b29eefaa3104c638997a8e5fe3 100644 --- a/o2web/source/x_component_Selector/Unit.js +++ b/o2web/source/x_component_Selector/Unit.js @@ -29,6 +29,9 @@ MWF.xApplication.Selector.Unit = new Class({ return; } + this._loadSelectItems(); + }, + _loadSelectItems: function(){ var afterLoadSelectItemFun = this.afterLoadSelectItem.bind(this); if (this.options.units.length){ @@ -41,6 +44,12 @@ MWF.xApplication.Selector.Unit = new Class({ unitList.push(unit.id || unit.distinguishedName || unit.unique || unit.levelName); } } + + if( this.isCheckStatusOrCount() ) { + this.loadingCount = "wait"; + this.loadCount( unitList ); + } + o2.Actions.load("x_organization_assemble_express").UnitAction.listObject( {"unitList" : unitList} , function (json) { debugger; if (json.data.length){ @@ -49,6 +58,7 @@ MWF.xApplication.Selector.Unit = new Class({ if (data.subDirectUnitCount){ var category = this._newItemCategory("ItemCategory", data, this, this.itemAreaNode ); this.subCategorys.push(category); + this.subCategoryMap[data.levelName] = category; } }else{ var item = this._newItem(data, this, this.itemAreaNode ); @@ -59,92 +69,25 @@ MWF.xApplication.Selector.Unit = new Class({ } afterLoadSelectItemFun(); }.bind(this), afterLoadSelectItemFun ) - - // var unitLoaded = 0; - // - // var loadUnitSuccess = function () { - // unitLoaded++; - // if( unitLoaded === this.options.units.length ){ - // afterLoadSelectItemFun(); - // } - // }.bind(this); - // var loadUnitFailure = loadUnitSuccess; - // - // this.options.units.each(function(unit){ - // - // var container = new Element("div").inject( this.itemAreaNode ); - // - // // this.action.listUnitByKey(function(json){ - // // if (json.data.length){ - // // json.data.each(function(data){ - // // if (data.subDirectUnitCount) var category = this._newItemCategory("ItemCategory", data, this, this.itemAreaNode); - // // }.bind(this)); - // // } - // // }.bind(this), null, comp); - // - // if (typeOf(unit)==="string"){ - // this.orgAction.getUnit(function(json){ - // json.data = typeOf( json.data ) == "object" ? [json.data] : json.data; - // if (json.data.length){ - // json.data.each( function(data){ - // if( this.options.expandSubEnable ){ - // if (data.subDirectUnitCount){ - // var category = this._newItemCategory("ItemCategory", data, this, container ); - // this.subCategorys.push(category); - // } - // }else{ - // var item = this._newItem( data, this, container ); - // this.items.push( item ); - // this.subItems.push(item); - // } - // }.bind(this)); - // } - // loadUnitSuccess(); - // }.bind(this), loadUnitFailure, unit); - // - // - // }else{ - // this.orgAction.getUnit(function(json){ - // json.data = typeOf( json.data ) == "object" ? [json.data] : json.data; - // if (json.data.length){ - // json.data.each( function(data){ - // if( this.options.expandSubEnable ) { - // if (data.subDirectUnitCount){ - // var category = this._newItemCategory("ItemCategory", data, this, container ); - // this.subCategorys.push(category); - // } - // }else{ - // var item = this._newItem(data, this, container ); - // this.items.push( item ); - // this.subItems.push(item); - // } - // }.bind(this)); - // } - // loadUnitSuccess(); - // }.bind(this), loadUnitFailure, unit.id); - // //if (unit.subDirectUnitCount) var category = this._newItemCategory("ItemCategory", unit, this, this.itemAreaNode); - // } - // - // }.bind(this)); }else{ this.orgAction.listTopUnit(function(json){ + // if( this.isCheckStatusOrCount() ) { + // this.loadingCount = "wait"; + // + // unitList = json.data.filter(function (data) { + // return !this.isExcluded( data ); + // }).map(function(data){ + // return unit.id || unit.distinguishedName || unit.unique || unit.levelName + // }.bind(this)).clean(); + // + // this.loadCount( unitList ); + // } json.data.each(function(data){ - // var flag = true; - // if (this.options.unitTypes.length){ - // flag = data.typeList.some(function(item){ - // return (!this.options.unitTypes.length) || (this.options.unitTypes.indexOf(item)!==-1) - // }.bind(this)); - // } - // if (flag){ if( !this.isExcluded( data ) ) { var unit = this._newItem(data, this, this.itemAreaNode, 1); this.items.push( unit ); this.subItems.push(unit); } - //unit.loadSubItem(); - // }else{ - // var category = this._newItemCategory("ItemCategory", data, this, this.itemAreaNode); - // } }.bind(this)); afterLoadSelectItemFun(); @@ -219,6 +162,158 @@ MWF.xApplication.Selector.Unit = new Class({ }, _newItemSearch: function(data, selector, container, level){ return new MWF.xApplication.Selector.Unit.SearchItem(data, selector, container, level); + }, + loadCount: function( unitList ){ + + var check = function () { + this.loadingCount = "ready"; + this.checkCountAndStatus(); + this.loadingCount = "done"; + }.bind(this); + + var unitLoaded, selectedUnitLoaded, excludeUnitLoaded; + var unitTree; + this.unitExcludedCount = {}; + this.unitSelectedCount = {}; + + debugger; + + var caculate = function () { + if (unitLoaded && selectedUnitLoaded && excludeUnitLoaded) { + + if( !this.allUnitObject )this.allUnitObject = {}; + + if( unitTree && unitTree.length ){ + unitTree.each( function ( tree ) { + if( !this.allUnitObject[ tree.levelName ] ){ + this.caculateNestedSubCount(tree) + } + }.bind(this) ); + check(); + } + + } + }.bind(this); + + this.getUnitCountMap(this.options.values, function (map) { + this.unitSelectedCount = map; + selectedUnitLoaded = true; + caculate(); + }.bind(this)); + + this.getUnitCountMap(this.options.exclude, function (map) { + this.unitExcludedCount = map; + excludeUnitLoaded = true; + caculate(); + }.bind(this)); + + o2.Actions.load("x_organization_assemble_express").UnitAction.listWithUnitTree({"unitList": unitList}, function (json) { + unitTree = json.data; + unitLoaded = true; + caculate(); + }.bind(this)) + }, + getUnitCountMap : function( identityList, callback ){ + var result = {}; + this.listUnitObject( identityList, function ( identityObjectList ) { + identityObjectList.each(function (id) { + if (id && id.levelName) { + result[id.levelName] = (result[id.levelName] || 0) + 1; + } + }.bind(this)); + if( callback )callback( result ); + }) + }, + listUnitObject : function( unitList, callback ){ + var list = []; + unitList.each( function (d) { + if( typeOf( d ) === "object"){ + if( !d.levelName || !d.distinguishedName )list.push( d.distinguishedName || d.id || d.unique ) + }else{ + list.push( d ) + } + }); + if( list.length > 0 ){ + o2.Actions.load("x_organization_assemble_express").UnitAction.listObject({ unitList : list }, function (json) { + var map = {}; + json.data.each( function (d) { map[ d.matchKey ] = d; }); + var unitObjectList = []; + unitList.each( function (d) { + var key = typeOf( d ) === "object" ? ( d.distinguishedName || d.id || d.unique ) : d; + unitObjectList.push( map[key] ? map[key] : d ); + }); + if( callback )callback( unitList ); + }.bind(this)) + }else{ + if( callback )callback( unitList ); + } + }, + caculateNestedSubCount : function ( tree ) { + if( this.isExcluded( tree ) )return; + var count; + var selectedCount; + + if(!this.allUnitObject[ tree.levelName ]){ + this.allUnitObject[ tree.levelName ] = tree; + count = tree.subDirectUnitCount; + if( this.unitExcludedCount && this.unitExcludedCount[ tree.levelName ] ){ + count = (count || 0) - this.unitExcludedCount[ tree.levelName ]; + } + + selectedCount = 0; + if( this.unitSelectedCount && this.unitSelectedCount[ tree.levelName ] ){ + selectedCount = this.unitSelectedCount[ tree.levelName ]; + } + }else{ + count = this.allUnitObject[ tree.levelName ].subNestedUnitCount || 0; + selectedCount = this.allUnitObject[ tree.levelName ].selectedNestedUnitCount || 0; + } + + var nameList = tree.levelName.split("/"); + var names = []; + nameList.each( function (n) { + names.push( n ); + var levelName = names.join("/"); + var unitObject = this.allUnitObject[levelName]; + if( unitObject ){ + unitObject.subNestedUnitCount = (unitObject.subNestedUnitCount || 0) + count; + unitObject.selectedNestedUnitCount = (unitObject.selectedNestedUnitCount || 0) + selectedCount; + } + }.bind(this)); + + tree.subUnits.each( function (unit) { + this.caculateNestedSubCount( unit ) + }.bind(this)) + + }, + _addSelectedCount: function( itemOrItemSelected, count ){ + var itemData = itemOrItemSelected.data; + [itemOrItemSelected.data.levelName].each(function(levelName){ + if(!levelName)return; + var list = levelName.split("/"); + var nameList = []; + var subCategoryMapList = [this.subCategoryMap]; + for (var j = 0; j < list.length; j++) { + nameList.push(list[j]); + var name = nameList.join("/"); + var maplist = []; + subCategoryMapList.each(function(subCategoryMap){ + if ( subCategoryMap[name] ) { + var category = subCategoryMap[name]; + category._addSelectedCount(count); + maplist.push( category.subCategoryMap ) ; + } + }); + subCategoryMapList = subCategoryMapList.concat(maplist); + + if( this.loadingCount === "done" ){ + var obj = this.allUnitObject[name]; + if (obj) { + obj.selectedNestedUnitCount = obj.selectedNestedUnitCount + count; + } + } + } + }.bind(this)); } }); @@ -820,6 +915,22 @@ MWF.xApplication.Selector.Unit.ItemSelected = new Class({ MWF.xApplication.Selector.Unit.ItemCategory = new Class({ Extends: MWF.xApplication.Selector.Identity.ItemCategory, + _getTotalCount : function(){ + if( !this.selector.allUnitObject )return 0; + var unit = this.selector.allUnitObject[this.data.levelName]; + var count = unit ? unit.subNestedUnitCount : 0; + return count; + }, + _getSelectedCount : function(){ + if( typeOf(this.selectedCount) === "number" )return this.selectedCount; + if( !this.selector.allUnitObject )return 0; + var unit = this.selector.allUnitObject[this.data.levelName]; + var count = unit ? unit.selectedNestedUnitCount : 0; + this.selectedCount = count + (this.selectedCount_wait || 0); + this.selectedCount_wait = 0; + return this.selectedCount; + }, + loadSub: function(callback){ if (!this.loaded){ this.selector.orgAction.listSubUnitDirect(function(subJson){ @@ -831,6 +942,7 @@ MWF.xApplication.Selector.Unit.ItemCategory = new Class({ this.selector.items.push( category ); if(this.subItems)this.subItems.push( category ); this.subCategorys.push( category ); + this.subCategoryMap[subData.levelName] = category; } //var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1); }.bind(this)); @@ -869,6 +981,7 @@ MWF.xApplication.Selector.Unit.ItemCategory = new Class({ category.load(); //if(this.subItems)this.subItems.push( category ); this.subCategorys.push( category ); + this.subCategoryMap[subData.levelName] = category; } //var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1); }.bind(this)); diff --git a/o2web/source/x_component_Selector/UnitWithType.js b/o2web/source/x_component_Selector/UnitWithType.js index e737dc132004482a4f1e4a6fa30796680cf52e12..290c16f56d4c843be45bf10e5f677de13cecb71d 100644 --- a/o2web/source/x_component_Selector/UnitWithType.js +++ b/o2web/source/x_component_Selector/UnitWithType.js @@ -29,6 +29,9 @@ MWF.xApplication.Selector.UnitWithType = new Class({ return; } + this._loadSelectItems(); + }, + _loadSelectItems: function(){ var afterLoadSelectItemFun = this.afterLoadSelectItem.bind(this); var data = {}; @@ -42,6 +45,11 @@ MWF.xApplication.Selector.UnitWithType = new Class({ } }.bind(this)); + if( this.isCheckStatusOrCount() ) { + this.loadingCount = "wait"; + this.loadCount( data.unitList ); + } + //data.unitList = this.options.units; this.orgAction.listUnitByType(function(json){ if (json.data.length){ @@ -55,6 +63,7 @@ MWF.xApplication.Selector.UnitWithType = new Class({ if (data.woSubDirectUnitList.length){ var category = this._newItemCategory("ItemCategory", data, this, this.itemAreaNode); this.subCategorys.push(category); + this.subCategoryMap[data.levelName] = category; } } } @@ -225,6 +234,7 @@ MWF.xApplication.Selector.UnitWithType.Item = new Class({ if (subData.woSubDirectUnitList.length){ // ? 原来是data.woSubDirectUnitList.length 2020-3-1 var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1, this); this.subCategorys.push( category ); + this.subCategoryMap[subData.levelName] = category; } } } @@ -249,6 +259,7 @@ MWF.xApplication.Selector.UnitWithType.Item = new Class({ if (subData.woSubDirectUnitList.length){ var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1, this); this.subCategorys.push( category ); + this.subCategoryMap[subData.levelName] = category; } } } @@ -334,6 +345,7 @@ MWF.xApplication.Selector.UnitWithType.ItemCategory = new Class({ if (subData.woSubDirectUnitList.length){ var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1, this); this.subCategorys.push(category); + this.subCategoryMap[subData.levelName] = category; } } } @@ -390,6 +402,7 @@ MWF.xApplication.Selector.UnitWithType.ItemCategory = new Class({ if (subData.woSubDirectUnitList.length){ var category = this.selector._newItemCategory("ItemCategory", subData, this.selector, this.children, this.level+1, this); this.subCategorys.push(category); + this.subCategoryMap[subData.levelName] = category; } } } diff --git a/o2web/source/x_component_Template/Selector/Custom.js b/o2web/source/x_component_Template/Selector/Custom.js index 0f976853de2d81566e5c722a14c825f1dcef7cf3..427dbdcef508188d95fc3148b4d15c73fac8c5af 100644 --- a/o2web/source/x_component_Template/Selector/Custom.js +++ b/o2web/source/x_component_Template/Selector/Custom.js @@ -72,8 +72,17 @@ MWF.xApplication.Template.Selector.Custom = new Class({ this.subCategorys = []; //直接的分类 this.subItems = []; //直接的选择项 + + this.availableStatusTypes = ["identity","custom"]; + + this._init(); + }, + _init : function(){ + this.selectType = "custom"; + this.className = "Custom" }, loadSelectItems: function (addToNext) { + this.loadingCount = "done"; if (!this.options.category) { this.options.selectableItems.each(function (it) { var name = typeOf(it) === "string" ? it : it.name; @@ -83,6 +92,9 @@ MWF.xApplication.Template.Selector.Custom = new Class({ this.subItems.push( item ); }.bind(this)) } else { + if( this.isCheckStatusOrCount() ){ + this.loadCount(); + } this.options.selectableItems.each(function (item, index) { if (item.isItem) { var item = this._newItem(item, this, this.itemAreaNode); @@ -199,6 +211,80 @@ MWF.xApplication.Template.Selector.Custom = new Class({ } else { if (callback) callback(); } + }, + + loadCount: function(){ + this.allCategoryDataObject = {}; + this.getValueString(this.options.values); + this.calculateCount(); + }, + reloadCount: function(){ + var map = this.allCategoryDataObject; + for(var key in map){ + map[key].subNestedItemCount = 0; + map[key].selectedNestedItemCount = 0; + } + var values = this.selectedItems.map(function (item) { return item.data; }.bind(this)); + this.getValueString(values); + this.calculateCount(); + }, + getValueString: function(values){ + this.valueStringList = values.map(function (item) { + switch (o2.typeOf(item)) { + case "string": + return item; + case "object": + return this.options.uniqueFlag ? item[this.options.uniqueFlag] : (item.id || item.name); + default: + return ""; + } + }.bind(this)); + }, + calculateCount: function( data, parentLevelName ){ + var map = this.allCategoryDataObject; + if( data ){ + var levelName = parentLevelName ? (parentLevelName+"/"+data.name) : data.name; + if( !map[levelName] )map[levelName] = data; + + if( data.subItemList && data.subItemList.length ){ + + var selectedItems = data.subItemList.filter(function(item){ + var string = this.options.uniqueFlag ? item[this.options.uniqueFlag] : (item.id || item.name); + return this.valueStringList.contains(string); + }.bind(this)); + + var nameList = []; + levelName.split("/").each(function(name){ + nameList.push(name); + var lName = nameList.join("/"); + var d = map[lName]; + if( d ){ + d.subNestedItemCount = (d.subNestedItemCount || 0) + data.subItemList.length; + d.selectedNestedItemCount = (d.selectedNestedItemCount || 0) + selectedItems.length; + } + }); + } + + if( data.subCategoryList && data.subCategoryList.length ){ + data.subCategoryList.each(function (category) { + this.calculateCount( category, levelName ); + }.bind(this)) + } + + }else{ + this.options.selectableItems.each(function (item, i) { + if( !item.isItem )this.calculateCount( item, "" ); + }.bind(this)) + } + }, + addSelectedCount: function( itemOrItemSelected, count, items ){ + var itemData = itemOrItemSelected.data; + debugger; + items.each(function(item){ + if(item.category && item.category._addSelectedCount){ + item.category._addSelectedCount( count, true ); + } + }.bind(this)); } }); MWF.xApplication.Template.Selector.Custom.Item = new Class({ @@ -295,6 +381,15 @@ MWF.xApplication.Template.Selector.Custom.ItemSelected = new Class({ }.bind(this)); } } + + debugger; + + if( !this.isFromValues ){ + if( this.selector.isCheckStatusOrCount() ){ + this.selector.addSelectedCount(this, 1, items||[]); + } + } + if( this.afterCheck )this.afterCheck(); } }); @@ -305,6 +400,9 @@ MWF.xApplication.Template.Selector.Custom.ItemCategory = new Class({ return this.data.name; }, createNode: function () { + if( !this.levelName ){ + this.levelName = this.category ? (this.category.levelName + "/" + this.data.name) : this.data.name; + } this.node = new Element("div", { "styles": this.selector.css.selectorItemCategory_department }).inject(this.container); @@ -316,6 +414,37 @@ MWF.xApplication.Template.Selector.Custom.ItemCategory = new Class({ _getTtiteText: function () { return this.data.name; }, + _addSelectedCount : function( count, nested ){ //增加数字并向上回溯 + if( this.selector.loadingCount === "done" ){ + var c = ( this._getSelectedCount() || 0 ) + count; + this.selectedCount = c; + this._checkCountAndStatus( c ); + }else{ + this.selectedCount_wait = (this.selectedCount_wait || 0) + count; + } + if( nested && this.category && this.category._addSelectedCount ){ + this.category._addSelectedCount(count, nested); + } + }, + _getTotalCount : function(){ + // return this.subItems.length; + if( !this.selector.allCategoryDataObject )return 0; + var d = this.selector.allCategoryDataObject[this.levelName]; + return d ? d.subNestedItemCount : 0; + }, + _getSelectedCount : function(){ + if( typeOf(this.selectedCount) === "number" )return this.selectedCount; + if( !this.selector.allCategoryDataObject )return 0; + var d = this.selector.allCategoryDataObject[this.levelName]; + var count = d ? d.selectedNestedItemCount : 0; + this.selectedCount = count + (this.selectedCount_wait || 0); + this.selectedCount_wait = 0; + return this.selectedCount; + }, + // _getSelectedCount : function(){ + // var list = this.subItems.filter( function (item) { return item.isSelected; }); + // return list.length; + // }, clickItem: function (callback) { if (this._hasChild() || this.selector.options.expandEmptyCategory ) { var firstLoaded = !this.loaded; @@ -389,6 +518,7 @@ MWF.xApplication.Template.Selector.Custom.ItemCategory = new Class({ this.subCategorys.push( category ); }.bind(this)); } + this.loaded = true; if (callback) callback(); } else { @@ -414,6 +544,22 @@ MWF.xApplication.Template.Selector.Custom.ItemCategory = new Class({ this.actionNode.setStyles(this.selector.css.selectorItemCategoryActionNode_collapse); this.isExpand = false; } + + debugger; + + if( this.selector.isCheckStatusOrCount() ){ + if( this.selector.loadingCount === "done" ){ + this.checkCountAndStatus(); + } + } + }, + reloadCount: function () { + if( this.selector.isCheckStatusOrCount() ){ + this.selector.reloadCount(); + if( this.selector.loadingCount === "done" ){ + this.checkCountAndStatus(); + } + } } }); @@ -435,6 +581,17 @@ MWF.xApplication.Template.Selector.Custom.ItemCategorySelectable = new Class({ _getTtiteText: function () { return this.data.name; }, + + _addSelectedCount : function( count, nested ){ //增加数字并向上回溯 + + }, + _getTotalCount : function(){ + + }, + _getSelectedCount : function(){ + + }, + destroy : function(){ if( this.isSelected )this.unSelected(); this.selector.items.erase( this ); @@ -574,5 +731,8 @@ MWF.xApplication.Template.Selector.Custom.ItemCategorySelectable = new Class({ }, afterLoad : function () { + }, + reloadCount: function () { + } }); \ No newline at end of file