MWF.xApplication.Selector = MWF.xApplication.Selector || {}; MWF.xApplication.Template = MWF.xApplication.Template || {}; MWF.xApplication.Template.Selector = MWF.xApplication.Template.Selector || {}; MWF.xDesktop.requireApp("Selector", "Person", null, false); MWF.xDesktop.requireApp("Selector", "Unit", null, false); // this.options.selectableItems = [ // { // "name": "项目1", // "id": "item1", // "isItem" : true //第一层的item需要isItem = true // }, // { // "name": "项目2", // "id": "item2", // "isItem" : true //第一层的item需要isItem = true // }, // { // "name": "分类1", // "id": "category1", // "subItemList": [ // { // "id": "item1.1", // "name": "项目1.1" // }, // { // "id": "item1.2", // "name": "项目1.2" // } // ], // "subCategoryList" : [ // { // "name": "分类1.1", // "id": "category1.1", // "subItemList" : [ // { // "id": "item1.1.1", // "name": "项目1.1.1" // } // ] // } // ] // } // ]; MWF.xApplication.Template.Selector.Custom = new Class({ Extends: MWF.xApplication.Selector.Person, options: { "style": "default", "count": 0, "title": "选择列表", "values": [], "selectableItems": [], "names": [], "category": false, "expand": true, "categorySelectable" : false, "expandSubEnable" : true, "uniqueFlag" : false, "defaultExpandLevel" : 1 }, initialize: function (container, options) { this.setOptions(options); this.path = "../x_component_Selector/$Selector/"; this.cssPath = "../x_component_Selector/$Selector/" + this.options.style + "/css.wcss"; this._loadCss(true); this.container = $(container); this.selectedItems = []; this.items = []; // this.categorys = []; 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; var id = typeOf(it) === "string" ? it : it.id; var item = this._newItem({name: name, id: id}, this, this.itemAreaNode); this.items.push(item); 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); this.items.push(item); this.subItems.push( item ); }else{ // if ( (item.subItemList && item.subItemList.length > 0) || item.subCategoryList && item.subCategoryList.length > 0 ) { if( this.options.categorySelectable ){ var category = this._newItemCategorySelectable(item, this, this.itemAreaNode); this.items.push(category); this.subItems.push( category ); this.subCategorys.push( category ); }else{ var category = this._newItemCategory(item, this, this.itemAreaNode); this.subCategorys.push( category ); } // item.subItemList.each(function (subItem, index) { // var item = this._newItem(subItem, this, category.children, 2, category); // this.items.push(item); // category.subItems.push(item); // }.bind(this)); // } } }.bind(this)); } if(this.afterLoadSelectItem)this.afterLoadSelectItem(); }, _scrollEvent: function (y) { return true; }, _getChildrenItemIds: function (data) { return data.subItemList || []; }, _newItemCategory: function (data, selector, container, level, parentCategory, delay) { return new MWF.xApplication.Template.Selector.Custom.ItemCategory(data, selector, container, level, parentCategory, delay) }, _newItemCategorySelectable: function (data, selector, container, level, category, delay) { return new MWF.xApplication.Template.Selector.Custom.ItemCategorySelectable(data, selector, container, level, category, delay) }, _listItemByKey: function (callback, failure, key) { if (key) { this.initSearchArea(true); this.searchInItems(key); } else { this.initSearchArea(false); } }, _newItemSelected: function (data, selector, container, level, category, delay) { return new MWF.xApplication.Template.Selector.Custom.ItemSelected(data, selector, container, level, category, delay) }, _listItemByPinyin: function (callback, failure, key) { if (key) { this.initSearchArea(true); this.searchInItems(key); } else { this.initSearchArea(false); } }, nestData : function( data, isItem ){ if( !this.nestedData )this.nestedData = {}; var setNest = function (d, isItem) { if( isItem ){ this.nestedData[ d["id"] || d["name"] ] = d; }else if( this.options.categorySelectable ){ this.nestedData[ d["id"] || d["name"] ] = { id : d.id , name : d.name }; if( d.subItemList )this.nestData( d.subItemList, true ); if( d.subCategoryList )this.nestData( d.subCategoryList ); }else{ if( d.subItemList )this.nestData( d.subItemList, true ); if( d.subCategoryList )this.nestData( d.subCategoryList ); } }.bind(this); if( data ){ for( var i=0; i