MWF.xDesktop.requireApp("process.Xform", "$Selector", null, false); /** @class Combox 组合框组件。 * @o2cn 组合框 * @example * //可以在脚本中获取该组件 * //方法1: * var field = this.form.get("fieldId"); //获取组件对象 * //方法2 * var field = this.target; //在组件本身的脚本中获取,比如事件脚本、默认值脚本、校验脚本等等 * @extends MWF.xApplication.process.Xform.$Selector * @o2category FormComponents * @o2range {Process|CMS} * @hideconstructor */ MWF.xApplication.process.Xform.Combox = MWF.APPCombox = new Class( /** @lends MWF.xApplication.process.Xform.Combox# */ { Implements: [Events], Extends: MWF.APP$Selector, iconStyle: "selectIcon", options: { /** * 手工输入完成后触发。 * @event MWF.xApplication.process.Xform.Combox#commitInput * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ /** * 值改变时触发。 * @event MWF.xApplication.process.Xform.Combox#change * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zTS|组件事件说明} */ "moduleEvents": ["load", "queryLoad", "postLoad", "commitInput", "change"] }, 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; }, _loadUserInterface: function(){ if ( this.isSectionMergeRead() ) { //区段合并显示 this._loadMergeReadNode(); }else{ if( this.isSectionMergeEdit() ){ this._loadMergeEditNode(); }else{ this._loadNode(); } // if (this.json.compute === "show"){ // this._setValue(this._computeValue()); // }else{ // this._loadValue(); // } } }, loadVal: function(){ if (this.json.compute === "show"){ this._setValue(this._computeValue()); }else{ this._loadValue(); } }, /** * @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(); } }, _loadNodeRead: function(){ this.node.empty(); this.node.set({ "nodeId": this.json.id, "MWFType": this.json.type }); this.loadVal(); //new Element("select").inject(this.node); }, _loadMergeReadContentNode: function( contentNode, data ){ this.mergeRead = true; contentNode.setStyles({ "overflow": "hidden"}); var textList = this.getTextListByValue( data.data ); if( typeOf(textList.then) === "function" ){ Promise.resolve(textList).then(function (tList) { this.__setValueRead( data.data, tList, contentNode ); }.bind(this)) }else{ this.__setValueRead( data.data, textList, contentNode ); } // textList.each(function(text, i){ // if (iy2) || y2=="auto") ? y1 : y2; // size.y = (y=="auto") ? "auto" : y.toInt(); // //alert(size.y) //} this.iconNode.setStyle("height", ""+size.y+"px"); //alert(this.iconNode.getStyle("height")) } }, _searchOptions: function(){ if (this.json.itemType === "dynamic"){ return function(value, callback){ var event = { "value": value, "callback": callback }; this.form.Macro.fire(((this.json.itemDynamic) ? this.json.itemDynamic.code : ""), this, event); }.bind(this); }else{ return null; } }, /** * @summary 获取选择项。 * @return {Array | Promise} 返回选择项数组或Promise,如:
[
     *  "女|female",
     *  "男|male"
     * ]
* @example * this.form.get('fieldId').getOptions(); * @example * //异步 * var opt = this.form.get('fieldId').getOptions(); * Promise.resolve(opt).then(function(options){ * //options为选择项数组 * }) */ getOptions: function(async, refresh){ if( this.optionsCache && !refresh )return this.optionsCache; this.optionsCache = null; var opt = this._getOptions(async, refresh); if( (opt && typeOf(opt.then) === "function") ){ var p = Promise.resolve( opt ).then(function(option){ this.moduleSelectAG = null; this.optionsCache = this.parseOptions(option || []); return this.optionsCache; }.bind(this)); this.moduleSelectAG = p; return p; }else{ this.optionsCache = this.parseOptions(opt || []); return this.optionsCache; } }, parseOptions: function(list){ // var list = []; // if (this.json.itemType === "values"){ // list = this.json.itemValues; // }else if (this.json.itemType === "script"){ // list = this.form.Macro.exec(((this.json.itemScript) ? this.json.itemScript.code : ""), this); // } if (list.length){ var options = []; list.each(function(v){ if (typeOf(v)==="object"){ options.push(v); }else{ v = v.toString(); var arr = v.split("|"); var o = { "text": "", "keyword": "", "value": "" }; switch (arr.length){ case 0: break; case 1: o.text = arr[0]; o.keyword = arr[0]; o.value = arr[0]; break; case 2: o.text = arr[0]; o.keyword = arr[0]; o.value = arr[1]; break; case 3: o.text = arr[0]; o.keyword = arr[1]; o.value = arr[2]; break; default: o.text = arr[0]; o.keyword = arr[1]; o.value = arr[2]; } options.push(o); } }.bind(this)); return options; } return []; }, /** * 当表单上没有对应组件的时候,可以使用this.data[fieldId] = data赋值。 * @summary 为组件赋值。 * @param value{String} . * @example * this.form.get("fieldId").setData("test"); //赋文本值 * @example * //如果无法确定表单上是否有组件,需要判断 * if( this.form.get('fieldId') ){ //判断表单是否有无对应组件 * this.form.get('fieldId').setData( data ); * }else{ * this.data['fieldId'] = data; * } */ setData: function(value){ this._setBusinessData(value); this._setValue(value); }, _setValue: function(value){ if (!value) value = []; if (value.length==1 && (!value[0])) value = []; if (typeOf(value) !=="array") value = [value]; if (this.combox){ var textData = this.getTextData( value ); if( typeOf(textData.then) === "function" ){ Promise.resolve(textData).then(function (tData) { this.combox.clear(); this.__setValueEdit( tData ); }.bind(this)) }else{ this.combox.clear(); this.__setValueEdit( textData ) } }else{ var textList = this.getTextListByValue( value ); if( typeOf(textList.then) === "function" ){ Promise.resolve(textList).then(function (tList) { this.__setValueRead( value, tList ); }.bind(this)) }else{ this.__setValueRead( value, textList ); } } }, __setValueEdit: function(textData){ var comboxValues = []; textData.value.each(function(v, i){ comboxValues.push({ "text": textData.text[i] || v, "value": v }); }.bind(this)); this.combox.addNewValues(comboxValues); this.fieldModuleLoaded = true; }, __setValueRead: function(value, textList, contentNode){ if(!contentNode)contentNode = new Element("div", { "styles": { "overflow": "hidden"} }).inject(this.node); textList.each(function(text, i){ if (i