/*!
* PageUtil.js
* Copyright (c) 2018 CreativeDream
* Website: xxx
* Version: 1.0.0 (03-05-2018)
* Requires: jQuery v1.7.1 or later
*/
var i18next = "undefined" === typeof i18next ? parent.top.i18next : i18next,
IsWaiting = null,
bLeavePage = false,
g_db = {
/**
* Check the capability
* @private
* @method SupportLocalStorage
* @return {Object} description
*/
SupportLocalStorage: function () {
'use strict';
return typeof localStorage !== "undefined";
},
/**
* Insert data
* @private
* @method SetItem
* @param {String} sKey key鍵
* @param {Object} sValue Value值
* @return {Object} description
*/
SetItem: function (sKey, sValue) {
'use strict';
var bRes = false;
if (this.SupportLocalStorage()) {
localStorage.setItem(sKey, sValue);
bRes = true;
}
return bRes;
},
/**
* Fetch data
* @private
* @method GetItem
* @param {String} sKey key鍵
* @return {Object} description
*/
GetItem: function (sKey) {
'use strict';
var sRes = null;
if (this.SupportLocalStorage()) {
sRes = localStorage.getItem(sKey);
}
return sRes;
},
/**
* Remove data
* @private
* @method RemoveItem
* @param {String} sKey key鍵
* @return {Object} description
*/
RemoveItem: function (sKey) {
'use strict';
var bRes = false;
if (this.SupportLocalStorage()) {
localStorage.removeItem(sKey);
bRes = true;
}
return bRes;
},
/**
* Description for GetDic
* @private
* @method GetDic
* @param {String} sKey key鍵
* @return {Object} description
*/
GetDic: function (sKey) {
'use strict';
var dicRes = null,
vTemp;
if (this.SupportLocalStorage()) {
vTemp = localStorage.getItem(sKey);
if (null !== vTemp) {
dicRes = JSON.parse(vTemp);
}
}
return dicRes;
},
/**
* Description for SetDic
* @private
* @method SetDic
* @param {String} sKey key鍵
* @param {Object} dicValue json對象
* @return {Object} description
*/
SetDic: function (sKey, dicValue) {
'use strict';
var bRes = false;
if (this.SupportLocalStorage()) {
localStorage.setItem(sKey, JSON.stringify(dicValue));
bRes = true;
}
return bRes;
}
},
g_gd = {
webapilonginurl: "/api/Service/GetLogin",
webapiurl: "/api/Cmd/GetData",
projectname: "Eurotran",
projectver: "Origtek",
relpath: "",
debugmode: window.location.host === '192.168.1.105',
debugcolor: "#732C6B",
IsEDU: g_db.GetItem("isedu") === "true"
},
g_ul = {
/**
* Get token from db
* @returns {String} Token in localStorage
*/
GetToken: function () {
'use strict';
return g_db.GetItem("token");
},
/**
* Set token to db
* @param {String} sTokenValue api token
*/
SetToken: function (sTokenValue) {
'use strict';
g_db.SetItem("token", sTokenValue);
},
/**
* Set signature to db
* @return {Object} 簽名
*/
GetSignature: function () {
'use strict';
return g_db.GetItem("signature");
},
/**
* Set signature to db
* @param {String} sSignatureValue api signature
*/
SetSignature: function (sSignatureValue) {
'use strict';
g_db.SetItem("signature", sSignatureValue);
},
/**
* Set language
* @param {String} sLang 多語系值
*/
SetLang: function (sLang) {
'use strict';
g_db.SetItem("lang", sLang);
},
/**
* Get language
* @returns {String} language in localStorage
*/
GetLang: function () {
'use strict';
return g_db.GetItem("lang");
},
/**
* Set login method
* @param {String} sLoginMethod method
*/
SetLoginMethod: function (sLoginMethod) {
'use strict';
g_db.SetItem("LoginMethod", sLoginMethod);
},
/**
* Get login method
* @returns {String} login method in localStorage
*/
GetLoginMethod: function () {
'use strict';
return g_db.GetItem("LoginMethod");
},
/**
* Check is edu environment
* @returns {String} login method in localStorage
*/
IsEDU: function () {
'use strict';
return g_db.GetItem("isedu");
},
/**
* 產生隨機數
* @param {Number} len 指定长度,比如random(8)
* @return {String} rnd 亂數碼
*/
RndNum: function (len) {
var rnd = "";
len = len || 10;
for (var i = 0; i < len; i++)
rnd += Math.floor(Math.random() * 10);
return rnd;
}
},
g_api = {
ConnectLite: function (i_sModuleName, i_sFuncName, i_dicData, i_sSuccessFunc, i_FailFunc, i_bAsyn, i_sShwd) {
window.IsWaiting = i_sShwd;
return this.ConnectLiteWithoutToken(i_sModuleName, i_sFuncName, i_dicData, i_sSuccessFunc, i_FailFunc, i_bAsyn);
},
ConnectLiteWithoutToken: function (i_sModuleName, i_sFuncName, i_dicData, i_sSuccessFunc, i_FailFunc, i_bAsyn) {
var dicData = {},
dicParameters = {},
token = g_ul.GetToken(),
lang = g_ul.GetLang(),
signature = g_ul.GetSignature();
dicParameters.ORIGID = g_db.GetItem('orgid');
dicParameters.USERID = g_db.GetItem('userid');
dicParameters.MODULE = i_sModuleName;
dicParameters.TYPE = i_sFuncName;
dicParameters.PROJECT = g_gd.projectname;
dicParameters.PROJECTVER = g_gd.projectver;
dicParameters.TRACEDUMP = null; //
i_dicData = i_dicData || {};
if (g_db.GetItem('dblockDict') !== null) {
i_dicData.dblockDict = g_db.GetItem('dblockDict');
}
dicParameters.DATA = i_dicData;
if (lang !== null) {
dicParameters.LANG = lang;
}
if (token !== null) {
dicParameters.TOKEN = token;
}
if (signature !== null) {
dicParameters.SIGNATURE = signature;
}
dicParameters.CUSTOMDATA = {};
if (window.sProgramId) {
dicParameters.CUSTOMDATA.program_id = sProgramId;
}
dicParameters.CUSTOMDATA.module_id = "webapp";
dicData.url = i_dicData.hasOwnProperty("url") ? i_dicData.url : g_gd.webapiurl;
dicData.successfunc = i_sSuccessFunc;
dicData.dicparameters = dicParameters;
dicData.failfunc = "function" === typeof i_FailFunc ? i_FailFunc : function (jqXHR, textStatus, errorThrown) {
alert("ConnectLite Fail jqXHR:" + jqXHR + " textStatus:" + textStatus + " errorThrown:" + errorThrown);
};
dicData.useasync = "boolean" === typeof i_bAsyn ? i_bAsyn : true;
return this.AjaxPost(dicData);
},
AjaxPost: function (i_dicData) {
'use strict';
var defaultOption = {
useasync: true,
successfunc: null,
failfunc: null,
alwaysfunc: null,
url: null,
dicparameters: null
},
runOption = $.extend(defaultOption, i_dicData),
runSuccess = function (res) {
if (res.RESULT === -1) { // ╠message.TokenVerifyFailed⇒您的身份認證已經過期,請重新登入╣ ╠common.Tips⇒提示╣
layer.alert(i18next.t("message.TokenVerifyFailed"), { icon: 0, title: i18next.t("common.Tips") }, function (index) {
window.top.location.href = '/Page/login.html';
});
}
else {
if (runOption.successfunc) {
runOption.successfunc(res);
}
}
};
return $.ajax({
type: 'POST',
url: runOption.url,
data: "=" + btoa2(encodeURIComponent(JSON.stringify(runOption.dicparameters))),
success: runSuccess,
error: runOption.failfunc,
beforeSend: function (xhr) {
var token = g_ul.GetToken(),
timestamp = $.now(),
nonce = g_ul.RndNum();
xhr.setRequestHeader("orgid", runOption.dicparameters.ORIGID);
xhr.setRequestHeader("userid", runOption.dicparameters.USERID);
xhr.setRequestHeader("token", token);
xhr.setRequestHeader("timestamp", timestamp);
xhr.setRequestHeader("nonce", nonce);
},
async: true !== runOption.useasync ? false : true
}).always(runOption.alwaysfunc);
}
};
var CanDo = (function (w, d) {
'use strict';
var CanDo = function (config) {
return new CanDo.fn._init(config);
};
CanDo.fn = CanDo.prototype = {
constructor: CanDo,
_init: function (config) {
var cando = this,
dfoptions = {
cusBtns: [],//客製化按鈕
goTop: true,//置頂圖標
searchBar: true,//是否有搜尋區塊
goBack: true,//是否返回查詢頁面
insertGo: true,//新增完后是否跳轉
updateGo: true,//修改完后是否跳轉
deleteGo: true,//刪除完后是否跳轉
pageSize: parent.top.SysSet.GridRecords || 0,//Grid顯示筆數
gridPages: parent.top.SysSet.GridPages || 15,//Grid按鈕顯示數量
queryPageidx: 1,//當前頁面索引
toFirstPage: false
};
$.extend(dfoptions, config);
for (var key in cando._pageParam) {
var val = dfoptions[key];
if (val) {
cando._pageParam[key] = val;
}
}
cando.options = dfoptions;
cando.ids = {};
cando.params = {};
cando.UE_Editor = {};
cando.currentPageValue = [];
cando.validator = null;
cando.CheckId = '';
cando.action = cando._getAction();
cando.ProgramId = cando._getProgramId();
cando.QueryPrgId = cando._getQueryPrgId();
cando.EditPrgId = cando._getEditPrgId();
w.sProgramId = cando.ProgramId;
cando.data = cando._data;
cando.pageParam = cando._pageParam;
cando.setGrid = function (grid) {
cando.Grid = grid;
};
if (typeof cando.options.cusBtns === 'function') {
cando.options.cusBtns = cando.options.cusBtns(cando);
}
var idKeys = cando.options.idKeys,
paramKeys = cando.options.paramKeys,
index,
_key;
if (idKeys && $.isArray(idKeys)) {
for (index in idKeys) {
if ('clear,insert,remove'.indexOf(index) === -1) {
_key = idKeys[index];
cando.ids[_key] = cando._getUrlParam(_key);
cando.CheckId += cando.ids[_key] || '';
}
}
}
if (paramKeys && $.isArray(paramKeys)) {
for (index in paramKeys) {
if ('clear,insert,remove'.indexOf(index) === -1) {
_key = paramKeys[index];
cando.params[_key] = cando._getUrlParam(_key);
}
}
}
//ToolBar(功能函數)
cando.initButtonHandler = function (inst, e) {
return cando._buttonHandler.call(cando, inst, e);
};
//查詢(分頁)
cando.getPage = function (args) {
return cando._getPage(args);
};
//查詢(單筆)
cando.getOne = function (args) {
return cando._getOne(args);
};
//新增
cando.getInsert = function (p, args) {
return cando._getInsert(args);
};
//修改
cando.getUpdate = function (args) {
return cando._getUpdate(args);
};
//刪除
cando.getDelete = function (args) {
return cando._getDelete(args);
};
//匯出
cando.getExcel = function (args) {
if (args) {
return cando._getPage(args);
}
};
//Grid新增
cando.gridInsert = function (args) {
if (args) {
return cando._gridInsert(args);
}
};
//Grid新增
cando.gridUpdate = function (args) {
if (args) {
return cando._gridUpdate(args);
}
};
//Grid新增
cando.gridDelete = function (args) {
if (args) {
return cando._gridDelete(args);
}
};
for (_key in cando) {
var _key_ = _key.replace('_', ''),
_val = dfoptions[_key_];
if (_val && _key !== 'constructor') {
cando[_key_] = _val;
}
}
if (!cando.form) {
cando.form = cando._form;
}
if (!cando.jsGrid) {
cando.jsGrid = cando._jsGrid;
}
//pageInit(功能初始化)
cando._pageInit().done(function () {
var editorIds = cando.options.ueEditorIds;
if ($.isArray(editorIds)) {
for (var index in editorIds) {
if ('clear,insert,remove'.indexOf(index) === -1) {
var key = editorIds[index];
if ($('#UE_' + key).length > 0) {
cando.UE_Editor[key] = UE.getEditor('UE_' + key);
}
}
}
}
if (typeof cando.pageInit === 'function') {
cando.pageInit.call(cando, cando);
}
if (typeof cando.options.validRulesCus === 'function') {
cando.options.validRulesCus(cando);
}
if (typeof cando.options.validRules === 'function') {
cando.options.validRules = cando.options.validRules(cando);
}
cando.validator = cando.form.validate(cando.options.validRules || {});
});
},
_service: {
cotrl: '/Controller.ashx',
com: 'Common',
opm: 'OpmCom',
eip: 'EipCom',
sys: 'SysCom',
auth: 'Authorize'
},
_api: {
getpage: 'QueryPage',
getlist: 'QueryList',
getone: 'QueryOne',
getcout: 'QueryCout',
insert: 'Insert',
update: 'Update',
delete: 'Delete',
ginsert: 'GridInsert',
gupdate: 'GridUpdate',
gdelete: 'GridDelete',
order: 'UpdateOrderByValue'
},
_data: {},
_form: $('#form_main'),
_jsGrid: $("#jsGrid"),
_pageParam: {
pageIndex: 1,
pageSize: 10,
sortField: 'OrderByValue',
sortOrder: 'asc'
},
/**
* 通過url獲取程式id
* @param {String} path 文件路徑
* @return {String} 程式ID
*/
_getProgramId: function (path) {
var herf = path || d.location.href,
herfs = herf.split('/');
herfs = herfs[herfs.length - 1].split('.');
return herfs[0] || '';
},
/**
* 通過查詢程式ID獲取編輯頁面程式ID
* @return {String} 編輯頁面程式ID
*/
_getEditPrgId: function () {
var prgid = this._getProgramId();
return prgid.replace('_Qry', '_Upd');
},
/**
* 通過編輯程式ID獲取查詢程式ID
* @return {String} 編輯頁面程式ID
*/
_getQueryPrgId: function () {
var prgid = this._getProgramId();
return prgid.replace('_Upd', '_Qry');
},
/**
* ToolBar 按鈕事件 function
* @param {Object} inst 按鈕物件對象
* @param {Object} e 事件對象
* @return {Boolean} 停止標記
*/
_buttonHandler: function (inst, e) {
var cando = this,
id = inst.id;
if (!$.isEmptyObject(cando.UE_Editor)) {
for (var key in cando.UE_Editor) {
if ($('#' + key).length > 0) {
$('#' + key).val(cando.UE_Editor[key].getContentTxt());
}
}
}
switch (id) {
case "Toolbar_Qry":
if (!cando.form.valid()) {
cando.validator.focusInvalid();
return false;
}
var iNum = $('#PerPageNum').val();
cando.Grid && (cando.Grid.pageSize = iNum === '' ? cando.options.pageSize || 10 : iNum);
cando._cacheQueryCondition();
cando.Grid && cando.Grid.openPage(cando.options.toFirstPage ? 1 : cando.pageParam.pageIndex);
if (typeof cando.options.afterQuery === 'function') {
cando.options.afterQuery(cando);
}
break;
case "Toolbar_Save":
if (!cando.form.valid()) {
cando.validator.focusInvalid();
return false;
}
if (cando.action === 'add') {
cando.getInsert.call(cando, cando, cando.action);
}
else {
cando.getUpdate.call(cando, cando);
}
break;
case "Toolbar_ReAdd":
if (!cando.form.valid()) {
cando.validator.focusInvalid();
return false;
}
cando.getInsert.call(cando, cando, 'readd');
break;
case "Toolbar_Clear":
cando._clearPageVal();
break;
case "Toolbar_Leave":
cando._pageLeave();
break;
case "Toolbar_Add":
parent.openPageTab(cando.EditPrgId, '?Action=Add');
break;
case "Toolbar_Upd":
break;
case "Toolbar_Copy":
break;
case "Toolbar_Del": // ╠message.ConfirmToDelete⇒確定要刪除嗎 ?╣ ╠common.Tips⇒提示╣
layer.confirm(i18next.t("message.ConfirmToDelete"), { icon: 3, title: i18next.t('common.Tips') }, function (index) {
cando.getDelete.call(cando);
layer.close(index);
});
break;
case "Toolbar_Exp":
if (cando.Grid.data.length === 0) {
showMsg(i18next.t("message.NoDataExport"));// ╠message.NoDataExport⇒沒有資料匯出╣
return false;
}
cando.getExcel({ Excel: true });
break;
default:
{
var actions = cando.options.cusBtns.filter(function (item) { return item.id === id; });
if (actions.length > 0 && typeof actions[0].action === 'function') {
actions[0].action(cando);
}
else {
alert("No handle '" + id + "'");
}
}
break;
}
},
/**
* 通過編輯程式ID獲取查詢程式ID
*/
_initGrid: function () {
var cando = this,
iheight = $('body').height() - $('.page-title').height() - $('#searchbar').height() - 87;
if (typeof cando.options.gridFields === 'function') {
cando.options.gridFields = cando.options.gridFields(cando);
}
cando.jsGrid.jsGrid({
width: "100%",
height: iheight + "px",
autoload: true,
pageLoading: true,
inserting: cando.options.inserting || false,
editing: true,
sorting: true,
paging: true,
pageIndex: cando.options.toFirstPage ? 1 : cando.options.queryPageidx,
pageSize: cando.options.pageSize,
pageButtonCount: cando.options.gridPages,
invalidMessage: i18next.t('common.InvalidData'),
confirmDeleting: true,
deleteConfirm: i18next.t('message.ConfirmToDelete'),
pagePrevText: "<",
pageNextText: ">",
pageFirstText: "<<",
pageLastText: ">>",
fields: cando.options.gridFields,
onItemEditing: function (args) {
if (typeof cando.options.onItemEditing === 'function') {
cando.options.onItemEditing(args);
}
},
onPageChanged: function (args) {
if (typeof cando.options.onPageChanged === 'function') {
cando.options.onPageChanged(cando, args);
}
else {
cando._cacheQueryCondition(args.pageIndex);
}
},
rowClick: function (args) {
if (typeof cando.options.rowClick === 'function') {
cando.options.rowClick(cando, args);
}
else {
if (navigator.userAgent.match(/mobile/i)) {
var _param = cando._getParamsStr(cando.ids, args.item);
cando._goToEdit(cando.EditPrgId, '?Action=Upd' + _param);
}
}
},
rowDoubleClick: function (args) {
if (typeof cando.options.rowDoubleClick === 'function') {
cando.options.rowDoubleClick(cando, args);
}
else {
var _param = cando._getParamsStr(cando.ids, args.item);
parent.top.openPageTab(cando.EditPrgId, '?Action=Upd' + _param);
}
},
controller: {
loadData: function (args) {
return cando.getPage(args);
},
insertItem: function (args) {
return cando.gridInsert(args);
},
updateItem: function (args) {
return cando.gridUpdate(args);
},
deleteItem: function (args) {
return cando.gridDelete(args);
}
},
onInit: function (args) {
cando.setGrid(args.grid);
}
});
},
/**
* 基本查詢(分頁)
* @param {String} args 參數
* @return {Object} Ajax對象
*/
_getPage: function (args) {
var cando = this,
qrParam = cando._getFormSerialize();
$.extend(qrParam, cando.pageParam, args);
cando.pageParam.pageIndex = qrParam.pageIndex;
return g_api.ConnectLite(cando.ProgramId, cando._api.getpage, qrParam, function (res) {
if (res.RESULT) {
var oRes = res.DATA.rel;
if (args.Excel) {//匯出
cando._downLoadFile.call(cando, oRes);
if (layer && args.Index) {
layer.close(args.Index);
}
}
}
});
},
/**
* 基本查詢(單筆)
* @return {Object} Ajax對象
*/
_getOne: function () {
var cando = this,
data = clone(cando.ids);
if (typeof cando.options.getOneParams === 'function') {
data = cando.options.getOneParams(cando);
}
return g_api.ConnectLite(cando.ProgramId, cando._api.getone, data,
function (res) {
if (res.RESULT) {
cando.data = res.DATA.rel;
var jsonStrKeys = cando.options.jsonStrKeys;
if (jsonStrKeys && $.isArray(jsonStrKeys)) {
for (var index in jsonStrKeys) {
if ('clear,insert,remove'.indexOf(index) === -1) {
var key = jsonStrKeys[index],
val = cando.data[key];
if (typeof val === 'string' && val !== '') {
cando.data[key] = JSON.parse(val);
}
}
}
}
if (typeof cando.options.getOneBack === 'function') {
cando.options.getOneBack(cando, cando.data);
}
else {
cando._setFormVal(cando.data);
cando._setUEValues(cando.data);
}
setTimeout(function () {
cando._getPageVal();//緩存頁面值,用於清除
}, 500);
}
},
function () {
showMsg(i18next.t("message.GetOne_Error"), 'error'); // ╠message.GetOne_Error⇒獲取當前資料異常╣
});
},
/**
* 基本新增
* @param {String} flag 新增 or 儲存后新增
* @return {Object} Ajax對象
*/
_getInsert: function (flag) {
var cando = this,
data = cando._getFormSerialize();
data = cando._getUEValues(data);
if (typeof cando.options.getInsertParams === 'function') {
data = cando.options.getInsertParams(cando, data);
}
data = $.extend(cando.data, data);
return g_api.ConnectLite(cando.ProgramId, cando._api.insert, data, function (res) {
if (res.RESULT) {
w.bRequestStorage = false;
var oRes = res.DATA.rel;
if (typeof cando.options.getInsertBack === 'function') {
cando.options.getInsertBack(cando, oRes, flag);
}
else {
if (!cando.options.goBack) {
var _param = cando._getParamsStr(cando.ids, oRes);
showMsgAndGo(i18next.t("message.Insert_Success"), cando.ProgramId, '?Action=Upd' + _param); // ╠message.Save_Success⇒新增成功╣
}
else {
if (flag === 'add') {
if (cando.options.insertGo) {
showMsgAndGo(i18next.t("message.Insert_Success"), cando.QueryPrgId); // ╠message.Insert_Success⇒新增成功╣
}
else {
showMsg(i18next.t("message.Insert_Success"), 'success'); //╠message.Insert_Success⇒新增成功╣
}
}
else {
showMsgAndGo(i18next.t("message.Insert_Success"), cando.ProgramId, '?Action=Add'); // ╠message.Insert_Success⇒新增成功╣
}
}
}
}
else {
showMsg(i18next.t("message.Insert_Failed") + '
' + res.MSG, 'error');// ╠message.Insert_Failed⇒新增失敗╣
}
}, function () {
showMsg(i18next.t("message.Insert_Error"), 'error');// ╠message.Insert_Error⇒新增資料異常╣
});
},
/**
* 基本修改
* @return {Object} Ajax對象
*/
_getUpdate: function () {
var cando = this,
data = cando._getFormSerialize();
data = cando._getUEValues(data);
if (typeof cando.options.getUpdateParams === 'function') {
data = cando.options.getUpdateParams(cando, data);
}
data = $.extend(cando.data, data, cando.ids);
return g_api.ConnectLite(cando.ProgramId, cando._api.update, data, function (res) {
if (res.RESULT) {
w.bRequestStorage = false;
var oRes = res.DATA.rel;
if (typeof cando.options.getUpdateBack === 'function') {
cando.options.getUpdateBack(cando, oRes);
}
else {
if (cando.options.updateGo) {
showMsgAndGo(i18next.t("message.Modify_Success"), cando.QueryPrgId); //╠message.Modify_Success⇒修改成功╣
}
else {
showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
if (w.bLeavePage) {
setTimeout(function () {
cando._pageLeave();
}, 1000);
}
}
}
}
else {
showMsg(i18next.t("message.Modify_Failed") + '
' + res.MSG, 'error');// ╠message.Modify_Failed⇒修改失敗╣
}
}, function () {
showMsg(i18next.t("message.Modify_Error"), 'error');//╠message.Modify_Error⇒修改資料異常╣
});
},
/**
* 基本刪除
* @param {String} args 參數
* @return {Object} Ajax對象
*/
_getDelete: function (args) {
var cando = this,
data = clone(cando.ids);
if (typeof cando.options.getDeleteParams === 'function') {
data = cando.options.getDeleteParams(cando);
}
return g_api.ConnectLite(cando.ProgramId, cando._api.delete, data, function (res) {
if (res.RESULT) {
var oRes = res.DATA.rel;
if (typeof cando.options.getDeleteBack === 'function') {
cando.options.getDeleteBack(cando, oRes);
} else {
if (cando.options.deleteGo) {
showMsgAndGo(i18next.t("message.Delete_Success"), cando.QueryPrgId); // ╠message.Delete_Success⇒刪除成功╣
}
else {
showMsg(i18next.t("message.Delete_Success"), 'success'); //╠message.Delete_Success⇒刪除成功╣
}
}
}
else {
showMsg(i18next.t("message.Delete_Failed") + '
' + res.MSG, 'error');// ╠message.Delete_Failed⇒刪除失敗╣
}
}, function () {
showMsg(i18next.t("message.Delete_Error"), 'error'); // ╠message.Delete_Error⇒刪除資料異常╣
});
},
/**
* Grid新增
* @param {String} data 新增參數
* @return {Object} Ajax對象
*/
_gridInsert: function (data) {
var cando = this;
if (typeof cando.options.getGridInsertParams === 'function') {
data = cando.options.getGridInsertParams(cando, data);
}
return g_api.ConnectLite(cando.ProgramId, cando._api.ginsert, data, function (res) {
if (res.RESULT) {
var oRes = res.DATA.rel;
if (typeof cando.options.getGridInsertBack === 'function') {
cando.options.getGridInsertBack(cando, oRes);
}
else {
showMsg(i18next.t("message.Insert_Success"), 'success'); // ╠message.Insert_Success⇒新增成功╣
}
}
else {
showMsg(i18next.t("message.Insert_Failed") + '
' + res.MSG, 'error');// ╠message.Insert_Failed⇒新增失敗╣
}
}, function () {
showMsg(i18next.t("message.Insert_Error"), 'error');// ╠message.Insert_Error⇒新增資料異常╣
});
},
/**
* Grid修改
* @param {String} data 修改參數
* @return {Object} Ajax對象
*/
_gridUpdate: function (data) {
var cando = this;
if (typeof cando.options.getGridUpdateParams === 'function') {
data = cando.options.getGridUpdateParams(cando, data);
}
return g_api.ConnectLite(cando.ProgramId, cando._api.gupdate, data, function (res) {
if (res.RESULT) {
var oRes = res.DATA.rel;
if (typeof cando.options.getGridUpdateBack === 'function') {
cando.options.getGridUpdateBack(cando, oRes);
}
else {
showMsg(i18next.t("message.Modify_Success"), 'success'); //╠message.Modify_Success⇒修改成功╣
}
}
else {
showMsg(i18next.t("message.Modify_Failed") + '
' + res.MSG, 'error');// ╠message.Modify_Failed⇒修改失敗╣
}
}, function () {
showMsg(i18next.t("message.Modify_Error"), 'error');//╠message.Modify_Error⇒修改資料異常╣
});
},
/**
* Grid刪除
* @param {String} data 刪除參數
* @return {Object} Ajax對象
*/
_gridDelete: function (data) {
var cando = this;
if (typeof cando.options.getGridDeleteParams === 'function') {
data = cando.options.getGridDeleteParams(cando);
}
return g_api.ConnectLite(cando.ProgramId, cando._api.gdelete, data, function (res) {
if (res.RESULT) {
var oRes = res.DATA.rel;
if (typeof cando.options.getGridDeleteBack === 'function') {
cando.options.getGridDeleteBack(cando, oRes);
} else {
showMsg(i18next.t("message.Delete_Success"), 'success'); // ╠message.Delete_Success⇒刪除成功╣
}
}
else {
showMsg(i18next.t("message.Delete_Failed") + '
' + res.MSG, 'error');// ╠message.Delete_Failed⇒刪除失敗╣
}
}, function () {
showMsg(i18next.t("message.Delete_Error"), 'error'); // ╠message.Delete_Error⇒刪除資料異常╣
});
},
/**
* 基本匯出
* @param {String} args 參數
*/
_getExcel: function (args) {
},
/**
* 基本查詢(分頁)
* @param {String} args 參數
* @return {Object} Ajax對象
*/
_pageInit: function (args) {
var cando = this;
if (navigator.userAgent.match(/mobile/i)) {
$('.ismobile').hide();
}
if ($("#tabs").length > 0) {
$("#tabs").tabs().find('li').on('click', function () {
var that = this;
$('#tabs>ul>li').removeClass('active');
$(this).addClass('active');
if (typeof cando.options.tabAction === 'function') {
cando.options.tabAction(that, cando);
}
});
}
setTimeout(function () {
if ($.datepicker !== undefined) {
$.datepicker.regional['zh-TW'] = {
dayNames: ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"],
dayNamesMin: ["日", "一", "二", "三", "四", "五", "六"],
monthNames: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
monthNamesShort: ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"],
prevText: "上月",
nextText: "次月",
weekHeader: "週",
showMonthAfterYear: true, // True if the year select precedes month, false for month then year//設置是否在面板的头部年份后面显示月份
dateFormat: "yy/mm/dd"
};
$.datepicker.setDefaults($.datepicker.regional["zh-TW"]);
}
//註冊日曆控件(不含時間)
if ($('.date-picker').length > 0) {
$('.date-picker').datepicker({
changeYear: true,
changeMonth: true,
altFormat: 'yyyy/MM/dd',
onSelect: function (r, e) {
if (typeof cando.options.onSelect === 'function') {
cando.options.onSelect(r, e);
}
},
afterInject: function (r, e) { }
});
}
//註冊日曆控件(含時間)
if ($('.datetime-picker').length > 0) {
$('.datetime-picker').each(function () {
var iHour = ($(this).attr('hour') || 9) * 1,
iMinute = ($(this).attr('minute') || 0) * 1,
iStepMinute = ($(this).attr('stepminute') || 15) * 1;
$(this).datetimepicker({
changeYear: true,
changeMonth: true,
altFormat: 'yyyy/MM/dd',
timeFormat: 'HH:mm',
//minDateTime: new Date(),
//maxDateTime: new Date().dateAdd('d', 5),
//defaultValue: newDate(null, true) + ' 08:00',
hour: iHour,
minute: iMinute,
stepMinute: iStepMinute,
hourGrid: 6,
minuteGrid: 15,
onSelect: function (r, e) {
if (typeof cando.options.onSelect === 'function') {
cando.options.onSelect(r, e);
}
},
afterInject: function (r, e) { }
});
});
}
//註冊日曆控件(時間)
if ($('.time-picker').length > 0) {
$('.time-picker').each(function () {
var iHour = ($(this).attr('hour') || 9) * 1,
iMinute = ($(this).attr('minute') || 0) * 1;
$(this).timepicker({
timeFormat: 'HH:mm',
hour: iHour,
minute: iMinute,
minuteGrid: 30,
stepMinute: 30,
onSelect: function (r, e) {
if (typeof cando.options.onSelect === 'function') {
cando.options.onSelect(r, e);
}
}
});
});
}
}, 1000);
//註冊顏色控件
if ($('.color-picker').length > 0) {
$('.color-picker').each(function () {
var that = this;
$(that).spectrum({
color: "#000000",
//flat: true,
showInput: true,
className: "full-spectrum",
showInitial: true,
showPalette: true,
showSelectionPalette: true,
maxPaletteSize: 10,
preferredFormat: "hex",
hide: function (color) {
$(that).val(color.toHexString());
},
palette: [
["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)",
"rgb(204, 204, 204)", "rgb(217, 217, 217)", "rgb(255, 255, 255)",
"rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)"],
["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)",
"rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)",
"rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)",
"rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)",
"rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)",
"rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)",
"rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)",
"rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)",
"rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)",
"rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)",
"rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"]
]
});
});
}
cando._keyInput(); //註冊欄位管控
cando._select2Init();//初始化select2
cando._uniformInit();//表單美化
if (cando.options.goTop) {
var elTop = $('