o2oa api: x-游戏厅捕鱼达人

source

/**
 * 数据网格数据结构.
 * @typedef {object} datagriddata
 * @property {array} data - 数据网格列表数据
 * @property {object} total - 统计数据
 * @example
 * 	{
	  "data": [ //数据网格条目
		{
		  "datagrid_datagrid$title": { //数据网格第1列title标识
			"org_20": {  //数据网格第1列字段标识,人员组件单个对象,存的是对象
			  "distinguishedname": "张三@bf007525-99a3-4178-a474-32865bdddec8@i",
			  "id": "bf007525-99a3-4178-a474-32865bdddec8",
			  "name": "张三",
			  "person": "0c828550-d8ab-479e-9880-09a59332f1ed",
			  "unit": "9e6ce205-86f6-4d84-96e1-83147567aa8d",
			  "unitlevelname": "兰德纵横/市场营销部",
			  "unitname": "市场营销部"
			}
		  },
		  "datagrid_datagrid$title1": { //数据网格第2列title标识
			"org_21": [{  //数据网格第2列字段标识,人员组件多个对象,存的是数组
			  "distinguishedname": "张三@bf007525-99a3-4178-a474-32865bdddec8@i",
			  "id": "bf007525-99a3-4178-a474-32865bdddec8",
			  "name": "张三",
			  "person": "0c828550-d8ab-479e-9880-09a59332f1ed",
			  "unit": "9e6ce205-86f6-4d84-96e1-83147567aa8d",
			  "unitlevelname": "兰德纵横/市场营销部",
			  "unitname": "市场营销部"
			},{
			  "distinguishedname": "李四@bf007525-99a3-4178-a474-32865bdddec8@i",
			  "id": "bf007525-99a3-4178-a474-32865bdddec8",
			  "name": "李四",
			  "person": "0c828550-d8ab-479e-9880-09a59332f1ed",
			  "unit": "9e6ce205-86f6-4d84-96e1-83147567aa8d",
			  "unitlevelname": "兰德纵横/市场营销部",
			  "unitname": "市场营销部"
			}]
		  },
		  "datagrid_datagrid$title_2": { //数据网格第2列title标识
			"number": "111" //数据网格第3列字段标识和值
		  },
		  "datagrid_datagrid$title_3": { //数据网格第3列title标识
			"textfield_2": "杭州" //数据网格第4列字段标识和值
		  },
		  "datagrid_datagrid$title_4": { //数据网格第4列title标识
			"attachment_1": [  //数据网格第5列字段标识
			  {
				"activityname": "拟稿",
				"extension": "jpg",
				"id": "9514758e-9e28-4bfe-87d7-824f2811f173",
				"lastupdatetime": "2020-12-09 21:48:03",
				"length": 452863.0,
				"name": "111.jpg",
				"person": "李四@lisi@p"
			  }
			]
		  }
		},
		...
	  ],
	  "total": {  //统计数据,列title设置了总计
		"datagrid_datagrid$title_2": "333", //总计列2
		"datagrid_datagrid$title_3": "2" //总计列3
	  }
	}
 */
mwf.xdesktop.requireapp("process.xform", "$module", null, false);
/** @class datagridpc 数据网格组件(pc端)。从v6.2开始建议用数据表格(datatable)代替。
 * @o2cn 数据网格pc端(过时)
 * @example
 * //可以在脚本中获取该组件
 * //方法1:
 * var datagrid = this.form.get("name"); //获取组件
 * //方法2
 * var datagrid = this.target; //在组件事件脚本中获取
 * @extends mwf.xapplication.process.xform.$module
 * @o2category formcomponents
 * @o2range {process|cms}
 * @hideconstructor
 */
mwf.xapplication.process.xform.datagridpc = new class(
	/** @lends mwf.xapplication.process.xform.datagridpc# */
	{
		implements: [events],
		extends: mwf.app$module,
		isedit: false,
		options: {
			/**
			 * 当前条目编辑完成时触发。通过this.event可以获取对应的tr。
			 * @event mwf.xapplication.process.xform.datagridpc#completelineedit
			 * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
			 */
			/**
			 * 添加条目时触发。通过this.event可以获取对应的tr。
			 * @event mwf.xapplication.process.xform.datagridpc#addline
			 * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
			 */
			/**
			 * 删除条目前触发。通过this.event可以获取对应的tr。
			 * @event mwf.xapplication.process.xform.datagridpc#deleteline
			 * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
			 */
			/**
			 * 删除条目后触发。
			 * @event mwf.xapplication.process.xform.datagridpc#afterdeleteline
			 * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
			 */
			/**
			 * 编辑条目时触发。
			 * @event mwf.xapplication.process.xform.datagridpc#editline
			 * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
			 */
			/**
			 * 导出excel的时候触发,this.event指向导出的数据,您可以通过修改this.event来修改数据。
			 * @event mwf.xapplication.process.xform.datagridpc#export
			 * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
			 * @example
			 * this.event数据格式如下:
			 * {
			 *  	data : [
			 *   		["姓名","性别","学历","专业","出生日期","毕业日期"], //标题
			 *  		[ "张三","男","大学本科","计算机","2001-1-2","2019-9-2" ], //第一行数据
			 *  		[ "李四","男","大学专科","数学","1998-1-2","2018-9-2" ]  //第二行数据
			 * 	], //导出的数据
			 *     colwidtharray : [100, 50, 100, 200, 150, 150], //每列宽度
			 *     title : "xxxx" //导出的excel文件标题
			 * }
			 */
			/**
			 * 在导入excel,进行数据校验后触发,this.event指向导入的数据。
			 * @event mwf.xapplication.process.xform.datagridpc#validimport
			 * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
			 * @example
			 * this.event数据格式如下:
			 * {
			 *  	data : [
			 *  	   {
			 *  	 	"姓名" : "张三",
			 *  	 	"性别" : "男",
			 *  	 	"学历" : "大学本科",
			 *  	    "专业" : "计算机",
			 *  	    "出生日期" : "aa01-1-2",
			 *  	 	"毕业日期" : "2019-9-2",
			 *  	 	"errortextlist" : [
			 *  	 	    "第5列:aa01-1-2不是正确的日期格式。"
			 *  	 	] //校验出的错误信息,如果该行数据正确,则无该字段
			 *  	 }
			 *  	 ...
			 *     ], //导入的数据
			 *     "validted" : true  //是否校验通过,可以在本事件中修改该参数,确定是否强制导入
			 * }
			 */
			/**
			 * 在导入excel,数据校验成功将要设置回数据网格的时候触发,this.event指向整理过的导入数据,格式见{@link datagriddata}。
			 * @event mwf.xapplication.process.xform.datagridpc#import
			 * @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
			 */
			"moduleevents": ["queryload","postload","load","completelineedit", "addline", "deleteline", "afterdeleteline","editline", "export", "import", "validimport"]
		},
		initialize: function(node, json, form, options){
			/**
			 * @ignore
			 * @member parentline
			 * @memberof mwf.xapplication.process.xform.datagridpc#
			 */
			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", "auto");
			this.node.setstyle("overflow-y", "hidden");
			this.table = this.node.getelement("table");
			this.editable = (this.readonly || this.json.isreadonly === true || this.form.json.isreadonly === true) ? false : true;
			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.deleteable = this.json.deleteable !== "no";
			this.addable = this.json.addable !== "no";
			//允许导入
			this.importenable  = this.editable && (this.json.impexptype === "impexp" || this.json.impexptype === "imp");
			//允许导出
			this.exportenable  = this.json.impexptype === "impexp" || this.json.impexptype === "exp";
			this.griddata = this._getvalue();
			if( this.griddata.data && o2.typeof(this.griddata.data)==="object"){
				this.griddata.data = [];
			}
			this.totalmodules = [];
			this._loaddatagridtitlemodules();
			if (this.editable!=false){
				this._loaddatagriddatamodules();
				this._addtitleactioncolumn();
				this._loadeditdatagrid(function(){
					this._loadimportexportaction();
					this.fieldmoduleloaded = true;
					this.fireevent("postload");
					this.fireevent("load");
				}.bind(this));
				//this._loadreaddatagrid();
			}else{
				this._loaddatagriddatamodules();
				this._getdatagrideditortr();
				this._loadreaddatagrid(function(){
					if(this.editortr)this.editortr.setstyle("display", "none");
					this._loadimportexportaction();
					this.fieldmoduleloaded = true;
					this.fireevent("postload");
					this.fireevent("load");
				}.bind(this));
			}
		},
		_loadstyles: function(){
			this.table.setstyles(this.json.tablestyles);
			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);
				if (value && !value.then) if (o2.typeof(value)=="array") value = {"data": value || []};
			}
			return value || {};
		},
		getvalue: function(){
			return this._getvalue();
		},
		_getdatagridtr: function(){
			this._getdatagridtitletr();
			this._getdatagrideditortr();
		},
		_getdatagridtitletr: function(){
			this.titletr = this.table.getelement("tr");
			return this.titletr;
		},
		_getdatagrideditortr: function(){
			var trs = this.table.getelements("tr");
			this.editortr = trs[trs.length-1];
			this.editortr.addclass("datagrideditortr");
			return this.editortr;
		},
		_addtitleactioncolumn: function(){
			if (!this.titletr) this._getdatagridtitletr();
			if (!this.editortr) this._getdatagrideditortr();
			var actionth = new element("th", {"styles": {"width": "46px"}}).inject(this.titletr, "top");
			new element("th").inject(this.titletr, "bottom");
			if( this.addable ){
				this._createaddlineaction(actionth);
			}
			//this._createdellineaction(actionth);
			var actionedittd = new element("td").inject(this.editortr, "top");
			this._createcompleteaction(actionedittd);
			if( this.deleteable ){
				this._createcancelaction(actionedittd);
			}
			new element("td").inject(this.editortr, "bottom");
			//if (this.totaltr){
			//    new element("td").inject(this.totaltr, "top");
			//    new element("td").inject(this.totaltr, "bottom");
			//    this.totalmodules.each(function(m){
			//        m.index = m.index 1;
			//    });
			//}
		},
		_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){
			var titleths = this.titletr.getelements("th");
			var editortds = this.editortr.getelements("td");
			if (this.griddata.data){
				this.griddata.data.each(function(data, idx){
					var tr = $(this.table.insertrow(idx 1));
					tr.store("data", data);
					titleths.each(function(th, index){
						var celldata = data[th.get("id")];
						var text = "";
						if( typeof( celldata ) !== "array" ) {
							for (key in celldata) {
								var value = celldata[key];
								text = this._getvaluetext(index - 1, value);
								break;
							}
						}
						this._createnewedittd(tr, index, editortds[index].get("id"), text, titleths.length-1, idx);
					}.bind(this));
				}.bind(this));
			}
			this.editortr.setstyle("display", "none");
			if (callback) callback();
		},
		_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;
					// case "address":
					// 	if (typeof(value)==="array"){
					//
					// 	}
					// 	break;
				}
			}
			return value;
		},
		_createnewedittd: function(tr, idx, id, text, lastidx, rowindex){
			var cell = $(tr.insertcell(idx));
			if (idx==0){
				cell.setstyles(this.form.css.gridlineactioncell);
				if( this.addable )this._createaddlineaction(cell);
				if( this.deleteable )this._createdellineaction(cell);
			}else if (idx == lastidx){
				cell.setstyles(this.form.css.gridmoveactioncell);
				this._createmovelineaction(cell);
			}else{
				cell.set("mwfid", id);
				var module = this.editmodules[idx-1];
				if( module && module.json.type == "imageclipper" ){
					this._createimage( cell, module, text )
				}else if( module && module.json.type == "image" ) {
					this._createimg(cell, module, rowindex);
				}else if( module && module.json.type == "button" ) {
					this._createbutton(cell, module, rowindex);
				}else if( module && module.json.type == "label" ) {
					this._createlabel(cell, module, rowindex);
				}else if( module && (module.json.type == "attachment" || module.json.type == "attachmentdg") ){
					this._createattachment( cell, module, text );
				}else{
					if( module && module.json.type == "textarea" ){
						cell.set("html", text);
					}else{
						cell.set("text", text);
					}
					// /cell.set("text", text);
				}
				if( !module ||  !["button"].contains( module.json.type ) ){
					cell.addevent("click", function(e){
						this._editline(e.target);
					}.bind(this));
				}
			}
			var json = this.form._getdomjson(cell);
			if (json){
				cell.store("datagrid", this);
				var module = this.form._loadmodule(json, cell);
				cell.store("module", module);
				this.form.modules.push(module);
				if( json.isshow === false )cell.hide();
			}
		},
		_createaddlineaction: function(td){
			var addlineaction = new element("div", {
				"styles": this.form.css.addlineaction,
				"events": {
					"click": function(e){
						this._addline(e.target);
					}.bind(this)
				}
			});
			addlineaction.inject(td);
		},
		_createdellineaction: function(td){
			var dellineaction = new element("div", {
				"styles": this.form.css.dellineaction,
				"events": {
					"click": function(e){
						this._deleteline(e);
					}.bind(this)
				}
			});
			dellineaction.inject(td);
		},
		_createcompleteaction: function(td){
			var completeaction = new element("div", {
				"styles": this.form.css.completelineaction,
				"events": {
					"click": function(e){
						this._completelineedit(e);
					}.bind(this)
				}
			});
			completeaction.inject(td);
		},
		_createcancelaction: function(td){
			var cancelaction = new element("div", {
				"styles": this.form.css.dellineaction,
				"events": {
					"click": function(e){
						this._cancellineedit(e);
					}.bind(this)
				}
			});
			cancelaction.inject(td);
		},
		_editline:function(td){
			if (this.isedit){
				if (!this._completelineedit()) return false;
			}
			this.currenteditline = td.getparent("tr");
			if (this.currenteditline){
				this.editortr.setstyles({
					//"background-color": "#fffeb5",
					"display": "table-row"
				});
				this.editortr.inject(this.currenteditline, "before");
				this.currenteditline.setstyle("display", "none");
				var data = this.currenteditline.retrieve("data");
				var titleths = this.titletr.getelements("th");
				titleths.each(function(th, idx){
					var id = th.get("id");
					var module = this.editmodules[idx-1];
					if (module){
						if (module.json.type=="sequence"){
							module.node.set("text", module.node.getparent("tr").rowindex);
						}else if( module.setdata ){
							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();
		},
		editvalidation: function(){
			var flag = true;
			this.editmodules.each(function(field, key){
				if (field.json.type!="sequence" && field.validationmode ){
					field.validationmode();
					if (!field.validation()) flag = false;
				}
			}.bind(this));
			return flag;
		},
		// _cancellineedit: function(e){
		// 	this.isedit = false;
		//
		// 	var flag = true;
		//
		// 	var griddata = {};
		// 	var newtr = null;
		//
		// 	if (this.currenteditline){
		// 		newtr = this.currenteditline;
		// 		griddata = this.currenteditline.retrieve("data");
		// 	}else{
		// 		newtr = new element("tr").inject(this.editortr, "before");
		// 		griddata = {};
		// 	}
		//
		// 	if (flag){
		// 		newtr.destroy();
		// 	}
		// 	this.currenteditline = null;
		//
		// 	this._editortrgoback();
		//
		// 	// if (this.json.contentstyles){
		// 	// 	var tds = newtr.getelements("td");
		// 	// 	tds.setstyles(this.json.contentstyles);
		// 	// }
		// 	// if (this.json.actionstyles){
		// 	// 	newtr.getfirst().setstyles(this.json.actionstyles);
		// 	// }
		//
		// 	// this._loadborderstyle();
		// 	// this._loadzebrastyle();
		// 	// this._loadsequence();
		//
		// 	this.fireevent("cancellineedit");
		// },
		_cancellineedit: function(e){
			var datagrid = this;
			this.form.confirm("warn", e, mwf.xapplication.process.xform.lp.canceldatagridlineedittitle, mwf.xapplication.process.xform.lp.canceldatagridlineedit, 300, 120, function(){
				if (datagrid.currenteditline) {
					datagrid.currenteditline.setstyle("display", "table-row");
				}
				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.isedit = false;
				datagrid.currenteditline = null;
				datagrid._editortrgoback();
				// this._loadborderstyle();
				// this._loadzebrastyle();
				// this._loadsequence();
				// this.getdata();
				// datagrid._loadzebrastyle();
				// datagrid._loadsequence();
				// datagrid._loadtotal();
				// datagrid.getdata();
				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 ){
			debugger;
			//this.currenteditline.getelemets(td);
			if (!this.editvalidation()){
				return false;
			}
			this.isedit = false;
			var flag = true;
			var saveflag = false;
			var griddata = {};
			var newtr = null;
			if (this.currenteditline){
				newtr = this.currenteditline;
				griddata = this.currenteditline.retrieve("data");
			}else{
				newtr = new element("tr").inject(this.editortr, "before");
				griddata = {};
			}
			var titleths = this.titletr.getelements("th");
			var editortds = this.editortr.getelements("td");
			var cells = newtr.getelements("td");
			titleths.each(function(th, idx){
				var cell = cells[idx];
				var id = th.get("id");
				var module = this.editmodules[idx-1];
				if (module){
					if (module.json.type=="sequence"){
						flag = false;
						var i = newtr.rowindex;
						var data = {"value": [i], "text": [i]};
					}else if (module.json.type=="attachment" || module.json.type == "attachmentdg"){
						saveflag = true;
						flag = false;
						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( data.value && data.value.length )flag = false;
						// 	if (!griddata[id]) griddata[id] = {};
						// 	griddata[id][module.json.id] = data.value;
					}else if( module.gettextdata ){
						var 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;
						}
					}
					if( data ){
						if (cell){
							if( module.json.type == "imageclipper" ){
								this._createimage( cell, module, data.text[0] );
							}else if( module.json.type == "attachment" || module.json.type == "attachmentdg" ){
								this._createattachment( cell, module, data );
							}else{
								var text = this._getvaluetext(idx-1, data.text.join(", "));
								if( module.json.type == "textarea"){
									cell.set("html", text);
								}else{
									cell.set("text", data.text.join(", "));
								}
							}
						}else{
							if( module.json.type == "attachment" || module.json.type == "attachmentdg" ){
								this._createnewedittd(newtr, idx, editortds[idx].get("id"), data, titleths.length-1);
							}else{
								var text = this._getvaluetext(idx-1, data.text.join(", "));
								this._createnewedittd(newtr, idx, editortds[idx].get("id"), text, titleths.length-1);
							}
						}
					}else{
						if (!cell) this._createnewedittd(newtr, idx, id, "", titleths.length-1);
					}
				}else{
					if (!cell) this._createnewedittd(newtr, idx, id, "", titleths.length-1);
				}
				module = null;
			}.bind(this));
			newtr.store("data", griddata);
			newtr.setstyle("display", "table-row");
			if (flag){
				newtr.destroy();
			}
			this.currenteditline = null;
			this._editortrgoback();
			if (this.json.contentstyles){
				var tds = newtr.getelements("td");
				tds.setstyles(this.json.contentstyles);
			}
			if (this.json.actionstyles){
				newtr.getfirst().setstyles(this.json.actionstyles);
			}
			this._loadborderstyle();
			this._loadzebrastyle();
			this._loadsequence();
			this.getdata();
			this.validationmode();
			this.fireevent("completelineedit", [newtr]);
			if( saveflag ){
				this.form.saveformdata();
			}
			return true;
		},
		// _createimg : function(cell, module, idx){
		// 	cell.empty();
		// 	if( module.node ){
		// 		var node = module.node.clone();
		// 		node.set("id", module.json ? (module.json.id  "_" idx) : "" );
		// 		node.inject(cell);
		// 	}
		// },
		_createimg : function(cell, module, idx){
			this._clonemodule(cell, module, idx);
		},
		_createlabel : function(cell, module, idx){
			this._clonemodule(cell, module, idx);
		},
		_createbutton : function(cell, module, idx){
			this._clonemodule(cell, module, idx);
		},
		_clonemodule : function(cell, module, idx){
			debugger;
			cell.empty();
			if( module.node && module.json ){
				var json = object.clone( module.json );
				json.id = json.id  "_" idx;
				var node = module.node.clone();
				node.set("id", json.id);
				node.inject(cell);
				this.form._loadmodule(json, node)
			}
		},
		_createimage : function( cell, module, data ){
			cell.empty();
			if( !data )return;
			var img = new element("img",{
				src : mwf.xdesktop.getimagesrc( data )
			}).inject( cell, "top" );
			if( module.json.clippertype == "size" ){
				var width = module.json.imagewidth;
				var height = module.json.imageheight;
				if (width && height) {
					img.setstyles({
						width: width   "px",
						height: height   "px"
					})
				}
			}
		},
		_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));
		},
		_editortrgoback: function(){
			this.editortr.setstyle("display", "none");
//		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");
			}
		},
		_addline: function(node){
			if (this.isedit){
				if (!this._completelineedit()) return false;
			}
			this.editortr.setstyles({
				//"background-color": "#fffeb5",
				"display": "table-row"
			});
			this.currenteditline = null;
			var currenttr = node.getparent("tr");
			if (currenttr){
				this.editortr.inject(currenttr, "after");
			}
			this.isedit =true;
			debugger;
			this._loadsequence();
			this.validationmode();
			this.fireevent("addline",[this.editortr]);
//		newtr.addevent("blur", function(e){
//			this._completelineedit();
//		}.bind(this));
		},
		_deleteline: function(e){
			var saveflag = false;
			var currenttr = e.target.getparent("tr");
			if (currenttr){
				var color = currenttr.getstyle("background");
				currenttr.store("bgcolor", color);
				currenttr.tween("background-color", "#ffd4d4");
				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", [currenttr]);
					var data = currenttr.retrieve("data");
					//var attkeys = [];
					var titleths = _self.titletr.getelements("th");
					titleths.each(function(th, i){
						var key = th.get("id");
						var module = (i>0) ? _self.editmodules[i-1] : null;
						if (key && module && (module.json.type=="attachment" || module.json.type=="attachmentdg")){
							data[key][module.json.id].each(function(d){
								_self.form.workaction.deleteattachment(d.id, _self.form.businessdata.work.id);
							});
							saveflag = true;
						}
					});
					currenttr.destroy();
					datagrid._loadzebrastyle();
					datagrid._loadsequence();
					datagrid._loadtotal();
					datagrid.getdata();
					this.close();
					_self.fireevent("afterdeleteline");
					if(saveflag){
						_self.form.saveformdata();
					}
				}, function(){
					var color = currenttr.retrieve("bgcolor");
					currenttr.tween("background", color);
					this.close();
				}, null, null, this.form.json.confirmstyle);
			}
			this.validationmode();
		},
		_createmovelineaction: function(td){
			var movelineaction = new element("div", {
				"styles": this.form.css.movelineaction,
				"events": {
					"mousedown": function(e){
						this._moveline(e);
					}.bind(this)
				}
			});
			movelineaction.inject(td);
		},
		_getmovedragnode: function(tr){
			var table = tr.getparent("table");
			var div = table.getparent("div");
			var size = div.getsize();
			var dragnode = div.clone().setstyle("width", size.x).inject(document.body);
			var dragtable = dragnode.getelement("table");
			dragtable.empty();
			var clone = tr.clone().setstyles(this.form.css.gridmovelinedragnodetr).inject(dragtable);
			var tds = tr.getelements("td");
			var clonetds = clone.getelements("td");
			tds.each(function(td, idx){
				var size = td.getcomputedsize();
				clonetds[idx].setstyle("width", size.width 1);
			});
			var coordinates = tr.getcoordinates();
			dragnode.setstyles(this.form.css.gridmovelinedragnode);
			dragnode.setstyles(coordinates);
			return dragnode;
		},
		_moveline: function(e){
			var trs = this.table.getelements("tr");
			var div = e.target;
			var tr = div.getparent("tr");
			var dragnode = this._getmovedragnode(tr);
			coordinates = dragnode.getcoordinates();
			var dragtr = dragnode.getelement("tr");
			var dragtable = dragnode.getelement("table");
			var color = tr.getstyle("background");
			tr.store("bgcolor", color);
			//tr.tween('background-color', '#f3f1ad');
			tr.tween('background-color', '#e4f6e9');
			var drag = new drag.move(dragnode, {
				"droppables": trs.erase(tr),
				"limit": {"x": [coordinates.left, coordinates.left]},
				ondrop: function(dragging, droppable){
					dragging.destroy();
					//debugger;
					var color = tr.retrieve("bgcolor");
					if (color){
						tr.tween("background", color);
					}else{
						tr.tween("background", "transparent");
					}
					//if (droppable){
					//    color = droppable.retrieve("bgcolor");
					//    if (color){
					//        droppable.tween("background", color);
					//    }else{
					//        droppable.tween("background", "transparent");
					//    }
					//}
					tr.setstyle("display", "table-row");
					if (droppable != null){
						tr.inject(dragtr, "after");
						dragtr.destroy();
						//this._loadzebrastyle();
						//this._loadsequence();
						//this._loadtotal();
						this._loaddatagridstyle();
						this.getdata();
					}
				}.bind(this),
				"onenter": function(dragging, drop){
					//var color = drop.getstyle("background");
					//if (color.touppercase()!='#d1eaf3') drop.store("bgcolor", color);
					//drop.tween("background-color", "#d1eaf3");
					dragnode.setstyle("display", "none");
					dragtr.inject(drop, "after");
				},
				"onleave": function(dragging, drop){
					//var color = drop.retrieve("bgcolor");
					//if (color){
					//	drop.tween("background", color);
					//}else{
					//	drop.tween("background", "transparent");
					//}
					dragtr.inject(dragtable);
					dragnode.setstyle("display", "block");
//				tr.setstyle("display", "table-row");
				},
				"ondrag": function(){
					this.table.setstyle("cursor", "move");
					dragnode.setstyle("cursor", "move");
				},
				"oncancel": function(dragging){
					dragging.destroy();
					var color = tr.retrieve("bgcolor");
					if (color){
						tr.tween("background", color);
					}else{
						tr.tween("background", "transparent");
					}
					tr.setstyle("display", "table-row");
				}
			});
			drag.start(e);
			tr.setstyle("display", "none");
		},
		_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 = 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._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");
			var lasttrs = this.table.getelements("tr");
			var lasttr = lasttrs[lasttrs.length-1];
			//var tds = lasttr.getelements("td");
			debugger;
			if (this.griddata.data){
				this.griddata.data.each(function(data, idx){
					var tr = this.table.insertrow(idx 1);
					tr.store("data", data);
					titleheaders.each(function(th, index){
						var cell = tr.insertcell(index);
						// cell.set("mwfid", tds[index].get("id"));
						var celldata = data[th.get("id")];
						var module = this.editmodules[index];
						if( typeof( celldata ) !== "array" ){
							if (celldata) {
								for (key in celldata) {
									var v = celldata[key];
									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 {
										var text = this._getvaluetext(index, v);
										if (module && module.json.type == "textarea") {
											cell.set("html", text);
										} else {
											cell.set("text", text);
										}
									}
									break;
								}
							}else if( module && module.json.type == "image" ) {
								this._createimg(cell, module, idx);
							}else if( module && module.json.type == "button" ) {
								this._createbutton(cell, module, idx);
							}else if( module && module.json.type == "label" ) {
								this._createlabel(cell, module, idx);
							}else if( module && module.json.type == "sequence" ){ //sequence
								cell.setstyle("text-align", "center");
								cell.set("text", tr.rowindex);
							}
						}
						var json = this.form._getdomjson(th);
						if( json && json.isshow === false )cell.hide();
					}.bind(this));
				}.bind(this));
			}
			this._loadtotal();
			if (callback) callback();
		},
		_loadimportexportaction: function(){
			debugger;
			this.impexpnode = this.node.getelement("div.impexpnode");
			if( this.impexpnode )this.impexpnode.destroy();
			this.impexpnode = null;
			if( !this.exportenable && !this.importenable )return;
			var position = ["lefttop","centertop","righttop"].contains( this.json.impexpposition || "" ) ? "top" : "bottom";
			var container = new element("div").inject(this.node, position);
			this.importexportareanode = new element("div").inject( container );
			if( ["lefttop","leftbottom"].contains( this.json.impexpposition || "" ) ){
				this.importexportareanode.setstyles({ "float" : "left" })
			}else if( ["righttop","rightbottom"].contains( this.json.impexpposition || "" ) ){
				this.importexportareanode.setstyles({ "float" : "right" })
			}else{
				this.importexportareanode.setstyles({ "margin" : "0px auto" })
			}
			if( this.exportenable ){
				this.exportactionnode = new element("div", {
					text : this.json.exportactiontext || mwf.xapplication.process.xform.lp.datagridexport
				}).inject(this.importexportareanode);
				var styles;
				if( this.json.exportactionstyles ){
					styles = this.json.exportactionstyles
				}else{
					styles = this.form.css.gridexportactionstyles;
				}
				this.exportactionnode.setstyles(styles);
				this.exportactionnode.addevent("click", function () {
					this.exporttoexcel();
				}.bind(this))
			}
			if( this.importenable ){
				this.importactionnode = new element("div", {
					text : this.json.importactiontext || mwf.xapplication.process.xform.lp.datagridimport
				}).inject(this.importexportareanode);
				var styles;
				if( this.json.importactionstyles ){
					styles = this.json.importactionstyles;
				}else{
					styles = this.form.css.gridimportactionstyles;
				}
				this.importactionnode.setstyles(styles);
				this.importactionnode.addevent("click", function () {
					this.importfromexcel();
				}.bind(this))
			}
			if( ["centertop","centerbottom"].contains( this.json.impexpposition ) ){
				var width = 2;
				if( this.exportactionnode ){
					width = width   this.exportactionnode.getsize().x  
						this.exportactionnode.getstyle("padding-left").tofloat()  
						  this.exportactionnode.getstyle("padding-right").tofloat()  
						  this.exportactionnode.getstyle("margin-left").tofloat()  
						  this.exportactionnode.getstyle("margin-right").tofloat()
				}
				if( this.importactionnode ){
					width = width   this.importactionnode.getsize().x  
						this.importactionnode.getstyle("padding-left").tofloat()  
						  this.importactionnode.getstyle("padding-right").tofloat()  
						  this.importactionnode.getstyle("margin-left").tofloat()  
						  this.importactionnode.getstyle("margin-right").tofloat()
				}
				this.importexportareanode.setstyle( "width", width "px" );
			}
		},
		_loaddatagridstyle: function(){
			//var ths = this.titletr.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.editortr){
				if (this.json.editstyles){
					var tds = this.editortr.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.titletr.getelements("th");
				ths.setstyles(this.json.titlestyles);
			}
		},
		loadgridcontentstyle: function(){
			if (this.json.contentstyles){
				var tds = this.table.getelements("td");
				tds.setstyles(this.json.contentstyles);
			}
		},
		_loadzebrastyle: function(){
			var trs = this.table.getelements("tr");
			for (var i=1; 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"  ){
			this._setbusinessdata(data);
			this.griddata = data;
			// if (this.isedit) this._completelineedit();
			if( this.isedit ){ //如果有在编辑的,取消编辑行
				if (this.currenteditline) {
					this.currenteditline.setstyle("display", "table-row");
				}
				this.isedit = false;
				this.currenteditline = null;
				this._editortrgoback();
			}
			if (this.griddata){
				var trs = this.table.getelements("tr");
				for (var i=1; i2){
				//this.table.rows[1].destroy();
				//}
				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 trs = this.table.getelements("tr"); for (var i=1; idata.value){ this.notvalidationmode(data.prompt); return false; } break; case "lt": if (v 0 ){ this.listimportallorgdata( orgtitlelist, importeddata, function () { checkandimport(); }.bind(this)); }else{ checkandimport(); } }.bind(this)); }, parseimporteddata: function(columnlist, importeddata){ var data = { "data" : [] }; importeddata.each( function( importedlinedata, lineindex ){ var linedata = {}; columnlist.each( function (obj, i) { var index = obj.index; var module = obj.module; var thjson = obj.thjson; var text = obj.text; var d = importedlinedata[text] || ""; var value; switch (module.json.type) { case "org": case "reader": case "author": case "personfield": case "orgfield": if( !d ){ value = []; }else{ var arr = d.split(/\s*,\s*/g ); //空格,空格 // if( arr.length === 0 ){ // value = this.getimportorgdata( d ); // }else{ value = []; arr.each( function(d, idx){ var obj = this.getimportorgdata( d ); value.push( obj ); }.bind(this)); // } } break; case "combox": case "address": arr = d.split(/\s*,\s*/g ); //空格,空格 value = arr; //arr.length === 1 ? arr[0] : arr; break; case "checkbox": arr = d.split(/\s*,\s*/g ); //空格,空格 var options = module.getoptionsobj(); arr.each( function( a, i ){ var idx = options.textlist.indexof( a ); arr[ i ] = idx > -1 ? options.valuelist[ idx ] : ""; }); value = arr.length === 1 ? arr[0] : arr; break; case "radio": case "select": value = d.replace(/ /g,""); //换行符 var options = module.getoptionsobj(); var idx = options.textlist.indexof( value ); value = idx > -1 ? options.valuelist[ idx ] : ""; break; case "textarea": value = d.replace(/ /g,"\n"); //换行符 break; case "calendar": value = d.replace(/ /g,""); //换行符 if( value ){ var format; if (!module.json.format){ if (module.json.selecttype==="datetime" || module.json.selecttype==="time"){ format = (module.json.selecttype === "time") ? "%h:%m" : (locale.get("date").shortdate " " "%h:%m") }else{ format = locale.get("date").shortdate; } }else{ format = module.json.format; } value = date.parse( value ).format( format ); } break; default: value = d.replace(/ /g,""); //换行符 break; } linedata[ thjson.id ] = {}; linedata[ thjson.id ][ module.json.id ] = value; }.bind(this)); data.data.push( linedata ); }.bind(this)); return data; }, setimportdata: function(columnlist, importeddata){ var data = this.parseimporteddata( columnlist, importeddata ); this.fireevent("import", [data] ); this.setdata( data ); this.form.notice( mwf.xapplication.process.xform.lp.importsuccess ); }, openimportederrordlg : function( columnlist, tabledata ){ var _self = this; var objecttostring = function (obj, type) { if(!obj)return ""; var arr = []; object.each(obj, function (value, key) { if( type === "style" ){ arr.push( key ":" value ";" ) }else{ arr.push( key "='" value "'" ) } }) return arr.join( " " ) } var htmlarray = [""]; var titlestyle = objecttostring( this.json.titlestyles, "style" ); htmlarray.push( "" ); columnlist.each( function (obj, i) { htmlarray.push( "" ); }); htmlarray.push( "" ); htmlarray.push( "" ); var contentstyles = object.clone( this.json.contentstyles ); if( !contentstyles[ "border-bottom" ] && !contentstyles[ "border" ] )contentstyles[ "border-bottom" ] = "1px solid #eee"; var contentstyle = objecttostring( object.merge( contentstyles, {"text-align":"left"}) , "style" ); tabledata.each( function( linedata, lineindex ){ htmlarray.push( "" ); columnlist.each( function (obj, i) { htmlarray.push( "" ); //换行符 }); htmlarray.push( "" ); htmlarray.push( "" ); }.bind(this)); htmlarray.push( "
" obj.text " " mwf.xapplication.process.xform.lp.validationinfor "
" ( linedata[ obj.text ] || '' ).replace(/ /g,"
") "
" ( linedata.errortextlist ? linedata.errortextlist.join("
") : "" ) "
" ); var div = new element("div", { style : "padding:10px;", html : htmlarray.join("") }); var dlg = o2.dl.open({ "style" : this.form.json.dialogstyle || "user", "title": mwf.xapplication.process.xform.lp.importfail, "content": div, "offset": {"y": 0}, "ismax": true, "width": 1000, "height": 700, "buttonlist": [ { "type": "exportwitherror", "text": mwf.xapplication.process.xform.lp.datagridexport, "action": function () { _self.exportwithimportdatatoexcel(columnlist, tabledata); } }, { "type": "cancel", "text": mwf.lp.process.button.cancel, "action": function () { dlg.close(); } } ], "onpostclose": function(){ dlg = null; }.bind(this) }); }, exportwithimportdatatoexcel : function ( columnlist, importeddata ) { debugger; var titleths = this.titletr.getelements("th"); // var editortds = this.editortr.getelements("td"); var resultarr = []; var colwidtharr = this.getexportcolwidtharray(); colwidtharr.push( 220 ); var dateindexarr = this.getexportdateindexarray(); //日期格式列下标 var titlearr = this.getexporttitlearray("import"); titlearr.push( mwf.xapplication.process.xform.lp.validationinfor ); resultarr.push( titlearr ); importeddata.each( function( linedata, lineindex ){ var array = []; columnlist.each( function (obj, i) { array.push( ( linedata[ obj.text ] || '' ).replace(/ /g, "\n") ); }); array.push( linedata.errortextlistexcel ? linedata.errortextlistexcel.join("\n") : "" ); resultarr.push( array ); }.bind(this)); var title; if( this.json.excelname && this.json.excelname.code ){ title = this.form.macro.exec(this.json.excelname.code, this); }else{ title = mwf.xapplication.process.xform.lp.exportdefaultname; } var titlea = title.split("."); if( ["xls","xlst"].contains( titlea[titlea.length-1].tolowercase() ) ){ titlea.splice( titlea.length-1 ); } title = titlea.join("."); var arg = { data : resultarr, colwidtharray : colwidtharr, title : title, witherror : true }; this.fireevent("export", [arg]); new mwf.xapplication.process.xform.datagridpc.excelutils(this).exporttoexcel( resultarr, arg.title || title, colwidtharr, dateindexarr ); }, checkimporteddata : function( columnlist, tabledata ){ var flag = true; var parseddata = this.parseimporteddata(columnlist, tabledata); var lp = mwf.xapplication.process.xform.lp; var columntext = lp.importvalidationcolumntext; var columntextexcel = lp.importvalidationcolumntextexcel; var excelutil = new mwf.xapplication.process.xform.datagridpc.excelutils(this); tabledata.each( function(linedata, lineindex){ var parsedlinedata = (parseddata && parseddata.data) ? parseddata.data[lineindex] : {}; var errortextlist = []; var errortextlistexcel = []; columnlist.each( function (obj, i) { var index = obj.index; var module = obj.module; var thjson = obj.thjson; var text = obj.text; var colinfor = columntext.replace( "{n}", index ); var colinforexcel = columntextexcel.replace( "{n}", excelutil.index2colname( index-1 ) ); var d = linedata[text] || ""; var parsedd = ""; var ptd = parsedlinedata[thjson.id]; if( typeof(ptd) === "object")parsedd = ptd[module.json.id]; if( d ){ switch (module.json.type) { case "org": case "reader": case "author": case "personfield": case "orgfield": var arr = d.split(/\s*,\s*/g ); //空格,空格 arr.each( function(d, idx){ var obj = this.getimportorgdata( d ); if( obj.errortext ){ errortextlist.push( colinfor obj.errortext lp.fullstop ); errortextlistexcel.push( colinforexcel obj.errortext lp.fullstop ); } }.bind(this)); break; case "number": if (isnan(d)){ errortextlist.push( colinfor d lp.notvalidnumber lp.fullstop ); errortextlistexcel.push( colinforexcel d lp.notvalidnumber lp.fullstop ); } break; case "calendar": if( !( isnan(d) && !isnan(date.parse(d) ))){ errortextlist.push(colinfor d lp.notvaliddate lp.fullstop ); errortextlistexcel.push( colinforexcel d lp.notvaliddate lp.fullstop ); } break; default: break; } } if (module.json.type!="sequence" && module.setdata && module.json.type!=="address"){ var haserror = false; if(["org","reader","author","personfield","orgfield"].contains(module.json.type)){ if(o2.typeof(parsedd)==="array" && parsedd.length){ haserror = parsedd.some(function (item) { return item.errortext; }) } } if( !haserror ){ module.setdata(parsedd); module.validationmode(); if (!module.validation() && module.errnode){ errortextlist.push(colinfor module.errnode.get("text")); errortextlistexcel.push( colinforexcel module.errnode.get("text")); module.errnode.destroy(); } } } }.bind(this)); if(errortextlist.length>0){ linedata.errortextlist = errortextlist; linedata.errortextlistexcel = errortextlistexcel; flag = false; } debugger; }.bind(this)); var arg = { validted : flag, data : tabledata }; this.fireevent( "validimport", [arg] ); return arg.validted; }, getimportorgdata : function( str ){ str = str.trim(); var flag = str.substr(str.length-2, 2); switch (flag.tolowercase()){ case "@i": return this.identitymapimported[str] || {"errortext": str mwf.xapplication.process.xform.lp.notexistinsystem }; case "@p": return this.personmapimported[str] || {"errortext": str mwf.xapplication.process.xform.lp.notexistinsystem }; case "@u": return this.unitmapimported[str] || {"errortext": str mwf.xapplication.process.xform.lp.notexistinsystem }; case "@g": return this.groupmapimported[str] || {"errortext": str mwf.xapplication.process.xform.lp.notexistinsystem }; default: return this.identitymapimported[str] || this.personmapimported[str] || this.unitmapimported[str] || this.groupmapimported[str] || {"errortext": str mwf.xapplication.process.xform.lp.notexistinsystem }; } }, listimportallorgdata : function (orgtitlelist, tabledata, callback) { var identitylist = [], personlist = [], unitlist = [], grouplist = []; if( orgtitlelist.length > 0 ){ tabledata.each( function( linedata, lineindex ){ // if( lineindex === 0 )return; orgtitlelist.each( function (title, index) { if( !linedata[title] )return; var arr = linedata[title].split(/\s*,\s*/g ); arr.each( function( a ){ a = a.trim(); var flag = a.substr(a.length-2, 2); switch (flag.tolowercase()){ case "@i": identitylist.push( a ); break; case "@p": personlist.push( a ); break; case "@u": unitlist.push( a ); break; case "@g": grouplist.push( a ); break; default: identitylist.push( a ); personlist.push( a ); unitlist.push( a ); grouplist.push( a ); break; } }) }) }); var identityloaded, personloaded, unitloaded, grouploaded; var check = function () { if( identityloaded && personloaded && unitloaded && grouploaded ){ if(callback)callback(); } }; this.identitymapimported = {}; if( identitylist.length ){ o2.actions.load("x_organization_assemble_express").identityaction.listobject({ identitylist : identitylist }, function (json) { json.data.each( function (d) { this.identitymapimported[ d.matchkey ] = d; }.bind(this)); identityloaded = true; check(); }.bind(this)) }else{ identityloaded = true; check(); } this.personmapimported = {}; if( personlist.length ){ o2.actions.load("x_organization_assemble_express").personaction.listobject({ personlist : personlist }, function (json) { json.data.each( function (d) { this.personmapimported[ d.matchkey ] = d; }.bind(this)); personloaded = true; check(); }.bind(this)) }else{ personloaded = true; check(); } this.unitmapimported = {}; if( unitlist.length ){ o2.actions.load("x_organization_assemble_express").unitaction.listobject({ unitlist : unitlist }, function (json) { json.data.each( function (d) { this.unitmapimported[ d.matchkey ] = d; }.bind(this)); unitloaded = true; check(); }.bind(this)) }else{ unitloaded = true; check(); } this.groupmapimported = {}; if( grouplist.length ){ o2.actions.load("x_organization_assemble_express").groupaction.listobject({ grouplist : grouplist }, function (json) { json.data.each( function (d) { this.groupmapimported[ d.matchkey ] = d; }.bind(this)); grouploaded = true; check(); }.bind(this)) }else{ grouploaded = true; check(); } } } }); mwf.xapplication.process.xform.datagridpc$title = new class({ extends: mwf.app$module, _afterloaded: function(){ this.datagrid = this.node.retrieve("datagrid"); if ((this.json.total == "number") || (this.json.total == "count")){ this.datagrid.totalmodules.push({ "module": this, "index": (this.datagrid.editable!=false) ? this.node.cellindex 1 : this.node.cellindex, "type": this.json.total }) } // this.form._loadmodules(this.node); } }); mwf.xapplication.process.xform.datagridpc$data = new class({ extends: mwf.app$module, _afterloaded: function(){ //this.form._loadmodules(this.node); this.datagrid = this.node.retrieve("datagrid"); var td = this.node; if (this.json.celltype == "sequence"){ var flag = true; for (var i=0; i
网站地图