Jelajahi Sumber

支持表单元素默认值异步返回。
完成基础$Input组件。Org组件基本完成,
*脚本中返回一个异步函数,来实现默认值的异步处理,异步函数使用Function.prototype.ag()方法创建,异步函数可作为平台服务器调用方法中的回调函数,平台服务器调用方法返回值为回调函数。
*脚本中的this.org方法的最后一个参数为是否异步标志,true是返回异步函数,false时同步执行,返回获取的值。(后端脚本都是同步的)
*组件的getValue方法异步处理时会返回一个ag函数(同步时或异步处理已经完成,返回组件的实际值),通过ag.then(function(value){});方法进行后续处理,或直接通过o2.AG.all(module.getValue()).then(function(value){});来处理。
*通过this.data.xxx=xxx设置值时,可赋值ag函数实现异步

*组件的getData方法返回组件当前的实际值,不考虑异步情况。
*通过this.data.xxx方法获取数据时不考虑异步情况
*org组件的addData方法用于允许输入是选人后的组件值添加,会同步获取人员信息,此处没有做异步处理。

huqi 5 tahun lalu
induk
melakukan
86c2e783de

+ 5 - 4
o2web/source/o2_core/o2.js

@@ -1683,13 +1683,14 @@
     var _AsyncGeneratorPrototype = _Class.create({
         initialize: function(resolve, reject, name){
             debugger;
+            this.isAG = true;
             this.name = name || "";
             this._createSuccess();
             this._createFailure();
             if (resolve) this.success.resolve = resolve;
             if (reject) this.failure.reject = reject;
         },
-        $family: function(){ return "o2_async_function"; },
+        //$family: function(){ return "o2_async_function"; },
         _createSuccess: function(){
             var _self = this;
             this.success = function(){
@@ -1736,7 +1737,7 @@
             if (!this.success) this._createSuccess();
             if (resolve){
                 if (this.isSuccess){
-                    resolve(this.result, this.arg);
+                    this.result = resolve(this.result, this.arg);
                 }else{
                     if (!this.success.resolve){
                         this.success.resolve = resolve;
@@ -1752,7 +1753,7 @@
             if (!this.failure) this._createFailure();
             if (reject){
                 if (this.isFailure){
-                    reject(this.result, this.arg);
+                    this.result = reject(this.result, this.arg);
                 }else{
                     if (!this.failure.reject){
                         this.failure.reject = reject;
@@ -1799,7 +1800,7 @@
                         check();
                     });
                 }else{
-                    if (o2.typeOf(a)=="o2_async_function"){
+                    if (a.isAG){
                         a.then(function(v){
                             o2.AG.all(v).then(function(r){
                                 result = result.concat(r);

+ 3 - 1
o2web/source/o2_core/o2/xDesktop/Common.js

@@ -614,7 +614,9 @@ MWF.org = {
                 "name": data.name,
                 "distinguishedName": data.distinguishedName,
                 "unitLevelName" : data.unitLevelName,
-                "person": data.person
+                "person": data.person,
+                "unit": data.unit,
+                "unitName": data.unitName,
             };
             if( data.ignoreEmpower )rData.ignoreEmpower = true;
             if( data.ignoredEmpower )rData.ignoredEmpower = true;

+ 6 - 4
o2web/source/x_component_process_Xform/$Input.js

@@ -183,14 +183,14 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input =  new Class({
         return (this.json.defaultValue && this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
     },
 	getValue: function(){
-	    debugger;
+        if (this.moduleValueAG) return this.moduleValueAG;
         var value = this._getBusinessData();
-        if (!value && this.moduleValueAG) value = this.moduleValueAG;
         if (!value) value = this._computeValue();
 		return value || "";
 	},
     _setValue: function(value){
-	    if (o2.typeOf(value)==="o2_async_function"){
+	    debugger;
+	    if (value && value.isAG){
 	        this.moduleValueAG = value;
             value.addResolve(function(v){
                 this._setValue(v);
@@ -255,7 +255,8 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input =  new Class({
         this.setData(this.getValue());
     },
 	setData: function(data){
-        if (o2.typeOf(data)==="o2_async_function"){
+        if (data && data.isAG){
+            this.moduleValueAG = data;
             data.addResolve(function(v){
                 this.setData(v);
             }.bind(this));
@@ -268,6 +269,7 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input =  new Class({
             }else{
                 this.node.set("text", data);
             }
+            this.moduleValueAG = null;
         }
 	},
 

+ 1 - 1
o2web/source/x_component_process_Xform/Calendar.js

@@ -24,7 +24,7 @@ MWF.xApplication.process.Xform.Calendar = MWF.APPCalendar =  new Class({
         }
     },
     _getValueAg: function(value,isDate){
-        if (o2.typeOf(value)=="o2_async_function"){
+        if (value && value.isAG){
             return value.then(function(v){
                 this._getValueAg(v, isDate);
             }.bind(this));

+ 1 - 1
o2web/source/x_component_process_Xform/Label.js

@@ -44,7 +44,7 @@ MWF.xApplication.process.Xform.Label = MWF.APPLabel =  new Class({
 		}
 	},
     _setNodeText: function(value){
-        if (o2.typeOf(value)==="o2_async_function"){
+        if (value && value.isAG){
             value.addResolve(function(v){
                 this._setNodeText(v);
             }.bind(this));

+ 2 - 1
o2web/source/x_component_process_Xform/Number.js

@@ -196,8 +196,9 @@ MWF.xApplication.process.Xform.Number = MWF.APPNumber =  new Class({
         return (this.json.defaultValue && this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "0");
     },
     getValue: function(){
+        if (this.moduleValueAG) return this.moduleValueAG;
         var value = this._getBusinessData();
         if (!value) value = this._computeValue();
         return value || "0";
     }
-});
+});

+ 117 - 85
o2web/source/x_component_process_Xform/Org.js

@@ -117,7 +117,7 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
             if (dutys.length){
                 dutys.each(function(duty){
                     if (duty.code) par = this.form.Macro.exec(duty.code, this);
-                    if (o2.typeOf(par)=="o2_async_function"){
+                    if (par && par.isAG){
                         var ag = o2.AG.all(par).then(function(p){
                             var uName = "";
                             if (p && p.length) uName = p[0].distinguishedName || p[0];
@@ -159,7 +159,7 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         if (this.json.defaultValue && this.json.defaultValue.code){
             var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
 
-            if (o2.typeOf(fd)=="o2_async_function"){
+            if (fd && fd.isAG){
                 // value.addResolve(function(v){
                 //     this._setBusinessData(v);
                 //     if (this.node.getFirst()) this.node.getFirst().set("value", v || "");
@@ -418,6 +418,7 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         }
     },
     resetData: function(){
+        debugger;
         var v = this.getValue();
         //this.setData((v) ? v.join(", ") : "");
         this.setData(v);
@@ -766,49 +767,7 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
             }
         }.bind(this));
     },
-    setData: function(value){
-        if (!value) return false;
-        var oldValues = this.getData();
-        var values = [];
-        var comboxValues = [];
-
-        var simple = this.json.storeRange === "simple";
-
-        var type = typeOf(value);
-        if (type==="array"){
-            value.each(function(v){
-                var vtype = typeOf(v);
-                var data = null;
-                if (vtype==="string"){
-                    var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
-                    this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, v, false);
-                }
-                if (vtype==="object") {
-                    data = MWF.org.parseOrgData(v, true, simple);
-                    if(data.woPerson)delete data.woPerson;
-                }
-                if (data){
-                    values.push(data);
-                    comboxValues.push({"text": this.getDataText(data),"value": data});
-                }
-            }.bind(this));
-        }
-        if (type==="string"){
-            var vData;
-            var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
-            this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, value, false);
-            if (vData){
-                values.push(vData);
-                comboxValues.push({"text": this.getDataText(vData),"value": vData});
-            }
-        }
-        if (type==="object"){
-            var vData = MWF.org.parseOrgData(value, true, simple);
-            if(vData.woPerson)delete vData.woPerson;
-            values.push( vData );
-            comboxValues.push({"text": this.getDataText(value),"value": vData});
-        }
-
+    checkChange: function(oldValues, values){
         var change = false;
         if (oldValues.length && values.length){
             if (oldValues.length === values.length){
@@ -824,46 +783,109 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         }else if (values.length || oldValues.length) {
             change = true;
         }
-        this._setBusinessData(values);
         if (change) this.fireEvent("change");
+    },
+    setData: function(value){
+        if (!value) return false;
+        var oldValues = this.getData();
+        if (value.length==1 && !(value[0])) value=[];
 
-        if (this.json.isInput){
-            if (this.combox){
-                this.combox.clear();
-                this.combox.addNewValues(comboxValues);
-            }else{
-                var node = this.node.getFirst();
-                if (node){
-                    node.empty();
-                    comboxValues.each(function(v, i){
-                        this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
-                    }.bind(this));
-                }
-            }
-            //
-            // this.combox.clear();
-            // values.each(function(v){
-            //     var vtype = typeOf(v);
-            //     if (vtype==="string"){
-            //         var data;
-            //         this.getOrgAction()[this.getValueMethod(v)](function(json){ data = json.data }.bind(this), null, v, false);
-            //         if (data) this.combox.addNewValue(this.getDataText(data), data);
-            //     }
-            //     if (vtype==="object"){
-            //         this.combox.addNewValue(this.getDataText(v), v);
-            //     }
-            // }.bind(this));
-        }else{
-            if (this.node.getFirst()){
-                var node = this.node.getFirst();
-                node.empty();
-                this.loadOrgWidget(values, node)
+        var ag = this._setValue(value);
+        ag.then(function(values){
+            if (values && values.isAG){
+                values.then(function(v){
+                    this.checkChange(oldValues, v)
+                }.bind(this));
             }else{
-                this.node.empty();
-                this.loadOrgWidget(values, this.node);
+                this.checkChange(oldValues, values)
             }
-        }
+        }.bind(this));
     },
+    // __setData: function(value){
+    //     if (!value) return false;
+    //     var oldValues = this.getData();
+    //     var values = [];
+    //     var comboxValues = [];
+    //
+    //     var simple = this.json.storeRange === "simple";
+    //
+    //     var type = typeOf(value);
+    //     if (type==="array"){
+    //         value.each(function(v){
+    //             var vtype = typeOf(v);
+    //             var data = null;
+    //             if (vtype==="string"){
+    //                 var error = (this.json.isInput) ? function(){ comboxValues.push(v); } : null;
+    //                 this.getOrgAction()[this.getValueMethod(v)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, v, false);
+    //             }
+    //             if (vtype==="object") {
+    //                 data = MWF.org.parseOrgData(v, true, simple);
+    //                 if(data.woPerson)delete data.woPerson;
+    //             }
+    //             if (data){
+    //                 values.push(data);
+    //                 comboxValues.push({"text": this.getDataText(data),"value": data});
+    //             }
+    //         }.bind(this));
+    //     }
+    //     if (type==="string"){
+    //         var vData;
+    //         var error = (this.json.isInput) ? function(){ comboxValues.push(value); } : null;
+    //         this.getOrgAction()[this.getValueMethod(value)](function(json){ vData = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), error, value, false);
+    //         if (vData){
+    //             values.push(vData);
+    //             comboxValues.push({"text": this.getDataText(vData),"value": vData});
+    //         }
+    //     }
+    //     if (type==="object"){
+    //         var vData = MWF.org.parseOrgData(value, true, simple);
+    //         if(vData.woPerson)delete vData.woPerson;
+    //         values.push( vData );
+    //         comboxValues.push({"text": this.getDataText(value),"value": vData});
+    //     }
+    //
+    //     var change = false;
+    //     if (oldValues.length && values.length){
+    //         if (oldValues.length === values.length){
+    //             for (var i=0; i<oldValues.length; i++){
+    //                 if ((oldValues[i].distinguishedName!==values[i].distinguishedName) || (oldValues[i].name!==values[i].name) || (oldValues[i].unique!==values[i].unique)){
+    //                     change = true;
+    //                     break;
+    //                 }
+    //             }
+    //         }else{
+    //             change = true;
+    //         }
+    //     }else if (values.length || oldValues.length) {
+    //         change = true;
+    //     }
+    //     this._setBusinessData(values);
+    //     if (change) this.fireEvent("change");
+    //
+    //     if (this.json.isInput){
+    //         if (this.combox){
+    //             this.combox.clear();
+    //             this.combox.addNewValues(comboxValues);
+    //         }else{
+    //             var node = this.node.getFirst();
+    //             if (node){
+    //                 node.empty();
+    //                 comboxValues.each(function(v, i){
+    //                     this.creteShowNode(v, (i===comboxValues.length-1)).inject(node);
+    //                 }.bind(this));
+    //             }
+    //         }
+    //     }else{
+    //         if (this.node.getFirst()){
+    //             var node = this.node.getFirst();
+    //             node.empty();
+    //             this.loadOrgWidget(values, node)
+    //         }else{
+    //             this.node.empty();
+    //             this.loadOrgWidget(values, this.node);
+    //         }
+    //     }
+    // },
     creteShowNode: function(data, islast){
         var nodeText = (data.text) ?  data.text : data;
         if (!islast) nodeText = nodeText + (this.json.splitShow || ", ");
@@ -912,7 +934,8 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         debugger;
         var values = [];
         var ags = [];
-        this.moduleValueAG = o2.AG.all(value).then(function(d) {
+        var simple = this.json.storeRange === "simple";
+        var ag = o2.AG.all(value).then(function(d) {
             if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
 
             d.each(function(dd){
@@ -926,17 +949,24 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
                         values.push(dd);
                     }
                 }
-            });
+            }.bind(this));
             if (ags.length){
-                o2.AG.all(ags).then(function(data){
-                    values.push(data);
+                return o2.AG.all(ags).then(function(data){
+                    values = values.concat(data);
                     this.__setValue(values);
-                });
+                    return values;
+                }.bind(this));
             }else{
                 this.__setValue(values);
+                return values
             }
+        }.bind(this));
 
+        this.moduleValueAG = ag;
+        ag.then(function(){
+            this.moduleValueAG = "";
         }.bind(this));
+        return ag;
     },
     __setValue: function(value){
         this.moduleValueAG = null;
@@ -1004,8 +1034,10 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         }else{
             if (this.node.getFirst()){
                 var node = this.node.getFirst();
+                node.empty();
                 this.loadOrgWidget(values, node)
             }else{
+                this.node.empty();
                 this.loadOrgWidget(values, this.node);
             }
         }