mwf.xdesktop.requireapp("process.xform", "number", null, false);
/** @class currency 货币输入组件。
* @o2cn 货币输入组件
* @example
* //可以在脚本中获取该组件
* //方法1:
* var field = this.form.get("name"); //获取组件
* //方法2
* var field = this.target; //在组件事件脚本中获取
* @extends mwf.xapplication.process.xform.number
* @o2category formcomponents
* @o2range {process|cms}
* @hideconstructor
*/
mwf.xapplication.process.xform.currency = mwf.appcurrency = new class({
implements: [events],
extends: mwf.appnumber,
iconstyle: "currencyicon",
_loadmergeamountreadnode: function(){
var data = this.getbusinessdatabyid();
var total = new decimal(0);
for( var key in data ){
total = total.plus(new decimal(data[key] || 0));
}
this.node.set("text", this.formatnumber(total.tostring()));
this.loadsymboleread();
},
_loadmergeaveragereadnode: function(){
var data = this.getbusinessdatabyid();
var total = new decimal(0);
for( var key in data ){
total = total.plus(new decimal(data[key] || 0));
}
var average = total.div( new decimal(object.keys(data).length) );
this.node.set("text", this.formatnumber(average.tostring()));
this.loadsymboleread();
},
_resetnodeedit: function(){
var input = new element("input", {
"styles": {
"background": "transparent",
"width": "100%",
"border": "0px"
}
});
input.setstyles( this.json.recoveryinputstyles || {} );
var node = new element("div", {"styles": {
"overflow": "hidden",
"position": "relative",
"margin-right": "20px",
"padding-right": "4px"
}}).inject(this.node, "after");
node.setstyles( this.json.recoverystyles || {} );
input.inject(node);
if( this.json.currencysymbol ){
var symbole = new element("span.mwfcurrencysymbol", {
text: this.json.currencysymbol
});
symbole.inject( node.offsetparent !== null ? node : this.form.node );
symbole.setstyles( this.json.symbolstyles || {} );
var width = symbole.getsize().x 5;
input.setstyles({
"padding-left": width "px",
"width": "calc( 100% - " width "px )"
});
if( node.offsetparent === null )symbole.inject( node );
symbole.setstyles({
"top": "0px",
"left": "0px",
"position": "absolute"
});
}
this.node.destroy();
this.node = node;
},
_loadnodeedit: function(){
//if (!this.json.preprocessing) this._resetnodeedit();
this._resetnodeedit();
var input = this.node.getfirst();
if( !input && this.nodehtml ){
this.node.set("html", this.nodehtml);
input = this.node.getfirst();
}
input.set(this.json.properties);
this.node.set({
"id": this.json.id,
"mwftype": this.json.type,
"events": {
"click": this.clickselect.bind(this)
}
});
if (this.json.showicon!='no' && !this.form.json.hidemoduleicon) {
this.iconnode = new element("div", {
"styles": this.form.css[this.iconstyle]
}).inject(this.node, "before");
}else if( this.form.json.nodestylewithhidemoduleicon ){
this.node.setstyles(this.form.json.nodestylewithhidemoduleicon)
}
this.node.getfirst().addevent("change", function(){
this.validationmode();
if (this.validation()) {
var value = this.getinputdata("change");
this._setbusinessdata(value);
this.node.getfirst().set("value", this.formatnumber( value.tostring() ));
this.fireevent("change");
}
}.bind(this));
this.node.getfirst().addevent("blur", function(){
this.validation();
}.bind(this));
this.node.getfirst().addevent("keyup", function(){
this.validationmode();
}.bind(this));
},
__setdata: function(data, firechange){
var old = this.getinputdata();
this._setbusinessdata(data);
if (this.node.getfirst()){
this.node.getfirst().set("value", this.formatnumber(data));
this.checkdescription();
this.validationmode();
}else{
this.node.set("text", this.formatnumber(data));
this.loadsymboleread();
}
if (firechange && old!==data) this.fireevent("change");
this.modulevalueag = null;
},
__setvalue: function(value){
var v = typeof( value ) === "string" ? this.unformatnumber( value ) : value;
v = this.isnumber( v ) ? parsefloat( v ) : v;
this._setbusinessdata(v);
var val = value;
if( this.json.emptyvalue === "string" ){
if( typeof(v)==="null" )val = "";
if( v === 0 )val = "0";
}else{
if( v === 0 || v === "" || typeof(v)==="null" )val = "0";
}
if (this.node.getfirst()) this.node.getfirst().set("value", value || val);
if (this.isreadonly()) {
this.node.set("text", value || val);
this.loadsymboleread()
}
this.modulevalueag = null;
this.fieldmoduleloaded = true;
return value;
},
loadsymboleread: function () {
var symbole = new element("span.mwfcurrencysymbol", {
text: this.json.currencysymbol,
styles: this.json.symbolstyles || {}
}).inject(this.node, "top");
var paddingright = symbole.getstyle("padding-right");
if( typeof(paddingright) === "string" && parseint(paddingright) === 0 ){
symbole.setstyle("padding-right", "5px");
}
}
});
source