提交 69f8ac1d 编写于 作者: NoSubject's avatar NoSubject

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

完成基础$Input组件。Org组件基本完成,
*脚本中返回一个异步函数,来实现默认值的异步处理,异步函数使用Function.prototype.ag()方法创建,异步函数可作为平台服务器调用方法中的回调函数,平台服务器调用方法返回值为回调函数。
*脚本中的this.org方法的最后一个参数为是否异步标志,true是返回异步函数,false时同步执行,返回获取的值。(后端脚本都是同步的)
*组件的getValue方法异步处理时会返回一个ag函数(同步时或异步处理已经完成,返回组件的实际值),通过ag.then(function(value){});方法进行后续处理,或直接通过o2.AG.all(module.getValue()).then(function(value){});来处理。
*通过this.data.xxx=xxx设置值时,可赋值ag函数实现异步

*组件的getData方法返回组件当前的实际值,不考虑异步情况。
*通过this.data.xxx方法获取数据时不考虑异步情况
*org组件的addData方法用于允许输入是选人后的组件值添加,会同步获取人员信息,此处没有做异步处理。
上级 86c2e783
......@@ -57,6 +57,24 @@ o2.widget.chart.Line = new Class({
}.bind(this));
//this.transition();
},
loadScales: function(){
this.xScale = d3.scaleBand().domain(this.data.map(function(d){ return d[this.item];}.bind(this)))
.rangeRound(this.getXScaleRange()).paddingOuter(0.3).paddingInner(0.3);
this.barsData = [];
this.bars.each(function(bar, i){
this.barsData.push(
this.data.map(function(d, idx) {
return {"name": d[this.item], "data": ((typeOf(bar.data)==="function") ? bar.data(d, i) : d[bar.data]), "text": ((typeOf(bar.text)==="function") ? bar.text(d, i) : d[bar.text])}
}.bind(this))
);
}.bind(this));
var max = d3.max(this.barsData, function(d){ return d3.max(d, function(d){return d.data}); });
var min = d3.min(this.barsData, function(d){ return d3.min(d, function(d){return d.data}); });
this.yScale = d3.scaleLinear().domain([min*0.9, max*1.1])
.range(this.getYScaleRange());
},
setEvents: function(){
var rects = this.group.selectAll("circle");
var texts = this.group.selectAll("text");
......@@ -129,4 +147,4 @@ o2.widget.chart.Line = new Class({
// .attr("y", function(d) { return this.yScale(d.data); }.bind(this));
.attr("d", function(d) { return lines(d) }.bind(this));
}
});
\ No newline at end of file
});
......@@ -191,21 +191,22 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input = new Class({
_setValue: function(value){
debugger;
if (value && value.isAG){
this.moduleValueAG = value;
value.addResolve(function(v){
this._setValue(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);
this.moduleValueAG = o2.AG.all(value).then(function(v){
this.__setValue(v);
}.bind(this));
}else{
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;
return value;
}else {
this.__setValue(value);
}
},
__setValue: function(value){
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;
return value;
},
_loadValue: function(){
this._setValue(this.getValue());
},
......@@ -256,22 +257,25 @@ MWF.xApplication.process.Xform.$Input = MWF.APP$Input = 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){
this.__setData(v);
}.bind(this));
}else{
this._setBusinessData(data);
if (this.node.getFirst()){
this.node.getFirst().set("value", data);
this.checkDescription();
this.validationMode();
}else{
this.node.set("text", data);
}
this.moduleValueAG = null;
this.__setData(data);
}
},
__setData: function(data){
this._setBusinessData(data);
if (this.node.getFirst()){
this.node.getFirst().set("value", data);
this.checkDescription();
this.validationMode();
}else{
this.node.set("text", data);
}
this.moduleValueAG = null;
},
createErrorNode: function(text){
......
......@@ -38,20 +38,12 @@ MWF.xApplication.process.Xform.Calendar = MWF.APPCalendar = new Class({
}
},
getValue: function(isDate){
if (this.moduleValueAG) return this.moduleValueAG;
var value = this._getBusinessData();
if( value && !isDate)return value;
if (!value && this.moduleValueAG) value = this.moduleValueAG;
if (!value) value = this._computeValue();
return value || "";
// var d = (!!value) ? Date.parse(value) : "";
// if (isDate){
// return d || null;
// }else{
// return (d) ? d.format(this.json.format) : "";
// }
},
getValueStr : function(){
var value = this._getBusinessData();
......
......@@ -131,21 +131,44 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect = new Class({
},
setOptions: function(){
var optionItems = this.getOptions();
if (!optionItems) optionItems = [];
if (o2.typeOf(optionItems)==="array"){
optionItems.each(function(item){
var tmps = item.split("|");
var text = tmps[0];
var value = tmps[1] || text;
this._setOptions(optionItems);
},
_setOptions: function(optionItems){
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", [optionItems])
}
var option = new Element("option", {
"value": value,
"text": text
}).inject(this.node);
}.bind(this));
this.fireEvent("setOptions", [options])
}
}.bind(this))
},
// __setOptions: function(){
// var optionItems = this.getOptions();
// if (!optionItems) optionItems = [];
// if (o2.typeOf(optionItems)==="array"){
// optionItems.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", [optionItems])
// }
// },
addOption: function(text, value){
var option = new Element("option", {
"value": value || text,
......@@ -153,21 +176,63 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect = new Class({
}).inject(this.node);
this.fireEvent("addOption", [text, value])
},
_setValue: function(value){
this.moduleValueAG = o2.AG.all(value).then(function(v){
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){
// this._setValue(v);
// }.bind(this));
// // this.moduleValueAG = value;
// // value.addResolve(function(v){
// // this._setValue(v);
// // }.bind(this));
// }else{
//
// }
},
__setValue: function(value){
if (!this.readonly && !this.json.isReadonly ) {
this._setBusinessData(value);
for (var i=0; i<this.node.options.length; i++){
var option = this.node.options[i];
if (option.value==value){
option.selected = true;
// break;
}else{
option.selected = false;
}
}
}
//this.node.set("value", value);
this._setBusinessData(value);
for (var i=0; i<this.node.options.length; i++){
var option = this.node.options[i];
if (option.value==value){
option.selected = true;
// break;
}else{
option.selected = false;
}
}
}
this.moduleValueAG = null;
},
// _setValue: function(value){
// if (!this.readonly && !this.json.isReadonly ) {
// this._setBusinessData(value);
// for (var i=0; i<this.node.options.length; i++){
// var option = this.node.options[i];
// if (option.value==value){
// option.selected = true;
// // break;
// }else{
// option.selected = false;
// }
// }
// }
// //this.node.set("value", value);
// },
getTextData: function(){
var value = [];
var text = [];
......@@ -208,6 +273,7 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect = new Class({
return (value.length==1) ? value[0] : value;
},
resetData: function(){
debugger;
this.setData(this.getValue());
},
getOptionsObj : function(){
......@@ -224,7 +290,20 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect = new Class({
}
return { textList : textList, valueList : valueList };
},
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;
}
},
__setData: function(data){
this._setBusinessData(data);
if (this.readonly|| this.json.isReadonly){
var d = typeOf(data) === "array" ? data : [data];
......@@ -234,7 +313,7 @@ MWF.xApplication.process.Xform.Select = MWF.APPSelect = new Class({
var idx = ops.valueList.indexOf( v );
result.push( idx > -1 ? ops.textList[idx] : v);
})
this.node.set("text", result.join(","))
this.node.set("text", result.join(","));
}else{
var ops = this.node.getElements("option");
ops.each(function(op){
......
......@@ -22,17 +22,53 @@ MWF.xApplication.process.Xform.Textarea = MWF.APPTextarea = new Class({
_loadNodeRead: function(){
this.node.empty();
},
_setValue: function(value){
this._setBusinessData(value);
if (this.node.getFirst()) this.node.getFirst().set("value", value || "");
if (this.readonly || this.json.isReadonly){
this.moduleValueAG = o2.AG.all(value).then(function(v){
this.moduleValueAG = null;
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));
return value;
// if (value && value.isAG){
// this.moduleValueAG = value;
// value.addResolve(function(v){
// this._setValue(v);
// }.bind(this));
// }else{
// this._setBusinessData(value);
// if (this.node.getFirst()) this.node.getFirst().set("value", value || "");
// 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);
// }
// return value;
// }
},
// _setValue: function(value){
// this._setBusinessData(value);
// if (this.node.getFirst()) this.node.getFirst().set("value", value || "");
// 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);
// }
// },
_resetNodeEdit: function(){
var input = new Element("textarea", {"styles": {
"background": "transparent",
......@@ -130,4 +166,4 @@ MWF.xApplication.process.Xform.Textarea = MWF.APPTextarea = new Class({
}
}
});
\ No newline at end of file
});
......@@ -57,7 +57,7 @@
</div>
</div>
</div>
<script type=""javascript>
<script type="javascript">
if (!window.FormData || !window.WebSocket || !window.JSON){
var loadingNode = document.getElementById("browser_loading");
var errorNode = document.getElementById("browser_error");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册