Просмотр исходного кода

支持表单默认值异步返回

huqi 5 лет назад
Родитель
Сommit
50ca9dec51

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

@@ -1689,6 +1689,7 @@
             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(){
@@ -1763,13 +1764,41 @@
     //@todo
     _AsyncGenerator.all = function(arr){
         var result = [];
-        arr.forEach(function(a){
-            if (o2.typeOf(a)=="function"){
+        var ag = function (){
+            return result;
+        }.ag();
 
-            }else{
+        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 (o2.typeOf(a)=="o2_async_function"){
+                        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;

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

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

+ 535 - 252
o2web/source/o2_core/o2/xScript/PageEnvironment.js

@@ -126,475 +126,758 @@ MWF.xScript.PageEnvironment = function (ev) {
     this.org = {
         //群组***************
         //获取群组--返回群组的对象数组
-        getGroup: function (name) {
+        getGroup: function(name, async){
             getOrgActions();
-            var data = { "groupList": getNameFlag(name) };
+            var data = {"groupList": getNameFlag(name)};
+
             var v = null;
-            orgActions.listGroup(data, function (json) { v = json.data; }, null, false);
-            return (v && v.length === 1) ? v[0] : v;
+            var cb = function(json){
+                v = json.data;
+                v = (v && v.length===1) ? v[0] : v
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listGroup(data, cb, null, !!async);
+            return (!!async) ? cb : v;
+
+            // var v = null;
+            // orgActions.listGroup(data, function(json){v = json.data;}, null, false);
+            // return (v && v.length===1) ? v[0] : v;
         },
         //查询下级群组--返回群组的对象数组
         //nested  布尔  true嵌套下级;false直接下级;默认false;
-        listSubGroup: function (name, nested) {
+        listSubGroup: function(name, nested, async){
             getOrgActions();
-            var data = { "groupList": getNameFlag(name) };
+            var data = {"groupList": getNameFlag(name)};
+
             var v = null;
-            if (nested) {
-                orgActions.listSubGroupNested(data, function (json) { v = json.data; }, null, false);
-            } else {
-                orgActions.listSubGroupDirect(data, function (json) { v = json.data; }, null, false);
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            if (nested){
+                orgActions.listSubGroupNested(data, cb, null, !!async);
+            }else{
+                orgActions.listSubGroupDirect(data, cb, null, !!async);
             }
-            return v;
+            return (!!async) ? cb : v;
+
+            // var v = null;
+            // if (nested){
+            //     orgActions.listSubGroupNested(data, function(json){v = json.data;}, null, false);
+            // }else{
+            //     orgActions.listSubGroupDirect(data, function(json){v = json.data;}, null, false);
+            // }
+            // return v;
         },
         //查询上级群组--返回群组的对象数组
         //nested  布尔  true嵌套上级;false直接上级;默认false;
-        listSupGroup: function (name, nested) {
+        listSupGroup:function(name, nested, async){
             getOrgActions();
-            var data = { "groupList": getNameFlag(name) };
+            var data = {"groupList": getNameFlag(name)};
+
             var v = null;
-            if (nested) {
-                orgActions.listSupGroupNested(data, function (json) { v = json.data; }, null, false);
-            } else {
-                orgActions.listSupGroupDirect(data, function (json) { v = json.data; }, null, false);
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            if (nested){
+                orgActions.listSupGroupNested(data, cb, null, !!async);
+            }else{
+                orgActions.listSupGroupDirect(data, cb, null, !!async);
             }
-            return v;
+            return (!!async) ? cb : v;
+            // var v = null;
+            // if (nested){
+            //     orgActions.listSupGroupNested(data, function(json){v = json.data;}, null, false);
+            // }else{
+            //     orgActions.listSupGroupDirect(data, function(json){v = json.data;}, null, false);
+            // }
+            // return v;
         },
         //人员所在群组(嵌套)--返回群组的对象数组
-        listGroupWithPerson: function (name) {
+        listGroupWithPerson:function(name, async){
             getOrgActions();
-            var data = { "personList": getNameFlag(name) };
+            var data = {"personList": getNameFlag(name)};
+
             var v = null;
-            orgActions.listGroupWithPerson(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listGroupWithPerson(data, cb, null, !!async);
+            return (!!async) ? cb : v;
+            // var v = null;
+            // orgActions.listGroupWithPerson(data, function(json){v = json.data;}, null, false);
+            // return v;
         },
         //群组是否拥有角色--返回true, false
-        groupHasRole: function (name, role) {
+        groupHasRole: function(name, role, async){
             getOrgActions();
-            nameFlag = (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
-            var data = { "group": nameFlag, "roleList": getNameFlag(role) };
+            nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
+            var data = {"group":nameFlag,"roleList":getNameFlag(role)};
+
             var v = false;
-            orgActions.groupHasRole(data, function (json) { v = json.data.value; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data.value;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.groupHasRole(data, cb, null, !!async);
+            return (!!async) ? cb : v;
+
+            // var v = false;
+            // orgActions.groupHasRole(data, function(json){v = json.data.value;}, null, false);
+            // return v;
         },
 
         //角色***************
         //获取角色--返回角色的对象数组
-        getRole: function (name) {
+        getRole: function(name, async){
             getOrgActions();
-            var data = { "roleList": getNameFlag(name) };
+            var data = {"roleList": getNameFlag(name)};
+
             var v = null;
-            orgActions.listRole(data, function (json) { v = json.data; }, null, false);
-            return (v && v.length === 1) ? v[0] : v;
+            var cb = function(json){
+                v = json.data;
+                v = (v && v.length===1) ? v[0] : v;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listRole(data, cb, null, !!async);
+            return (!!async) ? cb : v;
+
+            // var v = null;
+            // orgActions.listRole(data, function(json){v = json.data;}, null, false);
+            // return (v && v.length===1) ? v[0] : v;
         },
         //人员所有角色(嵌套)--返回角色的对象数组
-        listRoleWithPerson: function (name) {
+        listRoleWithPerson:function(name, async){
             getOrgActions();
-            var data = { "personList": getNameFlag(name) };
+            var data = {"personList": getNameFlag(name)};
+
             var v = null;
-            orgActions.listRoleWithPerson(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listRoleWithPerson(data, cb, null, !!async);
+            return (!!async) ? cb : v;
+            // var v = null;
+            // orgActions.listRoleWithPerson(data, function(json){v = json.data;}, null, false);
+            // return v;
         },
 
         //人员***************
         //人员是否拥有角色--返回true, false
-        personHasRole: function (name, role) {
+        personHasRole: function(name, role, async){
             getOrgActions();
-            nameFlag = (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
-            var data = { "person": nameFlag, "roleList": getNameFlag(role) };
+            nameFlag = (typeOf(name)==="object") ? (name.distinguishedName || name.id || name.unique || name.name) : name;
+            var data = {"person":nameFlag,"roleList":getNameFlag(role)};
+
             var v = false;
-            orgActions.personHasRole(data, function (json) { v = json.data.value; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data.value;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listRoleWithPerson(data, cb, null, !!async);
+            return (!!async) ? cb : v;
+
+            // var v = false;
+            // orgActions.personHasRole(data, function(json){v = json.data.value;}, null, false);
+            // return v;
         },
         //获取人员--返回人员的对象数组
-        getPerson: function (name) {
+        getPerson: function(name, async){
             getOrgActions();
-            var data = { "personList": getNameFlag(name) };
+            var data = {"personList": getNameFlag(name)};
+
             var v = null;
-            orgActions.listPerson(data, function (json) { v = json.data; }, null, false);
-            return (v && v.length === 1) ? v[0] : v;
+            var cb = function(json){
+                v = json.data;
+                v = (v && v.length===1) ? v[0] : v;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listPerson(data, cb, null, !!async);
+            return (!!async) ? cb : v;
+            // var v = null;
+            // orgActions.listPerson(data, function(json){v = json.data;}, null, false);
+            // return (v && v.length===1) ? v[0] : v;
         },
         //查询下级人员--返回人员的对象数组
         //nested  布尔  true嵌套下级;false直接下级;默认false;
-        listSubPerson: function (name, nested) {
+        listSubPerson: function(name, nested, async){
             getOrgActions();
-            var data = { "personList": getNameFlag(name) };
+            var data = {"personList": getNameFlag(name)};
+
             var v = null;
-            if (nested) {
-                orgActions.listPersonSubNested(data, function (json) { v = json.data; }, null, false);
-            } else {
-                orgActions.listPersonSubDirect(data, function (json) { v = json.data; }, null, false);
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            if (nested){
+                orgActions.listPersonSubNested(data, cb, null, !!async);
+            }else{
+                orgActions.listPersonSubDirect(data, cb, null, !!async);
             }
-            return v;
+            return (!!async) ? cb : v;
         },
         //查询上级人员--返回人员的对象数组
         //nested  布尔  true嵌套上级;false直接上级;默认false;
-        listSupPerson: function (name, nested) {
+        listSupPerson: function(name, nested, async){
             getOrgActions();
-            var data = { "personList": getNameFlag(name) };
+            var data = {"personList": getNameFlag(name)};
             var v = null;
-            if (nested) {
-                orgActions.listPersonSupNested(data, function (json) { v = json.data; }, null, false);
-            } else {
-                orgActions.listPersonSupDirect(data, function (json) { v = json.data; }, null, false);
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            if (nested){
+                orgActions.listPersonSupNested(data, cb, null, !!async);
+            }else{
+                orgActions.listPersonSupDirect(data, cb, null, !!async);
             }
-            return v;
+            return (!!async) ? cb : v;
         },
         //获取群组的所有人员--返回人员的对象数组
-        listPersonWithGroup: function (name) {
+        listPersonWithGroup: function(name, async){
             getOrgActions();
-            var data = { "groupList": getNameFlag(name) };
+            var data = {"groupList": getNameFlag(name)};
+
             var v = null;
-            orgActions.listPersonWithGroup(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listPersonWithGroup(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //获取角色的所有人员--返回人员的对象数组
-        listPersonWithRole: function (name) {
+        listPersonWithRole: function(name, async){
             getOrgActions();
-            var data = { "roleList": getNameFlag(name) };
+            var data = {"roleList": getNameFlag(name)};
             var v = null;
-            orgActions.listPersonWithRole(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listPersonWithRole(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //获取身份的所有人员--返回人员的对象数组
-        listPersonWithIdentity: function (name) {
+        listPersonWithIdentity: function(name, async){
             getOrgActions();
-            var data = { "identityList": getNameFlag(name) };
+            var data = {"identityList": getNameFlag(name)};
             var v = null;
-            orgActions.listPersonWithIdentity(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.listPersonWithIdentity(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //获取身份的所有人员--返回人员的对象数组或人员对象
-        getPersonWithIdentity: function(name){
+        getPersonWithIdentity: function(name, async){
             getOrgActions();
             var data = {"identityList": getNameFlag(name)};
             var v = null;
-            orgActions.listPersonWithIdentity(data, function(json){v = json.data;}, null, false);
-            return (v && v.length===1) ? v[0] : v;
+            var cb = function(json){
+                v = json.data;
+                v =  (v && v.length===1) ? v[0] : v;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.listPersonWithIdentity(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //查询组织成员的人员--返回人员的对象数组
         //nested  布尔  true嵌套的所有成员;false直接成员;默认false;
-        listPersonWithUnit: function (name, nested) {
+        listPersonWithUnit: function(name, nested, async){
             getOrgActions();
-            var data = { "unitList": getNameFlag(name) };
+            var data = {"unitList": getNameFlag(name)};
             var v = null;
-            if (nested) {
-                orgActions.listPersonWithUnitNested(data, function (json) { v = json.data; }, null, false);
-            } else {
-                orgActions.listPersonWithUnitDirect(data, function (json) { v = json.data; }, null, false);
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            if (nested){
+                orgActions.listPersonWithUnitNested(data, cb, null, !!async);
+            }else{
+                orgActions.listPersonWithUnitDirect(data, cb, null, !!async);
             }
-            return v;
+            return (!!async) ? cb : v;
         },
         //根据属性查询人员--返回人员的对象数组
         //name  string 属性名
         //value  string 属性值
-        listPersonWithAttribute: function (name, value) {
+        listPersonWithAttribute: function(name, value, async){
             getOrgActions();
-            var data = { "name": name, "attribute": value };
+            var data = {"name": name, "attribute": value};
             var v = null;
-            orgActions.listPersonWithAttribute(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listPersonWithAttribute(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //根据属性查询人员--返回人员的全称数组
         //name  string 属性名
         //value  string 属性值
-        listPersonNameWithAttribute: function (name, value) {
+        listPersonNameWithAttribute: function(name, value, async){
             getOrgActions();
-            var data = { "name": name, "attribute": value };
+            var data = {"name": name, "attribute": value};
             var v = null;
-            orgActions.listPersonWithAttributeValue(data, function (json) { v = json.data.personList; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data.personList;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listPersonWithAttributeValue(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
 
         //人员属性************
         //添加人员属性值(在属性中添加values值,如果没有此属性,则创建一个)
-        appendPersonAttribute: function (person, attr, values, success, failure) {
+        appendPersonAttribute: function(person, attr, values, success, failure, async){
             getOrgActions();
-            var personFlag = (typeOf(person) === "object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
-            var data = { "attributeList": values, "name": attr, "person": personFlag };
-            orgActions.appendPersonAttribute(data, function (json) {
-                if (json.data.value) {
-                    if (success) success();
-                } else {
-                    if (failure) failure(null, "", "append values failed");
-                }
-            }, function (xhr, text, error) {
-                if (failure) failure(xhr, text, error);
-            }, false);
+            var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
+            var data = {"attributeList":values,"name":attr,"person":personFlag};
+
+            var cb = function(json){
+                if (success) return success(json);
+            }.ag().catch(function(xhr, text, error){
+                if (failure) return failure(xhr, text, error);
+            });
+
+            orgActions.appendPersonAttribute(data, cb, null, !!async);
         },
         //设置人员属性值(将属性值修改为values,如果没有此属性,则创建一个)
-        setPersonAttribute: function (person, attr, values, success, failure) {
+        setPersonAttribute: function(person, attr, values, success, failure, async){
             getOrgActions();
-            var personFlag = (typeOf(person) === "object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
-            var data = { "attributeList": values, "name": attr, "person": personFlag };
-            orgActions.setPersonAttribute(data, function (json) {
-                if (json.data.value) {
-                    if (success) success();
-                } else {
-                    if (failure) failure(null, "", "append values failed");
-                }
-            }, function (xhr, text, error) {
-                if (failure) failure(xhr, text, error);
-            }, false);
+            var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
+            var data = {"attributeList":values,"name":attr,"person":personFlag};
+
+            var cb = function(json){
+                if (success) return success(json);
+            }.ag().catch(function(xhr, text, error){
+                if (failure) return failure(xhr, text, error);
+            });
+
+            orgActions.setPersonAttribute(data, cb, null, !!async);
         },
         //获取人员属性值
-        getPersonAttribute: function (person, attr) {
+        getPersonAttribute: function(person, attr, async){
             getOrgActions();
-            var personFlag = (typeOf(person) === "object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
-            var data = { "name": attr, "person": personFlag };
+            var personFlag = (typeOf(person)==="object") ? (person.distinguishedName || person.id || person.unique || person.name) : person;
+            var data = {"name":attr,"person":personFlag};
             var v = null;
-            orgActions.getPersonAttribute(data, function (json) { v = json.data.attributeList; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data.attributeList;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.getPersonAttribute(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //列出人员所有属性的名称
-        listPersonAttributeName: function (name) {
+        listPersonAttributeName: function(name, async){
             getOrgActions();
-            var data = { "personList": getNameFlag(name) };
+            var data = {"personList":getNameFlag(name)};
             var v = null;
-            orgActions.listPersonAttributeName(data, function (json) { v = json.data.nameList; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data.nameList;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listPersonAttributeName(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //列出人员的所有属性
-        listPersonAllAttribute: function (name) {
+        listPersonAllAttribute: function(name, async){
             getOrgActions();
-            var data = { "personList": getNameFlag(name) };
+            var data = {"personList":getNameFlag(name)};
             var v = null;
-            orgActions.listPersonAllAttribute(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.listPersonAllAttribute(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
 
         //身份**********
         //获取身份
-        getIdentity: function (name) {
+        getIdentity: function(name, async){
             getOrgActions();
-            var data = { "identityList": getNameFlag(name) };
+            var data = {"identityList":getNameFlag(name)};
             var v = null;
-            orgActions.listIdentity(data, function (json) { v = json.data; }, null, false);
-            return (v && v.length === 1) ? v[0] : v;
+            var cb = function(json){
+                v = json.data;
+                v = (v && v.length===1) ? v[0] : v
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listIdentity(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //列出人员的身份
-        listIdentityWithPerson: function (name) {
+        listIdentityWithPerson: function(name, async){
             getOrgActions();
-            var data = { "personList": getNameFlag(name) };
+            var data = {"personList":getNameFlag(name)};
             var v = null;
-            orgActions.listIdentityWithPerson(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listIdentityWithPerson(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //查询组织成员身份--返回身份的对象数组
         //nested  布尔  true嵌套的所有成员;false直接成员;默认false;
-        listIdentityWithUnit: function (name, nested) {
+        listIdentityWithUnit: function(name, nested, async){
             getOrgActions();
-            var data = { "unitList": getNameFlag(name) };
+            var data = {"unitList": getNameFlag(name)};
             var v = null;
-            if (nested) {
-                orgActions.listIdentityWithUnitNested(data, function (json) { v = json.data; }, null, false);
-            } else {
-                orgActions.listIdentityWithUnitDirect(data, function (json) { v = json.data; }, null, false);
+
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            if (nested){
+                orgActions.listIdentityWithUnitNested(data, cb, null, !!async);
+            }else{
+                orgActions.listIdentityWithUnitDirect(data, cb, null, !!async);
             }
-            return v;
+            return (!!async) ? cb : v;
         },
 
         //组织**********
         //获取组织
-        getUnit: function (name) {
+        getUnit: function(name, async){
             getOrgActions();
-            var data = { "unitList": getNameFlag(name) };
+            var data = {"unitList":getNameFlag(name)};
             var v = null;
-            orgActions.listUnit(data, function (json) { v = json.data; }, null, false);
-            return (v && v.length === 1) ? v[0] : v;
+            var cb = function(json){
+                v = json.data;
+                v = (v && v.length===1) ? v[0] : v;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listUnit(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //查询组织的下级--返回组织的对象数组
         //nested  布尔  true嵌套下级;false直接下级;默认false;
-        listSubUnit: function (name, nested) {
+        listSubUnit: function(name, nested){
             getOrgActions();
-            var data = { "unitList": getNameFlag(name) };
+            var data = {"unitList": getNameFlag(name)};
             var v = null;
-            if (nested) {
-                orgActions.listUnitSubNested(data, function (json) { v = json.data; }, null, false);
-            } else {
-                orgActions.listUnitSubDirect(data, function (json) { v = json.data; }, null, false);
+
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            if (nested){
+                orgActions.listUnitSubNested(data, cb, null, !!async);
+            }else{
+                orgActions.listUnitSubDirect(data, cb, null, !!async);
             }
-            return v;
+            return (!!async) ? cb : v;
         },
         //查询组织的上级--返回组织的对象数组
         //nested  布尔  true嵌套上级;false直接上级;默认false;
-        listSupUnit: function (name, nested) {
+        //async 布尔 true异步请求
+        listSupUnit: function(name, nested, async){
             getOrgActions();
-            var data = { "unitList": getNameFlag(name) };
+            var data = {"unitList": getNameFlag(name)};
+
             var v = null;
-            if (nested) {
-                orgActions.listUnitSupNested(data, function (json) { v = json.data; }, null, false);
-            } else {
-                orgActions.listUnitSupDirect(data, function (json) { v = json.data; }, null, false);
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            if (nested){
+                orgActions.listUnitSupNested(data, cb, null, !!async);
+            }else{
+                orgActions.listUnitSupDirect(data, cb, null, !!async);
             }
-            return v;
+            return (!!async) ? cb : v;
+
+            // if (callback){
+            //     if (nested){
+            //         orgActions.listUnitSupNested(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
+            //     }else{
+            //         orgActions.listUnitSupDirect(data, function(json){v = json.data; o2.runCallback(callback, "success", [v], this);});
+            //     }
+            // }else{
+            //     var v = null;
+            //     if (nested){
+            //         orgActions.listUnitSupNested(data, function(json){v = json.data;}, null, false);
+            //     }else{
+            //         orgActions.listUnitSupDirect(data, function(json){v = json.data;}, null, false);
+            //     }
+            //     return v;
+            // }
         },
         //根据个人身份获取组织
         //flag 数字    表示获取第几层的组织
         //     字符串  表示获取指定类型的组织
         //     空     表示获取直接所在的组织
-        getUnitByIdentity: function (name, flag) {
+        getUnitByIdentity: function(name, flag, async){
             getOrgActions();
             var getUnitMethod = "current";
             var v;
-            if (flag) {
-                if (typeOf(flag) === "string") getUnitMethod = "type";
-                if (typeOf(flag) === "number") getUnitMethod = "level";
+            if (flag){
+                if (typeOf(flag)==="string") getUnitMethod = "type";
+                if (typeOf(flag)==="number") getUnitMethod = "level";
             }
-            switch (getUnitMethod) {
+
+            var cb;
+            switch (getUnitMethod){
                 case "current":
-                    var data = { "identityList": getNameFlag(name) };
-                    orgActions.listUnitWithIdentity(data, function (json) { v = json.data; v = (v && v.length === 1) ? v[0] : v }, null, false);
+                    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);
                     break;
                 case "type":
-                    var data = { "identity": (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name, "type": flag };
-                    orgActions.getUnitWithIdentityAndType(data, function (json) { v = json.data; }, null, false);
+                    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);
                     break;
                 case "level":
-                    var data = { "identity": (typeOf(name) === "object") ? (name.distinguishedName || name.id || name.unique || name.name) : name, "level": flag };
-                    orgActions.getUnitWithIdentityAndLevel(data, function (json) { v = json.data; }, null, false);
+                    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);
                     break;
             }
-            return v;
+            return (!!async) ? cb : v;
         },
         //列出身份所在组织的所有上级组织
-        listAllSupUnitWithIdentity: function (name) {
+        listAllSupUnitWithIdentity: function(name, async){
             getOrgActions();
-            var data = { "identityList": getNameFlag(name) };
+            var data = {"identityList":getNameFlag(name)};
             var v = null;
-            orgActions.listUnitSupNestedWithIdentity(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.listUnitSupNestedWithIdentity(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //获取人员所在的所有组织
-        listUnitWithPerson: function (name) {
+        listUnitWithPerson: function(name, async){
             getOrgActions();
-            var data = { "personList": getNameFlag(name) };
+            var data = {"personList":getNameFlag(name)};
             var v = null;
-            orgActions.listUnitWithPerson(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.listUnitWithPerson(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
-        //列出身份所在组织的所有上级组织
-        listAllSupUnitWithPerson: function (name) {
+        //列出人员所在组织的所有上级组织
+        listAllSupUnitWithPerson: function(name, async){
             getOrgActions();
-            var data = { "personList": getNameFlag(name) };
+            var data = {"personList":getNameFlag(name)};
             var v = null;
-            orgActions.listUnitSupNestedWithPerson(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.listUnitSupNestedWithPerson(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //根据组织属性,获取所有符合的组织
-        listUnitWithAttribute: function (name, attribute) {
+        listUnitWithAttribute: function(name, attribute, async){
             getOrgActions();
-            var data = { "name": name, "attribute": attribute };
+            var data = {"name":name,"attribute":attribute};
             var v = null;
-            orgActions.listUnitWithAttribute(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.listUnitWithAttribute(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //根据组织职务,获取所有符合的组织
-        listUnitWithDuty: function (name, id) {
+        listUnitWithDuty: function(name, id, async){
             getOrgActions();
-            var data = { "name": "", "identity": (typeOf(id) === "object") ? (id.distinguishedName || id.id || id.unique || id.name) : id };
-            var v = null;
-            orgActions.listUnitWithDuty(data, function (json) { v = json.data; }, null, false);
-            return v;
-        },
-        //列出顶层组织
-        listTopUnit: function () {
-            var action = MWF.Actions.get("x_organization_assemble_control");
+            var data = {"name":name,"identity":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
             var v = null;
-            action.listTopUnit(function (json) {
+            var cb = function(json){
                 v = json.data;
-            }, null, false);
-            return v;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.listUnitWithDuty(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
 
         //组织职务***********
         //获取指定的组织职务的身份
-        getDuty: function (duty, id) {
+        getDuty: function(duty, id, async){
             getOrgActions();
-            var data = { "name": duty, "unit": (typeOf(id) === "object") ? (id.distinguishedName || id.id || id.unique || id.name) : id };
+            var data = {"name":duty,"unit":(typeOf(id)==="object") ? (id.distinguishedName || id.id || id.unique || id.name) : id};
             var v = null;
-            orgActions.getDuty(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.getDuty(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //获取身份的所有职务名称
-        listDutyNameWithIdentity: function (name) {
+        listDutyNameWithIdentity: function(name, async){
             getOrgActions();
-            var data = { "identityList": getNameFlag(name) };
+            var data = {"identityList":getNameFlag(name)};
             var v = null;
-            orgActions.listDutyNameWithIdentity(data, function (json) { v = json.data.nameList; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data.nameList;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.listDutyNameWithIdentity(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //获取组织的所有职务名称
-        listDutyNameWithUnit: function (name) {
+        listDutyNameWithUnit: function(name, async){
             getOrgActions();
-            var data = { "unitList": getNameFlag(name) };
+            var data = {"unitList":getNameFlag(name)};
             var v = null;
-            orgActions.listDutyNameWithUnit(data, function (json) { v = json.data.nameList; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data.nameList;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.listDutyNameWithUnit(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //获取组织的所有职务
-        listUnitAllDuty: function (name) {
+        listUnitAllDuty: function(name, async){
             getOrgActions();
-            var data = { "unitList": getNameFlag(name) };
+            var data = {"unitList":getNameFlag(name)};
             var v = null;
-            orgActions.listUnitAllDuty(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+            orgActions.listUnitAllDuty(data, cb, null, !!async);
+            return (!!async) ? cb : v;
+        },
+        //列出顶层组织
+        listTopUnit: function(async){
+            var action = MWF.Actions.get("x_organization_assemble_control");
+            var v = null;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            action.listTopUnit(cb, null, !!async);
+            return (!!async) ? cb : v;
         },
 
         //组织属性**************
         //添加组织属性值(在属性中添加values值,如果没有此属性,则创建一个)
-        appendUnitAttribute: function (unit, attr, values, success, failure) {
+        appendUnitAttribute: function(unit, attr, values, success, failure, async){
             getOrgActions();
-            var unitFlag = (typeOf(unit) === "object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
-            var data = { "attributeList": values, "name": attr, "unit": unitFlag };
-            orgActions.appendUnitAttribute(data, function (json) {
-                if (json.data.value) {
-                    if (success) success();
-                } else {
-                    if (failure) failure(null, "", "append values failed");
-                }
-            }, function (xhr, text, error) {
-                if (failure) failure(xhr, text, error);
-            }, false);
+            var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
+            var data = {"attributeList":values,"name":attr,"unit":unitFlag};
+
+            var cb = function(json){
+                if (success) return success(json);
+            }.ag().catch(function(xhr, text, error){
+                if (failure) return failure(xhr, text, error);
+            });
+
+            orgActions.appendPersonAttribute(data, cb, null, !!async);
+
+            // orgActions.appendUnitAttribute(data, function(json){
+            //     if (json.data.value){
+            //         if (success) success();
+            //     }else{
+            //         if (failure) failure(null, "", "append values failed");
+            //     }
+            // }, function(xhr, text, error){
+            //     if (failure) failure(xhr, text, error);
+            // }, false);
         },
         //设置组织属性值(将属性值修改为values,如果没有此属性,则创建一个)
-        setUnitAttribute: function (unit, attr, values, success, failure) {
+        setUnitAttribute: function(unit, attr, values, success, failure, async){
             getOrgActions();
-            var unitFlag = (typeOf(unit) === "object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
-            var data = { "attributeList": values, "name": attr, "unit": unitFlag };
-            orgActions.setUnitAttribute(data, function (json) {
-                if (json.data.value) {
-                    if (success) success();
-                } else {
-                    if (failure) failure(null, "", "append values failed");
-                }
-            }, function (xhr, text, error) {
-                if (failure) failure(xhr, text, error);
-            }, false);
+            var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
+            var data = {"attributeList":values,"name":attr,"unit":unitFlag};
+
+            var cb = function(json){
+                if (success) return success(json);
+            }.ag().catch(function(xhr, text, error){
+                if (failure) return failure(xhr, text, error);
+            });
+            orgActions.setUnitAttribute(data, cb, null, !!async);
+
+            // orgActions.setUnitAttribute(data, function(json){
+            //     if (json.data.value){
+            //         if (success) success();
+            //     }else{
+            //         if (failure) failure(null, "", "append values failed");
+            //     }
+            // }, function(xhr, text, error){
+            //     if (failure) failure(xhr, text, error);
+            // }, false);
         },
         //获取组织属性值
-        getUnitAttribute: function (unit, attr) {
+        getUnitAttribute: function(unit, attr, async){
             getOrgActions();
-            var unitFlag = (typeOf(unit) === "object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
-            var data = { "name": attr, "unit": unitFlag };
+            var unitFlag = (typeOf(unit)==="object") ? (unit.distinguishedName || unit.id || unit.unique || unit.name) : unit;
+            var data = {"name":attr,"unit":unitFlag};
             var v = null;
-            orgActions.getUnitAttribute(data, function (json) { v = json.data.attributeList; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data.attributeList;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.getUnitAttribute(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //列出组织所有属性的名称
-        listUnitAttributeName: function (name) {
+        listUnitAttributeName: function(name, async){
             getOrgActions();
-            var data = { "unitList": getNameFlag(name) };
+            var data = {"unitList":getNameFlag(name)};
             var v = null;
-            orgActions.listUnitAttributeName(data, function (json) { v = json.data.nameList; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data.nameList;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listUnitAttributeName(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         },
         //列出组织的所有属性
-        listUnitAllAttribute: function (name) {
+        listUnitAllAttribute: function(name, async){
             getOrgActions();
-            var data = { "unitList": getNameFlag(name) };
+            var data = {"unitList":getNameFlag(name)};
             var v = null;
-            orgActions.listUnitAllAttribute(data, function (json) { v = json.data; }, null, false);
-            return v;
+            var cb = function(json){
+                v = json.data;
+                return v;
+            }.ag().catch(function(json){ return v; });
+
+            orgActions.listUnitAllAttribute(data, cb, null, !!async);
+            return (!!async) ? cb : v;
         }
     };
 

+ 2 - 2
o2web/source/x_component_process_Xform/$Input.js

@@ -190,7 +190,7 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input =  new Class({
 		return value || "";
 	},
     _setValue: function(value){
-	    if (o2.typeOf(value)==="function" && value.addResolve){
+	    if (o2.typeOf(value)==="o2_async_function"){
 	        this.moduleValueAG = value;
             value.addResolve(function(v){
                 this._setValue(v);
@@ -255,7 +255,7 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input =  new Class({
         this.setData(this.getValue());
     },
 	setData: function(data){
-        if (o2.typeOf(data)==="function" && data.addResolve){
+        if (o2.typeOf(data)==="o2_async_function"){
             data.addResolve(function(v){
                 this.setData(v);
             }.bind(this));

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

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

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

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

+ 77 - 36
o2web/source/x_component_process_Xform/Org.js

@@ -117,29 +117,48 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
             if (dutys.length){
                 dutys.each(function(duty){
                     if (duty.code) par = this.form.Macro.exec(duty.code, this);
-                    if (o2.typeOf(par)=="function"){
-
+                    if (o2.typeOf(par)=="o2_async_function"){
+                        var ag = o2.AG.all(par).then(function(p){
+                            var uName = "";
+                            if (p && p.length) uName = p[0].distinguishedName || p[0];
+                            var code = "return this.org.getDuty(\""+duty.name+"\", \""+uName+"\", true)";
+                            var r = this.form.Macro.exec(code, this);
+
+                            o2.AG.all(r).then(function(d) {
+                                //var d = rd[0];
+                                if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
+                                var arr = [];
+                                d.each(function(dd){
+                                    if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
+                                });
+                                return arr;
+                            }.bind(this));
+                        }.bind(this));
+                        values.push(ag);
+                    }else{
+                        var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\")";
+                        var d = this.form.Macro.exec(code, this);
+                        if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
+                        d.each(function(dd){if (dd) values.push(MWF.org.parseOrgData(dd, true, simple));});
                     }
-                    var code = "return this.org.getDuty(\""+duty.name+"\", \""+par+"\")";
-                    var d = this.form.Macro.exec(code, this);
-                    if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
-                    d.each(function(dd){if (dd) values.push(MWF.org.parseOrgData(dd, true, simple));});
+
                 }.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)=="function"){
+            if (o2.typeOf(fd)=="o2_async_function"){
                 // value.addResolve(function(v){
                 //     this._setBusinessData(v);
                 //     if (this.node.getFirst()) this.node.getFirst().set("value", v || "");
                 //     if (this.readonly || this.json.isReadonly) this.node.set("text", v);
                 // }.bind(this));
-                fd.then(function(v){
-                    return this._valueMerge(values, v);
-                }.bind(this));
-                return fd;
+                values.push(fd);
+                // fd.then(function(v){
+                //     return this._valueMerge(values, v);
+                // }.bind(this));
+                // return fd;
             }else{
                 if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
                 fd.each(function(fdd){
@@ -879,32 +898,54 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg =  new Class({
         return node;
     },
     _setValue: function(value){
-        debugger;
-        if (o2.typeOf(value)==="function"){
-            var simple = this.json.storeRange === "simple";
-            var values = [];
-            value.addResolve(function(fd){
-                if (o2.typeOf(fd)==="function" && fd.addResolve){
-                    this._setValue(fd);
-                }else{
-                    if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
-                    fd.each(function(fdd){
-                        if (fdd){
-                            if (typeOf(fdd)==="string"){
-                                var data;
-                                this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, fdd, false);
-                                values.push(data);
-                            }else{
-                                values.push(fdd);
-                            }
-                        }
-                    }.bind(this));
-                    this.__setValue(values);
+        var values = [];
+        o2.AG.all(value).then(function(d) {
+            if (typeOf(d)!=="array") d = (d) ? [d.toString()] : [];
+
+            d.each(function(dd){
+                //if (dd) arr.push(MWF.org.parseOrgData(dd, true, simple));
+                if (dd){
+                    if (typeOf(dd)==="string"){
+                        var data;
+                        this.getOrgAction()[this.getValueMethod(dd)](function(json){
+                            data = MWF.org.parseOrgData(json.data, true, simple);
+                        }.bind(this), null, dd, false);
+
+                        values.push(data);
+                    }else{
+                        values.push(d);
+                    }
                 }
-            }.bind(this));
-        }else{
-            this.__setValue(value);
-        }
+            });
+            this.__setValue(values);
+        }.bind(this));
+
+
+        // if (o2.typeOf(value)==="function"){
+        //     var simple = this.json.storeRange === "simple";
+        //     var values = [];
+        //     value.addResolve(function(fd){
+        //         if (o2.typeOf(fd)==="function" && fd.addResolve){
+        //             this._setValue(fd);
+        //         }else{
+        //             if (typeOf(fd)!=="array") fd = (fd) ? [fd] : [];
+        //             fd.each(function(fdd){
+        //                 if (fdd){
+        //                     if (typeOf(fdd)==="string"){
+        //                         var data;
+        //                         this.getOrgAction()[this.getValueMethod(fdd)](function(json){ data = MWF.org.parseOrgData(json.data, true, simple); }.bind(this), null, fdd, false);
+        //                         values.push(data);
+        //                     }else{
+        //                         values.push(fdd);
+        //                     }
+        //                 }
+        //             }.bind(this));
+        //             this.__setValue(values);
+        //         }
+        //     }.bind(this));
+        // }else{
+        //     this.__setValue(value);
+        // }
     },
     __setValue: function(value){
         if (value.length==1 && !(value[0])) value=[];