提交 82bb28dc 编写于 作者: NoSubject's avatar NoSubject

表单组件默认值等脚本,支持异步返回

上级 b9ba6ee4
......@@ -216,11 +216,11 @@
callback.apply(b, par);
}else{
if (type==="function" || type==="object"){
if (callback[key]){
callback[key].apply(b, par);
var name = ("on-"+key).camelCase();
if (callback[name]){
callback[name].apply(b, par);
}else{
var name = ("on-"+key).camelCase();
if (callback[name]) callback[name].apply(b, par);
if (callback[key]) callback[key].apply(b, par);
}
}
}
......@@ -1365,7 +1365,6 @@
//var noCache = cache===false;
var noCache = !cache;
//if (Browser.name == "ie")
if (_cacheUrls.length){
for (var i=0; i<_cacheUrls.length; i++){
......@@ -1377,7 +1376,7 @@
}
}
var useWebWorker = (window.layout && layout.config && config.useWebWorker);
var useWebWorker = (window.layout && layout.config && layout.config.useWebWorker);
//var noCache = false;
if (!loadAsync || !useWebWorker){
var res = new Request.JSON({
......@@ -1423,6 +1422,9 @@
}
//Content-Type application/x-www-form-urlencoded; charset=utf-8
res.send(data);
var oReturn = (callback.success && callback.success.addResolve) ? callback.success : callback;
oReturn.res = res;
return oReturn;
}else{
var workerMessage = {
method: method,
......@@ -1449,8 +1451,13 @@
}else{
o2.runCallback(callback, "failure", [result.data]);
}
actionWorker.terminate();
}
actionWorker.postMessage(workerMessage);
var oReturn = (callback.success && callback.success.addResolve) ? callback.success : callback;
oReturn.actionWorker = actionWorker;
return oReturn;
//return callback;
}
//return res;
};
......@@ -1615,19 +1622,29 @@
// }
// }
// });
Date.getFromServer = function(callback){
if (callback){
o2.Actions.get("x_program_center").echo(function(json){
d = Date.parse(json.data.serverTime);
o2.runCallback(callback, "success", [d]);
});
}else{
var d;
o2.Actions.get("x_program_center").echo(function(json){
d = Date.parse(json.data.serverTime);
}, null, false);
return d;
}
Date.getFromServer = function(async){
var d;
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);
return (!!async) ? cd : d;
// if (callback){
// o2.Actions.get("x_program_center").echo(function(json){
// d = Date.parse(json.data.serverTime);
// o2.runCallback(callback, "success", [d]);
// });
// }else{
// var d;
// o2.Actions.get("x_program_center").echo(function(json){
// d = Date.parse(json.data.serverTime);
// }, null, false);
// return d;
// }
};
Object.appendChain = function(oChain, oProto) {
......@@ -1679,7 +1696,7 @@
if (_self.success.resolve) result = _self.success.resolve.apply(this, arguments);
if (_self.success.resolveList){
_self.success.resolveList.each(function(r){
r(result, arguments);
result = r(result, arguments) || result;
});
}
}
......@@ -1691,7 +1708,7 @@
if (_self.failure.reject) result = _self.failure.reject(arguments);
if (_self.failure.rejectList){
_self.failure.rejectList.each(function(r){
r(result, arguments);
result = r(result, arguments) || result;
});
}
}
......@@ -1699,25 +1716,43 @@
setResolve: function(resolve){
if (!this.success) this._createSuccess();
this.success.resolve = resolve;
return this;
},
setReject: function(reject){
if (!this.failure) this._createFailure();
this.reject = reject;
this.failure.reject = reject;
return this;
},
addResolve: function(resolve){
if (!this.success) this._createSuccess();
if (resolve){
if (!this.success.resolveList) this.success.resolveList = [];
this.success.resolveList.push(resolve);
if (!this.success.resolve){
this.success.resolve = resolve;
}else{
if (!this.success.resolveList) this.success.resolveList = [];
this.success.resolveList.push(resolve);
}
}
return this;
},
addReject: function(reject){
if (!this.failure) this._createFailure();
if (reject){
if (!this.success.rejectList) this.success.rejectList = [];
this.success.rejectList.push(reject);
if (!this.failure.reject){
this.failure.reject = reject;
}else{
if (!this.failure.rejectList) this.failure.rejectList = [];
this.failure.rejectList.push(reject);
}
}
}
return this;
},
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);
......@@ -1726,6 +1761,10 @@
o2.AsyncGenerator = o2.AG = _AsyncGenerator;
Function.prototype.ag = function(){
return o2.AG(this);
}
})();
o2.core = true;
......
......@@ -58,15 +58,16 @@ function V(httpRequest) {
json.xToken = xToken;
}
_worker.postMessage({"type": "done", "data": json});
_worker.close();
},
_errorRequest: function(){
_worker.postMessage({"type":"error", "data": {"status": this.request.status, "statusText": this.request.statusText, "responseText":this.request.responseText}});
_worker.close();
}
};
this.action = _action;
})();
debugger;
onmessage = function(e) {
debugger;
......
......@@ -92,6 +92,10 @@ MWF.xDesktop.Actions.RestActions = new Class({
var async = (option.async===false) ? false : true;
if (option.failure && option.failure.failure) option.failure = option.failure.failure;
if (!option.failure && option.success && option.success.failure){
option.failure = option.success.failure;
option.failure.owner = option.success;
}
var callback = new MWF.xDesktop.Actions.RestActions.Callback(option.success, option.failure);
if (action.enctype && (action.enctype.toLowerCase()=="formdata")){
......@@ -555,16 +559,16 @@ MWF.xDesktop.Actions.RestActions.Callback = new Class({
switch(responseJSON.type) {
case "success":
if (this.appendSuccess) this.appendSuccess(responseJSON);
if (this.success) this.success(responseJSON, responseText);
if (this.success) return this.success(responseJSON, responseText);
break;
case "warn":
MWF.xDesktop.notice("info", {x: "right", y:"top"}, responseJSON.errorMessage.join("\n"));
if (this.appendSuccess) this.appendSuccess(responseJSON);
if (this.success) this.success(responseJSON);
if (this.success) return this.success(responseJSON);
break;
case "error":
this.doError(null, responseText, responseJSON.message);
return this.doError(null, responseText, responseJSON.message);
break;
}
}else{
......@@ -582,7 +586,14 @@ MWF.xDesktop.Actions.RestActions.Callback = new Class({
},
doError: function(xhr, text, error){
if (this.appendFailure) this.appendFailure(xhr, text, error);
if (this.failure) this.failure(xhr, text, error);
if (this.failure && this.failure.owner){
if (this.failure.reject || (this.failure.rejectList && this.failure.rejectList.length)){
return this.failure(xhr, text, error);
}
this.failure = null;
}else{
if (this.failure) return this.failure(xhr, text, error);
}
if (!this.failure && !this.appendFailure){
if (xhr.status!=0){
var errorText = error;
......
......@@ -492,14 +492,18 @@ MWF.xDesktop.getServiceAddressConfigArray = function(config, callback, error) {
config.center.each(function(center){
requests.push(
MWF.xDesktop.getServiceAddressConfigObject(center, function(serviceAddressList, center){
debugger;
requests.each(function(res){
if (res) if (res.isRunning()){res.cancel();}
if (res && res.res) if (res.res.isRunning()){res.res.cancel();}
if (res && res.actionWorker) res.actionWorker.terminate();
});
if (callback) callback(serviceAddressList, center);
}.bind(this), function(){
debugger;
if (requests.length){
for (var i=0; i<requests.length; i++){
if (requests[i].isRunning()) return "";
if (requests[i].res) if (requests[i].res.isRunning()) return "";
if (requests[i].actionWorker && requests[i].actionWorker.terminate) return "";
}
}
if (error) error();
......
......@@ -184,11 +184,13 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input = new Class({
},
getValue: function(){
var value = this._getBusinessData();
if (!value && this.moduleValueAG) value = this.moduleValueAG;
if (!value) value = this._computeValue();
return value || "";
},
_setValue: function(value){
if (o2.typeOf(value)==="function" && value.addResolve){
this.moduleValueAG = value;
value.addResolve(function(v){
this._setValue(v);
// this._setBusinessData(v);
......@@ -199,6 +201,7 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input = new Class({
this._setBusinessData(value);
if (this.node.getFirst()) this.node.getFirst().set("value", value || "");
if (this.readonly || this.json.isReadonly) this.node.set("text", value);
this.moduleValueAG = null;
}
},
_loadValue: function(){
......@@ -250,13 +253,19 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input = new Class({
this.setData(this.getValue());
},
setData: function(data){
this._setBusinessData(data);
if (this.node.getFirst()){
this.node.getFirst().set("value", data);
this.checkDescription();
this.validationMode();
if (o2.typeOf(data)==="function" && data.addResolve){
data.addResolve(function(v){
this.setData(v);
}.bind(this));
}else{
this.node.set("text", data);
this._setBusinessData(data);
if (this.node.getFirst()){
this.node.getFirst().set("value", data);
this.checkDescription();
this.validationMode();
}else{
this.node.set("text", data);
}
}
},
......
......@@ -10,7 +10,9 @@ MWF.xApplication.process.Xform.Label = MWF.APPLabel = new Class({
if (this.json.valueType == "script"){
var code = (this.json.script) ? this.json.script.code : "";
if (code){
this.node.set("text", this.form.Macro.exec(code, this) || "");
var value = this.form.Macro.exec(code, this);
this._setNodeText(value);
//this.node.set("text", this.form.Macro.exec(code, this) || "");
}
}
if (this.json.prefixIcon || this.json.suffixIcon){
......@@ -41,7 +43,16 @@ MWF.xApplication.process.Xform.Label = MWF.APPLabel = new Class({
}
}
},
_setNodeText: function(value){
if (o2.typeOf(value)==="function" && value.addResolve){
value.addResolve(function(v){
this._setNodeText(v);
}.bind(this));
}else{
this.node.set("text", value || "");
}
},
setText: function(text){
this.node.set("text", text);
}
});
\ No newline at end of file
});
......@@ -868,21 +868,26 @@ MWF.xApplication.process.Xform.Org = MWF.APPOrg = new Class({
_setValue: function(value){
debugger;
if (o2.typeOf(value)==="object" && value.resolve){
var simple = this.json.storeRange === "simple";
var values = value.values;
value.resolve.addResolve(function(fd){
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);
if (o2.typeOf(fd)==="function" && fd.addResolve){
this._setValue({"values": values, "resolve": 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));
this.__setValue(values);
}
}.bind(this));
}else{
this.__setValue(value);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册