Просмотр исходного кода

为自定义选择器增加默认展开几层的功能 defaultExpandLevel

unknown 5 лет назад
Родитель
Сommit
ab7e8a702d

+ 4 - 2
o2web/source/x_component_Selector/Identity.js

@@ -19,6 +19,8 @@ MWF.xApplication.Selector.Identity = new Class({
         "selectAllEnable" : true //分类是否允许全选下一层
     },
     loadSelectItems: function(addToNext){
+	    debugger;
+
 	    var afterLoadSelectItemFun = this.afterLoadSelectItem.bind(this);
         if( this.options.resultType === "person" ){
             if( this.titleTextNode ){
@@ -37,7 +39,7 @@ MWF.xApplication.Selector.Identity = new Class({
                 if( unitLoaded === this.options.units.length ){
                     this.unitLoaded = true;
                     if( this.includeLoaded ){
-                        if(afterLoadSelectItemFun)afterLoadSelectItemFun();
+                        afterLoadSelectItemFun();
                     }
                 }
             }.bind(this);
@@ -46,7 +48,7 @@ MWF.xApplication.Selector.Identity = new Class({
             this.loadInclude( function () {
                 this.includeLoaded = true;
                 if( this.unitLoaded ){
-                    if(afterLoadSelectItemFun)afterLoadSelectItemFun();
+                    afterLoadSelectItemFun();
                 }
             }.bind(this));
 

+ 1 - 1
o2web/source/x_component_Selector/Person.js

@@ -1362,7 +1362,7 @@ MWF.xApplication.Selector.Person = new Class({
         }
     },
     afterLoadSelectItem : function(){
-        if( this.items.length === 0 && this.subCategorys.length === 0 ){
+        if( this.items.length === 0  ){ //&& this.subCategorys.length === 0
            this.noSelectableItemTextDiv = new Element("div", {
                text : this.lp.noSelectableItemText
            }).inject( this.itemAreaNode );

+ 8 - 1
o2web/source/x_component_Selector/Unit.js

@@ -219,6 +219,8 @@ MWF.xApplication.Selector.Unit.Item = new Class({
 
         this.check();
 
+        if(this.afterLoad)this.afterLoad();
+
         this.selector.fireEvent("postLoadItem",[this]);
     },
     _getShowName: function(){
@@ -237,7 +239,12 @@ MWF.xApplication.Selector.Unit.Item = new Class({
         this.isExpand = (this.selector.options.expand);
         if ( this._hasChild() || this.selector.options.expandEmptyCategory ){
             if (this.selector.options.expand){
-                if (this.level===1 && this._hasChild() ){
+                if( typeOf(this.selector.options.defaultExpandLevel) === "number" ){
+                    if (this.level <= this.selector.options.defaultExpandLevel && this._hasChild() ){
+                        this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_expand);
+                        this.loadSubItems();
+                    }
+                }else if (this.level===1 && this._hasChild() ){
                     this.levelNode.setStyles(this.selector.css.selectorItemLevelNode_expand);
                     this.loadSubItems();
                 }else{

+ 43 - 8
o2web/source/x_component_Template/Selector/Custom.js

@@ -55,7 +55,9 @@ MWF.xApplication.Template.Selector.Custom = new Class({
         "category": false,
         "expand": true,
         "categorySelectable" : false,
-        "expandSubEnable" : true
+        "expandSubEnable" : true,
+        "uniqueFlag" : false,
+        "defaultExpandLevel" : 1
     },
     initialize: function (container, options) {
         this.setOptions(options);
@@ -210,8 +212,14 @@ MWF.xApplication.Template.Selector.Custom.Item = new Class({
     },
     checkSelectedSingle: function () {
         var selectedItem = this.selector.options.values.filter(function (item, index) {
-            if (typeOf(item) === "object") return ( this.data.id && this.data.id === item.id) || (this.data.name && this.data.name === item.name);
-            if (typeOf(item) === "string") return ( this.data.id && this.data.id === item) || (this.data.name && this.data.name === item);
+            if( this.selector.options.uniqueFlag ){
+                var flag = this.selector.options.uniqueFlag;
+                if (typeOf(item) === "object") return ( this.data[flag] && this.data[flag] === item[flag] );
+                if (typeOf(item) === "string") return ( this.data[flag] && this.data[flag] === item );
+            }else{
+                if (typeOf(item) === "object") return ( this.data.id && this.data.id === item.id) || (this.data.name && this.data.name === item.name);
+                if (typeOf(item) === "string") return ( this.data.id && this.data.id === item) || (this.data.name && this.data.name === item);
+            }
             return false;
         }.bind(this));
         if (selectedItem.length) {
@@ -220,7 +228,12 @@ MWF.xApplication.Template.Selector.Custom.Item = new Class({
     },
     checkSelected: function () {
         var selectedItem = this.selector.selectedItems.filter(function (item, index) {
-            return ( item.data.id && item.data.id === this.data.id) || (item.data.name && item.data.name === this.data.name);
+            if( this.selector.options.uniqueFlag ){
+                var flag = this.selector.options.uniqueFlag;
+                return ( item.data[flag] && item.data[flag] === this.data[flag]);
+            }else{
+                return ( item.data.id && item.data.id === this.data.id) || (item.data.name && item.data.name === this.data.name);
+            }
         }.bind(this));
         if (selectedItem.length) {
             //selectedItem[0].item = this;
@@ -261,7 +274,12 @@ MWF.xApplication.Template.Selector.Custom.ItemSelected = new Class({
     check: function () {
         if (this.selector.items.length) {
             var items = this.selector.items.filter(function (item, index) {
-                return (item.data.id === this.data.id) || (item.data.name === this.data.name);
+                if( this.selector.options.uniqueFlag ){
+                    var flag = this.selector.options.uniqueFlag;
+                    return ( item.data[flag] && item.data[flag] === this.data[flag]);
+                }else{
+                    return ( item.data.id && item.data.id === this.data.id) || (item.data.name && item.data.name === this.data.name);
+                }
             }.bind(this));
             this.items = items;
             if (items.length) {
@@ -370,6 +388,9 @@ MWF.xApplication.Template.Selector.Custom.ItemCategory = new Class({
         return this._hasChildCategory() || this._hasChildItem();
     },
     check: function () {
+    },
+    afterLoad: function(){
+        if ( this.level <= this.selector.options.defaultExpandLevel  ) this.clickItem();
     }
 });
 
@@ -495,8 +516,14 @@ MWF.xApplication.Template.Selector.Custom.ItemCategorySelectable = new Class({
     },
     checkSelectedSingle: function () {
         var selectedItem = this.selector.options.values.filter(function (item, index) {
-            if (typeOf(item) === "object") return ( this.data.id && this.data.id === item.id) || (this.data.name && this.data.name === item.name);
-            if (typeOf(item) === "string") return ( this.data.id && this.data.id === item) || (this.data.name && this.data.name === item);
+            if( this.selector.options.uniqueFlag ){
+                var flag = this.selector.options.uniqueFlag;
+                if (typeOf(item) === "object") return ( this.data[flag] && this.data[flag] === item[flag] );
+                if (typeOf(item) === "string") return ( this.data[flag] && this.data[flag] === item );
+            }else{
+                if (typeOf(item) === "object") return ( this.data.id && this.data.id === item.id) || (this.data.name && this.data.name === item.name);
+                if (typeOf(item) === "string") return ( this.data.id && this.data.id === item) || (this.data.name && this.data.name === item);
+            }
             return false;
         }.bind(this));
         if (selectedItem.length) {
@@ -505,7 +532,12 @@ MWF.xApplication.Template.Selector.Custom.ItemCategorySelectable = new Class({
     },
     checkSelected: function () {
         var selectedItem = this.selector.selectedItems.filter(function (item, index) {
-            return ( item.data.id && item.data.id === this.data.id) || (item.data.name && item.data.name === this.data.name);
+            if( this.selector.options.uniqueFlag ){
+                var flag = this.selector.options.uniqueFlag;
+                return ( item.data[flag] && item.data[flag] === this.data[flag]);
+            }else{
+                return ( item.data.id && item.data.id === this.data.id) || (item.data.name && item.data.name === this.data.name);
+            }
         }.bind(this));
         if (selectedItem.length) {
             //selectedItem[0].item = this;
@@ -516,5 +548,8 @@ MWF.xApplication.Template.Selector.Custom.ItemCategorySelectable = new Class({
     },
     check: function () {
         this.checkSelected();
+    },
+    afterLoad : function () {
+
     }
 });