提交 03911af1 编写于 作者: NoSubject's avatar NoSubject

表单支持异步返回值脚本

上级 c202a061
......@@ -1422,7 +1422,7 @@
}
//Content-Type application/x-www-form-urlencoded; charset=utf-8
res.send(data);
var oReturn = (callback.success && callback.success.addResolve) ? callback.success : callback;
var oReturn = (callback.success && callback.success.isAG) ? callback.success : callback;
oReturn.res = res;
return oReturn;
}else{
......@@ -1624,14 +1624,15 @@
// });
Date.getFromServer = function(async){
var d;
var cb = function(json){
var cb = ((async && o2.typeOf(async)=="function") ? (async.isAG ? async : async.ag()) : 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);
return (!!async) ? cd : d;
return (!!async) ? cb : d;
// if (callback){
// o2.Actions.get("x_program_center").echo(function(json){
......
......@@ -91,11 +91,19 @@ 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;
}
if (!option.success){
option.success = function(v){return v;}.ag();
if (option.failure) {
option.success.catch(option.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")){
......
......@@ -192,6 +192,7 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input = new Class({
debugger;
if (value && value.isAG){
this.moduleValueAG = o2.AG.all(value).then(function(v){
if (o2.typeOf(v)=="array") v = v[0];
this.__setValue(v);
}.bind(this));
}else {
......@@ -258,6 +259,7 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input = 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{
......
......@@ -42,6 +42,15 @@ 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;
var d = (!!value) ? Date.parse(value) : "";
if (isDate){
return d || null;
}else{
//if (d) value = Date.parse(value).format(this.json.format);
return (d) ? d.format(this.json.format) : "";
}
return value || "";
},
......@@ -50,6 +59,17 @@ MWF.xApplication.process.Xform.Calendar = MWF.APPCalendar = new Class({
if (!value) value = this._computeValue();
return value;
},
__setValue: function(value){
var d = Date.parse(value);
var v = d.format(this.json.format);
this._setBusinessData(value);
if (this.node.getFirst()) this.node.getFirst().set("value", v || "");
if (this.readonly || this.json.isReadonly) this.node.set("text", v);
this.moduleValueAG = null;
return value;
},
clickSelect: function(){
debugger;
var _self = this;
......
......@@ -29,6 +29,7 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
this.deleteable = this.json.deleteable !== "no";
this.addable = this.json.addable !== "no";
debugger;
this.gridData = this._getValue();
this.totalModules = [];
......@@ -38,19 +39,23 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
this._loadDatagridDataModules();
this._addTitleActionColumn();
this._loadEditDatagrid();
this._loadEditDatagrid(function(){
this.fireEvent("postLoad");
this.fireEvent("load");
}.bind(this));
this.fireEvent("postLoad");
this.fireEvent("load");
//this._loadReadDatagrid();
}else{
this._loadDatagridDataModules();
this._getDatagridEditorTr();
this._loadReadDatagrid();
if(this.editorTr)this.editorTr.setStyle("display", "none");
this._loadReadDatagrid(function(){
if(this.editorTr)this.editorTr.setStyle("display", "none");
this.fireEvent("postLoad");
this.fireEvent("load");
}.bind(this));
this.fireEvent("postLoad");
this.fireEvent("load");
}
},
_loadStyles: function(){
......@@ -58,14 +63,18 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
this.node.setStyles(this.json.styles);
},
_getValue: function(){
if (this.moduleValueAG) return this.moduleValueAG;
var value = [];
value = this._getBusinessData();
if (!value){
if (this.json.defaultData && this.json.defaultData.code) value = this.form.Macro.exec(this.json.defaultData.code, this);
value = {"data": value || []};
if (!value.isAG) if (o2.typeOf(value)=="array") value = {"data": value || []};
}
return value || {};
},
getValue: function(){
return this._getValue();
},
_getDatagridTr: function(){
this._getDatagridTitleTr();
this._getDatagridEditorTr();
......@@ -109,7 +118,21 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
//}
},
_loadEditDatagrid: function(){
_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{
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");
var editorTds = this.editorTr.getElements("td");
......@@ -129,11 +152,11 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
}.bind(this));
}.bind(this));
}
this.editorTr.setStyle("display", "none");
if (callback) callback();
},
_getValueText: function(idx, value){
debugger;
var module = this.editModules[idx];
......@@ -696,9 +719,22 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
drag.start(e);
tr.setStyle("display", "none");
},
_loadReadDatagrid: function(){
this.gridData = this._getValue();
_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{
if (o2.typeOf(this.gridData)=="array") this.gridData = {"data": this.gridData};
this.__loadReadDatagrid(callback);
this.moduleValueAG = null;
}
},
__loadReadDatagrid: function(callback){
//this.gridData = this._getValue();
if (!this.titleTr) this._getDatagridTitleTr();
//var titleTr = this.table.getElement("tr");
var titleHeaders = this.titleTr.getElements("th");
......@@ -728,23 +764,6 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
var text = this._getValueText(index, v);
cell.set("text", text);
}
// if (typeOf(v)==="array"){
// var textArray = [];
// v.each( function( item ){
// if (typeOf(item)==="object"){
// textArray.push( item.name+((item.unitName) ? "("+item.unitName+")" : "") );
// }else{
// textArray.push(item);
// }
// }.bind(this));
// cell.set("text", textArray.join(", "));
// }else if (typeOf(v)==="object"){
// cell.set("text", v.name+((v.unitName) ? "("+v.unitName+")" : ""));
// }else{
// cell.set("text", v);
// }
break;
}
}else{ //Sequence
......@@ -755,14 +774,9 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
}.bind(this));
}.bind(this));
}
//lastTr.destroy();
this._loadTotal();
// this._loadSequenceRead();
if (callback) callback();
},
_loadDatagridStyle: function(){
......@@ -950,13 +964,27 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
this.setData(this._getValue());
},
setData: function(data){
// if( typeOf( data ) === "object" && typeOf(data.data) === "array" ){
if (data){
this._setBusinessData(data);
this.gridData = data;
if (!data){
data = this._getValue();
}
this._setData(data);
},
_setData: function(data){
if (data && data.isAG){
this.moduleValueAG = data;
data.addResolve(function(v){
this.setData(v);
}.bind(this));
}else{
this.gridData = this._getValue();
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" ){
this._setBusinessData(data);
this.gridData = data;
// if (this.isEdit) this._completeLineEdit();
if( this.isEdit ){ //如果有在编辑的,取消编辑行
......@@ -999,9 +1027,8 @@ MWF.xApplication.process.Xform.DatagridPC = new Class({
}
this._loadDatagridStyle();
}
},
getTotal: function(){
this._loadTotal();
return this.totalResaults;
......@@ -1252,4 +1279,4 @@ MWF.xApplication.process.Xform.DatagridPC$Data = new Class({
}.bind(this));
}
}
});
\ No newline at end of file
});
......@@ -160,6 +160,7 @@ MWF.xApplication.process.Xform.Radio = MWF.APPRadio = new Class({
_setValue: function(value){
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(){
......@@ -232,14 +233,23 @@ MWF.xApplication.process.Xform.Radio = MWF.APPRadio = new Class({
setData: function(data){
if (data && data.isAG){
this.moduleValueAG = data;
data.addResolve(function(v){
this.setData(v);
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);
this.moduleValueAG = null;
}
// 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){
......
......@@ -179,6 +179,7 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect = new Class({
_setValue: function(value){
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(){
......@@ -293,14 +294,22 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect = new Class({
setData: function(data){
if (data && data.isAG){
this.moduleValueAG = data;
data.addResolve(function(v){
this.setData(v);
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);
this.moduleValueAG = null;
}
// 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){
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册