/*! * 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 = $('
', { class: 'gotop', html: '', click: function () { return $("body,html").animate({ scrollTop: 0 }, 120), !1; } }); $('body').append(elTop.hide());//添加置頂控件 $(d).on('scroll', function () { var h = ($(d).height(), $(this).scrollTop()), toolbarH = -45, toolbarCss = {}, elToolBar = cando._getToolBar(); h > 0 ? elTop.fadeIn() : elTop.fadeOut(); if (h > 35) { toolbarH = h - 80; elToolBar.addClass('toolbar-float').removeClass('toolbar-fix'); } else { elToolBar.removeClass('toolbar-float').addClass('toolbar-fix'); } elToolBar.css('margin-top', toolbarH + 'px'); }); } if (cando.ProgramId) { var lang = g_ul.GetLang() || 'zh-TW'; cando._setLang(lang);//翻譯多語系 cando._getPageVal(); //緩存頁面值,用於清除 cando._createPageTitle(); //創建Header if (cando.options.searchBar) { //設置顯示于隱藏搜尋區塊 var iSearchBox_h = $('#searchbar').height(), elSlideUpDown = $('', { class: 'fa fa-arrow-up slide-box', click: function () { if ($(this).hasClass('fa-arrow-up')) { $(this).removeClass('fa-arrow-up').addClass('fa-arrow-down'); elSearchBox.slideUp(); !!cando.Grid && (cando.Grid.height = cando.Grid.dfheight.replace('px', '') * 1 + iSearchBox_h + 'px'); } else { $(this).removeClass('fa-arrow-down').addClass('fa-arrow-up'); elSearchBox.slideDown(); !!cando.Grid && (cando.Grid.height = cando.Grid.dfheight); } !!cando.Grid && cando.Grid.refresh(); //調整Grid slimscrollDIV高度,保證和實際高度一致 var elGridBox = $('.jsgrid-grid-body.slimscroll'); elGridBox.parent().css('height', elGridBox.css('height')); } }), elSlideDiv = $('
', { class: 'col-sm-12 up-down-go' }).append(elSlideUpDown), elSearchBox = $('#searchbar').after(elSlideDiv); } cando._reSetQueryPm(); //恢復之前查詢條件 //加載按鈕權限 return cando._getAuthority(cando).done(function () { }); } }, /** * 獲取權限 * @return {Object} Ajax對象 */ _getAuthority: function (outterCando) { var cando = this, topmod = cando._getTopMod(); return g_api.ConnectLite('Authorize', 'GetAuthorize', { ProgramID: cando.ProgramId, TopModuleID: topmod }, function (res) { if (res.RESULT) { var authorize = res.DATA.rel, btns = [], hasBtn = {}, lastBtn = null, elToolBar = cando._getToolBar(), initToolbar = function () {//等待 ToolBar(wedget)初始化ok后在執行,否則會報錯 elToolBar.ToolBar({ btns: btns, fncallback: cando.initButtonHandler }); cando._transLang(elToolBar); }, delayInitToolbar = function () { if ($.fn.ToolBar) { initToolbar(); } else { delayInitToolbar(); } }; $.each(authorize, function (idx, roleright) { if (roleright.AllowRight) { var saRights = roleright.AllowRight.split('|'); $.each(saRights, function (e, btnright) { var sBtn = $.trim(btnright); if (hasBtn[sBtn.toLowerCase()] === undefined) { hasBtn[sBtn.toLowerCase()] = sBtn; } }); } }); if (!hasBtn['upd']) { delete hasBtn.save; delete hasBtn.readd; } if (cando.action === 'upd') { delete hasBtn.readd; } if (cando.action === 'add') { delete hasBtn.del; } delete hasBtn.upd; delete hasBtn.view; for (var btnkey in hasBtn) { var oBtn = {}; oBtn.key = hasBtn[btnkey]; if (btnkey === 'leave') { lastBtn = oBtn; lastBtn.hotkey = 'ctrl + l'; } else { switch (btnkey) { case 'qry': oBtn.hotkey = 'enter'; break; case 'add': oBtn.hotkey = 'ctrl + i'; break; case 'readd': oBtn.hotkey = 'ctrl + r'; break; case 'save': oBtn.hotkey = 'ctrl + s'; break; case 'del': oBtn.hotkey = 'ctrl + d'; break; case 'clear': oBtn.hotkey = 'ctrl + q'; break; } btns.push(oBtn); } } if (cando.options.cusBtns.length > 0) { btns.push.apply(btns, cando.options.cusBtns); } if (lastBtn) { btns.push(lastBtn); } delayInitToolbar(); //button Ready時候 if (outterCando.ProgramId.indexOf('_Upd') > -1) { var action = outterCando._getAction(); if (action === 'upd') {//判斷當前頁面是否有人在操作 parent.top.msgs.server.checkEdit(outterCando.ProgramId, outterCando.CheckId); } outterCando.form.find(':input,select').not('[data-type=select2]').change(function () { if (!$(this).attr('data-trigger')) { w.bRequestStorage = true; } }); setTimeout(function () { outterCando.form.find('[data-type=select2]').change(function () { if (!$(this).attr('data-trigger')) { w.bRequestStorage = true; } }); }, 3000); } else { if (outterCando.ProgramId.indexOf('_Qry') > -1) { parent.top.msgs.server.removeEditPrg(outterCando.ProgramId.replace('_Qry', '_Upd'));//防止重複點擊首頁菜單導致之前編輯資料狀態無法移除 } var oQueryBtn = $('#Toolbar_Qry'); if (oQueryBtn.length > 0) { $('select').on('change', function (e, arg) { //select2下拉單改變自動查詢 setTimeout(function () { if (arg !== 'clear') {//清除動作(賦值)不查詢 $('#Toolbar_Qry').click(); } }, 10); }); $(':input[type="radio"],:input[type="checkbox"]').on('click', function (e, arg) { //radio值改變自動查詢 if (arg !== 'clear') {//清除動作(賦值)不查詢 $('#Toolbar_Qry').click(); } }); } } } }); }, /** * 取得頂層模組 * @return {String} 頂層模組 */ _getTopMod: function () { var cando = this, topmod = '', programList = g_db.GetDic('programList') || [], program = programList.filter(function (item) { return item.ModuleID === cando.ProgramId; })[0], getParent = function (modid) { var oMod = cando._getParentMod(modid); if (oMod.ParentID) { getParent(oMod.ParentID); } else { topmod = oMod.ModuleID; } }; getParent(program.ParentID); return topmod; }, /** * 序列化form表單 * @param {HTMLElement} fm 表單form物件 * @param {String} type 傳回類型 * @return {Object} fmdata 表單資料 */ _getFormSerialize: function (fm, type) { var cando = this, fmdata = {}; fm = fm || cando.form; reFreshInput(fm); if (type) { fmdata = fm.serializeJSON(); } else { fmdata = fm.serializeObject(); } reSetInput(fm); return fmdata; }, /** *取得程式所在模組的父層模組 * @param {String} modid 模組id * @return {Object} 模組對象 */ _getParentMod: function (modid) { var cando = this, programList = g_db.GetDic('programList') || [], parentProgram = programList.filter(function (item) { return item.ModuleID === modid && item.FilePath === '#'; })[0]; return parentProgram; }, /** * 儲存當前頁面的值 * @param {String} elId 要清除區塊的父層Id */ _getPageVal: function (elId) { var cando = this, //判斷傳入的樣式是否不存在或者等於空的情況 oHandle = elId !== undefined ? $('#' + elId) : cando.form; cando.currentPageValue = []; //儲存畫面值 oHandle.find(':input', 'textarea', 'select').each(function () { var ctl = {}; //實例化對象 ctl.ID = this.id; ctl.Type = this.type; if (ctl.ID && ctl.Type) { switch (this.type) { case 'text': case 'email': case 'url': case 'number': case 'range': case 'date': case 'search': case 'color': case 'password': case 'hidden': case 'textarea': ctl.Value = $(this).val(); break; case 'checkbox': case 'radio': ctl.Checked = this.checked; break; case 'select-multiple': case 'select-one': case 'select': ctl.Value = $(this).val() || ''; ctl.Html = $(this).html(); break; } cando.currentPageValue.push(ctl); } }); }, /** * 取得Url參數 * @param {String} name 取得部分的名稱 例如輸入"Action",就能取到"Add"之類參數 * @return {Object} url參數 */ _getUrlParam: function (name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"), //構造一個含有目標參數的正則表達式對象 r = w.location.search.substr(1).match(reg); //匹配目標參數 if (r !== null) { return unescape(r[2]);//返回參數值 } else { return null; } }, /** * 創建程式Title */ _createPageTitle: function () { var cando = this, handle = $('.page-title'), programList = g_db.GetItem('programList'), modTree = '', modTrees = [], setProgramPath = function (modid) { var oParent = cando._getParentMod(modid); if (oParent.ModuleID) { modTrees.unshift('
'); } if (oParent.ParentID) { setProgramPath(oParent.ParentID); } }; if (programList === null || programList === '') { return; } var programLists = $.parseJSON(programList), curProgramList = programLists.filter(function (item) { return item.ModuleID === cando.ProgramId; }); if (curProgramList.length === 0) { return; } var program = curProgramList[0]; if (!program.ParentID) { return; } setProgramPath(program.ParentID); modTrees.push('
'); modTree = modTrees.join(''); //串起父層路徑名稱 $.templates({ tmpl: '\
\

\ {{if showTable=="Y"}}
(Use:{{:MainTableName}})
{{/if}}\
' }); handle.html($.render.tmpl({ ProgramName: "common." + program.ModuleID, showTable: parent.top.SysSet.TbShowOrHide, MainTableName: program.MainTableName, ModTree: modTree })); cando._transLang(handle); if (navigator.userAgent.match(/mobile/i)) { $('.ismobile').hide(); } }, /** * 目的:恢復查詢條件 */ _reSetQueryPm: function () { var cando = this, qrParam = parent[cando.ProgramId + '_query']; if (qrParam) { cando._setFormVal(qrParam); if (qrParam.pageidx) { cando.options.queryPageidx = qrParam.pageidx; } } }, /** * 設定表單值 * @param {Object} json json對象 */ _setFormVal: function (json) { var cando = this; cando.form.find('[name]').each(function () { var id = this.id, name = this.name ? this.name.replace('[]', '') : '', type = this.type, value = json[name] || cando._getJsonVal(json, id) || ''; if (value) { switch (type) { case 'text': case 'email': case 'url': case 'number': case 'range': case 'date': case 'search': case 'color': case 'textarea': case 'select-one': case 'select': case 'hidden': var dataType = $(this).attr("data-type"); if (dataType && dataType === 'pop') { var sVal_Name = json[name + 'Name'] || value; $(this).attr("data-value", value); if (sVal_Name) $(this).val(sVal_Name); } else { if ($(this).hasClass('date-picker')) { value = newDate(value, 'date'); } else if ($(this).hasClass('date-picker') || $(this).hasClass('datetime-picker') || $(this).hasClass('date')) { value = newDate(value); } if (value) $(this).val(value); $(this).data('old', value); if (dataType && dataType === 'int' && value) { $(this).attr('data-value', value.toString().replace(/[^\d.]/g, '')); } } if (dataType === 'select2') { $(this).trigger("change", 'setval'); } break; case 'checkbox': if (typeof value === 'object') { if (value.indexOf(this.value) > -1) { this.checked = value; } } else { this.checked = typeof value === 'string' ? value === this.value : value; } $.uniform && $.uniform.update($(this).prop("checked", this.checked)); break; case 'radio': this.checked = this.value === value; $.uniform && $.uniform.update($(this).prop("checked", this.checked)); break; } if ((id === 'ModifyUserName' || id === 'CreateUserName') && 'select-one'.indexOf(this.type) === -1) { $(this).text(value); } else if (id === 'ModifyDate' || id === 'CreateDate') { $(this).text(newDate(value)); } } }); }, /** * 取得自定義json值 * @param {Object} json json對象 * @param {Object} name json鍵值 * @return {String} last 最終要獲取的對應的鍵值對的值 */ _getJsonVal: function (json, name) { var last = json, names = name.split('_'); for (var i = 0; i < names.length; i++) { if (!last[names[i]]) { last = ''; break; } last = last[names[i]]; } return last; }, /** * 取得(url)參數(格式)字串 * @param {Object} keys key值json對象 * @param {Object} from 資料來源 * @return {String} param 最終要獲取的參數(格式)字串 */ _getParamsStr: function (keys, from) { var param = ''; for (var key in keys) { param += '&' + key + '=' + encodeURIComponent(from[key]); } return param; }, /** * 清除畫面值 * @param {String} flag 是否為查詢清空(查詢頁面須全部清空,不保留原值) */ _clearPageVal: function () { var cando = this, pageval = cando.currentPageValue, elQryBtn = $('#Toolbar_Qry'); for (var i = 0; i < pageval.length; i++) { var ctl = pageval[i], curInput = $("#" + ctl.ID), ctlParent = curInput.parent(); try { switch (ctl.Type) { case 'text': case 'email': case 'url': case 'number': case 'range': case 'date': case 'search': case 'color': case 'password': case 'hidden': case 'textarea': curInput.val(ctl.Value); break; case 'checkbox': case 'radio': curInput[0].checked = ctl.Checked; $.uniform && $.uniform.update(curInput.prop("checked", curInput[0].checked)); break; case 'select-multiple': case 'select-one': case 'select': if (ctl.Html) { curInput.html(ctl.Html); } curInput.val(ctl.Value); if (curInput.attr('data-type') === 'select2') { curInput.trigger('change', 'clear'); } break; } } catch (e) { alert(e); } } if (elQryBtn.length > 0) { $('#Toolbar_Qry').click(); } }, /** * 離開事件 * @return {boolean} 停止標記 */ _pageLeave: function () { var cando = this, toLeave = function () { parent.top.openPageTab(cando.QueryPrgId); parent.top.msgs.server.removeEditPrg(cando.ProgramId); }; //當被lock住,不儲存任何資料,直接離開。 if (parent.bLockDataForm0430 !== undefined) toLeave(); if (w.bRequestStorage) { layer.confirm(i18next.t('message.HasDataTosave'), {//╠message.HasDataTosave⇒尚有資料未儲存,是否要儲存?╣ icon: 3, title: i18next.t('common.Tips'),// ╠message.Tips⇒提示╣ btn: [i18next.t('common.Yes'), i18next.t('common.No')] // ╠message.Yes⇒是╣ ╠common.No⇒否╣ }, function (index) { layer.close(index); w.bLeavePage = true; $('#Toolbar_Save').click(); }, function () { toLeave(); }); return false; } toLeave(); }, /** * 緩存查詢條件 * @param {HTMLElement}form 表單物件 */ _cacheQueryCondition: function (form) { var cando = this, _form = form || cando.form, prgid = cando.ProgramId || cando._getProgramId() || '', qrParam = {}; cando.options.toFirstPage = false; if (prgid) { if (!parent[prgid + '_query']) { parent[prgid + '_query'] = {}; } if (typeof _form === 'number') { parent[prgid + '_query'].pageidx = _form; } else { var oQueryPm_Old = clone(parent[prgid + '_query']), key; qrParam = cando._getFormSerialize(); for (key in qrParam) { parent[prgid + '_query'][key] = qrParam[key]; } for (key in oQueryPm_Old) { if (key !== 'pageidx' && parent[prgid + '_query'][key] !== oQueryPm_Old[key]) { cando.options.toFirstPage = true; break; } } } } }, /** * 獲取當前服務器地址 * @return {String} 當前服務器地址 */ _getServerUrl: function () { return w.location.origin || this._getHost(); }, /** * 獲取當前服務器地址 * @return {String} 當前服務器地址 */ _getHost: function () { var serverUrl = location.origin + '/'; if (!w.location.origin) { serverUrl = w.location.protocol + "//" + w.location.hostname + (w.location.port ? ':' + w.location.port : ''); } return serverUrl; }, /** * Toolbar物件 * @return {HTMLElement} New 一個Toolbar標籤 */ _getToolBar: function () { return $('#Toolbar'); }, /** * 獲取當前動作 * @return {String} add or upd */ _getAction: function () { var cando = this; return cando._getUrlParam('Action') === null ? 'add' : cando._getUrlParam('Action').toLowerCase(); }, /** * 下載文件 * @param {String} path 文件路徑(相對路勁) * @param {String} filename 文件名稱 */ _downLoadFile: function (path, filename) { var cando = this, serverUrl = cando._getServerUrl(), url = serverUrl + "/Controller.ashx"; url += '?action=downfile&path=' + path; if (filename) { url += '&filename=' + filename; } w.location.href = url; cando._closeWaiting(); }, /** * 開啟Waiting視窗 * @param {String} msg 提示文字 */ _showWaiting: function (msg) { $.blockUI({ message: $('
' + (msg || 'Waiting...') + '
'), css: { 'font-size': '36px', border: '0px', 'border-radius': '10px', 'background-color': '#FFF', padding: '15px 15px', opacity: .5, color: 'orange', cursor: 'wait', 'z-index': 1000000001 }, baseZ: 1000000000 }); w.setTimeout($.unblockUI, 60000);//預設開啟60秒後關閉 }, /** * 關閉Waiting視窗 * @param {Number} sleep 延遲時間,單位為毫秒 */ _closeWaiting: function (sleep) { $(function () { if (sleep === undefined) { sleep = 100; } setTimeout($.unblockUI, sleep); }); }, /** * select2特殊化處理 * @param {Object} el select2控制項 */ _select2Init: function (el) { var select2 = el === undefined ? $('select[data-type=select2]') : el.find('select[data-type=select2]'); //註冊客制化選單 if (select2.length > 0) { select2.each(function () { if ($(this).find('option').length > 0 && !$(this).attr('data-hasselect2')) { $(this).select2().attr('data-hasselect2', true); $(this).next().after($(this)); } }); } }, /** * 目的:異動模式點擊資料行彈出編輯按鈕 * @param {String} prgid 程式id * @param {String} params 參數 */ _goToEdit: function (prgid, params) { var cando = this; parent.top.layer.open({ type: 1, title: false, area: ['100px', '70px'],//寬度 shade: 0.75,//遮罩 shadeClose: true,//╠common.Edit⇒編輯╣ content: '
\ \
', success: function (layero, idx) { layero.find('#RowEdit').click(function () { parent.top.openPageTab(prgid, params); parent.top.layer.close(idx); }); cando._transLang(layero); } }); }, /** * radio特殊化處理 * @param {Object} el 表單控制項 */ _uniformInit: function (el) { var radio = $("input[type=radio]:not(.no-uniform)"); if (el) { radio = el.find("input[type=radio]:not(.no-uniform)"); } if (radio.length > 0) { radio.each(function () { $(this).uniform(); }); } }, /** * 目的:input文本處理 */ _keyInput: function () { //只能輸入數字 if ($('[data-keyint]').length > 0) { $('[data-keyint]').on('keyup blur', function (e) { this.value = this.value.replace(/\D/g, ''); }); } //只能输入英文 if ($('[data-keyeng]').length > 0) { $('[data-keyeng]').on('keyup blur', function (e) { this.value = this.value.replace(/[^a-zA-Z]/g, ''); }); } //只能输入中文 if ($('[data-keyeng]').length > 0) { $('[data-keyeng]').on('keyup blur', function (e) { this.value = this.value.replace(/[^\u4E00-\u9FA5]/g, ''); }); } //只能輸入數字和“-”,(手機/電話) if ($('[data-keytelno]').length > 0) { $('[data-keytelno]').on('keyup blur', function (e) { if (e.keyCode !== 8 && e.keyCode !== 37 && e.keyCode !== 39 && e.keyCode !== 46) { this.value = this.value.replace(/[^0-9\-\+\#\ ]/g, ''); } }); } //只能輸入數字和“-,+,#” if ($('[data-keyintg]').length > 0) { $('[data-keyintg]').on('keyup blur', function (e) { this.value = this.value.replace(/[^0-9\-\+\#]/g, ''); }); } //只允许输入英文 if ($('[data-keyeng]').length > 0) { $('[data-keyeng]').on('keyup blur', function (e) { this.value = this.value.replace(/[^\a-\z\A-\Z]/g, ''); }); } //只能输入英文字母和数字,不能输入中文 if ($('[data-keyinteng]').length > 0) { $('[data-keyinteng]').on('keyup blur', function (e) { this.value = this.value.replace(/[^0-9\a-\z\A-\Z\_]/g, ''); }); } //只能输入字母和汉字 if ($('[data-keycneng]').length > 0) { $('[data-keycneng]').on('keyup blur', function (e) { this.value = this.value.replace(/[/d]/g, ''); }); } //帳號輸入規則 if ($('[data-keymemberid]').length > 0) { $('[data-keymemberid]').on('keyup blur', function (e) { this.value = this.value.replace(/[^\w\.\/]/ig, ''); }); } //限制inout輸入長度 if ($('[_maxlength]').length > 0) { $('[_maxlength]').each(function () { var iPromiseLen = $(this).attr('_maxlength'); if (iPromiseLen) { $(this).on('input propertychange', function () { var sVal = this.value, sVal_New = '', iLen = 0, i = 0; for (; i < sVal.length; i++) { if ((sVal.charCodeAt(i) & 0xff00) !== 0) { iLen++; } iLen++; if (iLen > iPromiseLen * 1) { this.value = sVal_New; break; } sVal_New += sVal[i]; } }); } }); } }, /** * 設定多於系 * @param {String} lng 語種 * @param {HTMLElement} el 要翻譯的html標籤 * @param {Function} callback 回調函數 */ _setLang: function (lng, el, callback) { if (!lng) return; g_ul.SetLang(lng); i18next = "undefined" === typeof i18next ? parent.top.i18next : i18next; var cando = this, serverUrl = cando._getServerUrl(); $.getJSON(serverUrl + "/Scripts/lang/" + (parent.top.OrgID || 'TE') + "/" + lng + ".json?v=" + new Date().getTime().toString(), function (json) { var resources = {}; resources[lng] = { translation: json }; i18next.init({ lng: lng, resources: resources, useLocalStorage: false, //是否将语言包存储在localstorage //ns: { namespaces: ['trans'], defaultNs: 'trans' }, //加载的语言包 localStorageExpirationTime: 86400000 // 有效周期,单位ms。默认1 }, function (err, t) { cando._transLang(el); if (typeof callback === 'function') { callback(t); } }); }); }, /** * 翻譯語系 * @param {HTMLElement} dom 翻譯回調函數 */ _transLang: function (dom) { i18next = "undefined" === typeof i18next ? parent.top.i18next : i18next; var i18nHandle = dom === undefined ? $('[data-i18n]') : dom.find('[data-i18n]'), i18nHandlePlaceholder = dom === undefined ? $('[placeholderid]') : dom.find('[placeholderid]'); i18nHandle.each(function (idx, el) { var i18key = $(el).attr('data-i18n'); if (i18key) { var sLan = i18next.t(i18key); if (el.nodeName === 'INPUT' && el.type === 'button') { $(el).val(sLan); } else { $(el).html(sLan); } } }); i18nHandlePlaceholder.each(function (idx, el) { var i18key = $(el).attr("placeholderid"); if (i18key) { var sLan = i18next.t(i18key); if (sLan !== i18key) { $(el).attr("placeholder", sLan); } } }); }, /** * 獲取UE—Editor 值 * @param {Object} data 當前表單資料 * @return {Object} data 當前表單資料(含UE控件) */ _getUEValues: function (data) { var cando = this; if (!$.isEmptyObject(cando.UE_Editor)) { for (var key in cando.UE_Editor) { data[key] = cando.UE_Editor[key].getContent(); } } return data; }, /** * 設置UE—Editor 值 * @param {Object} data 當前編輯資料 */ _setUEValues: function (data) { var cando = this, readyToSet = function (_key) { cando.UE_Editor[_key].ready(function () { cando.UE_Editor[_key].setContent(data[_key] || ''); }); }; if (!$.isEmptyObject(cando.UE_Editor)) { for (var key in cando.UE_Editor) { readyToSet(key); } } } }; /** * 產生guid * @param {Number} len 指定长度,比如guid(8, 16) // "098F4D35" * @param {Number} radix 基数 * @return {String} guid */ w.guid = function (len, radix) { var buf = new Uint16Array(8), cryptObj = w.crypto || w.msCrypto, // For IE11 s4 = function (num) { var ret = num.toString(16); while (ret.length < 4) { ret = '0' + ret; } return ret; }; cryptObj.getRandomValues(buf); return s4(buf[0]) + s4(buf[1]) + '-' + s4(buf[2]) + '-' + s4(buf[3]) + '-' + s4(buf[4]) + '-' + s4(buf[5]) + s4(buf[6]) + s4(buf[7]); }; /** * 產生下拉選單(公用) * @param {Object} list datalist * @param {String} id 顯示的id名稱 * @param {String} name 顯示的name名稱 * @param {Boolean} showid 是否顯示id * @param {String} cusattr 客制化添加屬性 * @param {Boolean} isreapet 是否允許重複 * @return {String} option html */ w.createOptions = function (list, id, name, showid, cusattr, isreapet) { isreapet = isreapet || true; list = list || []; var Options = [], originAry = []; if (typeof list === 'number') { var intNum = list; while (list > 0) { var svalue = intNum - list + 1; svalue = $.trim(svalue); Options.push($('