mwf.xdesktop.requireapp("process.xform", "$input", null, false);
/** @class textfield 文本输入框。
* @o2cn 文本输入框
* @example
* //可以在脚本中获取该组件
* //方法1:
* var field = this.form.get("fieldid"); //获取组件对象
* //方法2
* var field = this.target; //在组件本身的脚本中获取,比如事件脚本、默认值脚本、校验脚本等等
*
* var data = field.getdata(); //获取值
* field.setdata("字符串值"); //设置值
* field.hide(); //隐藏字段
* var id = field.json.id; //获取字段标识
* var flag = field.isempty(); //字段是否为空
* @extends mwf.xapplication.process.xform.$input
* @o2category formcomponents
* @o2range {process|cms|portal}
* @hideconstructor
*/
mwf.xapplication.process.xform.textfield = mwf.apptextfield = new class({
implements: [events],
extends: mwf.app$input,
iconstyle: "textfieldicon",
// _loaduserinterface: function(){
// this._loadnode();
// if (this.json.compute === "show"){
// this._setvalue(this._computevalue());
// }else{
// this._loadvalue();
// }
// },
_loadnode: function(){
if (this.isreadonly()){
this._loadnoderead();
}else{
this._loadnodeedit();
}
},
loaddescription: function(){
if (this.isreadonly())return;
var v = this._getbusinessdata();
if (!v && v!==0){
if (this.json.description){
var size, w;
if( this.node.offsetparent === null ){ //隐藏
size = { y: 26 }
}else{
size = this.node.getfirst().getsize();
w = size.x-3;
if( this.hasicon() ){
if (common.browser.safari) w = w-20;
}
}
this.descriptionnode = new element("div", {"styles": this.form.css.descriptionnode, "text": this.json.description}).inject(this.node);
this.descriptionnode.setstyles({
"height": "" size.y "px",
"line-height": "" size.y "px"
});
if( w )this.descriptionnode.setstyles({
"width": "" w "px"
});
this.setdescriptionevent();
}
}
},
setdescriptionevent: function(){
if (this.descriptionnode){
if (common.browser.platform.name==="ios"){
this.descriptionnode.addevents({
"click": function(){
this.descriptionnode.setstyle("display", "none");
this.node.getfirst().focus();
this.node.getfirst().fireevent("click");
}.bind(this)
});
}else if (common.browser.platform.name==="android"){
this.descriptionnode.addevents({
"click": function(){
this.descriptionnode.setstyle("display", "none");
this.node.getfirst().focus();
this.node.getfirst().fireevent("click");
}.bind(this)
});
}else{
this.descriptionnode.addevents({
"click": function(){
this.descriptionnode.setstyle("display", "none");
this.node.getfirst().focus();
this.node.getfirst().fireevent("click");
}.bind(this)
});
}
this.node.getfirst().addevents({
"focus": function(){
this.descriptionnode.setstyle("display", "none");
}.bind(this),
"blur": function(){
if (!this.node.getfirst().get("value")) this.descriptionnode.setstyle("display", "block");
}.bind(this)
});
}
},
_loadnoderead: function(){
this.node.empty();
this.node.set({
"nodeid": this.json.id,
"mwftype": this.json.type
});
},
_resetnodeedit: function(){
var input = new element("input", {
"styles": {
"background": "transparent",
"width": (this.json.inputstyles && this.json.inputstyles.width) ? this.json.inputstyles.width : "100%",
"display": "block",
"border": "0px"
}
});
var node = new element("div", {"styles": {
"overflow": (this.json.styles && this.json.styles.overflow) ? this.json.styles.overflow : "hidden",
"position": "relative",
"margin-right": this.hasicon() ? "20px" : "0px",
"padding-right": "4px"
}}).inject(this.node, "after");
input.inject(node);
this.node.destroy();
this.node = node;
},
_loadnodeedit: function(){
if (!this.json.preprocessing) 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(){
var v = this.getinputdata("change");
//this._setbusinessdata(v);
this.validationmode();
if (this.validation()) {
this._setbusinessdata(v);
this.fireevent("change");
}
}.bind(this));
var inputnode = this.node.getfirst();
if (inputnode) inputnode.addevent("input", function(e){
var v=e.target.get("value");
this._setbusinessdata(v);
}.bind(this));
if (this.json.annmodel){
this.node.getfirst().addevent("focus", function(){
o2.actions.get("x_query_assemble_surface").calculateneural(this.json.annmodel, this.form.businessdata.work.id, function(json){
var arr = json.data.filter(function(d){
var value = this.node.getfirst().get("value");
return d.score>0.1 && (value.indexof(d.value)===-1)
}.bind(this));
if (arr.length){
if (!this.modelnode) this.createmodelnode();
this.modelnode.getlast().empty();
this.modelnode.show();
this.modelnode.position({ "relativeto": this.node, "position": "bottomleft", "edge": 'upperleft' });
arr.each(function(v){
var node = new element("div", {"text": v.value, "styles": this.form.css.modelitemnode}).inject(this.modelnode.getlast());
node.addevents({
"mouseover": function(){this.setstyle("color", "#0000ff");},
"mouseout": function(){this.setstyle("color", "#a31515");},
"mousedown": function(e){
var str = this.node.getfirst().get("value")
this.node.getfirst().set("value", ((str) ? str ", " e.target.get("text") : e.target.get("text")));
this.modelnode.hide();
}.bind(this)
});
}.bind(this));
}
}.bind(this));
}.bind(this));
this.node.getfirst().addevent("blur", function(){
if (this.modelnode) this.modelnode.hide();
}.bind(this));
}
this.node.getfirst().addevent("blur", function(){
this.validation();
}.bind(this));
this.node.getfirst().addevent("keyup", function(){
this.validationmode();
}.bind(this));
},
createmodelnode: function(){
this.modelnode = new element("div", {"styles": this.form.css.modelnode}).inject(this.node, "after");
new element("div", {"styles": this.form.css.modelnodetitle, "text": mwf.xapplication.process.xform.lp.anninput}).inject(this.modelnode);
new element("div", {"styles": this.form.css.modelnodecontent, "text": mwf.xapplication.process.xform.lp.anninput}).inject(this.modelnode);
},
getinputdata: function(){
if (this.node.getfirst()){
var v = this.node.getelement("input").get("value");
if (this.json.datatype=="number"){
var n = v.tofloat();
return (isnan(n)) ? 0 : n;
}
}else{
return this._getbusinessdata();
}
return v;
}
});
source