mwf.xdesktop.requireapp("process.xform", "$module", null, false);
/** @class datagridmobile 数据网格组件(移动端)。从v6.2开始建议用数据表格(datatable)代替。
* @o2cn 数据网格移动端(过时)
* @example
* //可以在脚本中获取该组件
* //方法1:
* var datagrid = this.form.get("name"); //获取组件
* //方法2
* var datagrid = this.target; //在组件事件脚本中获取
* @extends mwf.xapplication.process.xform.$module
* @o2category formcomponents
* @deprecated
* @o2range {process|cms}
* @hideconstructor
*/
mwf.xapplication.process.xform.datagridmobile = new class(
/** @lends mwf.xapplication.process.xform.datagridmobile# */
{
implements: [events],
extends: mwf.app$module,
isedit: false,
options: {
/**
* 当前条目编辑完成时触发。通过this.event可以获取对应的table。
* @event mwf.xapplication.process.xform.datagridmobile#completelineedit
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 添加条目时触发。通过this.event可以获取对应的table。
* @event mwf.xapplication.process.xform.datagridmobile#addline
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 删除条目前触发。通过this.event可以获取对应的table。
* @event mwf.xapplication.process.xform.datagridmobile#deleteline
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 删除条目后触发。
* @event mwf.xapplication.process.xform.datagridmobile#afterdeleteline
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 编辑条目时触发。
* @event mwf.xapplication.process.xform.datagridmobile#editline
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
"moduleevents": ["queryload","postload","load","completelineedit", "addline", "deleteline", "afterdeleteline","editline"]
},
initialize: function(node, json, form, options){
/**
* @ignore
* @member parentline
* @memberof mwf.xapplication.process.xform.datagridmobile#
*/
this.node = $(node);
this.node.store("module", this);
this.json = json;
this.form = form;
this.field = true;
this.fieldmoduleloaded = false;
},
load: function(){
this._loadmoduleevents();
if (this.fireevent("queryload")){
this._queryloaded();
this._loaduserinterface();
this._loadstyles();
this._loaddomevents();
//this._loadevents();
this._afterloaded();
this.fireevent("afterload");
// this.fireevent("load");
}
},
_loaduserinterface: function(){
// this.fireevent("queryload");
this.editmodules = [];
this.node.setstyle("overflow-x", "hidden");
this.node.setstyle("overflow-y", "hidden");
this.table = this.node.getelement("table");
this.createmobiletable();
this.editable = (!this.readonly);
if (this.editable && this.json.editablescript && this.json.editablescript.code){
this.editable = this.form.macro.exec(((this.json.editablescript) ? this.json.editablescript.code : ""), this);
}
//this.editable = false;
this.deleteable = this.json.deleteable !== "no";
this.addable = this.json.addable !== "no";
this.griddata = this._getvalue();
if( this.griddata.data && typeof(this.griddata.data)==="object"){
this.griddata.data = [];
}
this.totalmodules = [];
this._loaddatagridtitlemodules();
if (this.editable!=false){
this._loaddatagriddatamodules();
//this._addtitleactioncolumn();
// this._loadeditdatagrid();
// //this._loadreaddatagrid();
// this.fireevent("postload");
// this.fireevent("load");
this._loadeditdatagrid(function(){
this.fieldmoduleloaded = true;
this.fireevent("postload");
this.fireevent("load");
}.bind(this));
}else{
this._loaddatagriddatamodules();
this._loadreaddatagrid(function(){
this.fieldmoduleloaded = true;
this.fireevent("postload");
this.fireevent("load");
}.bind(this));
// this._loadreaddatagrid();
// this.fireevent("postload");
// this.fireevent("load");
}
},
createmobiletable: function(){
var mobiletable = new element("table").inject(this.node);
mobiletable.set(this.json.properties);
//mobiletable.setstyle("display", "none");
//mobiletable.setstyle("margin-bottom", "10px");
var trs = this.table.getelements("tr");
var titletds = trs[0].getelements("th");
var contenttds = trs[1].getelements("td");
titletds.each(function(titletd, i){
var mobiletr = mobiletable.insertrow();
//var mobiletr = new element("tr").inject(mobiletable);
var th = new element("th").inject(mobiletr);
th.set({
"html": titletd.get("html"),
"id": titletd.get("id"),
"mwftype": titletd.get("mwftype")
});
var td = new element("td").inject(mobiletr);
td.set({
"html": contenttds[i].get("html"),
"id": contenttds[i].get("id"),
"mwftype": contenttds[i].get("mwftype")
});
var json = this.form._getdomjson(titletd);
if( json && json.isshow === false )mobiletr.hide();
}.bind(this));
this.table.destroy();
this.table = null;
this.table = mobiletable;
},
_loadstyles: function(){
//this.table.setstyles(this.json.tablestyles);
this.node.setstyles(this.json.styles);
var tables = this.node.getelements("table");
tables.each(function(table){
table.setstyles(this.json.tablestyles);
}.bind(this));
},
_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);
if (value && !value.then) if (o2.typeof(value)=="array") value = {"data": value || []};
}
return value || [];
},
getvalue: function(){
return this._getvalue();
},
_getvaluetext: function(idx, value){
var module = this.editmodules[idx];
if (module){
switch (module.json.type){
case "select":
for (var i=0; i1) ? arr[1] : arr[0];
if (value===v) return text;
}
// var ops = module.node.getelements("option");
// for (var i=0; i");
break;
}
}
return value;
},
editvalidation: function(){
var flag = true;
this.editmodules.each(function(field, key){
if (field.json.type!="sequence"){
field.validationmode();
if (!field.validation()) flag = false;
}
}.bind(this));
return flag;
},
_loadreaddatagrid: function(callback){
var p = o2.promiseall(this.griddata).then(function(v){
this.griddata = v;
if (o2.typeof(this.griddata)=="array") this.griddata = {"data": this.griddata};
this.__loadreaddatagrid(callback);
this.modulevalueag = null;
return v;
}.bind(this), function(){});
this.modulevalueag = p;
if (this.modulevalueag) this.modulevalueag.then(function(){
this.modulevalueag = null;
}.bind(this), function(){
this.modulevalueag = null;
}.bind(this));
// 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();
var titleheaders = this.table.getelements("th");
var tds = this.table.getelements("td");
if (this.griddata.data){
this.griddata.data.each(function(data, idx){
var datadiv = new element("div.datadiv", {"styles": {"overflow": "hidden", "margin-bottom": "10px"}}); //.inject(this.node);
if (this.totaldiv){
datadiv.inject(this.totaldiv, "before");
}else{
datadiv.inject(this.node);
}
this._createitemtitlenode(datadiv, idx);
var tablediv = new element("div", {"styles": this.form.css.gridmobiletablenode }).inject(datadiv);
var table = new element("table").inject(tablediv);
table.set(this.json.properties);
table.store("data", data);
//table.setstyle("margin-bottom", "10px");
titleheaders.each(function(th, index){
var tr = table.insertrow(index);
var datath = new element("th").inject(tr);
datath.set("text", th.get("text"));
datath.setstyle("width", "30%");
var cell = tr.insertcell(1);
cell.set("mwfid", tds[index].get("id"));
var celldata = data[th.get("id")];
if( typeof( celldata ) !== "array" ) {
if (celldata) {
for (key in celldata) {
var v = celldata[key];
var module = this.editmodules[index];
if (module && module.json.type == "imageclipper") {
this._createimage(cell, module, v);
} else if (module && (module.json.type == "attachment" || module.json.type == "attachmentdg")) {
this._createattachment(cell, module, v);
} else {
text = this._getvaluetext(index, v);
if (module && module.json.type == "textarea") {
cell.set("html", text);
} else {
cell.set("text", text);
}
//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;
//
// cell.set("text", celldata[key]);
// break;
}
} else { //sequence
cell.setstyle("text-align", "left");
cell.set("text", idx 1);
}
}
var json = this.form._getdomjson(th);
if( json && json.isshow === false )tr.hide();
}.bind(this));
}.bind(this));
}
if (callback) callback();
//this._loadtotal();
},
_loadeditdatagrid: function(callback){
var p = o2.promiseall(this.griddata).then(function(v){
this.griddata = v;
if (o2.typeof(this.griddata)=="array") this.griddata = {"data": this.griddata};
this.__loadeditdatagrid(callback);
this.modulevalueag = null;
return v;
}.bind(this), function(){
this.modulevalueag = null;
}.bind(this));
this.modulevalueag = p;
if (this.modulevalueag) this.modulevalueag.then(function(){
this.modulevalueag = null;
}.bind(this), function(){
this.modulevalueag = null;
}.bind(this));
// 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){
//this._createhelpnode();
//this.griddata = this._getvalue();
var titleheaders = this.table.getelements("th");
var tds = this.table.getelements("td");
var _self = this;
if (this.griddata.data.length){
if( this.addaction )this.addaction.setstyle("display","none");
this.griddata.data.each(function(data, idx){
var datadiv = new element("div.datadiv", {"styles": {"overflow": "hidden", "margin-bottom": "10px"}}); //.inject(this.node);
if (this.totaldiv){
datadiv.inject(this.totaldiv, "before");
}else{
datadiv.inject(this.node);
}
this._createitemtitlenode(datadiv, idx);
var tablediv = new element("div", {"styles": this.form.css.gridmobiletablenode }).inject(datadiv);
var table = new element("table").inject(tablediv);
table.set(this.json.properties);
table.store("data", data);
//table.setstyle("margin-bottom", "10px");
titleheaders.each(function(th, index){
var tr = table.insertrow(index);
var datath = new element("th").inject(tr);
datath.set("text", th.get("text"));
datath.setstyle("width", "30%");
var cell = tr.insertcell(1);
cell.set("mwfid", tds[index].get("id"));
var celldata = data[th.get("id")];
if( typeof( celldata ) !== "array" ){
if ( celldata ){
for (key in celldata){
var v = celldata[key];
var module = this.editmodules[index];
if( module && module.json.type == "imageclipper" ){
this._createimage( cell, module, v )
}else if( module && (module.json.type == "attachment" || module.json.type == "attachmentdg") ){
this._createattachment( cell, module, v );
}else{
text = this._getvaluetext(index, v);
if( module && module.json.type == "textarea" ){
cell.set("html", text);
}else{
cell.set("text", text);
}
//cell.set("text", text);
}
// if (typeof(v)==="object"){
// cell.set("text", v.name ((v.unitname) ? "(" v.unitname ")" : ""));
// }else{
// cell.set("text", v);
// }
break;
//
// cell.set("text", celldata[key]);
// break;
}
}else{ //sequence
cell.setstyle("text-align", "left");
cell.set("text", idx 1);
}
}
var json = this.form._getdomjson(th);
if( json && json.isshow === false )tr.hide();
}.bind(this));
var size = datadiv.getsize();
//datadiv.setstyle("height", "" size.y "px");
//datadiv.addevent("touchstart", function(e){_self.actiontouchstart(this, e);});
//datadiv.addevent("touchmove", function(e){_self.actiontouchmove(this, e);});
//datadiv.addevent("touchend", function(e){_self.actiontouchend(this, e);});
//datadiv.addevent("touchcancel", function(e){_self.actiontouchcancel(this, e);});
//
//datadiv.addevent("mousedown", function(e){_self._actionmousedown(this, e);});
//datadiv.addevent("mouseup", function(e){_self._actionmouseup(this, e);});
//this.showmoveaction(datadiv, 60);
//this.showendmoveaction(datadiv);
}.bind(this));
}else{
if (this.addaction){
if( this.addable )this.addaction.setstyle("display", "block");
}else{
if( this.addable )this._loadaddaction();
}
// this._loadaddaction();
}
if (callback) callback();
//this._loadtotal();
},
_loadactions: function(titlediv){
var actionnode = new element("div", {
"styles": this.form.css.mobiledatagridactionnode
}).inject(titlediv);
var delaction = new element("div", {
"styles": this.form.css.mobiledatagriddelactionnode,
"text": mwf.xapplication.process.xform.lp["delete"]
}).inject(actionnode);
if( !this.deleteable )delaction.hide();
var editaction = new element("div", {
"styles": this.form.css.mobiledatagrideditactionnode,
"text": mwf.xapplication.process.xform.lp.edit
}).inject(actionnode);
var addaction = new element("div", {
"styles": this.form.css.mobiledatagridaddactionnode,
"text": mwf.xapplication.process.xform.lp.add
}).inject(actionnode);
if( !this.addable )addaction.hide();
var cancelaction = new element("div", {
"styles": this.form.css.mobiledatagridcancelactionnode,
"text": mwf.xapplication.process.xform.lp.canceledit
}).inject(actionnode);
var completeaction = new element("div", {
"styles": this.form.css.mobiledatagridcompleteactionnode,
"text": mwf.xapplication.process.xform.lp.completededit
}).inject(actionnode);
var _self = this;
if( this.deleteable )delaction.addevent("click", function(e){
_self._deleteline(this.getparent().getparent().getparent(), e);
});
editaction.addevent("click", function(e){
_self._editline(this.getparent().getparent().getparent(), e);
});
completeaction.addevent("click", function(e){
_self._completelineedit();
});
cancelaction.addevent("click", function(e){
_self._cancellineedit(e);
});
if( this.addable )addaction.addevent("click", function(e){
_self._addline();
});
},
_createimage : function( cell, module, data ){
cell.empty();
if( !data )return;
var img = new element("img",{
src : mwf.xdesktop.getimagesrc( data )
}).inject( cell, "top" );
img.setstyles({
"max-width": "90%"
})
},
_createattachment: function ( cell, module, data ){
cell.empty();
var options = {
"style": module.json.style || "default",
"title": mwf.xapplication.process.xform.lp.attachmentarea,
"liststyle": module.json.dg_liststyle || "icon",
"size": module.json.dg_size || "min",
"resize": (module.json.dg_resize === "y" || this.json.dg_resize === "true"),
"attachmentcount": 0,
"isupload": false,
"isdelete": false,
"isreplace": false,
"isdownload": true,
"issizechange": (module.json.dg_issizechange === "y" || module.json.dg_issizechange === "true"),
"readonly": true,
"availableliststyles": module.json.dg_availableliststyles ? module.json.dg_availableliststyles : ["list", "seq", "icon", "preview"],
"isdeleteoption": "n",
"isreplaceoption": "n",
"toolbargrouphidden": module.json.dg_toolbargrouphidden || []
};
if (this.readonly) options.readonly = true;
if(!this.editable && !this.addable)options.readonly = true;
var atts = [];
data.each(function(d){
var att = module.attachmentcontroller.attachments.find(function(a){
return d.id == a.data.id;
});
if (att) module.attachmentcontroller.removeattachment(att);
});
module.setattachmentbusinessdata();
var attachmentcontroller = new mwf.xapplication.process.xform.attachmentcontroller(cell, module, options);
attachmentcontroller.load();
data.each(function (att) {
var attachment = this.form.businessdata.attachmentlist.find(function(a){
return a.id==att.id;
});
var attdata = attachment || att;
//if (att.site===this.json.id || (this.json.isopeninoffice && this.json.officecontrolname===att.site)) this.attachmentcontroller.addattachment(att);
attachmentcontroller.addattachment(attdata);
}.bind(this));
},
_createitemtitlenode: function(node, idx){
var n = idx 1;
var titlediv = new element("div", {"styles": this.json.itemtitlestyles}).inject(node);
titlediv.setstyle("overflow", "hidden");
var textnode = new element("div.sequencediv", {
"styles": {"float": "left"},
"text": mwf.xapplication.process.xform.lp.item n
}).inject(titlediv);
//if (idx==0){
if( this.editable != false ){
this._loadactions(titlediv);
}
//}
},
_createhelpnode: function(){
this.helpnode = new element("div", {"styles": this.form.css.mobilegridhelpnode}).inject(this.node, "top");
this.helpcontentnode = new element("div", {"styles": this.form.css.mobilegridhelpcontentnode}).inject(this.helpnode);
this.helpcontentnode.set("html", mwf.xapplication.process.xform.lp.mobilegridhelp);
new mbox.tooltip({
content: this.helpcontentnode,
setstyles: {content: {padding: 15, lineheight: 20}},
attach: this.helpnode,
transition: 'flyin',
position: {
x: ['right'],
y: ['center']
},
event: 'click'
});
},
_editline:function(node){
if (this.isedit){
if (!this._completelineedit()) return false;
}
this.currenteditline = node;
var currentedittable = node.getelement("table");
if (this.currenteditline){
this.table.setstyles({
"background-color": "#fffeb5",
"display": "table"
});
this.table.inject(currentedittable, "after");
//this.currenteditline.setstyle("display", "none");
currentedittable.setstyle("display", "none");
var actions = this.currenteditline.getfirst("div").getlast("div").getelements("div");
if (actions[0]) actions[0].setstyle("display", "none");
if (actions[1]) actions[1].setstyle("display", "none");
if (actions[2]) actions[2].setstyle("display", "none");
if (actions[3]) actions[3].setstyle("display", "block");
if (actions[4]) actions[4].setstyle("display", "block");
//this.addaction.inject(this.table, "after");
//this.addaction.set("text", mwf.xapplication.process.xform.lp.completededit);
//this.addaction.removeevents("click");
//this.addaction.addevent("click", function(){
// this._completelineedit();
//}.bind(this));
var data = this.currenteditline.getelement("table").retrieve("data");
var titleths = this.table.getelements("th");
titleths.each(function(th, idx){
var id = th.get("id");
var module = this.editmodules[idx];
if (module){
if (module.json.type=="sequence"){
module.node.set("text", this.currenteditline.getelement("table").getelements("tr")[idx].getelement("td").get("text"));
}else {
if (data[id]) {
module.setdata(data[id][module.json.id]);
} else {
module.setdata(null);
}
}
}
}.bind(this));
//var cellidx = this.currenteditline.getelements("td").indexof(td);
//var module = this.editmodules[cellidx-1];
//if (module) module.focus();
this.fireevent("editline");
this.isedit =true;
}
this.validationmode();
},
_loadaddaction: function(){
if( !this.addaction ){
this.addaction = new element("div", {"styles": this.form.css.gridmobileactionnode}).inject(this.node, "top");
this.addaction.set("text", mwf.xapplication.process.xform.lp.addline);
this.addaction.addevent("click", function(){
this._addline();
}.bind(this));
}
},
_addline: function(){
if (this.isedit){
if (!this._completelineedit()) return false;
}
if (this.addaction) this.addaction.setstyle("display", "none");
var tables = this.node.getelements("table");
var idx;
var datadiv = new element("div.datagriddatadiv", {"styles": {"overflow": "hidden", "margin-bottom": "10px"}});
if (this.totaldiv){
idx = tables.length-2;
datadiv.inject(this.totaldiv, "before");
}else{
idx = tables.length-1;
datadiv.inject(this.node);
}
this._createitemtitlenode(datadiv, idx);
var tablediv = new element("div", {"styles": this.form.css.gridmobiletablenode }).inject(datadiv);
this.table.setstyles({
"background-color": "#fffeb5",
"display": "table"
});
this.currenteditline = null;
this.table.inject(tablediv);
var titleths = this.table.getelements("th");
titleths.each(function(th, i){
var id = th.get("id");
var module = this.editmodules[i];
if (module){
if (module.json.type=="sequence"){
module.node.set("text", idx 1);
}
}
}.bind(this));
this.isedit = true;
var actions = datadiv.getfirst("div").getlast("div").getelements("div");
if (actions[0]) actions[0].setstyle("display", "none");
if (actions[1]) actions[1].setstyle("display", "none");
if (actions[2]) actions[2].setstyle("display", "none");
if (actions[3]) actions[3].setstyle("display", "block");
if (actions[4]) actions[4].setstyle("display", "block");
if (!datadiv.isintoview()) datadiv.scrollintoview(true);
//this.addaction.set("text", mwf.xapplication.process.xform.lp.completededit);
//this.addaction.removeevents("click");
//this.addaction.addevent("click", function(){
// this._completelineedit();
//}.bind(this));
this.validationmode();
this.fireevent("addline", [this.table]);
},
_cancellineedit : function(e){
var datagrid = this;
var _self = this;
this.form.confirm("warn", e, mwf.xapplication.process.xform.lp.canceldatagridlineedittitle, mwf.xapplication.process.xform.lp.canceldatagridlineedit, 300, 120, function(){
datagrid.isedit = false;
if (datagrid.currenteditline) {
// datagrid.currenteditline.setstyle("display", "table-row");
var currentedittable = datagrid.currenteditline.getelement("table");
currentedittable.setstyle("display", "table");
var actions = datagrid.currenteditline.getfirst("div").getlast("div").getelements("div");
if (actions[0] && this.deleteable ) actions[0].setstyle("display", "block");
if (actions[1] ) actions[1].setstyle("display", "block");
if (actions[2] && this.addable ) actions[2].setstyle("display", "block");
if (actions[3]) actions[3].setstyle("display", "none");
if (actions[4]) actions[4].setstyle("display", "none");
datagrid._editortrgoback();
}else{
var datagriddatadiv = e.target.getparent(".datagriddatadiv");
datagrid._editortrgoback();
if(datagriddatadiv)datagriddatadiv.destroy();
}
datagrid.editmodules.each(function(module){
if (module && (module.json.type=="attachment" || module.json.type=="attachmentdg")){
module.attachmentcontroller.attachments.each(function(att){
datagrid.form.workaction.deleteattachment(att.data.id, datagrid.form.businessdata.work.id);
});
module.attachmentcontroller.clear();
}
});
datagrid.currenteditline = null;
if (!_self.griddata.data.length){
if (_self.addaction){
if( _self.addable )_self.addaction.setstyle("display", "block");
}else{
if( _self.addable )_self._loadaddaction();
}
}
this.close();
datagrid.fireevent("cancellineedit");
}, function(){
// var color = currenttr.retrieve("bgcolor");
// currenttr.tween("background", color);
this.close();
}, null, null, this.form.json.confirmstyle);
},
_completelineedit: function( ev ){
if (!this.editvalidation()){
return false;
}
this.isedit = false;
var saveflag = false;
//var flag = true;
var griddata = {};
var datanode = null;
var table;
if (this.currenteditline){
datanode = this.currenteditline;
griddata = datanode.getelement("table").retrieve("data");
this.currenteditline.getelement("table").setstyle("display", "table");
table = datanode.getelement("table");
var actions = this.currenteditline.getfirst("div").getlast("div").getelements("div");
if (actions[0] && this.deleteable ) actions[0].setstyle("display", "block");
if (actions[1]) actions[1].setstyle("display", "block");
if (actions[2] && this.addable ) actions[2].setstyle("display", "block");
if (actions[3]) actions[3].setstyle("display", "none");
if (actions[4]) actions[4].setstyle("display", "none");
}else{
//datanode = new element("div", {"styles": {"overflow": "hidden", "margin-bottom": "10px"}}).inject(this.table, "before");
//var tablediv = new element("div", {"styles": {"overflow": "hidden"}}).inject(datanode);
var datadiv = this.table.getparent(".datagriddatadiv");
if(datadiv){
datadiv.removeclass("datagriddatadiv").addclass("datadiv");
}
var actions = this.table.getparent().getprevious("div").getlast("div").getelements("div");
if (actions[0] && this.deleteable ) actions[0].setstyle("display", "block");
if (actions[1]) actions[1].setstyle("display", "block");
if (actions[2] && this.addable ) actions[2].setstyle("display", "block");
if (actions[3]) actions[3].setstyle("display", "none");
if (actions[4]) actions[4].setstyle("display", "none");
table = new element("table", {
styles : this.json.tablestyles
}).inject(this.table, "before");
table.set(this.json.properties);
griddata = {};
//datanode.addevent("touchstart", function(e){_self.actiontouchstart(this, e);});
//datanode.addevent("touchmove", function(e){_self.actiontouchmove(this, e);});
//datanode.addevent("touchend", function(e){_self.actiontouchend(this, e);});
//datanode.addevent("touchcancel", function(e){_self.actiontouchcancel(this, e);});
}
var tables = this.node.getelements("table");
var titleheaders = this.table.getelements("th");
var tds = this.table.getelements("td");
var datarows = table.getelements("tr");
titleheaders.each(function(th, idx){
var datarow = datarows[idx];
var id = th.get("id");
var module = this.editmodules[idx];
if (module){
var data;
if (module.json.type=="sequence"){
var i;
if (!this.currenteditline){
i = tables.length-1;
if (this.totaltable) i = tables.length-2;
}else{
i = this.currenteditline.getelement("table").getelements("tr")[idx].getelement("td").get("text");
}
data = {"value": [i], "text": [i]};
}else if( module.json.type=="attachment" || module.json.type == "attachmentdg" ) {
saveflag = true;
var data = module.gettextdata();
//data.site = module.json.site;
if (!griddata[id]) griddata[id] = {};
griddata[id][module.json.id] = data;
// }else if( ["orgfield","personfield","org","address"].contains(module.json.type) ){
// data = module.gettextdata();
// if (!griddata[id]) griddata[id] = {};
// griddata[id][module.json.id] = data.value;
}else{
data = module.gettextdata();
//if (data.value[0]) flag = false;
if (data.value.length<2){
if (!griddata[id]) griddata[id] = {};
griddata[id][module.json.id] = data.value[0];
}else{
if (!griddata[id]) griddata[id] = {};
griddata[id][module.json.id] = data.value;
}
}
var cell;
// var text = this._getvaluetext(idx, data.text.join(", "));
if (datarow){
cell = datarow.getelement("td");
if( module.json.type == "imageclipper" ){
this._createimage( cell, module, data.text );
}else if( module.json.type == "attachment" || module.json.type == "attachmentdg" ){
this._createattachment( cell, module, data );
}else{
var text = this._getvaluetext(idx, data.text.join(", "));
if( module && module.json.type == "textarea" ){
cell.set("html", text);
}else{
cell.set("text", text);
}
//cell.set("text", data.text.join(", "));
}
}else{
datarow = table.insertrow(idx);
var datath = new element("th").inject(datarow);
datath.set("text", th.get("text"));
datath.setstyle("width", "30%");
cell = datarow.insertcell(1);
cell.set("mwfid", tds[idx].get("id"));
var celldata = data[th.get("id")];
if( module.json.type == "imageclipper" ){
this._createimage( cell, module, data.text );
}else if( module.json.type == "attachment" || module.json.type == "attachmentdg" ){
this._createattachment( cell, module, data );
}else{
var text = this._getvaluetext(idx, data.text.join(", "));
if( module && module.json.type == "textarea" ){
cell.set("html", text);
}else{
cell.set("text", text);
}
//cell.set("text", data.text.join(", "));
}
}
}else{
if (!datarow) {
datarow = table.insertrow(idx);
var datath1 = new element("th").inject(datarow);
datath1.set("text", th.get("text"));
datath1.setstyle("width", "30%");
cell = datarow.insertcell(1);
}
}
var json = this.form._getdomjson(th);
if( json && json.isshow === false )datarow.hide();
module = null;
}.bind(this));
table.store("data", griddata);
table.setstyle("display", "table");
//if (flag){
// newtr.destroy();
//}
this.currenteditline = null;
this._editortrgoback();
this.getdata();
this._loaddatagridstyle();
this.validationmode();
this.fireevent("completelineedit", [table]);
if (this.addaction){
this.addaction.set("text", mwf.xapplication.process.xform.lp.addline);
this.addaction.removeevents("click");
this.addaction.addevent("click", function(){
this._addline();
}.bind(this));
}
if(saveflag){
this.form.saveformdata();
}
return true;
},
_editortrgoback: function(){
this.table.setstyle("display", "none");
this.table.inject(this.node, "top");
//if (this.totaldiv){
// this.addaction.inject(this.totaldiv, "before");
//}else{
// this.addaction.inject(this.node);
//}
// this.edittr.removeevents("blur");
// if (this.totaltr){
// this.editortr.inject(this.totaltr, "before");
// }else{
// var lasttrs = this.table.getelements("tr");
// var lasttr = lasttrs[lasttrs.length-1];
// this.editortr.inject(lasttr, "after");
// }
},
_actionmousedown: function(node, e){
var status = node.retrieve("editstatus");
if (!status){
node.store("editstatus", new date());
}
this._checkmousedown(node);
},
_checkmousedown: function(node){
var status = node.retrieve("editstatus");
if (status){
var d = (new date()).gettime();
if (d-status.gettime()>1000){
this._editline(node);
node.eliminate("editstatus");
}else{
window.settimeout(function(){
this._checkmousedown(node);
}.bind(this), 1000)
}
}
},
_actionmouseup: function(node, e){
node.eliminate("editstatus");
},
actiontouchstart: function(node, e){
var p = {"x": e.touches[0].pagex, "y": e.touches[0].pagey};
//node.store("start", p);
var action = node.retrieve("action");
if (action){
node.store("touchstatus", {"p": p, "status": "hide", "ishide": false});
}else{
node.store("touchstatus", {"p": p, "status": "show"});
}
this._actionmousedown(node, e);
//e.preventdefault();
},
actiontouchmove: function(node, e){
var touchstatus = node.retrieve("touchstatus");
var p = touchstatus.p;
var status = touchstatus.status;
var x = e.touches[0].pagex;
var y = e.touches[0].pagey;
if (math.abs(p.x-x)>10 || math.abs(p.y-y)>10){
this._actionmouseup(node);
}
if (status=="show"){
if ((p.x-x > 20) && math.abs(p.y-y)<40){
this.showmoveaction(node, p.x-x);
e.preventdefault();
}
}else{
if ((x-p.x > 20) && math.abs(p.y-y)<40){
touchstatus.ishide = true;
this.hidemoveaction(node, x- p.x);
e.preventdefault();
}
}
},
actiontouchend: function(node, e){
var touchstatus = node.retrieve("touchstatus");
var p = touchstatus.p;
var status = touchstatus.status;
if (status=="show"){
var action = node.retrieve("action");
if (action) this.showendmoveaction(node);
}else{
if (touchstatus.ishide) this.hideendmoveaction(node);
}
},
actiontouchcancel: function(node, e){
this._actionmouseup(node);
},
showendmoveaction: function(node){
var action = node.retrieve("action");
var tablenode = node.getlast("div");
new fx.tween(action, {"duration": 100}).start("width", "60px");
new fx.tween(tablenode, {"duration": 100}).start("margin-right", "60px");
var _self = this;
action.addevent("click", function(e){
_self._deleteline(node, e);
});
},
_deleteline: function(node, e){
var saveflag = false;
var currenttable = node.getelement("table");
if (currenttable){
var datagrid = this;
var _self = this;
this.form.confirm("warn", e, mwf.xapplication.process.xform.lp.deletedatagridlinetitle, mwf.xapplication.process.xform.lp.deletedatagridline, 300, 120, function(){
_self.fireevent("deleteline", [currenttable]);
var data = currenttable.retrieve("data");
//var attkeys = [];
var titleths = _self.table.getelements("th");
titleths.each(function(th, i){
var key = th.get("id");
var module = _self.editmodules[i];
if (key && module && (module.json.type=="attachment" || module.json.type=="attachmentdg")){
saveflag = true;
data[key][module.json.id].each(function(d){
_self.form.workaction.deleteattachment(d.id, _self.form.businessdata.work.id);
});
}
});
node.destroy();
//datagrid._loadzebrastyle();
datagrid._loadsequence();
datagrid._loadtotal();
datagrid.getdata();
if (!_self.griddata.data.length){
if (_self.addaction){
if( _self.addable )_self.addaction.setstyle("display", "block");
}else{
if( _self.addable )_self._loadaddaction();
}
}
this.close();
_self.fireevent("afterdeleteline");
if(saveflag){
_self.form.saveformdata();
}
}, function(){
//var color = currenttr.retrieve("bgcolor");
//currenttr.tween("background-color", color);
this.close();
}, null, null, this.form.json.confirmstyle);
}
this.validationmode();
},
hideendmoveaction: function(node){
var action = node.retrieve("action");
var tablenode = node.getlast("div");
new fx.tween(action, {"duration": 100}).start("width", "0px");
new fx.tween(tablenode, {"duration": 100}).start("margin-right", "0px").chain(function(){
action.destroy();
node.eliminate("action");
});
},
showmoveaction: function(node, length){
var action = node.retrieve("action");
var tablenode = node.getlast("div");
if (!action){
var size = node.getsize();
action = new element("div", {
"styles": this.form.css.gridmobiledeleteactionareanode
}).inject(node, "top");
var button = new element("div", {
"styles": this.form.css.gridmobiledeleteactionnode,
"text": mwf.xapplication.process.xform.lp["delete"]
}).inject(action);
action.setstyle("height","" size.y "px");
action.setstyle("line-height","" size.y "px");
node.store("action", action);
}
if (length>60) length = 60;
action.setstyle("width", "" length "px");
tablenode.setstyle("margin-right", "" length "px");
},
hidemoveaction: function(node, length){
var action = node.retrieve("action");
var tablenode = node.getlast("div");
var width = 60-length;
if (width<0) width=0;
if (action) action.setstyle("width", "" width "px");
tablenode.setstyle("margin-right", "" width "px");
},
_loaddatagridstyle: function(){
//var ths = this.node.getelements("th");
//ths.setstyles(this.form.css.datagridtitle);
this.loadgridtitlestyle();
this.loadgridcontentstyle();
//this.loadgridactionstyle();
this.loadgrideditstyle();
this._loadtotal();
this._loadborderstyle();
this._loadzebrastyle();
this._loadsequence();
},
loadgrideditstyle: function(){
if (this.table){
if (this.json.editstyles){
var tds = this.table.getelements("td");
tds.setstyles(this.json.editstyles);
}
}
},
//loadgridactionstyle: function(){
// if (this.editable!=false){
// if (this.json.actionstyles){
// var trs = this.table.getelements("tr");
// trs.each(function(tr, idx){
// if (idx != 0) tr.getfirst().setstyles(this.json.actionstyles);
// }.bind(this));
// }
// }
//},
loadgridtitlestyle: function(){
if (this.json.titlestyles){
var ths = this.node.getelements("th");
ths.setstyles(this.json.titlestyles);
}
},
loadgridcontentstyle: function(){
if (this.json.contentstyles){
var tds = this.node.getelements("td");
tds.setstyles(this.json.contentstyles);
}
},
_loadzebrastyle: function(){
if (this.json.zebracolor || this.json.backgroundcolor){
var tables = this.node.getelements("table");
tables.each(function(table){
this._loadtablezebrastyle(table);
}.bind(this));
}
},
_loadtablezebrastyle: function(table){
var trs = table.getelements("tr");
for (var i=0; i
* 当表单上没有对应组件的时候,可以使用this.data[fieldid] = data赋值。
* @summary 为数据网格赋值。
* @param data{datagriddata|promise|array} 必选,数组或promise.
* @example
* this.form.get("fieldid").setdata([]); //赋空值
* @example
* //如果无法确定表单上是否有组件,需要判断
* if( this.form.get('fieldid') ){ //判断表单是否有无对应组件
* this.form.get('fieldid').setdata( data );
* }else{
* this.data['fieldid'] = data;
* }
*@example
* //使用promise
* var field = this.form.get("fieldid");
* var promise = new promise(function(resolve, reject){ //发起异步请求
* var oreq = new xmlhttprequest();
* oreq.addeventlistener("load", function(){ //绑定load事件
* resolve(oreq.responsetext);
* });
* oreq.open("get", "/data.json"); //假设数据存放在data.json
* oreq.send();
* });
* promise.then( function(){
* var data = field.getdata(); //此时由于异步请求已经执行完毕,getdata方法获得data.json的值
* })
* field.setdata( promise );
*/
setdata: function(data){
if (!data){
data = this._getvalue();
}
this._setdata(data);
},
_setdata: function(data){
var p = o2.promiseall(this.data).then(function(v){
this.griddata = v;
if (o2.typeof(data)=="array") data = {"data": data};
this.__setdata(data);
this.modulevalueag = null;
return v;
}.bind(this), function(){
this.modulevalueag = null;
}.bind(this));
this.modulevalueag = p;
if (this.modulevalueag) this.modulevalueag.then(function(){
this.modulevalueag = null;
}.bind(this), function(){
this.modulevalueag = null;
}.bind(this));
// if (data && data.isag){
// this.modulevalueag = data;
// data.addresolve(function(v){
// this._setdata(v);
// }.bind(this));
// }else{
// 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" ){
// if (data){
// this._setbusinessdata(data);
// this.griddata = data;
// }else{
// this.griddata = this._getvalue();
// }
this._setbusinessdata(data);
this.griddata = data;
// if (this.isedit) this._completelineedit();
if( this.isedit ){
this.isedit = false;
if (this.currenteditline) {
this._editortrgoback();
this.currenteditline.destroy()
}else{
var datagriddatadiv = this.node.getelement(".datagriddatadiv");
this._editortrgoback();
if(datagriddatadiv)datagriddatadiv.destroy();
}
this.currenteditline = null;
}
if (this.griddata){
var divs = this.node.getelements(".datadiv");
for (var i=0; i2){
// tables[1].destroy();
// tables = this.node.getelements("table");
// }
if (this.editable!=false){
this._loadeditdatagrid();
//this._loadreaddatagrid();
}else{
this._loadreaddatagrid();
}
this._loaddatagridstyle();
}
},
/**
* @summary 获取总计数据.
* @example
* var totalobject = this.form.get('fieldid').gettotal();
* @return {object} 总计数据
*/
gettotal: function(){
this._loadtotal();
return this.totalresaults;
},
/**
* @summary 判断数据网格是否为空.
* @example
* if( this.form.get('fieldid').isempty() ){
* this.form.notice('至少需要添加一条数据', 'warn');
* }
* @return {boolean} 是否为空
*/
isempty: function(){
var data = this.getdata();
if( !data )return true;
if( typeof( data ) === "object" ){
if( typeof( data.data ) !== "array" )return true;
if( data.data.length === 0 )return true;
}
return false;
},
/**
* 在脚本中使用 this.data[fieldid] 也可以获取组件值。
* 区别如下:
* 1、当使用promise的时候
* 使用异步函数生成器(promise)为组件赋值的时候,用getdata方法立即获取数据,可能返回修改前的值,当promise执行完成以后,会返回修改后的值。
* this.data[fieldid] 立即获取数据,可能获取到异步函数生成器,当promise执行完成以后,会返回修改后的值。
* {@link https://www.yuque.com/o2oa/ixsnyt/ws07m0#eggil|具体差异请查看链接}
* 2、当表单上没有对应组件的时候,可以使用this.data[fieldid]获取值,但是this.form.get('fieldid')无法获取到组件。
* @summary 获取数据网格数据.
* @example
* var data = this.form.get('fieldid').getdata();
*@example
* //如果无法确定表单上是否有组件,需要判断
* var data;
* if( this.form.get('fieldid') ){ //判断表单是否有无对应组件
* data = this.form.get('fieldid').getdata();
* }else{
* data = this.data['fieldid']; //直接从数据中获取字段值
* }
* @example
* //使用promise
* var field = this.form.get("fieldid");
* var promise = new promise(function(resolve, reject){ //发起异步请求
* var oreq = new xmlhttprequest();
* oreq.addeventlistener("load", function(){ //绑定load事件
* resolve(oreq.responsetext);
* });
* oreq.open("get", "/data.json"); //假设数据存放在data.json
* oreq.send();
* });
* promise.then( function(){
* var data = field.getdata(); //此时由于异步请求已经执行完毕,getdata方法获得data.json的值
* })
* field.setdata( promise );
* @return {datagriddata}
*/
getdata: function(){
if (this.editable!=false){
if (this.isedit) this._completelineedit();
var data = [];
var tables = this.node.getelements("table");
for (var i=1; i<((this.totaltable) ? tables.length-1 : tables.length); i ){
var table = tables[i];
var d = table.retrieve("data");
if (d) data.push(d);
}
this.griddata = {};
this.griddata.data = data;
this._loadtotal();
this.griddata.total = this.totalresaults;
this._setbusinessdata(this.griddata);
return (this.griddata.data.length) ? this.griddata : {data:[]};
}else{
return this._getbusinessdata();
}
},
getamount: function(){
return this._loadtotal();
},
createerrornode: function(text){
var node = new element("div");
var iconnode = new element("div", {
"styles": {
"width": "20px",
"height": "20px",
"float": "left",
"background": " center center no-repeat"
}
}).inject(node);
var textnode = new element("div", {
"styles": {
"line-height": "20px",
"margin-left": "20px",
"text-align": "left",
"color": "red",
"word-break": "keep-all"
},
"text": text
}).inject(node);
return node;
},
notvalidationmode: function(text){
if (!this.isnotvalidationmode){
this.isnotvalidationmode = true;
this.node.store("borderstyle", this.node.getstyles("border-left", "border-right", "border-top", "border-bottom"));
this.node.setstyle("border", "1px solid red");
this.errnode = this.createerrornode(text).inject(this.node, "after");
this.shownotvalidationmode(this.node);
}
},
shownotvalidationmode: function(node){
var p = node.getparent("div");
if (p){
if (p.get("mwftype") == "tab$content"){
if (p.getparent("div").getstyle("display")=="none"){
var contentareanode = p.getparent("div").getparent("div");
var tabareanode = contentareanode.getprevious("div");
var idx = contentareanode.getchildren().indexof(p.getparent("div"));
var tabnode = tabareanode.getlast().getfirst().getchildren()[idx];
tabnode.click();
p = tabareanode.getparent("div");
}
}
this.shownotvalidationmode(p);
}
},
validationmode: function(){
if (this.isnotvalidationmode){
this.isnotvalidationmode = false;
this.node.setstyles(this.node.retrieve("borderstyle"));
if (this.errnode){
this.errnode.destroy();
this.errnode = null;
}
}
},
validationconfigitem: function(routename, data){
var flag = (data.status=="all") ? true: (routename == data.decision);
if (flag){
var n = this.getdata();
if( typeof(n)==="object" && json.stringify(n) === json.stringify({data:[]}) )n = "";
var v = (data.valuetype=="value") ? n : n.length;
switch (data.operateor){
case "isnull":
if (!v){
this.notvalidationmode(data.prompt);
return false;
}
break;
case "notnull":
if (v){
this.notvalidationmode(data.prompt);
return false;
}
break;
case "gt":
if (v>data.value){
this.notvalidationmode(data.prompt);
return false;
}
break;
case "lt":
if (v