/**====================================================================================================================================================
* 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. ORM哪家强?java,c#,php,python,go 逐一对比, 网友直呼:全面客观

    前言 最近一段时间,我使用golang开发了一个新的ORM库. 为了让这个库更好用,我比较研究了各语言的主流ORM库,发现有一些语言的ORM库确实很好用,而有另外一些语言的库那不是一般的难用. 然后我 ...

  2. idea正则替换

    将非 (股权)的替换成 股权

  3. Sublime下运行javascript,并带彩色提示

    最近和各种同事磨合技术,自闭中~ 首先让JS在Sublime上运行 去下载Node.js并且安装 安装完成后 cmd 输入 node -v 查看安装是否成功. 接着打开Sublime - 工具 > ...

  4. centos7笔记本使用iptables服务,将笔记本模拟成为出口路由器 PPPOE拨号+NAT+端口映射

    郑州洪水,闲置在家,捣鼓捣鼓 centos7笔记本使用iptables服务,将笔记本模拟成为出口路由器 PPPOE拨号+NAT+端口映射 环境: 1.笔记本单网口,无法做路由网关,手里有个闲置的USB ...

  5. 顺手写的redis分布式锁

    /** * 锁定一个key,***一定要手工释放锁 * * @param key * @return */ public boolean lockKey(String key) { return re ...

  6. Java堆外缓存(一个很有意思的应用)

    我们在开发过程中会遇到这样的场景:就是一个服务的各项 JVM 的配置都比较合理的情况下,它的 GC 情况还是不容乐观.分析之后发现有 2 个对象特别巨大,占了总存活堆内存的 90%以上.其中第 1 大 ...

  7. P13_协同工作_小程序权限管理的概念以及成员管理的两个方面

    协同工作和发布 - 协同工作 了解权限管理需求 在中大型的公司里,人员的分工非常仔细:同一个小程序项目,一般会有不同岗位.不同角色的员工同时参与设计与开发. 此时出于管理需要,我们迫切需要对不同岗位. ...

  8. P5_认识小程序项目的基本组成结构

    项目结构 了解项目的基本组成结构 pages 用来存放所有小程序的页面 utils 用来存放工具性质的模块(例如:格式化时间的自定义模块) app.js 小程序项目的入口文件 app.json 小程序 ...

  9. 使用nvm时报错:exit status 1: ļ Ѵ ʱ ޷ ļ 的解决办法

    1.出现问题 如图,安装完nvm后,使用[nvm use 版本号]命令切换版本,出现如题错误,具体截图如下 2.分析原因 1)安装路径是否包含中文 2)安装路径有空格 3)cmd使用是否是管理员方式打 ...

  10. 样本熵(SampEn)的C/C++代码实现与优化

    正文 本文不介绍什么是样本熵,具体推荐看此文https://blog.csdn.net/Cratial/article/details/79742363,写的很好,里面的示例也被我拿来测试代码写的对不 ...