Jelajahi Sumber

支持表单元素默认值异步返回

huqi 5 tahun lalu
induk
melakukan
6ab4671980

+ 27 - 12
o2web/source/o2_core/o2.js

@@ -212,10 +212,10 @@
         var type = o2.typeOf(callback).toLowerCase();
         if (!key) key = "success";
 
-        if (key.toLowerCase()==="success" && type==="function"){
+        if (key.toLowerCase()==="success" && (type==="function" || type==="o2_async_function")){
             callback.apply(b, par);
         }else{
-            if (type==="function" || type==="object"){
+            if (type==="function" || type==="object" || type==="o2_async_function"){
                 var name = ("on-"+key).camelCase();
                 if (callback[name]){
                     callback[name].apply(b, par);
@@ -1700,6 +1700,9 @@
                         result = r(result, arguments) || result;
                     });
                 }
+                _self.isSuccess = true;
+                _self.result = result;
+                _self.arg = arguments;
                 return result;
             }
         },
@@ -1713,6 +1716,10 @@
                         result = r(result, arguments) || result;
                     });
                 }
+                _self.isFailure = true;
+                _self.result = result;
+                _self.arg = arguments;
+                return result;
             }
         },
         setResolve: function(resolve){
@@ -1728,11 +1735,15 @@
         addResolve: function(resolve){
             if (!this.success) this._createSuccess();
             if (resolve){
-                if (!this.success.resolve){
-                    this.success.resolve = resolve;
+                if (this.isSuccess){
+                    resolve(this.result, this.arg);
                 }else{
-                    if (!this.success.resolveList) this.success.resolveList = [];
-                    this.success.resolveList.push(resolve);
+                    if (!this.success.resolve){
+                        this.success.resolve = resolve;
+                    }else{
+                        if (!this.success.resolveList) this.success.resolveList = [];
+                        this.success.resolveList.push(resolve);
+                    }
                 }
             }
             return this;
@@ -1740,11 +1751,15 @@
         addReject: function(reject){
             if (!this.failure) this._createFailure();
             if (reject){
-                if (!this.failure.reject){
-                    this.failure.reject = reject;
+                if (this.isFailure){
+                    reject(this.result, this.arg);
                 }else{
-                    if (!this.failure.rejectList) this.failure.rejectList = [];
-                    this.failure.rejectList.push(reject);
+                    if (!this.failure.reject){
+                        this.failure.reject = reject;
+                    }else{
+                        if (!this.failure.rejectList) this.failure.rejectList = [];
+                        this.failure.rejectList.push(reject);
+                    }
                 }
             }
             return this;
@@ -1776,7 +1791,7 @@
             if (count<=0)ag();
         }
 
-        window.setTimeout(function(){
+        //window.setTimeout(function(){
             arr.forEach(function(a){
                 if (typeOf(a)=="array"){
                     o2.AG.all(a).then(function(v){
@@ -1797,7 +1812,7 @@
                     }
                 }
             });
-        }, 0);
+        //}, 0);
         return ag;
     }
 

+ 1 - 2
o2web/source/o2_core/o2/xDesktop/WebSocket.js

@@ -42,8 +42,7 @@ MWF.xDesktop.WebSocket = new Class({
 
     connect: function(){
         if (layout.config.webSocketEnable){
-            var token = layout.session.token;
-            var ws = this.ws+"?x-token="+encodeURIComponent(token);
+            var ws = this.ws+"?x-token="+encodeURIComponent(layout.session.token);
             ws = o2.filterUrl(ws);
 
             try{

+ 9 - 13
o2web/source/x_component_process_FormDesigner/Module/Org/org.html

@@ -34,6 +34,13 @@
                     <input type="radio" name="isInput" value="false" text{(!$.isInput)?'checked':''}/>否
                 </td>
             </tr>
+            <tr>
+                <td class="editTableTitle">数据保存:</td>
+                <td class="editTableValue">
+                    <input type="radio" name="storeRange" value="full" text{($.section=='full')?'checked':''}/>完整
+                    <input type="radio" name="storeRange" value="simple" text{($.section!=='full')?'checked':''}/>精简
+                </td>
+            </tr>
             <tr>
                 <td class="editTableTitle">分隔符:</td>
                 <td class="editTableValue">
@@ -441,18 +448,7 @@
             <div style="height: 24px; line-height:24px; background-color: #EEE; padding: 0px 6px; border-top: 1px solid #999">通过编写脚本排除组织、身份、个人和群组的选择范围</div>
             <div class="MWFFormulaArea" name="exclude" title="脚本 (S)"></div>
         </div>
-        <div>
-            <div style="text-align: center; height: 24px; background-color: #F1F1F1; line-height: 24px; border-bottom: 1px solid #cccccc; border-top: 1px solid #cccccc;font-weight: bold;">数据保存</div>
-            <table width="100%" border="0" cellpadding="5" cellspacing="0" class="editTable">
-                <tr>
-                    <td class="editTableTitle">数据保存:</td>
-                    <td class="editTableValue">
-                        <input type="radio" name="storeRange" value="full" text{($.section!='simple')?'checked':''}/>完整
-                        <input type="radio" name="storeRange" value="simple" text{($.section=='simple')?'checked':''}/>精简
-                    </td>
-                </tr>
-            </table>
-        </div>
+
     </div>
     <div title="事件"  class="MWFTab">
         <div class="MWFEventsArea" name="events"></div>
@@ -492,4 +488,4 @@
     <div title="JSON"  class="MWFTab">
         <div class="MWFJSONArea" style="font-family: Verdana, Geneva, sans-serif; font-size:14px"></div>
     </div>
-</div>
+</div>

+ 32 - 40
o2web/source/x_component_process_Xform/Org.js

@@ -136,10 +136,21 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
                         }.bind(this));
                         values.push(ag);
                     }else{
-                        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()] : [];
-                        d.each(function(dd){if (dd) values.push(MWF.org.parseOrgData(dd, true, simple));});
+                        var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\", true)";
+                        var r = this.form.Macro.exec(code, this);
+                        var ag = o2.AG.all(r).then(function(d) {
+                            //var d = rd[0];
+                            if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
+                            var arr = [];
+                            d.each(function(dd){
+                                if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
+                            });
+                            return arr;
+                        }.bind(this));
+                        values.push(ag);
+
+                        // if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
+                        // d.each(function(dd){if (dd) values.push(MWF.org.parseOrgData(dd, true, simple));});
                     }
 
                 }.bind(this));
@@ -898,56 +909,37 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         return node;
     },
     _setValue: function(value){
+        debugger;
         var values = [];
-        o2.AG.all(value).then(function(d) {
+        var ags = [];
+        this.moduleValueAG = o2.AG.all(value).then(function(d) {
             if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
 
             d.each(function(dd){
                 //if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
                 if (dd){
                     if (typeOf(dd)==="string"){
-                        var data;
-                        this.getOrgAction()[this.getValueMethod(dd)](function(json){
-                            data = MWF.org.parseOrgData(json.data, true, simple);
-                        }.bind(this), null, dd, false);
-
-                        values.push(data);
+                        ags.push(this.getOrgAction()[this.getValueMethod(dd)](function(json){
+                            return MWF.org.parseOrgData(json.data, true, simple);
+                        }.bind(this).ag(), null, dd, true));
                     }else{
-                        values.push(d);
+                        values.push(dd);
                     }
                 }
             });
-            this.__setValue(values);
-        }.bind(this));
-
+            if (ags.length){
+                o2.AG.all(ags).then(function(data){
+                    values.push(data);
+                    this.__setValue(values);
+                });
+            }else{
+                this.__setValue(values);
+            }
 
-        // if (o2.typeOf(value)==="function"){
-        //     var simple = this.json.storeRange === "simple";
-        //     var values = [];
-        //     value.addResolve(function(fd){
-        //         if (o2.typeOf(fd)==="function" && fd.addResolve){
-        //             this._setValue(fd);
-        //         }else{
-        //             if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
-        //             fd.each(function(fdd){
-        //                 if (fdd){
-        //                     if (typeOf(fdd)==="string"){
-        //                         var data;
-        //                         this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, fdd, false);
-        //                         values.push(data);
-        //                     }else{
-        //                         values.push(fdd);
-        //                     }
-        //                 }
-        //             }.bind(this));
-        //             this.__setValue(values);
-        //         }
-        //     }.bind(this));
-        // }else{
-        //     this.__setValue(value);
-        // }
+        }.bind(this));
     },
     __setValue: function(value){
+        this.moduleValueAG = null;
         if (value.length==1 && !(value[0])) value=[];
         var values = [];
         var comboxValues = [];