|
|
@@ -1,5 +1,17 @@
|
|
|
MWF.xDesktop.requireApp("process.Xform", "$Module", null, false);
|
|
|
-MWF.xApplication.process.Xform.DatagridMobile = new Class({
|
|
|
+/** @class process.DatagridMobile 数据网格组件(移动端)。
|
|
|
+ * @example
|
|
|
+ * //可以在脚本中获取该组件
|
|
|
+ * //方法1:
|
|
|
+ * var attachment = this.form.get("name"); //获取组件
|
|
|
+ * //方法2
|
|
|
+ * var attachment = this.target; //在组件事件脚本中获取
|
|
|
+ * @extends MWF.xApplication.process.Xform.$Module
|
|
|
+ * @hideconstructor
|
|
|
+ */
|
|
|
+MWF.xApplication.process.Xform.DatagridMobile = new Class(
|
|
|
+/** @lends MWF.xApplication.process.Xform.DatagridMobile# */
|
|
|
+{
|
|
|
Implements: [Events],
|
|
|
Extends: MWF.APP$Module,
|
|
|
isEdit: false,
|
|
|
@@ -25,6 +37,7 @@ MWF.xApplication.process.Xform.DatagridMobile = new Class({
|
|
|
|
|
|
this.createMobileTable();
|
|
|
|
|
|
+
|
|
|
this.editable = (!this.readonly);
|
|
|
if (this.editable) this.editable = this.form.Macro.exec(((this.json.editableScript) ? this.json.editableScript.code : ""), this);
|
|
|
//this.editable = false;
|
|
|
@@ -1331,9 +1344,43 @@ MWF.xApplication.process.Xform.DatagridMobile = new Class({
|
|
|
if (this.table) this.table.setStyle("display", "none");
|
|
|
}
|
|
|
},
|
|
|
+ /**
|
|
|
+ * @summary 重置数据网格的值为默认值或置空。
|
|
|
+ * @example
|
|
|
+ * this.form.get('fieldName').resetData();
|
|
|
+ */
|
|
|
resetData: function(){
|
|
|
this.setData(this._getValue());
|
|
|
},
|
|
|
+ /**当参数为Promise的时候,请查看文档: {@link https://www.yuque.com/o2oa/ixsnyt/ws07m0|使用Promise处理表单异步}<br/>
|
|
|
+ * 当表单上没有对应组件的时候,可以使用this.data[fieldName] = data赋值。
|
|
|
+ * @summary 为数据网格赋值。
|
|
|
+ * @param data{DatagridData|Promise|Array} 必选,数组或Promise.
|
|
|
+ * @example
|
|
|
+ * this.form.get("fieldName").setData([]); //赋空值
|
|
|
+ * @example
|
|
|
+ * //如果无法确定表单上是否有组件,需要判断
|
|
|
+ * if( this.form.get('fieldName') ){ //判断表单是否有无对应组件
|
|
|
+ * this.form.get('fieldName').setData( data );
|
|
|
+ * }else{
|
|
|
+ * this.data['fieldName'] = data;
|
|
|
+ * }
|
|
|
+ *@example
|
|
|
+ * //使用Promise
|
|
|
+ * var field = this.form.get("fieldName");
|
|
|
+ * 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();
|
|
|
@@ -1459,10 +1506,24 @@ MWF.xApplication.process.Xform.DatagridMobile = new Class({
|
|
|
|
|
|
|
|
|
},
|
|
|
+ /**
|
|
|
+ * @summary 获取总计数据.
|
|
|
+ * @example
|
|
|
+ * var totalObject = this.form.get('fieldName').getTotal();
|
|
|
+ * @return {Object} 总计数据
|
|
|
+ */
|
|
|
getTotal: function(){
|
|
|
this._loadTotal();
|
|
|
return this.totalResaults;
|
|
|
},
|
|
|
+ /**
|
|
|
+ * @summary 判断数据网格是否为空.
|
|
|
+ * @example
|
|
|
+ * if( this.form.get('fieldName').isEmpty() ){
|
|
|
+ * this.form.notice('至少需要添加一条数据', 'warn');
|
|
|
+ * }
|
|
|
+ * @return {Boolean} 是否为空
|
|
|
+ */
|
|
|
isEmpty: function(){
|
|
|
var data = this.getData();
|
|
|
if( !data )return true;
|
|
|
@@ -1472,6 +1533,42 @@ MWF.xApplication.process.Xform.DatagridMobile = new Class({
|
|
|
}
|
|
|
return false;
|
|
|
},
|
|
|
+ /**
|
|
|
+ * 在脚本中使用 this.data[fieldName] 也可以获取组件值。
|
|
|
+ * 区别如下:<br/>
|
|
|
+ * 1、当使用Promise的时候<br/>
|
|
|
+ * 使用异步函数生成器(Promise)为组件赋值的时候,用getData方法立即获取数据,可能返回修改前的值,当Promise执行完成以后,会返回修改后的值。<br/>
|
|
|
+ * this.data[fieldName] 立即获取数据,可能获取到异步函数生成器,当Promise执行完成以后,会返回修改后的值。<br/>
|
|
|
+ * {@link https://www.yuque.com/o2oa/ixsnyt/ws07m0#EggIl|具体差异请查看链接}<br/>
|
|
|
+ * 2、当表单上没有对应组件的时候,可以使用this.data[fieldName]获取值,但是this.form.get('fieldName')无法获取到组件。
|
|
|
+ * @summary 获取数据网格数据.
|
|
|
+ * @example
|
|
|
+ * var data = this.form.get('fieldName').getData();
|
|
|
+ *@example
|
|
|
+ * //如果无法确定表单上是否有组件,需要判断
|
|
|
+ * var data;
|
|
|
+ * if( this.form.get('fieldName') ){ //判断表单是否有无对应组件
|
|
|
+ * data = this.form.get('fieldName').getData();
|
|
|
+ * }else{
|
|
|
+ * data = this.data['fieldName']; //直接从数据中获取字段值
|
|
|
+ * }
|
|
|
+ * @example
|
|
|
+ * //使用Promise
|
|
|
+ * var field = this.form.get("fieldName");
|
|
|
+ * 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();
|
|
|
@@ -1629,7 +1726,15 @@ MWF.xApplication.process.Xform.DatagridMobile = new Class({
|
|
|
}
|
|
|
return true;
|
|
|
},
|
|
|
-
|
|
|
+ /**
|
|
|
+ * @summary 根据组件的校验设置进行校验。
|
|
|
+ * @param {String} routeName - 可选,路由名称.
|
|
|
+ * @example
|
|
|
+ * if( !this.form.get('fieldName').validation() ){
|
|
|
+ * return false;
|
|
|
+ * }
|
|
|
+ * @return {Boolean} 是否通过校验
|
|
|
+ */
|
|
|
validation: function(routeName, opinion){
|
|
|
if (this.isEdit){
|
|
|
if (!this.editValidation()){
|