فهرست منبع

使用Promise支持表单的异步默认值

huqi 5 سال پیش
والد
کامیت
9f42d2cf92

+ 1 - 1
o2web/gulpfile.js

@@ -602,7 +602,7 @@ gulp.task("cleanAll", getCleanTask('/'));
 
 gulp.task("o2:new-v:html", function () {
     var path = "x_desktop";
-    var src = options.dest + '/x_desktop/*.html';
+    var src = 'source/x_desktop/*.html';
     var dest = options.dest + '/x_desktop/';
     return gulp.src(src)
         .pipe(assetRev())

+ 197 - 173
o2web/source/o2_core/o2.js

@@ -207,23 +207,35 @@
     this.o2.uuid = _uuid;
 
 
-    var _runCallback = function(callback, key, par, bind){
+    var _runCallback = function(callback, key, par, bind, promise_cb){
         var b = bind || callback;
-        var type = o2.typeOf(callback).toLowerCase();
         if (!key) key = "success";
 
-        if (key.toLowerCase()==="success" && (type==="function" || type==="o2_async_function")){
-            callback.apply(b, par);
-        }else{
-            if (type==="function" || type==="object" || type==="o2_async_function"){
+        var cb;
+        if (callback){
+            var type = o2.typeOf(callback).toLowerCase();
+            if (key.toLowerCase()==="success" && type==="function"){
+                cb = callback;
+            }else{
                 var name = ("on-"+key).camelCase();
-                if (callback[name]){
-                    callback[name].apply(b, par);
-                }else{
-                    if (callback[key]) callback[key].apply(b, par);
-                }
+                cb = (callback[name]) ? callback[name] : ((callback[key]) ? callback[key] : null);
             }
         }
+        if (cb) return (promise_cb) ? promise_cb(cb.apply(b, par)) : cb.apply(b, par) ;
+        return (promise_cb) ? promise_cb.apply(b, par) : null;
+
+        // if (key.toLowerCase()==="success" && (type==="function" || type==="o2_async_function")){
+        //     (promise_cb) ? promise_cb(callback.apply(b, par)) : callback.apply(b, par) ;
+        // }else{
+        //     if (type==="function" || type==="object" || type==="o2_async_function"){
+        //         var name = ("on-"+key).camelCase();
+        //         if (callback[name]){
+        //             (promise_cb) ? promise_cb(callback[name].apply(b, par)) : callback[name].apply(b, par);
+        //         }else{
+        //             if (callback[key]) (promise_cb) ? promise_cb(callback[key].apply(b, par)) : callback[key].apply(b, par);
+        //         }
+        //     }
+        // }
 
 
         // if (typeOf(callback).toLowerCase() === 'function'){
@@ -1379,6 +1391,7 @@
         var useWebWorker = (window.layout && layout.config && layout.config.useWebWorker);
         //var noCache = false;
         if (!loadAsync || !useWebWorker){
+            debugger;
             var res;
             var p = new Promise(function(s,f){
                 res = new Request.JSON({
@@ -1399,13 +1412,13 @@
                                 layout.session.token = xToken;
                             }
                         }
-                        o2.runCallback(callback, "success", [responseJSON]);
+                        return o2.runCallback(callback, "success", [responseJSON],null, s);
                     },
                     onFailure: function(xhr){
-                        o2.runCallback(callback, "requestFailure", [xhr]);
+                        return o2.runCallback(callback, "requestFailure", [xhr], null, f);
                     }.bind(this),
                     onError: function(text, error){
-                        o2.runCallback(callback, "error", [text, error]);
+                        return o2.runCallback(callback, "error", [text, error], null, f);
                     }.bind(this)
                 });
 
@@ -1426,7 +1439,7 @@
                 res.send(data);
             }.bind(this));
 
-            var oReturn = (callback.success && callback.success.isAG) ? callback.success : callback;
+            //var oReturn = (callback.success && callback.success.isAG) ? callback.success : callback;
             var oReturn = p;
             oReturn.res = res;
             return oReturn;
@@ -1442,24 +1455,28 @@
                 token: (window.layout && layout.session && layout.session.user) ? layout.session.user.token : ""
             }
             var actionWorker = new Worker("../o2_core/o2/actionWorker.js");
-            actionWorker.onmessage = function(e) {
-                result = e.data;
-                if (result.type==="done"){
-                    var xToken = result.data.xToken;
-                    if (xToken){
-                        if (window.layout){
-                            if (!layout.session) layout.session = {};
-                            layout.session.token = xToken;
+            var p = new Promise(function(s,f){
+                actionWorker.onmessage = function(e) {
+                    result = e.data;
+                    if (result.type==="done"){
+                        var xToken = result.data.xToken;
+                        if (xToken){
+                            if (window.layout){
+                                if (!layout.session) layout.session = {};
+                                layout.session.token = xToken;
+                            }
                         }
+                        o2.runCallback(callback, "success", [result.data], null, s);
+                    }else{
+                        o2.runCallback(callback, "failure", [result.data], null, f);
                     }
-                    o2.runCallback(callback, "success", [result.data]);
-                }else{
-                    o2.runCallback(callback, "failure", [result.data]);
+                    actionWorker.terminate();
                 }
-                actionWorker.terminate();
-            }
-            actionWorker.postMessage(workerMessage);
-            var oReturn = (callback.success && callback.success.addResolve) ? callback.success : callback;
+                actionWorker.postMessage(workerMessage);
+            }.bind(this));
+
+            //var oReturn = (callback.success && callback.success.addResolve) ? callback.success : callback;
+            var oReturn = p;
             oReturn.actionWorker = actionWorker;
             return oReturn;
             //return callback;
@@ -1629,15 +1646,15 @@
     // });
     Date.getFromServer = function(async){
         var d;
-        var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
+        var cb = ((async && o2.typeOf(async)=="function") ? async : null) || function(json){
         //var cb = function(json){
             d = Date.parse(json.data.serverTime);
             return d;
-        }.ag().catch(function(json){ return d; });
+        };
 
-        o2.Actions.get("x_program_center").echo(cb, null, !!async);
+        var promise = o2.Actions.get("x_program_center").echo(cb, null, !!async);
 
-        return (!!async) ? cb : d;
+        return (!!async) ? promise : d;
 
             // if (callback){
             //     o2.Actions.get("x_program_center").echo(function(json){
@@ -1686,147 +1703,154 @@
         return oReturn;
     }
 
-    var _AsyncGeneratorPrototype = _Class.create({
-        initialize: function(resolve, reject, name){
-            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"; },
-        _createSuccess: function(){
-            var _self = this;
-            this.success = function(){
-                var result;
-                if (_self.success.resolve) result = _self.success.resolve.apply(this, arguments);
-                if (_self.success.resolveList){
-                    _self.success.resolveList.each(function(r){
-                        result = r(result, arguments) || result;
-                    });
-                }
-                _self.isSuccess = true;
-                _self.result = result;
-                _self.arg = arguments;
-                return result;
-            }
-        },
-        _createFailure: function(){
-            var _self = this;
-            this.failure = function(){
-                var result;
-                if (_self.failure.reject) result = _self.failure.reject.apply(this, arguments);
-                if (_self.failure.rejectList){
-                    _self.failure.rejectList.each(function(r){
-                        result = r(result, arguments) || result;
-                    });
-                }
-                _self.isFailure = true;
-                _self.result = result;
-                _self.arg = arguments;
-                return result;
-            }
-        },
-        setResolve: function(resolve){
-            if (!this.success) this._createSuccess();
-            this.success.resolve = resolve;
-            return this;
-        },
-        setReject: function(reject){
-            if (!this.failure) this._createFailure();
-            this.failure.reject = reject;
-            return this;
-        },
-        addResolve: function(resolve){
-            if (!this.success) this._createSuccess();
-            if (resolve){
-                if (this.isSuccess){
-                    this.result = resolve(this.result, this.arg);
-                }else{
-                    if (!this.success.resolve){
-                        this.success.resolve = resolve;
-                    }else{
-                        if (!this.success.resolveList) this.success.resolveList = [];
-                        this.success.resolveList.push(resolve);
-                    }
-                }
-            }
-            return this;
-        },
-        addReject: function(reject){
-            if (!this.failure) this._createFailure();
-            if (reject){
-                if (this.isFailure){
-                    this.result = reject(this.result, this.arg);
-                }else{
-                    if (!this.failure.reject){
-                        this.failure.reject = reject;
-                    }else{
-                        if (!this.failure.rejectList) this.failure.rejectList = [];
-                        this.failure.rejectList.push(reject);
-                    }
-                }
-            }
-            return this;
-        },
-        then: function(resolve){
-            return this.addResolve(resolve);
-        },
-        "catch": function(reject){
-            return this.addReject(reject);
-        },
-    });
-    var _AsyncGenerator = function(resolve, reject, name){
-        var asyncGeneratorPrototype = new _AsyncGeneratorPrototype(resolve, reject, name);
-        return Object.appendChain(asyncGeneratorPrototype, "if (this.success) this.success.apply(this, arguments);");
-    }
-
-    //@todo
-    _AsyncGenerator.all = function(arr){
-        var result = [];
-        var ag = function (){
-            return result;
-        }.ag();
-
-        if (o2.typeOf(arr) !== "array") arr = [arr];
-
-        var count  = arr.length;
-        var check = function(){
-            count--;
-            if (count<=0)ag();
-        }
-
-        //window.setTimeout(function(){
-            arr.forEach(function(a){
-                if (typeOf(a)=="array"){
-                    o2.AG.all(a).then(function(v){
-                        result = result.concat(v);
-                        check();
-                    });
-                }else{
-                    if (a && a.isAG){
-                        a.then(function(v){
-                            o2.AG.all(v).then(function(r){
-                                result = result.concat(r);
-                                check();
-                            });
-                        });
-                    }else{
-                        result.push(a);
-                        check();
-                    }
-                }
-            });
-        //}, 0);
-        return ag;
-    }
-
-    o2.AsyncGenerator = o2.AG = _AsyncGenerator;
+    // user promise
+    // var _AsyncGeneratorPrototype = _Class.create({
+    //     initialize: function(resolve, reject, name){
+    //         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"; },
+    //     _createSuccess: function(){
+    //         var _self = this;
+    //         this.success = function(){
+    //             var result;
+    //             if (_self.success.resolve) result = _self.success.resolve.apply(this, arguments);
+    //             if (_self.success.resolveList){
+    //                 _self.success.resolveList.each(function(r){
+    //                     result = r(result, arguments) || result;
+    //                 });
+    //             }
+    //             _self.isSuccess = true;
+    //             _self.result = result;
+    //             _self.arg = arguments;
+    //             return result;
+    //         }
+    //     },
+    //     _createFailure: function(){
+    //         var _self = this;
+    //         this.failure = function(){
+    //             var result;
+    //             if (_self.failure.reject) result = _self.failure.reject.apply(this, arguments);
+    //             if (_self.failure.rejectList){
+    //                 _self.failure.rejectList.each(function(r){
+    //                     result = r(result, arguments) || result;
+    //                 });
+    //             }
+    //             _self.isFailure = true;
+    //             _self.result = result;
+    //             _self.arg = arguments;
+    //             return result;
+    //         }
+    //     },
+    //     setResolve: function(resolve){
+    //         if (!this.success) this._createSuccess();
+    //         this.success.resolve = resolve;
+    //         return this;
+    //     },
+    //     setReject: function(reject){
+    //         if (!this.failure) this._createFailure();
+    //         this.failure.reject = reject;
+    //         return this;
+    //     },
+    //     addResolve: function(resolve){
+    //         if (!this.success) this._createSuccess();
+    //         if (resolve){
+    //             if (this.isSuccess){
+    //                 this.result = resolve(this.result, this.arg);
+    //             }else{
+    //                 if (!this.success.resolve){
+    //                     this.success.resolve = resolve;
+    //                 }else{
+    //                     if (!this.success.resolveList) this.success.resolveList = [];
+    //                     this.success.resolveList.push(resolve);
+    //                 }
+    //             }
+    //         }
+    //         return this;
+    //     },
+    //     addReject: function(reject){
+    //         if (!this.failure) this._createFailure();
+    //         if (reject){
+    //             if (this.isFailure){
+    //                 this.result = reject(this.result, this.arg);
+    //             }else{
+    //                 if (!this.failure.reject){
+    //                     this.failure.reject = reject;
+    //                 }else{
+    //                     if (!this.failure.rejectList) this.failure.rejectList = [];
+    //                     this.failure.rejectList.push(reject);
+    //                 }
+    //             }
+    //         }
+    //         return this;
+    //     },
+    //     then: function(resolve){
+    //         return this.addResolve(resolve);
+    //     },
+    //     "catch": function(reject){
+    //         return this.addReject(reject);
+    //     },
+    // });
+    // var _AsyncGenerator = function(resolve, reject, name){
+    //     var asyncGeneratorPrototype = new _AsyncGeneratorPrototype(resolve, reject, name);
+    //     return Object.appendChain(asyncGeneratorPrototype, "if (this.success) this.success.apply(this, arguments);");
+    // }
+    //
+    // //@todo
+    // _AsyncGenerator.all = function(arr){
+    //     var result = [];
+    //     var ag = function (){
+    //         return result;
+    //     }.ag();
+    //
+    //     if (o2.typeOf(arr) !== "array") arr = [arr];
+    //
+    //     var count  = arr.length;
+    //     var check = function(){
+    //         count--;
+    //         if (count<=0)ag();
+    //     }
+    //
+    //     //window.setTimeout(function(){
+    //         arr.forEach(function(a){
+    //             if (typeOf(a)=="array"){
+    //                 o2.AG.all(a).then(function(v){
+    //                     result = result.concat(v);
+    //                     check();
+    //                 });
+    //             }else{
+    //                 if (a && a.isAG){
+    //                     a.then(function(v){
+    //                         o2.AG.all(v).then(function(r){
+    //                             result = result.concat(r);
+    //                             check();
+    //                         });
+    //                     });
+    //                 }else{
+    //                     result.push(a);
+    //                     check();
+    //                 }
+    //             }
+    //         });
+    //     //}, 0);
+    //     return ag;
+    // }
+    //
+    // o2.AsyncGenerator = o2.AG = _AsyncGenerator;
+    //
+    // Function.prototype.ag = function(){
+    //     return o2.AG(this);
+    // };
 
-    Function.prototype.ag = function(){
-        return o2.AG(this);
+    var _promiseAll = function(p){
+        var method = (o2.typeOf(p)=="array") ? "all" : "resolve";
+        return Promise[method](p);
     }
+    o2.promiseAll = _promiseAll;
 
 })();
 o2.core = true;

+ 12 - 14
o2web/source/o2_core/o2/xDesktop/Actions/RestActions.js

@@ -91,20 +91,18 @@ MWF.xDesktop.Actions.RestActions = new Class({
 
             var async = (option.async===false) ? false : true;
 
-            if (!option.success) option.success = function(v){return v;}.ag();
-            if (option.success && !option.success.isAG) option.success = option.success.ag();
-
-            //console.log(option.success)
-
-            if (option.failure && option.failure.failure) option.failure = option.failure.failure;
-            if (option.failure) {
-                option.success.catch(option.failure);
-                option.failure.owner = option.success;
-            }
-            if (!option.failure && option.success && option.success.failure){
-                option.failure = option.success.failure;
-                option.failure.owner = option.success;
-            }
+            // if (!option.success) option.success = function(v){return v;}.ag();
+            // if (option.success && !option.success.isAG) option.success = option.success.ag();
+            //
+            // if (option.failure && option.failure.failure) option.failure = option.failure.failure;
+            // if (option.failure) {
+            //     option.success.catch(option.failure);
+            //     option.failure.owner = option.success;
+            // }
+            // if (!option.failure && option.success && option.success.failure){
+            //     option.failure = option.success.failure;
+            //     option.failure.owner = option.success;
+            // }
 
             // if (option.failure && option.failure.failure) option.failure = option.failure.failure;
             // if (!option.failure && option.success && option.success.failure){

+ 1 - 1
o2web/source/o2_core/o2/xScript/Actions/UnitActions.js

@@ -3,7 +3,7 @@ MWF.xScript.Actions = MWF.xScript.Actions || {};
 MWF.require("MWF.xDesktop.Actions.RestActions", null, false);
 var invoke = function(serviceName){
     return function(data, success, failure, async){
-        this.action.invoke({"name": serviceName,"data": data, "async": async, "success": success,"failure": failure});
+        return this.action.invoke({"name": serviceName,"data": data, "async": async, "success": success,"failure": failure});
     }
 };
 

+ 174 - 146
o2web/source/o2_core/o2/xScript/CMSEnvironment.js

@@ -85,10 +85,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = (v && v.length===1) ? v[0] : v
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listGroup(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listGroup(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = null;
             // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
@@ -109,15 +109,15 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
-
+            };
 
+            var promise;
             if (nested){
-                orgActions.listSubGroupNested(data, cb, null, !!async);
+                promise = orgActions.listSubGroupNested(data, cb, null, !!async);
             }else{
-                orgActions.listSubGroupDirect(data, cb, null, !!async);
+                promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
 
             // var v = null;
             // if (nested){
@@ -138,14 +138,15 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise
             if (nested){
-                orgActions.listSupGroupNested(data, cb, null, !!async);
+                var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
             }else{
-                orgActions.listSupGroupDirect(data, cb, null, !!async);
+                var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
             // var v = null;
             // if (nested){
             //     orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
@@ -164,10 +165,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listGroupWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
             // return v;
@@ -183,10 +184,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data.value;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.groupHasRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.groupHasRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = false;
             // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
@@ -205,10 +206,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = null;
             // orgActions.listRole(data, function(json){v = json.data;}, null, false);
@@ -224,10 +225,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listRoleWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
             // return v;
@@ -245,10 +246,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data.value;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listRoleWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = false;
             // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
@@ -265,10 +266,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
             // return (v && v.length===1) ? v[0] : v;
@@ -284,14 +285,15 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonSubNested(data, cb, null, !!async);
+                promise = orgActions.listPersonSubNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonSubDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //查询上级人员--返回人员的对象数组
         //nested  布尔  true嵌套上级;false直接上级;默认false;
@@ -303,14 +305,15 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonSupNested(data, cb, null, !!async);
+                promise = orgActions.listPersonSupNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonSupDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //获取群组的所有人员--返回人员的对象数组
         listPersonWithGroup: function(name, async){
@@ -322,10 +325,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithGroup(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取角色的所有人员--返回人员的对象数组
         listPersonWithRole: function(name, async){
@@ -336,10 +339,11 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise
+            promise = orgActions.listPersonWithRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有人员--返回人员的对象数组
         listPersonWithIdentity: function(name, async){
@@ -350,10 +354,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有人员--返回人员的对象数组或人员对象
         getPersonWithIdentity: function(name, async){
@@ -365,10 +369,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v =  (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织成员的人员--返回人员的对象数组
         //nested  布尔  true嵌套的所有成员;false直接成员;默认false;
@@ -380,14 +384,15 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonWithUnitNested(data, cb, null, !!async);
+                promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //根据属性查询人员--返回人员的对象数组
         //name  string 属性名
@@ -400,10 +405,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据属性查询人员--返回人员的全称数组
         //name  string 属性名
@@ -416,10 +421,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data.personList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //人员属性************
@@ -461,10 +466,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data.attributeList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.getPersonAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员所有属性的名称
         listPersonAttributeName: function(name, async){
@@ -475,10 +480,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data.nameList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonAttributeName(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员的所有属性
         listPersonAllAttribute: function(name, async){
@@ -489,10 +494,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonAllAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //身份**********
@@ -506,10 +511,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员的身份
         listIdentityWithPerson: function(name, async){
@@ -520,10 +525,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listIdentityWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织成员身份--返回身份的对象数组
         //nested  布尔  true嵌套的所有成员;false直接成员;默认false;
@@ -532,18 +537,29 @@ MWF.xScript.CMSEnvironment = function(ev){
             var data = {"unitList": getNameFlag(name)};
             var v = null;
 
+            // var cb = function(json){
+            //     v = json.data;
+            //     if (async && o2.typeOf(async)=="function") return async(v);
+            //     return v;
+            // }.ag().catch(function(json){ return json; });
+
             var cb = function(json){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            if (nested){
-                orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
-            }else{
-                orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
-            }
-            return (!!async) ? cb : v;
+            var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
+            var promise = orgActions[method](data, cb, null, !!async);
+            promise.name = "org";
+
+            //
+            // if (nested){
+            //     orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
+            // }else{
+            //     orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
+            // }
+            return (!!async) ? promise : v;
         },
 
         //组织**********
@@ -557,10 +573,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnit(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnit(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织的下级--返回组织的对象数组
         //nested  布尔  true嵌套下级;false直接下级;默认false;
@@ -572,14 +588,15 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listUnitSubNested(data, cb, null, !!async);
+                promise = orgActions.listUnitSubNested(data, cb, null, !!async);
             }else{
-                orgActions.listUnitSubDirect(data, cb, null, !!async);
+                promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //查询组织的上级--返回组织的对象数组
         //nested  布尔  true嵌套上级;false直接上级;默认false;
@@ -593,14 +610,15 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listUnitSupNested(data, cb, null, !!async);
+                promise = orgActions.listUnitSupNested(data, cb, null, !!async);
             }else{
-                orgActions.listUnitSupDirect(data, cb, null, !!async);
+                promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
 
             // if (callback){
             //     if (nested){
@@ -632,6 +650,7 @@ MWF.xScript.CMSEnvironment = function(ev){
             }
 
             var cb;
+            var promise;
             switch (getUnitMethod){
                 case "current":
                     var data = {"identityList":getNameFlag(name)};
@@ -641,47 +660,47 @@ MWF.xScript.CMSEnvironment = function(ev){
                     // }.ag().catch(function(json){ return json; });
 
 
-                    var cb = function(json){
+                    cb = function(json){
                         v = json.data;  v=(v&&v.length===1) ? v[0] : v;
                         if (async && o2.typeOf(async)=="function") return async(v);
                         return v;
-                    }.ag().catch(function(json){ return json; });
+                    };
 
 
-                    orgActions.listUnitWithIdentity(data, cb, null, !!async);
+                    promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
                     break;
                 case "type":
                     var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
 
-                    var cb = function(json){
+                    cb = function(json){
                         v = json.data;
                         if (async && o2.typeOf(async)=="function") return async(v);
                         return v;
-                    }.ag().catch(function(json){ return json; });
+                    };
 
                     // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
                     //     v = json.data;  return v;
                     // }.ag().catch(function(json){ return json; });
 
-                    orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
+                    promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
                     break;
                 case "level":
                     var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
 
-                    var cb = function(json){
+                    cb = function(json){
                         v = json.data;  v=(v&&v.length===1) ? v[0] : v;
                         if (async && o2.typeOf(async)=="function") return async(v);
                         return v;
-                    }.ag().catch(function(json){ return json; });
+                    };
 
                     // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
                     //     v = json.data;  return v;
                     // }.ag().catch(function(json){ return json; });
 
-                    orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
+                    promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
                     break;
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //列出身份所在组织的所有上级组织
         listAllSupUnitWithIdentity: function(name, async){
@@ -692,10 +711,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取人员所在的所有组织
         listUnitWithPerson: function(name, async){
@@ -706,10 +725,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员所在组织的所有上级组织
         listAllSupUnitWithPerson: function(name, async){
@@ -720,10 +739,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据组织属性,获取所有符合的组织
         listUnitWithAttribute: function(name, attribute, async){
@@ -734,10 +753,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitWithAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据组织职务,获取所有符合的组织
         listUnitWithDuty: function(name, id, async){
@@ -748,10 +767,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitWithDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //组织职务***********
@@ -760,14 +779,15 @@ MWF.xScript.CMSEnvironment = function(ev){
             getOrgActions();
             var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
             var v = null;
+
             var cb = function(json){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.getDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.getDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有职务名称
         listDutyNameWithIdentity: function(name, async){
@@ -778,10 +798,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取组织的所有职务名称
         listDutyNameWithUnit: function(name, async){
@@ -792,10 +812,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data.nameList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listDutyNameWithUnit(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取组织的所有职务
         listUnitAllDuty: function(name, async){
@@ -806,10 +826,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitAllDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出顶层组织
         listTopUnit: function(async){
@@ -819,10 +839,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            action.listTopUnit(cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = action.listTopUnit(cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //组织属性**************
@@ -883,10 +903,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data.attributeList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.getUnitAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出组织所有属性的名称
         listUnitAttributeName: function(name, async){
@@ -897,10 +917,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data.nameList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitAttributeName(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出组织的所有属性
         listUnitAllAttribute: function(name, async){
@@ -911,10 +931,10 @@ MWF.xScript.CMSEnvironment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitAllAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         }
     };
 
@@ -2149,21 +2169,29 @@ MWF.xScript.createCMSDict = function(application){
             if (success===true) async=true;
             if (failure===true) async=true;
 
+            // var cb = function(json){
+            //     value = json.data;
+            //     MWF.xScript.addDictToCache(opt, path, value);
+            //     if (success && o2.typeOf(success)=="function") value = success(json.data);
+            //     return value;
+            // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
+
             var cb = function(json){
                 value = json.data;
                 MWF.xScript.addDictToCache(opt, path, value);
                 if (success && o2.typeOf(success)=="function") value = success(json.data);
                 return value;
-            }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
+            };
 
+            var promise;
             if (path){
                 var p = encodePath( path );
                 //var p = path.replace(/\./g, "/");
-                action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
+                promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
             }else{
-                action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
+                promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
             }
-            return (!!async) ? cb : value;
+            return (!!async) ? promise : value;
 
             // if (path){
             //     var p = encodePath( path );

+ 175 - 146
o2web/source/o2_core/o2/xScript/Environment.js

@@ -252,10 +252,10 @@ MWF.xScript.Environment = function(ev){
                 v = (v && v.length===1) ? v[0] : v
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listGroup(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listGroup(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = null;
             // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
@@ -276,15 +276,15 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
-
+            };
 
+            var promise;
             if (nested){
-                orgActions.listSubGroupNested(data, cb, null, !!async);
+                promise = orgActions.listSubGroupNested(data, cb, null, !!async);
             }else{
-                orgActions.listSubGroupDirect(data, cb, null, !!async);
+                promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
 
             // var v = null;
             // if (nested){
@@ -305,14 +305,15 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise
             if (nested){
-                orgActions.listSupGroupNested(data, cb, null, !!async);
+                var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
             }else{
-                orgActions.listSupGroupDirect(data, cb, null, !!async);
+                var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
             // var v = null;
             // if (nested){
             //     orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
@@ -331,10 +332,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listGroupWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
             // return v;
@@ -350,10 +351,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data.value;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.groupHasRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.groupHasRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = false;
             // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
@@ -372,10 +373,10 @@ MWF.xScript.Environment = function(ev){
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = null;
             // orgActions.listRole(data, function(json){v = json.data;}, null, false);
@@ -391,10 +392,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listRoleWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
             // return v;
@@ -412,10 +413,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data.value;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listRoleWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = false;
             // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
@@ -432,10 +433,10 @@ MWF.xScript.Environment = function(ev){
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
             // return (v && v.length===1) ? v[0] : v;
@@ -451,14 +452,15 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonSubNested(data, cb, null, !!async);
+                promise = orgActions.listPersonSubNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonSubDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //查询上级人员--返回人员的对象数组
         //nested  布尔  true嵌套上级;false直接上级;默认false;
@@ -470,14 +472,15 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonSupNested(data, cb, null, !!async);
+                promise = orgActions.listPersonSupNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonSupDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //获取群组的所有人员--返回人员的对象数组
         listPersonWithGroup: function(name, async){
@@ -489,10 +492,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithGroup(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取角色的所有人员--返回人员的对象数组
         listPersonWithRole: function(name, async){
@@ -503,10 +506,11 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise
+            promise = orgActions.listPersonWithRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有人员--返回人员的对象数组
         listPersonWithIdentity: function(name, async){
@@ -517,10 +521,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有人员--返回人员的对象数组或人员对象
         getPersonWithIdentity: function(name, async){
@@ -532,10 +536,10 @@ MWF.xScript.Environment = function(ev){
                 v =  (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织成员的人员--返回人员的对象数组
         //nested  布尔  true嵌套的所有成员;false直接成员;默认false;
@@ -547,14 +551,15 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonWithUnitNested(data, cb, null, !!async);
+                promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //根据属性查询人员--返回人员的对象数组
         //name  string 属性名
@@ -567,10 +572,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据属性查询人员--返回人员的全称数组
         //name  string 属性名
@@ -583,10 +588,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data.personList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //人员属性************
@@ -628,10 +633,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data.attributeList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.getPersonAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员所有属性的名称
         listPersonAttributeName: function(name, async){
@@ -642,10 +647,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data.nameList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonAttributeName(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员的所有属性
         listPersonAllAttribute: function(name, async){
@@ -656,10 +661,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonAllAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //身份**********
@@ -673,10 +678,10 @@ MWF.xScript.Environment = function(ev){
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员的身份
         listIdentityWithPerson: function(name, async){
@@ -687,10 +692,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listIdentityWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织成员身份--返回身份的对象数组
         //nested  布尔  true嵌套的所有成员;false直接成员;默认false;
@@ -699,18 +704,29 @@ MWF.xScript.Environment = function(ev){
             var data = {"unitList": getNameFlag(name)};
             var v = null;
 
+            // var cb = function(json){
+            //     v = json.data;
+            //     if (async && o2.typeOf(async)=="function") return async(v);
+            //     return v;
+            // }.ag().catch(function(json){ return json; });
+
             var cb = function(json){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            if (nested){
-                orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
-            }else{
-                orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
-            }
-            return (!!async) ? cb : v;
+            var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
+            var promise = orgActions[method](data, cb, null, !!async);
+            promise.name = "org";
+
+            //
+            // if (nested){
+            //     orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
+            // }else{
+            //     orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
+            // }
+            return (!!async) ? promise : v;
         },
 
         //组织**********
@@ -724,10 +740,10 @@ MWF.xScript.Environment = function(ev){
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnit(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnit(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织的下级--返回组织的对象数组
         //nested  布尔  true嵌套下级;false直接下级;默认false;
@@ -739,14 +755,15 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listUnitSubNested(data, cb, null, !!async);
+                promise = orgActions.listUnitSubNested(data, cb, null, !!async);
             }else{
-                orgActions.listUnitSubDirect(data, cb, null, !!async);
+                promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //查询组织的上级--返回组织的对象数组
         //nested  布尔  true嵌套上级;false直接上级;默认false;
@@ -760,14 +777,15 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listUnitSupNested(data, cb, null, !!async);
+                promise = orgActions.listUnitSupNested(data, cb, null, !!async);
             }else{
-                orgActions.listUnitSupDirect(data, cb, null, !!async);
+                promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
 
             // if (callback){
             //     if (nested){
@@ -799,6 +817,7 @@ MWF.xScript.Environment = function(ev){
             }
 
             var cb;
+            var promise;
             switch (getUnitMethod){
                 case "current":
                     var data = {"identityList":getNameFlag(name)};
@@ -808,47 +827,47 @@ MWF.xScript.Environment = function(ev){
                     // }.ag().catch(function(json){ return json; });
 
 
-                    var cb = function(json){
+                    cb = function(json){
                         v = json.data;  v=(v&&v.length===1) ? v[0] : v;
                         if (async && o2.typeOf(async)=="function") return async(v);
                         return v;
-                    }.ag().catch(function(json){ return json; });
+                    };
 
 
-                    orgActions.listUnitWithIdentity(data, cb, null, !!async);
+                    promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
                     break;
                 case "type":
                     var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
 
-                    var cb = function(json){
+                    cb = function(json){
                         v = json.data;
                         if (async && o2.typeOf(async)=="function") return async(v);
                         return v;
-                    }.ag().catch(function(json){ return json; });
+                    };
 
                     // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
                     //     v = json.data;  return v;
                     // }.ag().catch(function(json){ return json; });
 
-                    orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
+                    promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
                     break;
                 case "level":
                     var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
 
-                    var cb = function(json){
+                    cb = function(json){
                         v = json.data;  v=(v&&v.length===1) ? v[0] : v;
                         if (async && o2.typeOf(async)=="function") return async(v);
                         return v;
-                    }.ag().catch(function(json){ return json; });
+                    };
 
                     // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
                     //     v = json.data;  return v;
                     // }.ag().catch(function(json){ return json; });
 
-                    orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
+                    promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
                     break;
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //列出身份所在组织的所有上级组织
         listAllSupUnitWithIdentity: function(name, async){
@@ -859,10 +878,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取人员所在的所有组织
         listUnitWithPerson: function(name, async){
@@ -873,10 +892,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员所在组织的所有上级组织
         listAllSupUnitWithPerson: function(name, async){
@@ -887,10 +906,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据组织属性,获取所有符合的组织
         listUnitWithAttribute: function(name, attribute, async){
@@ -901,10 +920,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitWithAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据组织职务,获取所有符合的组织
         listUnitWithDuty: function(name, id, async){
@@ -915,10 +934,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitWithDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //组织职务***********
@@ -927,14 +946,15 @@ MWF.xScript.Environment = function(ev){
             getOrgActions();
             var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
             var v = null;
+
             var cb = function(json){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.getDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.getDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有职务名称
         listDutyNameWithIdentity: function(name, async){
@@ -945,10 +965,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取组织的所有职务名称
         listDutyNameWithUnit: function(name, async){
@@ -959,10 +979,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data.nameList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listDutyNameWithUnit(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取组织的所有职务
         listUnitAllDuty: function(name, async){
@@ -973,10 +993,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitAllDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出顶层组织
         listTopUnit: function(async){
@@ -986,10 +1006,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            action.listTopUnit(cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = action.listTopUnit(cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //组织属性**************
@@ -1050,10 +1070,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data.attributeList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.getUnitAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出组织所有属性的名称
         listUnitAttributeName: function(name, async){
@@ -1064,10 +1084,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data.nameList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitAttributeName(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出组织的所有属性
         listUnitAllAttribute: function(name, async){
@@ -1078,10 +1098,10 @@ MWF.xScript.Environment = function(ev){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitAllAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         }
     };
 
@@ -1819,6 +1839,7 @@ MWF.xScript.JSONData = function(data, callback, key, parent, _form){
     };
     var setter = function(data, callback, k, _self){
         return function(v){
+            debugger;
             data[k] = v;
             //debugger;
             //this.add(k, v, true);
@@ -2235,21 +2256,29 @@ MWF.xScript.createDict = function(application){
             if (success===true) async=true;
             if (failure===true) async=true;
 
+            // var cb = function(json){
+            //     value = json.data;
+            //     MWF.xScript.addDictToCache(opt, path, value);
+            //     if (success && o2.typeOf(success)=="function") value = success(json.data);
+            //     return value;
+            // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
+
             var cb = function(json){
                 value = json.data;
                 MWF.xScript.addDictToCache(opt, path, value);
                 if (success && o2.typeOf(success)=="function") value = success(json.data);
                 return value;
-            }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
+            };
 
+            var promise;
             if (path){
                 var p = encodePath( path );
                 //var p = path.replace(/\./g, "/");
-                action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
+                promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
             }else{
-                action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
+                promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
             }
-            return (!!async) ? cb : value;
+            return (!!async) ? promise : value;
 
             // if (path){
             //     var p = encodePath( path );

+ 262 - 145
o2web/source/o2_core/o2/xScript/PageEnvironment.js

@@ -131,14 +131,16 @@ MWF.xScript.PageEnvironment = function (ev) {
             var data = {"groupList": getNameFlag(name)};
 
             var v = null;
+
             var cb = function(json){
                 v = json.data;
                 v = (v && v.length===1) ? v[0] : v
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listGroup(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listGroup(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = null;
             // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
@@ -151,17 +153,23 @@ MWF.xScript.PageEnvironment = function (ev) {
             var data = {"groupList": getNameFlag(name)};
 
             var v = null;
+            // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
+            //     v = json.data;
+            //     return v;
+            // }.ag().catch(function(json){ return json; });
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listSubGroupNested(data, cb, null, !!async);
+                promise = orgActions.listSubGroupNested(data, cb, null, !!async);
             }else{
-                orgActions.listSubGroupDirect(data, cb, null, !!async);
+                promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
 
             // var v = null;
             // if (nested){
@@ -180,15 +188,17 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
+            var promise
             if (nested){
-                orgActions.listSupGroupNested(data, cb, null, !!async);
+                var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
             }else{
-                orgActions.listSupGroupDirect(data, cb, null, !!async);
+                var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
             // var v = null;
             // if (nested){
             //     orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
@@ -205,11 +215,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listGroupWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
             // return v;
@@ -223,11 +234,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = false;
             var cb = function(json){
                 v = json.data.value;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.groupHasRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.groupHasRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = false;
             // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
@@ -244,11 +256,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var cb = function(json){
                 v = json.data;
                 v = (v && v.length===1) ? v[0] : v;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = null;
             // orgActions.listRole(data, function(json){v = json.data;}, null, false);
@@ -262,11 +275,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listRoleWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
             // return v;
@@ -282,11 +296,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = false;
             var cb = function(json){
                 v = json.data.value;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listRoleWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = false;
             // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
@@ -301,11 +316,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var cb = function(json){
                 v = json.data;
                 v = (v && v.length===1) ? v[0] : v;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
             // return (v && v.length===1) ? v[0] : v;
@@ -319,15 +335,17 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonSubNested(data, cb, null, !!async);
+                promise = orgActions.listPersonSubNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonSubDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //查询上级人员--返回人员的对象数组
         //nested  布尔  true嵌套上级;false直接上级;默认false;
@@ -337,15 +355,17 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonSupNested(data, cb, null, !!async);
+                promise = orgActions.listPersonSupNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonSupDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //获取群组的所有人员--返回人员的对象数组
         listPersonWithGroup: function(name, async){
@@ -355,11 +375,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listPersonWithGroup(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取角色的所有人员--返回人员的对象数组
         listPersonWithRole: function(name, async){
@@ -368,11 +389,13 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listPersonWithRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise
+            promise = orgActions.listPersonWithRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有人员--返回人员的对象数组
         listPersonWithIdentity: function(name, async){
@@ -381,10 +404,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.listPersonWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有人员--返回人员的对象数组或人员对象
         getPersonWithIdentity: function(name, async){
@@ -394,10 +419,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var cb = function(json){
                 v = json.data;
                 v =  (v && v.length===1) ? v[0] : v;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.listPersonWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织成员的人员--返回人员的对象数组
         //nested  布尔  true嵌套的所有成员;false直接成员;默认false;
@@ -407,15 +434,17 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonWithUnitNested(data, cb, null, !!async);
+                promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //根据属性查询人员--返回人员的对象数组
         //name  string 属性名
@@ -426,11 +455,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listPersonWithAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据属性查询人员--返回人员的全称数组
         //name  string 属性名
@@ -441,11 +471,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data.personList;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //人员属性************
@@ -485,11 +516,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data.attributeList;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.getPersonAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员所有属性的名称
         listPersonAttributeName: function(name, async){
@@ -498,11 +530,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data.nameList;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listPersonAttributeName(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员的所有属性
         listPersonAllAttribute: function(name, async){
@@ -511,10 +544,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.listPersonAllAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //身份**********
@@ -525,12 +560,13 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
-                v = (v && v.length===1) ? v[0] : v
+                v = (v && v.length===1) ? v[0] : v;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员的身份
         listIdentityWithPerson: function(name, async){
@@ -539,11 +575,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listIdentityWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织成员身份--返回身份的对象数组
         //nested  布尔  true嵌套的所有成员;false直接成员;默认false;
@@ -552,17 +589,29 @@ MWF.xScript.PageEnvironment = function (ev) {
             var data = {"unitList": getNameFlag(name)};
             var v = null;
 
+            // var cb = function(json){
+            //     v = json.data;
+            //     if (async && o2.typeOf(async)=="function") return async(v);
+            //     return v;
+            // }.ag().catch(function(json){ return json; });
+
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            if (nested){
-                orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
-            }else{
-                orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
-            }
-            return (!!async) ? cb : v;
+            var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
+            var promise = orgActions[method](data, cb, null, !!async);
+            promise.name = "org";
+
+            //
+            // if (nested){
+            //     orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
+            // }else{
+            //     orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
+            // }
+            return (!!async) ? promise : v;
         },
 
         //组织**********
@@ -574,11 +623,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var cb = function(json){
                 v = json.data;
                 v = (v && v.length===1) ? v[0] : v;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listUnit(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnit(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织的下级--返回组织的对象数组
         //nested  布尔  true嵌套下级;false直接下级;默认false;
@@ -586,18 +636,19 @@ MWF.xScript.PageEnvironment = function (ev) {
             getOrgActions();
             var data = {"unitList": getNameFlag(name)};
             var v = null;
-
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listUnitSubNested(data, cb, null, !!async);
+                promise = orgActions.listUnitSubNested(data, cb, null, !!async);
             }else{
-                orgActions.listUnitSubDirect(data, cb, null, !!async);
+                promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //查询组织的上级--返回组织的对象数组
         //nested  布尔  true嵌套上级;false直接上级;默认false;
@@ -609,15 +660,17 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listUnitSupNested(data, cb, null, !!async);
+                promise = orgActions.listUnitSupNested(data, cb, null, !!async);
             }else{
-                orgActions.listUnitSupDirect(data, cb, null, !!async);
+                promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
 
             // if (callback){
             //     if (nested){
@@ -649,24 +702,57 @@ MWF.xScript.PageEnvironment = function (ev) {
             }
 
             var cb;
+            var promise;
             switch (getUnitMethod){
                 case "current":
                     var data = {"identityList":getNameFlag(name)};
-                    cb = function(json){ v = json.data;  v=(v&&v.length===1) ? v[0] : v; return v; }.ag().catch(function(json){ return v; });
-                    orgActions.listUnitWithIdentity(data, cb, null, !!async);
+
+                    // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
+                    //     v = json.data;  v=(v&&v.length===1) ? v[0] : v; return v;
+                    // }.ag().catch(function(json){ return json; });
+
+
+                    cb = function(json){
+                        v = json.data;  v=(v&&v.length===1) ? v[0] : v;
+                        if (async && o2.typeOf(async)=="function") return async(v);
+                        return v;
+                    };
+
+
+                    promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
                     break;
                 case "type":
                     var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
-                    cb = function(json){ v = json.data; }.ag().catch(function(json){ return v; });
-                    orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
+
+                    cb = function(json){
+                        v = json.data;
+                        if (async && o2.typeOf(async)=="function") return async(v);
+                        return v;
+                    };
+
+                    // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
+                    //     v = json.data;  return v;
+                    // }.ag().catch(function(json){ return json; });
+
+                    promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
                     break;
                 case "level":
                     var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
-                    cb = function(json){ v = json.data; }.ag().catch(function(json){ return v; });
-                    orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
+
+                    cb = function(json){
+                        v = json.data;  v=(v&&v.length===1) ? v[0] : v;
+                        if (async && o2.typeOf(async)=="function") return async(v);
+                        return v;
+                    };
+
+                    // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
+                    //     v = json.data;  return v;
+                    // }.ag().catch(function(json){ return json; });
+
+                    promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
                     break;
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //列出身份所在组织的所有上级组织
         listAllSupUnitWithIdentity: function(name, async){
@@ -675,10 +761,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取人员所在的所有组织
         listUnitWithPerson: function(name, async){
@@ -687,10 +775,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.listUnitWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员所在组织的所有上级组织
         listAllSupUnitWithPerson: function(name, async){
@@ -699,10 +789,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据组织属性,获取所有符合的组织
         listUnitWithAttribute: function(name, attribute, async){
@@ -711,10 +803,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.listUnitWithAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据组织职务,获取所有符合的组织
         listUnitWithDuty: function(name, id, async){
@@ -723,10 +817,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.listUnitWithDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //组织职务***********
@@ -735,12 +831,15 @@ MWF.xScript.PageEnvironment = function (ev) {
             getOrgActions();
             var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
             var v = null;
+
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.getDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            var promise = orgActions.getDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有职务名称
         listDutyNameWithIdentity: function(name, async){
@@ -748,11 +847,13 @@ MWF.xScript.PageEnvironment = function (ev) {
             var data = {"identityList":getNameFlag(name)};
             var v = null;
             var cb = function(json){
-                v = json.data.nameList;
+                v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取组织的所有职务名称
         listDutyNameWithUnit: function(name, async){
@@ -761,10 +862,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data.nameList;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.listDutyNameWithUnit(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取组织的所有职务
         listUnitAllDuty: function(name, async){
@@ -773,10 +876,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
-            orgActions.listUnitAllDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            };
+
+            var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出顶层组织
         listTopUnit: function(async){
@@ -784,11 +889,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            action.listTopUnit(cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = action.listTopUnit(cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //组织属性**************
@@ -847,11 +953,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data.attributeList;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.getUnitAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出组织所有属性的名称
         listUnitAttributeName: function(name, async){
@@ -860,11 +967,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data.nameList;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listUnitAttributeName(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出组织的所有属性
         listUnitAllAttribute: function(name, async){
@@ -873,11 +981,12 @@ MWF.xScript.PageEnvironment = function (ev) {
             var v = null;
             var cb = function(json){
                 v = json.data;
+                if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return v; });
+            };
 
-            orgActions.listUnitAllAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         }
     };
 
@@ -1873,21 +1982,29 @@ MWF.xScript.createDict = function(application){
             if (success===true) async=true;
             if (failure===true) async=true;
 
+            // var cb = function(json){
+            //     value = json.data;
+            //     MWF.xScript.addDictToCache(opt, path, value);
+            //     if (success && o2.typeOf(success)=="function") value = success(json.data);
+            //     return value;
+            // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
+
             var cb = function(json){
                 value = json.data;
                 MWF.xScript.addDictToCache(opt, path, value);
                 if (success && o2.typeOf(success)=="function") value = success(json.data);
                 return value;
-            }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
+            };
 
+            var promise;
             if (path){
                 var p = encodePath( path );
                 //var p = path.replace(/\./g, "/");
-                action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
+                promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
             }else{
-                action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
+                promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
             }
-            return (!!async) ? cb : value;
+            return (!!async) ? promise : value;
 
             // if (path){
             //     var p = encodePath( path );

+ 174 - 146
o2web/source/o2_core/o2/xScript/ViewEnvironment.js

@@ -61,10 +61,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = (v && v.length===1) ? v[0] : v
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listGroup(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listGroup(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = null;
             // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
@@ -85,15 +85,15 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
-
+            };
 
+            var promise;
             if (nested){
-                orgActions.listSubGroupNested(data, cb, null, !!async);
+                promise = orgActions.listSubGroupNested(data, cb, null, !!async);
             }else{
-                orgActions.listSubGroupDirect(data, cb, null, !!async);
+                promise = orgActions.listSubGroupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
 
             // var v = null;
             // if (nested){
@@ -114,14 +114,15 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise
             if (nested){
-                orgActions.listSupGroupNested(data, cb, null, !!async);
+                var promise = orgActions.listSupGroupNested(data, cb, null, !!async);
             }else{
-                orgActions.listSupGroupDirect(data, cb, null, !!async);
+                var promise = orgActions.listSupGroupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
             // var v = null;
             // if (nested){
             //     orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
@@ -140,10 +141,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listGroupWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listGroupWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
             // return v;
@@ -159,10 +160,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data.value;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.groupHasRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.groupHasRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = false;
             // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
@@ -181,10 +182,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = null;
             // orgActions.listRole(data, function(json){v = json.data;}, null, false);
@@ -200,10 +201,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listRoleWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
             // return v;
@@ -221,10 +222,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data.value;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listRoleWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listRoleWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
 
             // var v = false;
             // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
@@ -241,10 +242,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
             // var v = null;
             // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
             // return (v && v.length===1) ? v[0] : v;
@@ -260,14 +261,15 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonSubNested(data, cb, null, !!async);
+                promise = orgActions.listPersonSubNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonSubDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonSubDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //查询上级人员--返回人员的对象数组
         //nested  布尔  true嵌套上级;false直接上级;默认false;
@@ -279,14 +281,15 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonSupNested(data, cb, null, !!async);
+                promise = orgActions.listPersonSupNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonSupDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonSupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //获取群组的所有人员--返回人员的对象数组
         listPersonWithGroup: function(name, async){
@@ -298,10 +301,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithGroup(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithGroup(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取角色的所有人员--返回人员的对象数组
         listPersonWithRole: function(name, async){
@@ -312,10 +315,11 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithRole(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise
+            promise = orgActions.listPersonWithRole(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有人员--返回人员的对象数组
         listPersonWithIdentity: function(name, async){
@@ -326,10 +330,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有人员--返回人员的对象数组或人员对象
         getPersonWithIdentity: function(name, async){
@@ -341,10 +345,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v =  (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织成员的人员--返回人员的对象数组
         //nested  布尔  true嵌套的所有成员;false直接成员;默认false;
@@ -356,14 +360,15 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listPersonWithUnitNested(data, cb, null, !!async);
+                promise = orgActions.listPersonWithUnitNested(data, cb, null, !!async);
             }else{
-                orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
+                promise = orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //根据属性查询人员--返回人员的对象数组
         //name  string 属性名
@@ -376,10 +381,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据属性查询人员--返回人员的全称数组
         //name  string 属性名
@@ -392,10 +397,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data.personList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //人员属性************
@@ -437,10 +442,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data.attributeList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.getPersonAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.getPersonAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员所有属性的名称
         listPersonAttributeName: function(name, async){
@@ -451,10 +456,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data.nameList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonAttributeName(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonAttributeName(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员的所有属性
         listPersonAllAttribute: function(name, async){
@@ -465,10 +470,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listPersonAllAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listPersonAllAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //身份**********
@@ -482,10 +487,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员的身份
         listIdentityWithPerson: function(name, async){
@@ -496,10 +501,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listIdentityWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listIdentityWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织成员身份--返回身份的对象数组
         //nested  布尔  true嵌套的所有成员;false直接成员;默认false;
@@ -508,18 +513,29 @@ MWF.xScript.ViewEnvironment = function (ev) {
             var data = {"unitList": getNameFlag(name)};
             var v = null;
 
+            // var cb = function(json){
+            //     v = json.data;
+            //     if (async && o2.typeOf(async)=="function") return async(v);
+            //     return v;
+            // }.ag().catch(function(json){ return json; });
+
             var cb = function(json){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            if (nested){
-                orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
-            }else{
-                orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
-            }
-            return (!!async) ? cb : v;
+            var method = (nested) ? "listIdentityWithUnitNested" : "listIdentityWithUnitDirect";
+            var promise = orgActions[method](data, cb, null, !!async);
+            promise.name = "org";
+
+            //
+            // if (nested){
+            //     orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
+            // }else{
+            //     orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
+            // }
+            return (!!async) ? promise : v;
         },
 
         //组织**********
@@ -533,10 +549,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = (v && v.length===1) ? v[0] : v;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnit(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnit(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //查询组织的下级--返回组织的对象数组
         //nested  布尔  true嵌套下级;false直接下级;默认false;
@@ -548,14 +564,15 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listUnitSubNested(data, cb, null, !!async);
+                promise = orgActions.listUnitSubNested(data, cb, null, !!async);
             }else{
-                orgActions.listUnitSubDirect(data, cb, null, !!async);
+                promise = orgActions.listUnitSubDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //查询组织的上级--返回组织的对象数组
         //nested  布尔  true嵌套上级;false直接上级;默认false;
@@ -569,14 +586,15 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
+            var promise;
             if (nested){
-                orgActions.listUnitSupNested(data, cb, null, !!async);
+                promise = orgActions.listUnitSupNested(data, cb, null, !!async);
             }else{
-                orgActions.listUnitSupDirect(data, cb, null, !!async);
+                promise = orgActions.listUnitSupDirect(data, cb, null, !!async);
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
 
             // if (callback){
             //     if (nested){
@@ -608,6 +626,7 @@ MWF.xScript.ViewEnvironment = function (ev) {
             }
 
             var cb;
+            var promise;
             switch (getUnitMethod){
                 case "current":
                     var data = {"identityList":getNameFlag(name)};
@@ -617,47 +636,47 @@ MWF.xScript.ViewEnvironment = function (ev) {
                     // }.ag().catch(function(json){ return json; });
 
 
-                    var cb = function(json){
+                    cb = function(json){
                         v = json.data;  v=(v&&v.length===1) ? v[0] : v;
                         if (async && o2.typeOf(async)=="function") return async(v);
                         return v;
-                    }.ag().catch(function(json){ return json; });
+                    };
 
 
-                    orgActions.listUnitWithIdentity(data, cb, null, !!async);
+                    promise = orgActions.listUnitWithIdentity(data, cb, null, !!async);
                     break;
                 case "type":
                     var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"type":flag};
 
-                    var cb = function(json){
+                    cb = function(json){
                         v = json.data;
                         if (async && o2.typeOf(async)=="function") return async(v);
                         return v;
-                    }.ag().catch(function(json){ return json; });
+                    };
 
                     // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
                     //     v = json.data;  return v;
                     // }.ag().catch(function(json){ return json; });
 
-                    orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
+                    promise = orgActions.getUnitWithIdentityAndType(data, cb, null, !!async);
                     break;
                 case "level":
                     var data = {"identity":(typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name,"level":flag};
 
-                    var cb = function(json){
+                    cb = function(json){
                         v = json.data;  v=(v&&v.length===1) ? v[0] : v;
                         if (async && o2.typeOf(async)=="function") return async(v);
                         return v;
-                    }.ag().catch(function(json){ return json; });
+                    };
 
                     // var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : null) || function(json){
                     //     v = json.data;  return v;
                     // }.ag().catch(function(json){ return json; });
 
-                    orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
+                    promise = orgActions.getUnitWithIdentityAndLevel(data, cb, null, !!async);
                     break;
             }
-            return (!!async) ? cb : v;
+            return (!!async) ? promise : v;
         },
         //列出身份所在组织的所有上级组织
         listAllSupUnitWithIdentity: function(name, async){
@@ -668,10 +687,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取人员所在的所有组织
         listUnitWithPerson: function(name, async){
@@ -682,10 +701,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出人员所在组织的所有上级组织
         listAllSupUnitWithPerson: function(name, async){
@@ -696,10 +715,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据组织属性,获取所有符合的组织
         listUnitWithAttribute: function(name, attribute, async){
@@ -710,10 +729,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitWithAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            promise = orgActions.listUnitWithAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //根据组织职务,获取所有符合的组织
         listUnitWithDuty: function(name, id, async){
@@ -724,10 +743,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitWithDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitWithDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //组织职务***********
@@ -736,14 +755,15 @@ MWF.xScript.ViewEnvironment = function (ev) {
             getOrgActions();
             var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
             var v = null;
+
             var cb = function(json){
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.getDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.getDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取身份的所有职务名称
         listDutyNameWithIdentity: function(name, async){
@@ -754,10 +774,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取组织的所有职务名称
         listDutyNameWithUnit: function(name, async){
@@ -768,10 +788,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data.nameList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listDutyNameWithUnit(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listDutyNameWithUnit(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //获取组织的所有职务
         listUnitAllDuty: function(name, async){
@@ -782,10 +802,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitAllDuty(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitAllDuty(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出顶层组织
         listTopUnit: function(async){
@@ -795,10 +815,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            action.listTopUnit(cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = action.listTopUnit(cb, null, !!async);
+            return (!!async) ? promise : v;
         },
 
         //组织属性**************
@@ -859,10 +879,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data.attributeList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.getUnitAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.getUnitAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出组织所有属性的名称
         listUnitAttributeName: function(name, async){
@@ -873,10 +893,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data.nameList;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitAttributeName(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitAttributeName(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         },
         //列出组织的所有属性
         listUnitAllAttribute: function(name, async){
@@ -887,10 +907,10 @@ MWF.xScript.ViewEnvironment = function (ev) {
                 v = json.data;
                 if (async && o2.typeOf(async)=="function") return async(v);
                 return v;
-            }.ag().catch(function(json){ return json; });
+            };
 
-            orgActions.listUnitAllAttribute(data, cb, null, !!async);
-            return (!!async) ? cb : v;
+            var promise = orgActions.listUnitAllAttribute(data, cb, null, !!async);
+            return (!!async) ? promise : v;
         }
     };
 
@@ -1727,21 +1747,29 @@ if( !MWF.xScript.createDict ){
                 if (success===true) async=true;
                 if (failure===true) async=true;
 
+                // var cb = function(json){
+                //     value = json.data;
+                //     MWF.xScript.addDictToCache(opt, path, value);
+                //     if (success && o2.typeOf(success)=="function") value = success(json.data);
+                //     return value;
+                // }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
+
                 var cb = function(json){
                     value = json.data;
                     MWF.xScript.addDictToCache(opt, path, value);
                     if (success && o2.typeOf(success)=="function") value = success(json.data);
                     return value;
-                }.ag().catch(function(xhr, text, error){ if (failure && o2.typeOf(failure)=="function") return failure(xhr, text, error); });
+                };
 
+                var promise;
                 if (path){
                     var p = encodePath( path );
                     //var p = path.replace(/\./g, "/");
-                    action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
+                    promise = action[ ( (enableAnonymous && type == "cms") ? "getDictDataAnonymous" : "getDictData" ) ](encodeURIComponent(this.name), applicationId, p, cb, null, !!async);
                 }else{
-                    action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
+                    promise = action[ ( (enableAnonymous && type == "cms") ? "getDictRootAnonymous" : "getDictRoot" ) ](this.name, applicationId, cb, null, !!async);
                 }
-                return (!!async) ? cb : value;
+                return (!!async) ? promise : value;
 
                 // if (path){
                 //     var p = encodePath( path );

+ 36 - 22
o2web/source/x_component_process_Xform/$Input.js

@@ -191,19 +191,25 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input =  new Class({
 	},
     _setValue: function(value){
 	    debugger;
-	    if (value && value.isAG){
-	        var ag = o2.AG.all(value).then(function(v){
-	            if (o2.typeOf(v)=="array") v = v[0];
-                this.__setValue(v);
-            }.bind(this));
-            this.moduleValueAG = ag;
-	        ag.then()
-        }else {
-            Promise.resolve(value).then(function(v){
-                this.__setValue(v);
-            }.bind(this));
+	    // if (value && value.isAG){
+	    //     var ag = o2.AG.all(value).then(function(v){
+	    //         if (o2.typeOf(v)=="array") v = v[0];
+        //         this.__setValue(v);
+        //     }.bind(this));
+        //     this.moduleValueAG = ag;
+	    //     ag.then(function(){
+        //         this.moduleValueAG = null;
+        //     }.bind(this));
+        // }else {
+        var p = o2.promiseAll(value).then(function(v){
+            this.__setValue(v);
+        }.bind(this));
+        this.moduleValueAG = p;
+        p.then(function(){
+            this.moduleValueAG = null;
+        }.bind(this));
             //this.__setValue(value);
-        }
+        // }
 
     },
     __setValue: function(value){
@@ -263,17 +269,25 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input =  new Class({
         this.setData(this.getValue());
     },
 	setData: function(data){
-        if (data && data.isAG){
-            this.moduleValueAG = o2.AG.all(data).then(function(v){
-                if (o2.typeOf(v)=="array") v = v[0];
-                this.__setData(v);
-            }.bind(this));
-        }else{
-            Promise.resolve(data).then(function(v){
-                this.__setValue(v);
-            }.bind(this));
+        // if (data && data.isAG){
+        //     var ag = o2.AG.all(data).then(function(v){
+        //         if (o2.typeOf(v)=="array") v = v[0];
+        //         this.__setData(v);
+        //     }.bind(this));
+        //     this.moduleValueAG = ag;
+        //     ag.then(function(){
+        //         this.moduleValueAG = null;
+        //     }.bind(this));
+        // }else{
+        var p = o2.promiseAll(data).then(function(v){
+            this.__setValue(v);
+        }.bind(this));
+        this.moduleValueAG = p;
+        p.then(function(){
+            this.moduleValueAG = null;
+        }.bind(this));
             //this.__setData(data);
-        }
+        //}
 	},
     __setData: function(data){
         this._setBusinessData(data);

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

@@ -42,7 +42,7 @@ MWF.xApplication.process.Xform.Calendar = MWF.APPCalendar =  new Class({
         var value = this._getBusinessData();
         if( value && !isDate)return value;
         if (!value) value = this._computeValue();
-        if (value.isAG) return value;
+        if (value.then) return value;
 
         var d = (!!value) ? Date.parse(value) : "";
         if (isDate){

+ 37 - 17
o2web/source/x_component_process_Xform/Checkbox.js

@@ -100,7 +100,7 @@ MWF.xApplication.process.Xform.Checkbox = MWF.APPCheckbox =  new Class({
     },
 
     _setOptions: function(optionItems){
-        this.moduleSelectAG = o2.AG.all(optionItems).then(function(radioValues){
+        var p = o2.promiseAll(optionItems).then(function(radioValues){
             this.moduleSelectAG = null;
             if (!radioValues) radioValues = [];
             if (o2.typeOf(radioValues)==="array"){
@@ -149,29 +149,48 @@ MWF.xApplication.process.Xform.Checkbox = MWF.APPCheckbox =  new Class({
                 }.bind(this));
             }
         }.bind(this));
-        if (this.moduleSelectAG) this.moduleSelectAG.then(function(){
+        this.moduleSelectAG = p;
+        if (p) p.then(function(){
             this.moduleSelectAG = null;
         }.bind(this));
 	},
 
     _setValue: function(value){
-        this.moduleValueAG = o2.AG.all(value).then(function(v){
+        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.moduleValueAG = null;
                     this.__setValue(v);
+                    return v;
                 }.bind(this));
             }else{
-                this.moduleValueAG = null;
-                this.__setValue(v);
+                this.__setValue(v)
             }
             return v;
         }.bind(this));
-
+        this.moduleValueAG = p;
         if (this.moduleValueAG) this.moduleValueAG.then(function(){
-            this.moduleValueAG = "";
+            this.moduleValueAG = null;
         }.bind(this));
+
+        // this.moduleValueAG = o2.AG.all(value).then(function(v){
+        //     if (this.moduleSelectAG){
+        //         this.moduleValueAG = this.moduleSelectAG;
+        //         this.moduleSelectAG.then(function(){
+        //             this.moduleValueAG = null;
+        //             this.__setValue(v);
+        //         }.bind(this));
+        //     }else{
+        //         this.moduleValueAG = null;
+        //         this.__setValue(v);
+        //     }
+        //     return v;
+        // }.bind(this));
+        //
+        // if (this.moduleValueAG) this.moduleValueAG.then(function(){
+        //     this.moduleValueAG = "";
+        // }.bind(this));
     },
 
     __setValue: function(value){
@@ -241,15 +260,16 @@ MWF.xApplication.process.Xform.Checkbox = MWF.APPCheckbox =  new Class({
     },
 
     setData: function(data){
-        if (data && data.isAG){
-            this.moduleValueAG = data;
-            data.addResolve(function(v){
-                this.setData(v);
-            }.bind(this));
-        }else{
-            this.__setData(data);
-            this.moduleValueAG = null;
-        }
+	    return this._setValue(data);
+        // if (data && data.isAG){
+        //     this.moduleValueAG = data;
+        //     data.addResolve(function(v){
+        //         this.setData(v);
+        //     }.bind(this));
+        // }else{
+        //     this.__setData(data);
+        //     this.moduleValueAG = null;
+        // }
     },
 
     __setData: function(data){

+ 59 - 25
o2web/source/x_component_process_Xform/DatagridPC.js

@@ -64,7 +64,7 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
 		value = this._getBusinessData();
 		if (!value){
 			if (this.json.defaultData && this.json.defaultData.code) value = this.form.Macro.exec(this.json.defaultData.code, this);
-			if (!value.isAG) if (o2.typeOf(value)=="array") value = {"data": value || []};
+			if (!value.then) if (o2.typeOf(value)=="array") value = {"data": value || []};
 		}
 		return value || {};
 	},
@@ -115,18 +115,28 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
 	},
 
 	_loadEditDatagrid: function(callback){
-		debugger;
-		if (this.gridData && this.gridData.isAG){
-			this.moduleValueAG = this.gridData;
-			this.gridData.addResolve(function(v){
-				this.gridData = v;
-				this._loadEditDatagrid(callback);
-			}.bind(this));
-		}else{
+		var p = o2.promiseAll(this.gridData).then(function(v){
+			this.gridData = v;
 			if (o2.typeOf(this.gridData)=="array") this.gridData = {"data": this.gridData};
 			this.__loadEditDatagrid(callback);
 			this.moduleValueAG = null;
-		}
+			return v;
+		}.bind(this));
+		this.moduleValueAG = p;
+		if (this.moduleValueAG) this.moduleValueAG.then(function(){
+			this.moduleValueAG = null;
+		}.bind(this));
+		// if (this.gridData && this.gridData.isAG){
+		// 	this.moduleValueAG = this.gridData;
+		// 	this.gridData.addResolve(function(v){
+		// 		this.gridData = v;
+		// 		this._loadEditDatagrid(callback);
+		// 	}.bind(this));
+		// }else{
+		// 	if (o2.typeOf(this.gridData)=="array") this.gridData = {"data": this.gridData};
+		// 	this.__loadEditDatagrid(callback);
+		// 	this.moduleValueAG = null;
+		// }
 	},
 	__loadEditDatagrid: function(callback){
 		var titleThs = this.titleTr.getElements("th");
@@ -733,17 +743,29 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
 		tr.setStyle("display", "none");
 	},
 	_loadReadDatagrid: function(callback){
-		if (this.gridData && this.gridData.isAG){
-			this.moduleValueAG = this.gridData;
-			this.gridData.addResolve(function(v){
-				this.gridData = v;
-				this._loadReadDatagrid(callback);
-			}.bind(this));
-		}else{
+		var p = o2.promiseAll(this.gridData).then(function(v){
+			this.gridData = v;
 			if (o2.typeOf(this.gridData)=="array") this.gridData = {"data": this.gridData};
 			this.__loadReadDatagrid(callback);
 			this.moduleValueAG = null;
-		}
+			return v;
+		}.bind(this));
+		this.moduleValueAG = p;
+		if (this.moduleValueAG) this.moduleValueAG.then(function(){
+			this.moduleValueAG = null;
+		}.bind(this));
+
+		// if (this.gridData && this.gridData.isAG){
+		// 	this.moduleValueAG = this.gridData;
+		// 	this.gridData.addResolve(function(v){
+		// 		this.gridData = v;
+		// 		this._loadReadDatagrid(callback);
+		// 	}.bind(this));
+		// }else{
+		// 	if (o2.typeOf(this.gridData)=="array") this.gridData = {"data": this.gridData};
+		// 	this.__loadReadDatagrid(callback);
+		// 	this.moduleValueAG = null;
+		// }
 	},
 
 	__loadReadDatagrid: function(callback){
@@ -987,16 +1009,28 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
 		this._setData(data);
 	},
 	_setData: function(data){
-		if (data && data.isAG){
-			this.moduleValueAG = data;
-			data.addResolve(function(v){
-				this._setData(v);
-			}.bind(this));
-		}else{
+		var p = o2.promiseAll(this.data).then(function(v){
+			this.gridData = v;
 			if (o2.typeOf(data)=="array") data = {"data": data};
 			this.__setData(data);
 			this.moduleValueAG = null;
-		}
+			return v;
+		}.bind(this));
+		this.moduleValueAG = p;
+		if (this.moduleValueAG) this.moduleValueAG.then(function(){
+			this.moduleValueAG = null;
+		}.bind(this));
+
+		// if (data && data.isAG){
+		// 	this.moduleValueAG = data;
+		// 	data.addResolve(function(v){
+		// 		this._setData(v);
+		// 	}.bind(this));
+		// }else{
+		// 	if (o2.typeOf(data)=="array") data = {"data": data};
+		// 	this.__setData(data);
+		// 	this.moduleValueAG = null;
+		// }
 	},
 	__setData: function(data){
 		// if( typeOf( data ) === "object" && typeOf(data.data) === "array"  ){

+ 9 - 2
o2web/source/x_component_process_Xform/Label.js

@@ -49,10 +49,17 @@ MWF.xApplication.process.Xform.Label = MWF.APPLabel =  new Class({
                 this._setNodeText(v);
             }.bind(this));
         }else{
-            this.node.set("text", value || "");
+            o2.promiseAll(value).then(function(v){
+                this.node.set("text", v || "");
+            }.bind(this));
+            //this.node.set("text", value || "");
         }
     },
     setText: function(text){
-        this.node.set("text", text);
+        o2.promiseAll(text).then(function(v){
+            this.node.set("text", v || "");
+        }.bind(this));
+
+        //this.node.set("text", text);
     }
 });

+ 159 - 30
o2web/source/x_component_process_Xform/Org.js

@@ -101,6 +101,76 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         }
     },
     _computeValue: function(){
+        debugger;
+        var simple = this.json.storeRange === "simple";
+        var values = [];
+        if (this.json.identityValue) {
+            this.json.identityValue.each(function(v){
+                if (v) values.push(MWF.org.parseOrgData(v, true, simple))
+            });
+        }
+        if (this.json.unitValue) {
+            this.json.unitValue.each(function(v){ if (v) values.push(MWF.org.parseOrgData(v, true, simple))});
+        }
+        if (this.json.dutyValue) {
+            var dutys = JSON.decode(this.json.dutyValue);
+            var par;
+            if (dutys.length){
+                dutys.each(function(duty){
+                    if (duty.code) par = this.form.Macro.exec(duty.code, this);
+                    if (par){
+                        var promise = o2.promiseAll(par).then(function(p){
+                            var uName = p.distinguishedName || p;
+                            if (o2.typeOf(p)=="array") uName = p[0].distinguishedName || p[0];
+                            var code = "return this.org.getDuty(\""+duty.name+"\", \""+uName+"\", true)";
+                            var r = (!!uName) ? this.form.Macro.exec(code, this) : "";
+
+                            return o2.promiseAll(r).then(function(d){
+                                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));
+                        }.bind(this));
+                        values.push(promise);
+                    }
+                }.bind(this));
+            }
+        }
+        if (this.json.defaultValue && this.json.defaultValue.code){
+            var fd = this.form.Macro.exec(this.json.defaultValue.code, this);
+            if (o2.typeOf(fd)=="array"){
+                fd.each(function(v){values.push(v);});
+            }else{
+                values.push(fd);
+            }
+
+            // if (fd && fd.isAG){
+            //     values.push(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));
+            // }
+        }
+        // if (this.json.count>0){
+        //     return values.slice(0, this.json.count);
+        // }
+        return values;
+        //return (this.json.defaultValue.code) ? this.form.Macro.exec(this.json.defaultValue.code, this): (value || "");
+    },
+    __computeValue: function(){
         var simple = this.json.storeRange === "simple";
         var values = [];
         if (this.json.identityValue) {
@@ -432,12 +502,15 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         if( data.length === 0 )return true;
         return false;
     },
+
     getInputData: function(){
         if (this.json.isInput){
             if (this.combox)return this.combox.getData();
-            return this._getBusinessData();
+            //return this._getBusinessData();
+            return this.node.retrieve("data");
         }else{
-            return this._getBusinessData();
+            //return this._getBusinessData();
+            return this.node.retrieve("data");
         }
     },
     _loadNodeRead: function(){
@@ -639,6 +712,7 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
                     //this.fireEvent("change");
                 }.bind(this),
                 "onChange": function(){
+                    this.node.store("data", this.getInputData());
                     this._setBusinessData(this.getInputData());
                     this.fireEvent("change");
                 }.bind(this),
@@ -676,7 +750,10 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
 
         this.combox.addEvent("change", function(){
             this.validationMode();
-            if (this.validation()) this._setBusinessData(this.getInputData("change"));
+            if (this.validation()){
+                this.node.store("data", this.getInputData());
+                this._setBusinessData(this.getInputData("change"));
+            }
         }.bind(this));
     },
 
@@ -729,7 +806,10 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         this.node.getFirst().setStyle("height", "auto");
         this.node.getFirst().addEvent("change", function(){
             this.validationMode();
-            if (this.validation()) this._setBusinessData(this.getInputData("change"));
+            if (this.validation()){
+                this.node.store("data", this.getInputData());
+                this._setBusinessData(this.getInputData("change"));
+            }
         }.bind(this));
     },
     getDataText: function(data){
@@ -794,15 +874,19 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         var oldValues = this.getData();
         if (value.length==1 && !(value[0])) value=[];
 
-        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.checkChange(oldValues, values)
-            }
+        var promise = this._setValue(value);
+        promise.then(function(values){
+            o2.promiseAll(values).then(function(v){
+                this.checkChange(oldValues, v)
+            }.bind(this));
+
+            // if (values && values.isAG){
+            //     values.then(function(v){
+            //         this.checkChange(oldValues, v)
+            //     }.bind(this));
+            // }else{
+            //     this.checkChange(oldValues, values)
+            // }
         }.bind(this));
     },
     // __setData: function(value){
@@ -939,23 +1023,27 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         var ags = [];
         var simple = this.json.storeRange === "simple";
         var flag = false;
-        var ag = 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"){
-                        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(dd);
+        if (typeOf(value)!=="array") value = (!!value) ? [value] : [];
+        //value = (value.flat) ? value.flat() : value.flatten();
+
+        var p = o2.promiseAll(value).then(function(d){
+            if (typeOf(d)!=="array") d = (!!d) ? [d] : [];
+            d.each(function(da){
+                if (typeOf(da)!=="array") da = (!!da) ? [da] : [];
+                da.each(function(dd){
+                    if (dd){
+                        if (typeOf(dd)==="string"){
+                            ags.push(this.getOrgAction()[this.getValueMethod(dd)](function(json){
+                                return MWF.org.parseOrgData(json.data, true, simple);
+                            }.bind(this), null, dd, true));
+                        }else{
+                            values.push(dd);
+                        }
                     }
-                }
+                }.bind(this));
             }.bind(this));
             if (ags.length){
-                return o2.AG.all(ags).then(function(data){
+                return o2.promiseAll(ags).then(function(data){
                     values = values.concat(data);
                     flag = true;
                     this.__setValue(values);
@@ -968,15 +1056,55 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
             }
         }.bind(this));
 
-        this.moduleValueAG = ag;
-        if (ag) ag.then(function(){
+        this.moduleValueAG = p;
+        if (p) p.then(function(){
             this.moduleValueAG = null;
         }.bind(this));
-        return ag;
+        return p;
+
+        // var ag = 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"){
+        //                 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(dd);
+        //             }
+        //         }
+        //     }.bind(this));
+        //     if (ags.length){
+        //         return o2.AG.all(ags).then(function(data){
+        //             values = values.concat(data);
+        //             flag = true;
+        //             this.__setValue(values);
+        //             return values;
+        //         }.bind(this));
+        //     }else{
+        //         flag = true;
+        //         this.__setValue(values);
+        //         return values
+        //     }
+        // }.bind(this));
+        //
+        // this.moduleValueAG = ag;
+        // if (ag) ag.then(function(){
+        //     this.moduleValueAG = null;
+        // }.bind(this));
+        // return ag;
     },
     __setValue: function(value){
         this.moduleValueAG = null;
         if (value.length==1 && !(value[0])) value=[];
+
+        if (this.json.count>0){
+            value = value.slice(0, this.json.count);
+        }
+
         var values = [];
         var comboxValues = [];
         var type = typeOf(value);
@@ -1012,6 +1140,7 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
             comboxValues.push({"text": this.getDataText(v),"value": v});
         }
 
+        this.node.store("data", values);
         this._setBusinessData(values);
 
         if (this.json.isInput){

+ 86 - 12
o2web/source/x_component_process_Xform/Radio.js

@@ -106,7 +106,7 @@ MWF.xApplication.process.Xform.Radio = MWF.APPRadio =  new Class({
     },
 
 	_setOptions: function(optionItems){
-        this.moduleSelectAG = o2.AG.all(optionItems).then(function(radioValues){
+        var p = o2.promiseAll(optionItems).then(function(radioValues){
             this.moduleSelectAG = null;
 
             if (!radioValues) radioValues = [];
@@ -154,19 +154,74 @@ MWF.xApplication.process.Xform.Radio = MWF.APPRadio =  new Class({
                     }.bind(this));
                 }.bind(this));
             }
-        }.bind(this))
-        if (this.moduleSelectAG) this.moduleSelectAG.then(function(){
+        }.bind(this));
+        this.moduleSelectAG = p;
+        if (p) p.then(function(){
             this.moduleSelectAG = null;
         }.bind(this));
+
+        // this.moduleSelectAG = o2.AG.all(optionItems).then(function(radioValues){
+        //     this.moduleSelectAG = null;
+        //
+        //     if (!radioValues) radioValues = [];
+        //     if (o2.typeOf(radioValues)==="array"){
+        //         var flag = (new MWF.widget.UUID).toString();
+        //         radioValues.each(function(item){
+        //             var tmps = item.split("|");
+        //             var text = tmps[0];
+        //             var value = tmps[1] || text;
+        //
+        //             var radio = new Element("input", {
+        //                 "type": "radio",
+        //                 "name": (this.json.properties && this.json.properties.name) ? this.json.properties.name : flag+this.json.id,
+        //                 "value": value,
+        //                 "showText": text,
+        //                 "styles": this.json.buttonStyles
+        //             }).inject(this.node);
+        //             //radio.appendText(text, "after");
+        //
+        //             var textNode = new Element( "span", {
+        //                 "text" : text,
+        //                 "styles" : { "cursor" : "default" }
+        //             }).inject(this.node);
+        //             textNode.addEvent("click", function( ev ){
+        //                 if( this.radio.get("disabled") === true || this.radio.get("disabled") === "true" )return;
+        //                 this.radio.checked = true;
+        //                 this.radio.fireEvent("change");
+        //                 this.radio.fireEvent("click");
+        //             }.bind( {radio : radio} ) );
+        //
+        //             radio.addEvent("click", function(){
+        //                 this.validationMode();
+        //                 if (this.validation()) this._setBusinessData(this.getInputData("change"));
+        //             }.bind(this));
+        //
+        //             Object.each(this.json.events, function(e, key){
+        //                 if (e.code){
+        //                     if (this.options.moduleEvents.indexOf(key)!=-1){
+        //                     }else{
+        //                         radio.addEvent(key, function(event){
+        //                             return this.form.Macro.fire(e.code, this, event);
+        //                         }.bind(this));
+        //                     }
+        //                 }
+        //             }.bind(this));
+        //         }.bind(this));
+        //     }
+        // }.bind(this))
+        // if (this.moduleSelectAG) this.moduleSelectAG.then(function(){
+        //     this.moduleSelectAG = null;
+        // }.bind(this));
 	},
 
     _setValue: function(value){
-        this.moduleValueAG = o2.AG.all(value).then(function(v){
+        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.__setValue(v);
+                    return v;
                 }.bind(this));
             }else{
                 this.__setValue(v)
@@ -174,9 +229,27 @@ MWF.xApplication.process.Xform.Radio = MWF.APPRadio =  new Class({
             return v;
         }.bind(this));
 
+        this.moduleValueAG = p;
         if (this.moduleValueAG) this.moduleValueAG.then(function(){
             this.moduleValueAG = null;
         }.bind(this));
+
+        // 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 (this.moduleValueAG) this.moduleValueAG.then(function(){
+        //     this.moduleValueAG = null;
+        // }.bind(this));
     },
 
     __setValue: function(value){
@@ -238,14 +311,15 @@ MWF.xApplication.process.Xform.Radio = MWF.APPRadio =  new Class({
     },
 
     setData: function(data){
-        if (data && data.isAG){
-            this.moduleValueAG = o2.AG.all(data).then(function(v){
-                if (o2.typeOf(v)=="array") v = v[0];
-                this.__setData(v);
-            }.bind(this));
-        }else{
-            this.__setData(data);
-        }
+        return this._setValue(data);
+        // if (data && data.isAG){
+        //     this.moduleValueAG = o2.AG.all(data).then(function(v){
+        //         if (o2.typeOf(v)=="array") v = v[0];
+        //         this.__setData(v);
+        //     }.bind(this));
+        // }else{
+        //     this.__setData(data);
+        // }
 
         // if (data && data.isAG){
         //     this.moduleValueAG = data;

+ 48 - 11
o2web/source/x_component_process_Xform/Select.js

@@ -134,7 +134,7 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect =  new Class({
 		this._setOptions(optionItems);
 	},
 	_setOptions: function(optionItems){
-		this.moduleSelectAG = o2.AG.all(optionItems).then(function(options){
+		var p = o2.promiseAll(optionItems).then(function(options){
 			this.moduleSelectAG = null;
 			if (!options) options = [];
 			if (o2.typeOf(options)==="array"){
@@ -151,9 +151,31 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect =  new Class({
 				this.fireEvent("setOptions", [options])
 			}
 		}.bind(this));
-		if (this.moduleSelectAG) this.moduleSelectAG.then(function(){
+		this.moduleSelectAG = p;
+		if (p) p.then(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();
@@ -181,12 +203,13 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect =  new Class({
 	},
 
 	_setValue: function(value){
-		this.moduleValueAG = o2.AG.all(value).then(function(v){
+		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.__setValue(v);
+					return v;
 				}.bind(this));
 			}else{
 				this.__setValue(v)
@@ -194,10 +217,23 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect =  new Class({
 			return v;
 		}.bind(this));
 
+		this.moduleValueAG = p;
 		if (this.moduleValueAG) this.moduleValueAG.then(function(){
 			this.moduleValueAG = null;
 		}.bind(this));
 
+		// 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){
@@ -301,14 +337,15 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect =  new Class({
 	},
 
 	setData: function(data){
-		if (data && data.isAG){
-			this.moduleValueAG = o2.AG.all(data).then(function(v){
-				if (o2.typeOf(v)=="array") v = v[0];
-				this.__setData(v);
-			}.bind(this));
-		}else{
-			this.__setData(data);
-		}
+		return this._setValue(data);
+		// if (data && data.isAG){
+		// 	this.moduleValueAG = o2.AG.all(data).then(function(v){
+		// 		if (o2.typeOf(v)=="array") v = v[0];
+		// 		this.__setData(v);
+		// 	}.bind(this));
+		// }else{
+		// 	this.__setData(data);
+		// }
 		// if (data && data.isAG){
 		// 	this.moduleValueAG = data;
 		// 	data.addResolve(function(v){

+ 22 - 5
o2web/source/x_component_process_Xform/Textarea.js

@@ -4,7 +4,6 @@ MWF.xApplication.process.Xform.Textarea = MWF.APPTextarea =  new Class({
 	Extends: MWF.APP$Input,
 	
 	_loadUserInterface: function(){
-debugger;
 		this._loadNode();
         if (this.json.compute == "show"){
             this._setValue(this._computeValue());
@@ -25,8 +24,7 @@ debugger;
 
 
     _setValue: function(value){
-        this.moduleValueAG = o2.AG.all(value).then(function(v){
-            this.moduleValueAG = null;
+        var p = o2.promiseAll(value).then(function(v){
             if (o2.typeOf(v)=="array") v = v[0];
             this._setBusinessData(v);
             if (this.node.getFirst()) this.node.getFirst().set("value", v || "");
@@ -37,12 +35,31 @@ debugger;
                 var text = value.replace(reg2,"&lt").replace(reg3,"&gt").replace(reg,"<br/>");
                 this.node.set("html", text);
             }
+            //this.__setValue(v);
         }.bind(this));
-
-        if (this.moduleValueAG) this.moduleValueAG.then(function(){
+        this.moduleValueAG = p;
+        p.then(function(){
             this.moduleValueAG = null;
         }.bind(this));
 
+        // this.moduleValueAG = o2.AG.all(value).then(function(v){
+        //     this.moduleValueAG = null;
+        //     if (o2.typeOf(v)=="array") v = v[0];
+        //     this._setBusinessData(v);
+        //     if (this.node.getFirst()) this.node.getFirst().set("value", v || "");
+        //     if (this.readonly || this.json.isReadonly){
+        //         var reg = new RegExp("\n","g");
+        //         var reg2 = new RegExp("\u003c","g"); //尖括号转义,否则内容会截断
+        //         var reg3 = new RegExp("\u003e","g");
+        //         var text = value.replace(reg2,"&lt").replace(reg3,"&gt").replace(reg,"<br/>");
+        //         this.node.set("html", text);
+        //     }
+        // }.bind(this));
+        //
+        // if (this.moduleValueAG) this.moduleValueAG.then(function(){
+        //     this.moduleValueAG = null;
+        // }.bind(this));
+
         return value;
 
         // if (value && value.isAG){