| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- 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.xApplication.Template.Selector.Custom = new Class({
- Extends: MWF.xApplication.Selector.Person,
- options: {
- "style": "default",
- "count": 0,
- "title": "选择列表",
- "values": [],
- "selectableItems" : [],
- "names": [],
- "category" : false,
- "expand": false
- },
- 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 = [];
- },
- loadSelectItems: function(addToNext){
- 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);
- }.bind(this))
- }else{
- this.options.selectableItems.each(function (item, index) {
- if( item.isItem ){
- var item = this._newItem(item, this, this.itemAreaNode);
- this.items.push(item);
- }
- if(item.subItemList && item.subItemList.length>0){
- var category = this._newItemCategory(item, this, this.itemAreaNode);
- 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));
- }
- },
- _scrollEvent: function(y){
- return true;
- },
- _getChildrenItemIds: function(data){
- return data.subItemList || [];
- },
- _newItemCategory: function(data, selector, item, level){
- return new MWF.xApplication.Template.Selector.Custom.ItemCategory(data, selector, item, level)
- },
- _listItemByKey: function(callback, failure, key){
- if (key){
- this.initSearchArea(true);
- this.searchInItems(key);
- }else{
- this.initSearchArea(false);
- }
- },
- _newItemSelected: function(data, selector, item){
- return new MWF.xApplication.Template.Selector.Custom.ItemSelected(data, selector, item)
- },
- _listItemByPinyin: function(callback, failure, key){
- if (key){
- this.initSearchArea(true);
- this.searchInItems(key);
- }else{
- this.initSearchArea(false);
- }
- },
- _getItem: function(callback, failure, id, async){
- if (callback) callback.apply(id, [{"id":id}]);
- },
- _newItem: function(data, selector, container, level, category){
- return new MWF.xApplication.Template.Selector.Custom.Item(data, selector, container, level, category);
- },
- createItemsSearchData: function(callback){
- if (!this.itemsSearchData){
- this.itemsSearchData = [];
- MWF.require("MWF.widget.PinYin", function(){
- var initIds = [];
- this.items.each(function(item){
- if (initIds.indexOf(item.data.name)==-1){
- var text = item._getShowName().toLowerCase();
- var pinyin = text.toPY().toLowerCase();
- var firstPY = text.toPYFirst().toLowerCase();
- this.itemsSearchData.push({
- "text": text,
- "pinyin": pinyin,
- "firstPY": firstPY,
- "data": item.data
- });
- initIds.push(item.data.name);
- }
- }.bind(this));
- delete initIds;
- if (callback) callback();
- }.bind(this));
- }else{
- if (callback) callback();
- }
- }
- });
- MWF.xApplication.Template.Selector.Custom.Item = new Class({
- Extends: o2.xApplication.Selector.Person.Item,
- _getShowName: function(){
- return this.data.name;
- },
- _setIcon: function(){
- var style = this.selector.options.style;
- this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/"+style+"/icon/processicon.png)");
- },
- _getTtiteText: function(){
- return this.data.name;
- },
- loadSubItem: function(){
- return false;
- },
- checkSelectedSingle: function(){
- var selectedItem = this.selector.options.values.filter(function(item, index){
- if (typeOf(item)==="object") return (this.data.id === item.id) || (this.data.name === item.name) ;
- if (typeOf(item)==="string") return (this.data.id === item) || (this.data.name === item);
- return false;
- }.bind(this));
- if (selectedItem.length){
- this.selectedSingle();
- }
- },
- checkSelected: function(){
- var selectedItem = this.selector.selectedItems.filter(function(item, index){
- return (item.data.id === this.data.id) || (item.data.name === this.data.name);
- }.bind(this));
- if (selectedItem.length){
- //selectedItem[0].item = this;
- selectedItem[0].addItem(this);
- this.selectedItem = selectedItem[0];
- this.setSelected();
- }
- }
- });
- MWF.xApplication.Template.Selector.Custom.ItemSelected = new Class({
- Extends: o2.xApplication.Selector.Person.ItemSelected,
- _getShowName: function(){
- return this.data.name;
- },
- _setIcon: function(){
- var style = this.selector.options.style;
- this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/"+style+"/icon/processicon.png)");
- },
- _getTtiteText: function(){
- return this.data.name;
- },
- 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);
- }.bind(this));
- this.items = items;
- if (items.length){
- items.each(function(item){
- item.selectedItem = this;
- item.setSelected();
- }.bind(this));
- }
- }
- }
- });
- MWF.xApplication.Template.Selector.Custom.ItemCategory = new Class({
- Extends: o2.xApplication.Selector.Person.ItemCategory,
- _getShowName: function(){
- return this.data.name;
- },
- createNode: function(){
- this.node = new Element("div", {
- "styles": this.selector.css.selectorItemCategory_department
- }).inject(this.container);
- this.loaded = true;
- },
- _setIcon: function(){
- var style = this.selector.options.style;
- this.iconNode.setStyle("background-image", "url("+"/x_component_Selector/$Selector/"+style+"/icon/applicationicon.png)");
- },
- _getTtiteText: function(){
- return this.data.name;
- },
- _hasChildItem : function(){
- return this._hasChild();
- },
- _hasChild: function(){
- return (this.data.subItemList && this.data.subItemList.length);
- },
- check: function(){}
- });
|