Agilepoint中的JS Method 封装
/**====================================================================================================================================================
* eform helper
*/
efh = function () { /**
* eform help error handler
*/
function _handleError(fieldId, error, caller) {
caller = caller ? caller : "[caller undefined]";
console.log($.format("Error @efh.{0}(fieldId:\"{1}\"):", caller, fieldId));
console.log(error);
} /**
* Show control
* @param {string} fieldId: Field internal name
*/
var showControl = function (fieldId) {
var options = {};
options.fieldId = fieldId;
options.propertyName = eFormHelper.constants.fieldProperty.Visible;
options.value = true;
eFormHelper.updateFieldProperty(options, function (result) {
if (!result.isSuccess && result.error.message && !result.error.message.includes("UpdateIsPropertyModifiedForProp")) {
_handleError(fieldId, result.error, "showControl");
}
});
}; /**
* Hide control
* @param {string} fieldId: Field internal name
*/
var hideControl = function (fieldId) {
var options = {};
options.fieldId = fieldId;
options.propertyName = eFormHelper.constants.fieldProperty.Visible;
options.value = false;
eFormHelper.updateFieldProperty(options, function (result) {
if (!result.isSuccess && result.error.message && !result.error.message.includes("UpdateIsPropertyModifiedForProp")) {
_handleError(fieldId, result.error, "hideControl");
}
});
}; /**
* Enable control
* @param {string} fieldId: Field internal name
*/
var enableControl = function (fieldId) {
var options = {};
options.fieldId = fieldId;
options.propertyName = eFormHelper.constants.fieldProperty.Enabled;
options.value = true;
eFormHelper.updateFieldProperty(options, function (result) {
if (!result.isSuccess && result.error.message && !result.error.message.includes("UpdateIsPropertyModifiedForProp")) {
_handleError(fieldId, result.error, "enableControl");
}
});
}; /**
* Disable control
* @param {string} fieldId Field internal name
*/
var disableControl = function (fieldId) {
var options = {};
options.fieldId = fieldId;
options.propertyName = eFormHelper.constants.fieldProperty.Enabled;
options.value = false;
eFormHelper.updateFieldProperty(options, function (result) {
if (!result.isSuccess && result.error.message && !result.error.message.includes("UpdateIsPropertyModifiedForProp")) {
_handleError(fieldId, result.error, "disableControl");
}
});
}; /**
* Mandatory control(强制控制)
* @param {string} fieldId: Field internal name
*/
var mandatoryControl = function (fieldId) {
var options = {};
options.fieldId = fieldId;
options.propertyName = eFormHelper.constants.fieldProperty.Mandatory;
options.value = true;
eFormHelper.updateFieldProperty(options, function (result) {
if (!result.isSuccess && result.error.message && !result.error.message.includes("UpdateIsPropertyModifiedForProp")) {
_handleError(fieldId, result.error, "requireControl");
}
});
}; /**
* Make control non-mandatory(非强制性)
* @param {string} fieldId: Field internal name
*/
var nonmandatoryControl = function (fieldId) {
var options = {};
options.fieldId = fieldId;
options.propertyName = eFormHelper.constants.fieldProperty.Mandatory;
options.value = false;
eFormHelper.updateFieldProperty(options, function (result) {
if (!result.isSuccess && result.error.message && !result.error.message.includes("UpdateIsPropertyModifiedForProp")) {
_handleError(fieldId, result.error, "notRequiredControl");
}
});
}; /**
* Pop up a notification message.(通知消息框)
* @param {string} message message
* @param {function} callback
* @param {function} closeTimeout: the time of the message window close.
*/
var alertMessage = function (message, callback, closeTimeout) {
ShowMessage(message, "通知", eFormHelper.constants.messagetype.Info, callback);
if (closeTimeout) {
setTimeout(function (message) {
var $closeButton = $(".popupMessage").filter(function () { return this.innerText == message; }).closest(".k-widget.k-window").find(".k-icon.k-i-close").last();
if ($closeButton.length > 0) {
$closeButton.click();
}
}, closeTimeout, message);
}
}; /**
* Pop up a warning message.(警告框)
* @param {string} message message
* @param {function} callback
*/
var alertWarning = function (message, callback) {
ShowMessage(message, "警告", eFormHelper.constants.messagetype.Warning, callback);
}; /**
* Pop up an error message.
* @param {string} error: error message
* @param {function} callback
*/
var alertError = function (error, callback) {
ShowMessage(error, "エラー", eFormHelper.constants.messagetype.Error, callback);
}; /**
* Pop up a confirmation message.(确认框)
* @param {string} message message
* @param {function} callback
*/
var confirmMessage = function (message, callback) {
var options = {};
options.value = message;
options.callback = callback;
eFormHelper.confirmMessage(options, function (result) {
if (result.isSuccess) {
if (typeof callback == "function") {
options.callback(result.data);
}
} else {
_handleError(fieldId, result.error, "confirmMessage");
}
});
}; /**
* Call the control rule(执行窗体运行规则)
* @param {string} fieldId: Field internal name
*/
var invokeRule = function (fieldId) {
var options = {};
options.fieldId = fieldId;
eFormHelper.triggerControlRule(options, function (result) {
if (!result.isSuccess) {
_handleError(fieldId, result.error, "invokeRule");
}
});
}; /**
* Trigger AutoLookup
* @param {string} fieldId: Field internal name
* @param {function} done: Successful callback
* @param {function} fail: Failed callback
*/
var triggerAutoLookup = function (fieldId, done, fail) {
var options = {};
options.fieldId = fieldId;
eFormHelper.triggerAutoLookup(options, function (result) {
if (result.isSuccess) {
if (typeof done == "function") {
done();
}
} else {
_handleError(fieldId, result.error, "triggerAutoLookup");
if (typeof fail == "function") {
fail();
}
}
});
}; /**
* execute Lookup
* @param {string} fieldId fieldId Field internal name
* @param {function} done: Successful callback
* @param {function} fail: Failed callback
*/
var executeLookup = function (lookupName, done, fail) {
var options = {};
options.lookupName = lookupName;
options.lookupType = eFormHelper.constants.lookuptype.multicolumn
eFormHelper.executeLookup(options, function (result) {
if (result.isSuccess) {
if (typeof done == "function") {
done(result);
}
} else {
_handleError(lookupName, result.error, "executeLookup");
if (typeof fail == "function") {
fail();
}
}
});
} /**
* Reset subform(重置子窗体)
* @param {*} field Field internal name
* @param {*} rowCount: the blank row after clear subform.
*/
var resetSubForm = function (field, rowCount) { clearSubForm(field); if (!$.isNumeric(rowCount) || rowCount < 1) {
rowCount = 1;
}
var options = {};
options.fieldId = field;
options.value = [];
for (var i = 0; i < rowCount; i++) {
options.value.push({});
}
eFormHelper.addRowsToSubForm(options, $.noop());
}; /**
* Add rows to Subform(子表增加行)
* @param {*} field Field internal name
* @param {*} value Multiple values. e.g.[{Field1-1:'value1-1',Field1-2:'value1-2'},{Field2-1:'value2-1',Field2-2:'value2-2'}]
*/
var addRowsToSubForm = function (fieldId, value) {
var options = {};
options.fieldId = fieldId;
options.value = value;
eFormHelper.addRowsToSubForm(options, function (result) {
if (!result.isSuccess) {
_handleError(fieldId, result.error, "addRowsToSubForm");
}
});
}; /**
* clear a Subform(清除子窗体)
* @param {*} field Field internal name
*/
var clearSubForm = function (field) { var options = {};
options.fieldId = field;
options.rowIndex = '*';
_CustomizeDeleteRowsFromSubForm(options, function(result)
{
if (!result.isSuccess)
{
console.log(result.error); //Logs the error and error description, if any.
}
});
}; /**
* To delete the Row(s) from a SubForm(子表删除行)
* Copied from the standard API, but it has been fixed so that the confirmation dialog is not displayed when executing from JS
* even if it is set to display the delet confirmation dialog on the control property.
* @param {options} set fieldId and rowIndex
* Specifies rowIndex as asterisk (*) to delete all rows,
* or you can specify the row number with comma separation to delete specific rows. For example, '1,2'
* @param {callback} callback
*/
var _CustomizeDeleteRowsFromSubForm = function (options, callBack) {
var result = {
isSuccess: false,
error: {}
};
if (options.fieldId == undefined || options.fieldId == '' || $.isEmptyObject(options.fieldId)) {
result.error = 'argument exception';
return callBack(result);
}
try {
var ctrl = '';
eFormHelper.getField(options, function (res) {
ctrl = res.data;
});
var fb = $(ctrl).closest('.control').parent().data(Constants.previewWidgetKey);
if (fb === undefined) {
result.error = "no path found with given fieldId";
}
if (typeof options.rowIndex == "string") {
var strIndices = options.rowIndex;
var rowIndices = strIndices.split(',');
if (rowIndices.length >= 1) {
var $subFormContent = fb.target._getContentElementWithFb(fb);
var fieldId = $subFormContent[0].id;
var subFormContentRows = document.getElementById(fieldId).querySelectorAll(".subFormContentRow");
var deleteRowsList = [];
rowIndices.forEach(function (rowNumber) {
if (rowNumber !== '*') {
deleteRowsList.push(subFormContentRows[rowNumber - 1]);
} else {
for (var i = 0; i < subFormContentRows.length; i++) {
deleteRowsList.push(subFormContentRows[i]);
}
}
});
deleteRowsList.forEach(function (item) {
var delButton = item.querySelector(':scope > .subFormContentRowChildWrapper > .rowActionButtons > .deleteSubFormRow');
//Changed to call the customized row delete event.
_CustomizeExecuteDeleteRowEvent(fb, $(delButton));
});
result.isSuccess = true;
} else { result.error = 'no records found';
}
} } catch (ex) {
result.isSuccess = false;
result.error = ex;
}
if (typeof callBack == 'function') {
callBack(result);
}
}; /**
* SubForm Rows delete event.(行删除事件)
* Copied from the standard API, but not displays the confirmation dialog when delete subform row.
* @param {e}
* @param {t}
*/
var _CustomizeExecuteDeleteRowEvent = function (e, t) {
try {
var a = e.target._getContentElementWithFb(e);
if ("true" == t.parents(".subFormContentRow:first").attr("isreadonlyrow")){
return;
};
e.target._handleDataSourceChangeLog(e, t.parents(".subFormContentRow:first"), "Delete");
e.target._deleteContentRow(e, a.find("> .subFormContentRow").index(t.parents(".subFormContentRow:first")), t);
e.target._deleteRecordSubFormEvent(e);
} catch (e) {
FormBuilder._log(e)
}
}; /**
* Set the cover
* @param {*} isShow: if shwo the cover.
*/
var toggleLoader = function (isShow) {
__loader = __loader || document.querySelector('.loader');
var toggler = function () {
if (isShow) {
__loader.style.display = 'block';
} else {
__loader.style.display = 'none';
}
}; clearTimeout(timeOut);
timeOut = setTimeout(function () {
toggler();
}, 10);
}; /**
* Get field value (Be careful of timing issues!)
* @param {string} fieldId
* @returns {string} value
*/
var getFieldValue = function (fieldId) {
var options = {};
options.fieldId = fieldId;
eFormHelper.getFieldValue(options, function (result) {
if (!result.isSuccess) {
_handleError(fieldId, result.error);
}
options.result = result;
});
if (options.result.isSuccess) {
return options.result.data;
}
}; /**
* Set field value (Be careful of timing issues!)
* @param {string} fieldId
* @returns {string} value
*/
function setFieldValue(fieldId, value) {
var options = {};
options.fieldId = fieldId;
if(typeof value == "number")
{value = value.toString();}
options.value = value ? value : "";
eFormHelper.setFieldValue(options, function (result) {
if (!result.isSuccess) {
_handleError(fieldId, result.error);
}
});
} /**
* Get field Object
* @param {string} fieldName
* @returns fieldld object
*/
function getFieldObject(fieldName) {
var fieldObj = {};
eFormHelper.getField({ fieldId: fieldName }, function (result) { fieldObj = result.data; });
return fieldObj;
} /**
* Get field Text
* @param {string} fieldName
* @returns fieldld object
*/
function getFieldText(fieldName) {
var returndata;
eFormHelper.getFieldText ({ fieldId: fieldName}, function (result) {returndata = result.data});
return returndata;
} /*
* Validation
* @date : 2021-12-26
* @author : Joe Ma
* @version : 1.0.0
*/
function triggerValidate(fieldName)
{
var id= efh.getFieldObject(fieldName).uniqueId().get(0).id;
efh.mandatoryControl(id);
var valid=false;
var options = {};
options.fieldId = fieldName;
eFormHelper.triggerControlValidation(options, function (result)
{
if (result.isSuccess)
{
if ($('#'+id).matchingParent('div').find('.lblValidationMsg').get(0).innerText=="")
{
valid=true;
}
console.log(fieldName+":"+valid);
}else{
console.log(result.error); // logs the hold exception object
}
});
efh.nonmandatoryControl(id);
return valid;
} /*
* Asyc Execute Lookup(同步执行lookup)
* @param (string) lookup name
*/
function asycExecuteLookup(lkName)
{
return new Promise(function(resolve, reject) {
eFormHelper.executeLookup({ lookupName: lkName, lookupType: eFormHelper.constants.lookuptype.multicolumn }, function (result) {
if (result.data) {
if (!$.isArray(result.data)) {
result.data = [result.data];
}
resolve(result.data);
}
else
{
reject("Failed");
}
});
})
} /*
* Validation(执行公式)
* @date : 2022-03-17
* @author : Delong
* @version : 1.0.0
*/
function triggerFormula(fieldId)
{
var options = {};
options.fieldId = fieldId;
eFormHelper.triggerFormula(options, function (result)
{
if (result.isSuccess)
{
console.log(result.data); //logs the data holds the empty object
}
else
{
console.log(result.error); // logs the hold exception object
}
});
} /**
* return eform helper
* @returns {function[]}
*/
return {
showControl: showControl,
hideControl: hideControl,
enableControl: enableControl,
disableControl: disableControl,
mandatoryControl: mandatoryControl,
nonmandatoryControl: nonmandatoryControl,
alertMessage: alertMessage,
alertWarning: alertWarning,
alertError: alertError,
confirmMessage: confirmMessage,
invokeRule: invokeRule,
triggerAutoLookup: triggerAutoLookup,
executeLookup: executeLookup,
resetSubForm: resetSubForm,
addRowsToSubForm: addRowsToSubForm,
clearSubForm: clearSubForm,
toggleLoader: toggleLoader,
getFieldValue: getFieldValue,
setFieldValue: setFieldValue,
getFieldObject: getFieldObject,
getFieldText: getFieldText,
triggerValidate: triggerValidate,
asycExecuteLookup: asycExecuteLookup,
triggerFormula: triggerFormula
};
}();
Agilepoint中的JS Method 封装的更多相关文章
- vue中对axios进行封装
在刚结束的项目中对axios进行了实践(好不容易碰上一个不是jsonp的项目), 以下为在项目中对axios的封装,仅封装了post方法,因为项目中只用到了post,如有需要请自行进行修改 src/c ...
- 在webView 中使用JS 调用 Android / IOS的函数 Function
最近做一个项目,混合了NativeCode 和 HTML,为了便于JS 调用App的一些方法,统一封装一个Js方法,记录如下 Android 端首先要再WebView中允许JS的调用 WebView ...
- react request.js 函数封装
1.request.js 函数封装 import { Toast } from 'antd-mobile'; import axios from 'axios'; import store from ...
- Blazor组件自做三 : 使用JS隔离封装ZXing扫码
Blazor组件自做三 : 使用JS隔离封装ZXing扫码 本文基础步骤参考前两篇文章 Blazor组件自做一 : 使用JS隔离封装viewerjs库 Blazor组件自做二 : 使用JS隔离制作手写 ...
- Blazor组件自做四 : 使用JS隔离封装signature_pad签名组件
运行截图 演示地址 响应式演示 感谢szimek写的棒棒的signature_pad.js项目, 来源: https://github.com/szimek/signature_pad 正式开始 1. ...
- JS 对象封装的常用方式
JS是一门面向对象语言,其对象是用prototype属性来模拟的,下面,来看看如何封装JS对象. 常规封装 function Person (name,age,sex){ this.name = na ...
- m.jd.com首页中的js效果
m.jd.com中的部分js效果 昨天把m.jd.com的首页布局写好了,今天写一下首页中部分js效果.头部背景色透明度的改变,焦点图轮播,京东快报的小轮播,以及秒杀倒计时.这里html,css样式就 ...
- html或者jsp页面引用jar包中的js文件
一,页面上引用jar包中的js文件的方法 使用java web框架AppFuse的时候发现,jquery.bootstrap等js框架都封装到jar包里面了.这些js文件通过一个wro4j的工具对其进 ...
- JSF页面中使用js函数回调后台bean方法并获取返回值的方法
由于primefaces在国内使用的并不是太多,因此,国内对jsf做系统.详细的介绍的资料很少,即使有一些资料,也仅仅是对国外资料的简单翻译或者是仅仅讲表面现象(皮毛而已),它们的语句甚至还是错误的, ...
- Magento中调用JS文件的几种方法
一.全局调用方法: 通过该方法每个页面都会引用这个JS文件,除非是类似jQuery这样的系统文件,不然不推荐这种方法. 文件路径:/app/design/frontend/default/Your_T ...
随机推荐
- PWA-H5 Web App优化探索之路(Service Worker,Lighthouse)
PWA是什么? Progressive Web App 渐进式web应用程序,简单来说,就是可以让你的WEB App,带来与原生App相媲美的用户体验.. 为什么要用PWA? 简单来说,是为了web应 ...
- Xmake v2.7.6 发布,新增 Verilog 和 C++ Modules 分发支持
Xmake 是一个基于 Lua 的轻量级跨平台构建工具. 它非常的轻量,没有任何依赖,因为它内置了 Lua 运行时. 它使用 xmake.lua 维护项目构建,相比 makefile/CMakeLis ...
- JS基础简介
JS基础简介 一.JS简介 JavaScript(简称'js')是一种具有函数优先的轻量级.解释型或及时编译型的编程语言.虽然它是作为开发web页面的脚本语言而出名,但是它也被用到了很多的非浏览器环境 ...
- DML_修改数据
DML_修改数据 修改数据: 语法: update 表名 set 列名1 = 值1,列名2 = 值2, ... [ where 条件 ] ; 注意: 1. 如果不加任何条件,则会将表中所有记录全部修改 ...
- 【推荐】MySQL数据库设计SQL规范
1 命名规范 1.[强制]库名.表名.字段名必须使用小写字母并采用下划线分割,禁止拼音英文混用:(禁用-,-相当于运算符) 2.[建议]库名.表名.字段名在满足业务需求的条件下使用最小长度: 如inf ...
- day01-SpringMVC基本介绍-01
SpringMVC介绍-01 1.离线文档 解压 spring-5.3.8-dist.zip文件. 位置:spring-framework-5.3.8/docs/reference/html/web. ...
- Spring异步Async和事务Transactional注解
Spring开发中我们我们常常用到@Transaction和@Async,但这2个注解加在一起很多的开发者不敢用,担心事务不生效.下面我们就仔细讲解一下这2个注解同时运用,文章用3个场景讲述它们之间的 ...
- RA-Depth: Resolution Adaptive Self-Supervised Monocular Depth Estimation
注:刚入门depth estimation,这也是以后的主要研究方向,欢迎同一个方向的加入QQ群(602708168)交流. 1. 论文简介 论文题目:RA-Depth: Resolution Ada ...
- 浅谈Pytest中的marker
浅谈Pytest中的marker 没有注册marker 我们写一个简单的测试 # test_demo.py import pytest @pytest.mark.login def test_demo ...
- MySQL中的函数使用
有三张表,学生表(t_student),班级表(t_class),成绩表(t_grade),三张表的字段设计如下 查询大竹 ...