/**====================================================================================================================================================
* 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 封装的更多相关文章

  1. vue中对axios进行封装

    在刚结束的项目中对axios进行了实践(好不容易碰上一个不是jsonp的项目), 以下为在项目中对axios的封装,仅封装了post方法,因为项目中只用到了post,如有需要请自行进行修改 src/c ...

  2. 在webView 中使用JS 调用 Android / IOS的函数 Function

    最近做一个项目,混合了NativeCode 和 HTML,为了便于JS 调用App的一些方法,统一封装一个Js方法,记录如下 Android 端首先要再WebView中允许JS的调用 WebView ...

  3. react request.js 函数封装

    1.request.js  函数封装 import { Toast } from 'antd-mobile'; import axios from 'axios'; import store from ...

  4. Blazor组件自做三 : 使用JS隔离封装ZXing扫码

    Blazor组件自做三 : 使用JS隔离封装ZXing扫码 本文基础步骤参考前两篇文章 Blazor组件自做一 : 使用JS隔离封装viewerjs库 Blazor组件自做二 : 使用JS隔离制作手写 ...

  5. Blazor组件自做四 : 使用JS隔离封装signature_pad签名组件

    运行截图 演示地址 响应式演示 感谢szimek写的棒棒的signature_pad.js项目, 来源: https://github.com/szimek/signature_pad 正式开始 1. ...

  6. JS 对象封装的常用方式

    JS是一门面向对象语言,其对象是用prototype属性来模拟的,下面,来看看如何封装JS对象. 常规封装 function Person (name,age,sex){ this.name = na ...

  7. m.jd.com首页中的js效果

    m.jd.com中的部分js效果 昨天把m.jd.com的首页布局写好了,今天写一下首页中部分js效果.头部背景色透明度的改变,焦点图轮播,京东快报的小轮播,以及秒杀倒计时.这里html,css样式就 ...

  8. html或者jsp页面引用jar包中的js文件

    一,页面上引用jar包中的js文件的方法 使用java web框架AppFuse的时候发现,jquery.bootstrap等js框架都封装到jar包里面了.这些js文件通过一个wro4j的工具对其进 ...

  9. JSF页面中使用js函数回调后台bean方法并获取返回值的方法

    由于primefaces在国内使用的并不是太多,因此,国内对jsf做系统.详细的介绍的资料很少,即使有一些资料,也仅仅是对国外资料的简单翻译或者是仅仅讲表面现象(皮毛而已),它们的语句甚至还是错误的, ...

  10. Magento中调用JS文件的几种方法

    一.全局调用方法: 通过该方法每个页面都会引用这个JS文件,除非是类似jQuery这样的系统文件,不然不推荐这种方法. 文件路径:/app/design/frontend/default/Your_T ...

随机推荐

  1. git操作失误,提交代码因为网络问题没有成功,然后操作时候点错按钮导致代码全部没有了,也没用备份,如何解决

    最好的提交代码办法, 1.先创建一个空文件夹, 2.然后创建一个在线仓库 3. git remote add origin '仓库地址' 4.查看远程仓库 git remote remove orig ...

  2. Go语言的template

    html/template包实现了数据驱动的模板,用于生成可防止代码注入的安全的HTML内容.它提供了和 text/template包相同的接口,Go语言中输出HTML的场景都应使用html/temp ...

  3. JSP第十次作业

    1.实现 删除 回复邮件2.实现阅读邮件功能:在main.jsp中点击任意邮件的标题,进入到detail.jsp显示邮件详情,包括发件人,主题,内容,时间.同时需要把邮件状态修改为已读. com.gd ...

  4. 快速入门API Explorer

    摘要:华为云API Explorer为开发者提供一站式API解决方案统一平台,集成华为云服务所有开放 API,支持全量快速检索.可视化调试.帮助文档.代码示例等能力,帮助开发者快速查找.学习API和使 ...

  5. log4j 完美版配置

    百度的LOG4J配置记录一下 目前无时间阅读,反正能用就行了 # priority :debug<info<warn<error #you cannot specify every ...

  6. VUE10 计算属性

    1 Vue计算属性简介 1)定义:我们需要一个属性,但是这个属性不存在,但是可以通过已有的属性计算得来,那么就可以定义一个计算属性. 2)原理:底层借助了Object.defineproperty方法 ...

  7. 有效的字母异位词&两个数组的交集& 快乐数& 两数之和

    一.有效的字母异位词 242. 有效的字母异位词 1.方法概述 因为本题中字符串只包含小写字母,就可以定义一个数组来记录字符串中字符出现的次数.遍历第一个字符串,用charAt拿到对应的小写字母然后减 ...

  8. 9.【go-kit教程】go-kit集成Prometheus

    在 Go kit 中集成 Prometheus 进行 API 监控可以帮助开发人员更好地了解系统的性能和行为,提高系统的可观察性和可靠性.下面是一个简单的示例,演示如何在 Go kit 中集成 Pro ...

  9. .net 中的几种事务

    在一个MIS系统中,没有用事务那就绝对是有问题的,要么就只有一种情况:你的系统实在是太小了,业务业务逻辑有只要一步执行就可以完成了.因此掌握事务处理的方法是很重要,进我的归类在.net中大致有以下4种 ...

  10. webserver 简单demo

    以调用天气服务为例: 1.添加服务引用 2.点窗口做下角(高级->添加web引用->URL输入框输入天气服务地址(http://www.webxml.com.cn/WebServices/ ...