o2oa api: x-游戏厅捕鱼达人

source

mwf.xdesktop.requireapp("process.xform", "$selector", null, false);
/** @class select 下拉选择组件。
 * 在8.1之后,支持从数据字典、视图和查询获取可选项。获取过程为异步。
 * @o2cn 下拉选择
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var field = this.form.get("fieldid"); //获取组件对象
 * //方法2
 * var field = this.target; //在组件本身的脚本中获取,比如事件脚本、默认值脚本、校验脚本等等
 *
 * var data = field.getdata(); //获取值
 * field.setdata("字符串值"); //设置值
 * field.hide(); //隐藏字段
 * var id = field.json.id; //获取字段标识
 * var flag = field.isempty(); //字段是否为空
 * @extends mwf.xapplication.process.xform.$selector
 * @o2category formcomponents
 * @o2range {process|cms|portal}
 * @hideconstructor
 */
mwf.xapplication.process.xform.select = mwf.appselect =  new class(
	/** @lends mwf.xapplication.process.xform.select# */
	{
	implements: [events],
	extends: mwf.app$selector,
	iconstyle: "selecticon",
		/**
		 * 值改变时触发。可以通过this.event获取修改后的选择项(dom对象)。
		 * @event mwf.xapplication.process.xform.select#change
		 * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
		 */
	/**
	 * @ignore
	 * @member {element} descriptionnode
	 * @memberof mwf.xapplication.process.xform.select#
	 */
    initialize: function(node, json, form, options){
        this.node = $(node);
        this.node.store("module", this);
        this.json = json;
        this.form = form;
        this.field = true;
		this.fieldmoduleloaded = false;
		this.nodehtml = this.node.get("html");
    },
	/**
	 * @summary 重新加载组件。会执行postload事件。
	 * @example
	 * this.form.get("fieldid").reload(); //重新加载事件
	 */
	reload: function(){
		if (this.areanode){
			this.node = this.areanode;
			this.areanode.empty();
			this.areanode = null;
		}
		this._beforereloaded();
		this._loaduserinterface();
		this._loadstyles();
		this._afterloaded();
		this._afterreloaded();
		this.fireevent("postload");
	},
    _loadnode: function(){
        if (this.isreadonly()){
            this._loadnoderead();
        }else{
            this._loadnodeedit();
        }
    },
	_loadmergereadcontentnode: function( contentnode, data ){
		this._showvalue(contentnode, data.data);
	},
    _loadnoderead: function(){
        this.node.empty();
		this.node.set({
			"nodeid": this.json.id,
			"mwftype": this.json.type
		});
        var value = this.getvalue();
        this._showvalue( this.node, value );
    },
	__showvalue: function(node, value, optionitems){
        if (value){
            if (typeof(value)!=="array") value = [value];
            var texts = [];
            optionitems.each(function(item){
                var tmps = item.split("|");
                var t = tmps[0];
                var v = tmps[1] || t;
                if (v){
                    if (value.indexof(v)!=-1){
                        texts.push(t);
                    }
                }
            });
            node.set("text", texts.join(", "));
        }
	},
	_loaddomevents: function(){
		object.each(this.json.events, function(e, key){
			if (e.code){
				if (this.options.moduleevents.indexof(key)===-1){
					this.node.addevent(key, function(event){
						return this.form.macro.fire(e.code, this, event);
					}.bind(this));
				}
			}
		}.bind(this));
	},
    _loadevents: function(){
        object.each(this.json.events, function(e, key){
            if (e.code){
                if (this.options.moduleevents.indexof(key)!=-1){
                    this.addevent(key, function(event){
                        return this.form.macro.fire(e.code, this, event);
                    }.bind(this));
                }else{
                    this.node.addevent(key, function(event){
                        return this.form.macro.fire(e.code, this, event);
                    }.bind(this));
                }
            }
        }.bind(this));
    },
	addmoduleevent: function(key, fun){
		if (this.options.moduleevents.indexof(key)!==-1){
			this.addevent(key, function(event){
				return (fun) ? fun(this, event) : null;
			}.bind(this));
		}else{
			this.node.addevent(key, function(event){
				return (fun) ? fun(this, event) : null;
			}.bind(this));
		}
	},
    _loadstyles: function(){
    	if (this.areanode){
            if (this.json.styles) if (this.areanode) this.areanode.setstyles(this.json.styles);
            if (this.json.inputstyles) this.node.setstyles(this.json.inputstyles);
		}else{
            if (this.json.styles) this.node.setstyles(this.json.styles);
		}
    },
	_resetnodeedit: function(){
		this.node.empty();
		var select = new element("select");
		select.set(this.json.properties);
		select.inject(this.node);
	},
    _loadnodeedit: function(){
		if (!this.json.preprocessing) this._resetnodeedit();
		var select = this.node.getfirst();
		if( !select && this.nodehtml ){
			this.node.set("html", this.nodehtml);
			select = this.node.getfirst();
		}
		this.areanode = this.node;
		this.areanode.set({
			"id": this.json.id,
			"mwftype": this.json.type
		});
		this.node = select;
		this.node.set({
			"styles": {
				"margin-right": "12px"
			}
		});
		// this.node.set({
		// 	"id": this.json.id,
		// 	"mwftype": this.json.type,
		// 	"styles": {
		// 		"margin-right": "12px"
		// 	}
		// });
		
		this.setoptions();
        this.node.addevent("change", function( ev ){
			var v = this.getinputdata("change");
			this._setbusinessdata(v);
            this.validationmode();
            if (this.validation()) {
				//this._setenvironmentdata(v);
				this.fireevent("change", [this._getselectedoption()]);
			}
        }.bind(this));
	},
	_setoptions: function(optionitems){
		var p = o2.promiseall(optionitems).then(function(options){
			this.moduleselectag = null;
			if (!options) options = [];
			if (o2.typeof(options)==="array"){
				options.each(function(item){
					var tmps = item.split("|");
					var text = tmps[0];
					var value = tmps[1] || text;
					var option = new element("option", {
						"value": value,
						"text": text
					}).inject(this.node);
				}.bind(this));
				this.fireevent("setoptions", [options])
			}
		}.bind(this), function(){
			this.moduleselectag = null;
		}.bind(this));
		this.moduleselectag = p;
		if (p) p.then(function(){
			this.moduleselectag = null;
		}.bind(this), function(){
			this.moduleselectag = null;
		}.bind(this));
		// this.moduleselectag = o2.ag.all(optionitems).then(function(options){
		// 	this.moduleselectag = null;
		// 	if (!options) options = [];
		// 	if (o2.typeof(options)==="array"){
		// 		options.each(function(item){
		// 			var tmps = item.split("|");
		// 			var text = tmps[0];
		// 			var value = tmps[1] || text;
		//
		// 			var option = new element("option", {
		// 				"value": value,
		// 				"text": text
		// 			}).inject(this.node);
		// 		}.bind(this));
		// 		this.fireevent("setoptions", [options])
		// 	}
		// }.bind(this));
		// if (this.moduleselectag) this.moduleselectag.then(function(){
		// 	this.moduleselectag = null;
		// }.bind(this));
	},
	// __setoptions: function(){
	// 	var optionitems = this.getoptions();
    //     if (!optionitems) optionitems = [];
    //     if (o2.typeof(optionitems)==="array"){
	// 		optionitems.each(function(item){
	// 			var tmps = item.split("|");
	// 			var text = tmps[0];
	// 			var value = tmps[1] || text;
	//
	// 			var option = new element("option", {
	// 				"value": value,
	// 				"text": text
	// 			}).inject(this.node);
	// 		}.bind(this));
	// 		this.fireevent("setoptions", [optionitems])
	// 	}
	// },
	addoption: function(text, value){
        var option = new element("option", {
            "value": value || text,
            "text": text
        }).inject(this.node);
		this.fireevent("addoption", [text, value])
	},
	_setvalue: function(value, m, firechange){
		var mothed = m || "__setvalue";
		if (!!value){
			var p = o2.promiseall(value).then(function(v){
				if (o2.typeof(v)=="array") v = v[0];
				if (this.moduleselectag){
					this.modulevalueag = this.moduleselectag;
					this.moduleselectag.then(function(){
						this[mothed](v, firechange);
						return v;
					}.bind(this), function(){});
				}else{
					this[mothed](v, firechange)
				}
				return v;
			}.bind(this), function(){});
			this.modulevalueag = p;
			if (this.modulevalueag) this.modulevalueag.then(function(){
				this.modulevalueag = null;
			}.bind(this), function(){
				this.modulevalueag = null;
			}.bind(this));
		}else{
			this[mothed](value, firechange);
		}
		// this.modulevalueag = o2.ag.all(value).then(function(v){
		// 	if (o2.typeof(v)=="array") v = v[0];
		// 	if (this.moduleselectag){
		// 		this.modulevalueag = this.moduleselectag;
		// 		this.moduleselectag.then(function(){
		// 			this.__setvalue(v);
		// 		}.bind(this));
		// 	}else{
		// 		this.__setvalue(v)
		// 	}
		// 	return v;
		// }.bind(this));
		// if (value && value.isag){
		// 	this.modulevalueag = o2.ag.all(value),then(function(v){
		// 		this._setvalue(v);
		// 	}.bind(this));
		// 	// this.modulevalueag = value;
		// 	// value.addresolve(function(v){
		// 	// 	this._setvalue(v);
		// 	// }.bind(this));
		// }else{
		//
		// }
	},
	__setvalue: function(value){
		if (!this.isreadonly()) {
			this._setbusinessdata(value);
			var ops = this.node.getelements("option");
			for (var i=0; i -1 ? ops.textlist[idx] : v);
                    })
                    this.node.set("text", result.join(","));
                }.bind(this))
			}else{
			    d.each( function (v) {
                    var idx = ops.valuelist.indexof( v );
                    result.push( idx > -1 ? ops.textlist[idx] : v);
                })
                this.node.set("text", result.join(","));
			}
		}else{
			var ops = this.node.getelements("option");
			ops.each(function(op){
				if (typeof(data)==="array"){
					if (data.indexof(op.get("value"))!=-1){
						op.set("selected", true);
						selectedoption = op;
					}else{
						op.set("selected", false);
					}
				}else{
					if (data == op.get("value")){
						op.set("selected", true);
						selectedoption = op;
					}else{
						op.set("selected", false);
					}
				}
			});
			this.validationmode();
		}
		this.fieldmoduleloaded = true;
		this.fireevent("setdata", [data]);
		if (firechange && old!==data) this.fireevent("change", [selectedoption]);
	},
	getexceldata: function( type ){
		var value = this.getdata();
		if( type === "value" )return value;
		var options = this.getoptionsobj();
		return promise.resolve(options).then(function (opts) {
			var idx = opts.valuelist.indexof( value );
			var text = idx > -1 ? opts.textlist[ idx ] : "";
			return text;
		});
	},
	setexceldata: function(d, type){
		var value = d.replace(/
/g,""); //换行符
		this.exceldata = value;
		if( type === "value" ){
			this.setdata(value, true);
		}else{
			var options = this.getoptionsobj();
			this.moduleexcelag = promise.resolve(options).then(function (opts) {
				var idx = opts.textlist.indexof( value );
				value = idx > -1 ? opts.valuelist[ idx ] : "";
				this.setdata(value, true);
				this.moduleexcelag = null;
			}.bind(this));
		}
	}
	
}); 
网站地图