/**====================================================================================================================================================
* 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. day04-视图和视图解析器

    视图和视图解析器 1.基本介绍 在SpringMVC中的目标方法,最终返回的都是一个视图(有各种视图) 注意,这里的视图是一个类对象,不是一个页面!! 返回的视图都会由一个视图解析器来处理(视图解析器 ...

  2. Djanngo-bbs项目

    1.项目开发基本流程 1.需求分析 2.架构设计 3.分组开发 4.提交测试 5.交付上线 2.项目流程 仿造博客园项目(核心:文章的增删改查) 1.表分析: 1.1用户表 1.2个人站点表 1.3文 ...

  3. 在Flask中构建API接口的相关概念

    在Flask中构建API接口的相关概念 重定向行为 斜杠 以下两个路由的不同之处在于是否使用尾部的斜杠. 第一个路由的URL尾部有一个斜杠,看起来就像一个文件夹,访问一个没有斜杠结尾的URL时,Fla ...

  4. VUE16 检测数据变化的原理

    部分转自:https://www.vue-js.com/topic/6129d7d661c8f900316ae37a 1 简介 Vue采用MVVM(数据驱动视图)的模式,去充当MVVM中的VM层,在数 ...

  5. 【论文笔记】FCN全卷积网络

    全卷积网络(FCN)是用于图片语义分割的一种卷积神经网络(CNN),由Jonathan Long,Evan Shelhamer 和Trevor Darrell提出,由此开启了深度学习在语义分割中的应用 ...

  6. 深度优先搜索算法-dfs讲解

    迷宫问题 有一个迷宫: S**. .... ***T (其中字符S表示起点,字符T表示终点,字符*表示墙壁,字符.表示平地.你需要从S出发走到T,每次只能向上下左右相邻的位置移动,不能走出地图,也不能 ...

  7. P24_wxss - wxss与css的关系

    WXSS 模板样式 什么是 WXSS WXSS (WeiXin Style Sheets)是一套样式语言,用于美化 WXML 的组件样式,类似于网页开发中的 CSS. WXSS 和 CSS 的关系 W ...

  8. SpringCloud GateWay网关(入门)

    1.介绍 强烈推荐,看官网文档 Spring Cloud Gateway ①简介 Cloud全家桶里有个重要组件:网关 SpringCloud Gateway基于WebFlux框架 WebFlux底层 ...

  9. 微信小程序分包

    当我们程序太大的时候,打开小程序就会比较慢,此处就需要用到分包加载,按照模块划分不同的包,让用户在需要的时候才加载对用的模块,也就是用户在进入某些页面的时候才下载该页面的资源,提高小程序的打开速度,以 ...

  10. JZOJ 5355. 【NOIP2017提高A组模拟9.9】保命

    题目 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄做一些防火措施,保障自己.猫.奶牛的生命安全. 农夫约的农庄里有N+1 座建筑,排成了一排,编号为0-N.对于0 < ...