Преглед изворни кода

表单默认值支持异步返回

huqi пре 5 година
родитељ
комит
917c141005

+ 11 - 0
o2web/source/o2_core/o2.js

@@ -1699,6 +1699,7 @@
                         result = r(result, arguments) || result;
                     });
                 }
+                return result;
             }
         },
         _createFailure: function(){
@@ -1758,6 +1759,16 @@
         var asyncGeneratorPrototype = new _AsyncGeneratorPrototype(resolve, reject, name);
         return Object.appendChain(asyncGeneratorPrototype, "if (this.success) this.success.apply(this, arguments);");
     }
+    _AsyncGenerator.all = function(arr){
+        var result = [];
+        arr.forEach(function(a){
+            if (o2.typeOf(a)=="function"){
+
+            }else{
+
+            }
+        });
+    }
 
     o2.AsyncGenerator = o2.AG = _AsyncGenerator;
 

+ 3 - 1
o2web/source/x_component_process_Xform/$Input.js

@@ -183,6 +183,7 @@ 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;
         var value = this._getBusinessData();
         if (!value && this.moduleValueAG) value = this.moduleValueAG;
         if (!value) value = this._computeValue();
@@ -202,6 +203,7 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input =  new Class({
             if (this.node.getFirst()) this.node.getFirst().set("value", value || "");
             if (this.readonly || this.json.isReadonly) this.node.set("text", value);
             this.moduleValueAG = null;
+            return value;
         }
     },
 	_loadValue: function(){
@@ -240,7 +242,7 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input =  new Class({
     },
 	getData: function(when){
         if (this.json.compute == "save") this._setValue(this._computeValue());
-		return this.getInputData();
+        return this.getInputData();
 	},
     getInputData: function(){
         if (this.node.getFirst()){

+ 25 - 8
o2web/source/x_component_process_Xform/Calendar.js

@@ -23,18 +23,35 @@ MWF.xApplication.process.Xform.Calendar = MWF.APPCalendar =  new Class({
             });
         }
     },
+    _getValueAg: function(value,isDate){
+        if (o2.typeOf(value)=="function" && value.addResolve){
+            return value.then(function(v){
+                this._getValueAg(v, isDate);
+            }.bind(this));
+        }else{
+            var d = (!!value) ? Date.parse(value) : "";
+            if (isDate){
+                return d || null;
+            }else{
+                return (d) ? d.format(this.json.format) : "";
+            }
+        }
+    },
     getValue: function(isDate){
         var value = this._getBusinessData();
         if( value && !isDate)return value;
 
+        if (!value && this.moduleValueAG) value = this.moduleValueAG;
         if (!value) value = this._computeValue();
-        var d = (!!value) ? Date.parse(value) : "";
-        if (isDate){
-            return d || null;
-        }else{
-            //if (d) value = Date.parse(value).format(this.json.format);
-            return (d) ? d.format(this.json.format) : "";
-        }
+
+        return value || "";
+
+        // var d = (!!value) ? Date.parse(value) : "";
+        // if (isDate){
+        //     return d || null;
+        // }else{
+        //     return (d) ? d.format(this.json.format) : "";
+        // }
     },
     getValueStr : function(){
         var value = this._getBusinessData();
@@ -184,4 +201,4 @@ MWF.xApplication.process.Xform.Calendar = MWF.APPCalendar =  new Class({
         }
         return resultArr[0] + "-" + resultArr[1] + "-" + resultArr[2] + " " + resultArr[3]+":"+resultArr[4]+":"+resultArr[5];
     }
-}); 
+}); 

+ 20 - 7
o2web/source/x_component_process_Xform/Org.js

@@ -91,7 +91,15 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         //}
     },
 
-
+    _valueMerge: function(values, v){
+        if (o2.typeOf(v)=="function"){
+            return v.then(function(re){
+                this._valueMerge(values, re)
+            }.bind(this));
+        }else{
+            return values.concat(v);
+        }
+    },
     _computeValue: function(){
         var simple = this.json.storeRange === "simple";
         var values = [];
@@ -109,6 +117,9 @@ 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)=="function"){
+
+                    }
                     var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\")";
                     var d = this.form.Macro.exec(code, this);
                     if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
@@ -120,13 +131,15 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
             var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
 
             if (o2.typeOf(fd)=="function"){
-                debugger;
                 // value.addResolve(function(v){
                 //     this._setBusinessData(v);
                 //     if (this.node.getFirst()) this.node.getFirst().set("value", v || "");
                 //     if (this.readonly || this.json.isReadonly) this.node.set("text", v);
                 // }.bind(this));
-                return {"values": values, "resolve": fd};
+                fd.then(function(v){
+                    return this._valueMerge(values, v);
+                }.bind(this));
+                return fd;
             }else{
                 if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
                 fd.each(function(fdd){
@@ -867,12 +880,12 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
     },
     _setValue: function(value){
         debugger;
-        if (o2.typeOf(value)==="object" && value.resolve){
+        if (o2.typeOf(value)==="function"){
             var simple = this.json.storeRange === "simple";
-            var values = value.values;
-            value.resolve.addResolve(function(fd){
+            var values = [];
+            value.addResolve(function(fd){
                 if (o2.typeOf(fd)==="function" && fd.addResolve){
-                    this._setValue({"values": values, "resolve": fd});
+                    this._setValue(fd);
                 }else{
                     if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
                     fd.each(function(fdd){