/*! * 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=!1,g_db={SupportLocalStorage:function(){"use strict";return typeof localStorage!="undefined"},SetItem:function(n,t){"use strict";var i=!1;return this.SupportLocalStorage()&&(localStorage.setItem(n,t),i=!0),i},GetItem:function(n){"use strict";var t=null;return this.SupportLocalStorage()&&(t=localStorage.getItem(n)),t},RemoveItem:function(n){"use strict";var t=!1;return this.SupportLocalStorage()&&(localStorage.removeItem(n),t=!0),t},GetDic:function(n){"use strict";var i=null,t;return this.SupportLocalStorage()&&(t=localStorage.getItem(n),null!==t&&(i=JSON.parse(t))),i},SetDic:function(n,t){"use strict";var i=!1;return this.SupportLocalStorage()&&(localStorage.setItem(n,JSON.stringify(t)),i=!0),i}},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={GetToken:function(){"use strict";return g_db.GetItem("token")},SetToken:function(n){"use strict";g_db.SetItem("token",n)},GetSignature:function(){"use strict";return g_db.GetItem("signature")},SetSignature:function(n){"use strict";g_db.SetItem("signature",n)},SetLang:function(n){"use strict";g_db.SetItem("lang",n)},GetLang:function(){"use strict";return g_db.GetItem("lang")},SetLoginMethod:function(n){"use strict";g_db.SetItem("LoginMethod",n)},GetLoginMethod:function(){"use strict";return g_db.GetItem("LoginMethod")},IsEDU:function(){"use strict";return g_db.GetItem("isedu")},RndNum:function(n){var i="",t;for(n=n||10,t=0;t0&&(i.UE_Editor[n]=UE.getEditor("UE_"+n)));typeof i.pageInit=="function"&&i.pageInit.call(i,i);typeof i.options.validRulesCus=="function"&&i.options.validRulesCus(i);typeof i.options.validRules=="function"&&(i.options.validRules=i.options.validRules(i));i.validator=i.form.validate(i.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"},_getProgramId:function(n){var r=n||t.location.href,i=r.split("/");return i=i[i.length-1].split("."),i[0]||""},_getEditPrgId:function(){var n=this._getProgramId();return n.replace("_Qry","_Upd")},_getQueryPrgId:function(){var n=this._getProgramId();return n.replace("_Upd","_Qry")},_buttonHandler:function(n){var t=this,u=n.id,i,f,r;if(!$.isEmptyObject(t.UE_Editor))for(i in t.UE_Editor)$("#"+i).length>0&&$("#"+i).val(t.UE_Editor[i].getContentTxt());switch(u){case"Toolbar_Qry":if(!t.form.valid())return t.validator.focusInvalid(),!1;f=$("#PerPageNum").val();t.Grid&&(t.Grid.pageSize=f===""?t.options.pageSize||10:f);t._cacheQueryCondition();t.Grid&&t.Grid.openPage(t.options.toFirstPage?1:t.pageParam.pageIndex);typeof t.options.afterQuery=="function"&&t.options.afterQuery(t);break;case"Toolbar_Save":if(!t.form.valid())return t.validator.focusInvalid(),!1;t.action==="add"?t.getInsert.call(t,t,t.action):t.getUpdate.call(t,t);break;case"Toolbar_ReAdd":if(!t.form.valid())return t.validator.focusInvalid(),!1;t.getInsert.call(t,t,"readd");break;case"Toolbar_Clear":t._clearPageVal();break;case"Toolbar_Leave":t._pageLeave();break;case"Toolbar_Add":parent.openPageTab(t.EditPrgId,"?Action=Add");break;case"Toolbar_Upd":break;case"Toolbar_Copy":break;case"Toolbar_Del":layer.confirm(i18next.t("message.ConfirmToDelete"),{icon:3,title:i18next.t("common.Tips")},function(n){t.getDelete.call(t);layer.close(n)});break;case"Toolbar_Exp":if(t.Grid.data.length===0)return showMsg(i18next.t("message.NoDataExport")),!1;t.getExcel({Excel:!0});break;default:r=t.options.cusBtns.filter(function(n){return n.id===u});r.length>0&&typeof r[0].action=="function"?r[0].action(t):alert("No handle '"+u+"'")}},_initGrid:function(){var n=this,t=$("body").height()-$(".page-title").height()-$("#searchbar").height()-87;typeof n.options.gridFields=="function"&&(n.options.gridFields=n.options.gridFields(n));n.jsGrid.jsGrid({width:"100%",height:t+"px",autoload:!0,pageLoading:!0,inserting:n.options.inserting||!1,editing:!0,sorting:!0,paging:!0,pageIndex:n.options.toFirstPage?1:n.options.queryPageidx,pageSize:n.options.pageSize,pageButtonCount:n.options.gridPages,invalidMessage:i18next.t("common.InvalidData"),confirmDeleting:!0,deleteConfirm:i18next.t("message.ConfirmToDelete"),pagePrevText:"<",pageNextText:">",pageFirstText:"<<",pageLastText:">>",fields:n.options.gridFields,onItemEditing:function(t){if(typeof n.options.onItemEditing=="function")n.options.onItemEditing(t)},onPageChanged:function(t){if(typeof n.options.onPageChanged=="function")n.options.onPageChanged(n,t);else n._cacheQueryCondition(t.pageIndex)},rowClick:function(t){if(typeof n.options.rowClick=="function")n.options.rowClick(n,t);else if(navigator.userAgent.match(/mobile/i)){var i=n._getParamsStr(n.ids,t.item);n._goToEdit(n.EditPrgId,"?Action=Upd"+i)}},rowDoubleClick:function(t){if(typeof n.options.rowDoubleClick=="function")n.options.rowDoubleClick(n,t);else{var i=n._getParamsStr(n.ids,t.item);parent.top.openPageTab(n.EditPrgId,"?Action=Upd"+i)}},controller:{loadData:function(t){return n.getPage(t)},insertItem:function(t){return n.gridInsert(t)},updateItem:function(t){return n.gridUpdate(t)},deleteItem:function(t){return n.gridDelete(t)}},onInit:function(t){n.setGrid(t.grid)}})},_getPage:function(n){var t=this,i=t._getFormSerialize();return $.extend(i,t.pageParam,n),t.pageParam.pageIndex=i.pageIndex,g_api.ConnectLite(t.ProgramId,t._api.getpage,i,function(i){if(i.RESULT){var r=i.DATA.rel;n.Excel&&(t._downLoadFile.call(t,r),layer&&n.Index&&layer.close(n.Index))}})},_getOne:function(){var n=this,t=clone(n.ids);return typeof n.options.getOneParams=="function"&&(t=n.options.getOneParams(n)),g_api.ConnectLite(n.ProgramId,n._api.getone,t,function(t){var i,u,f,r;if(t.RESULT){if(n.data=t.DATA.rel,i=n.options.jsonStrKeys,i&&$.isArray(i))for(u in i)"clear,insert,remove".indexOf(u)===-1&&(f=i[u],r=n.data[f],typeof r=="string"&&r!==""&&(n.data[f]=JSON.parse(r)));typeof n.options.getOneBack=="function"?n.options.getOneBack(n,n.data):(n._setFormVal(n.data),n._setUEValues(n.data));setTimeout(function(){n._getPageVal()},500)}},function(){showMsg(i18next.t("message.GetOne_Error"),"error")})},_getInsert:function(t){var i=this,r=i._getFormSerialize();return r=i._getUEValues(r),typeof i.options.getInsertParams=="function"&&(r=i.options.getInsertParams(i,r)),r=$.extend(i.data,r),g_api.ConnectLite(i.ProgramId,i._api.insert,r,function(r){var u,f;r.RESULT?(n.bRequestStorage=!1,u=r.DATA.rel,typeof i.options.getInsertBack=="function"?i.options.getInsertBack(i,u,t):i.options.goBack?t==="add"?i.options.insertGo?showMsgAndGo(i18next.t("message.Insert_Success"),i.QueryPrgId):showMsg(i18next.t("message.Insert_Success"),"success"):showMsgAndGo(i18next.t("message.Insert_Success"),i.ProgramId,"?Action=Add"):(f=i._getParamsStr(i.ids,u),showMsgAndGo(i18next.t("message.Insert_Success"),i.ProgramId,"?Action=Upd"+f))):showMsg(i18next.t("message.Insert_Failed")+"
"+r.MSG,"error")},function(){showMsg(i18next.t("message.Insert_Error"),"error")})},_getUpdate:function(){var t=this,i=t._getFormSerialize();return i=t._getUEValues(i),typeof t.options.getUpdateParams=="function"&&(i=t.options.getUpdateParams(t,i)),i=$.extend(t.data,i,t.ids),g_api.ConnectLite(t.ProgramId,t._api.update,i,function(i){if(i.RESULT){n.bRequestStorage=!1;var r=i.DATA.rel;typeof t.options.getUpdateBack=="function"?t.options.getUpdateBack(t,r):t.options.updateGo?showMsgAndGo(i18next.t("message.Modify_Success"),t.QueryPrgId):(showMsg(i18next.t("message.Modify_Success"),"success"),n.bLeavePage&&setTimeout(function(){t._pageLeave()},1e3))}else showMsg(i18next.t("message.Modify_Failed")+"
"+i.MSG,"error")},function(){showMsg(i18next.t("message.Modify_Error"),"error")})},_getDelete:function(){var n=this,t=clone(n.ids);return typeof n.options.getDeleteParams=="function"&&(t=n.options.getDeleteParams(n)),g_api.ConnectLite(n.ProgramId,n._api.delete,t,function(t){if(t.RESULT){var i=t.DATA.rel;typeof n.options.getDeleteBack=="function"?n.options.getDeleteBack(n,i):n.options.deleteGo?showMsgAndGo(i18next.t("message.Delete_Success"),n.QueryPrgId):showMsg(i18next.t("message.Delete_Success"),"success")}else showMsg(i18next.t("message.Delete_Failed")+"
"+t.MSG,"error")},function(){showMsg(i18next.t("message.Delete_Error"),"error")})},_gridInsert:function(n){var t=this;return typeof t.options.getGridInsertParams=="function"&&(n=t.options.getGridInsertParams(t,n)),g_api.ConnectLite(t.ProgramId,t._api.ginsert,n,function(n){if(n.RESULT){var i=n.DATA.rel;typeof t.options.getGridInsertBack=="function"?t.options.getGridInsertBack(t,i):showMsg(i18next.t("message.Insert_Success"),"success")}else showMsg(i18next.t("message.Insert_Failed")+"
"+n.MSG,"error")},function(){showMsg(i18next.t("message.Insert_Error"),"error")})},_gridUpdate:function(n){var t=this;return typeof t.options.getGridUpdateParams=="function"&&(n=t.options.getGridUpdateParams(t,n)),g_api.ConnectLite(t.ProgramId,t._api.gupdate,n,function(n){if(n.RESULT){var i=n.DATA.rel;typeof t.options.getGridUpdateBack=="function"?t.options.getGridUpdateBack(t,i):showMsg(i18next.t("message.Modify_Success"),"success")}else showMsg(i18next.t("message.Modify_Failed")+"
"+n.MSG,"error")},function(){showMsg(i18next.t("message.Modify_Error"),"error")})},_gridDelete:function(n){var t=this;return typeof t.options.getGridDeleteParams=="function"&&(n=t.options.getGridDeleteParams(t)),g_api.ConnectLite(t.ProgramId,t._api.gdelete,n,function(n){if(n.RESULT){var i=n.DATA.rel;typeof t.options.getGridDeleteBack=="function"?t.options.getGridDeleteBack(t,i):showMsg(i18next.t("message.Delete_Success"),"success")}else showMsg(i18next.t("message.Delete_Failed")+"
"+n.MSG,"error")},function(){showMsg(i18next.t("message.Delete_Error"),"error")})},_getExcel:function(){},_pageInit:function(){var n=this,i,r;if(navigator.userAgent.match(/mobile/i)&&$(".ismobile").hide(),$("#tabs").length>0)$("#tabs").tabs().find("li").on("click",function(){var t=this;$("#tabs>ul>li").removeClass("active");$(this).addClass("active");typeof n.options.tabAction=="function"&&n.options.tabAction(t,n)});if(setTimeout(function(){$.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:!0,dateFormat:"yy/mm/dd"},$.datepicker.setDefaults($.datepicker.regional["zh-TW"]));$(".date-picker").length>0&&$(".date-picker").datepicker({changeYear:!0,changeMonth:!0,altFormat:"yyyy/MM/dd",onSelect:function(t,i){if(typeof n.options.onSelect=="function")n.options.onSelect(t,i)},afterInject:function(){}});$(".datetime-picker").length>0&&$(".datetime-picker").each(function(){var t=($(this).attr("hour")||9)*1,i=($(this).attr("minute")||0)*1,r=($(this).attr("stepminute")||15)*1;$(this).datetimepicker({changeYear:!0,changeMonth:!0,altFormat:"yyyy/MM/dd",timeFormat:"HH:mm",hour:t,minute:i,stepMinute:r,hourGrid:6,minuteGrid:15,onSelect:function(t,i){if(typeof n.options.onSelect=="function")n.options.onSelect(t,i)},afterInject:function(){}})});$(".time-picker").length>0&&$(".time-picker").each(function(){var t=($(this).attr("hour")||9)*1,i=($(this).attr("minute")||0)*1;$(this).timepicker({timeFormat:"HH:mm",hour:t,minute:i,minuteGrid:30,stepMinute:30,onSelect:function(t,i){if(typeof n.options.onSelect=="function")n.options.onSelect(t,i)}})})},1e3),$(".color-picker").length>0&&$(".color-picker").each(function(){var n=this;$(n).spectrum({color:"#000000",showInput:!0,className:"full-spectrum",showInitial:!0,showPalette:!0,showSelectionPalette:!0,maxPaletteSize:10,preferredFormat:"hex",hide:function(t){$(n).val(t.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)"]]})}),n._keyInput(),n._select2Init(),n._uniformInit(),n.options.goTop){i=$("
",{"class":"gotop",html:'',click:function(){return $("body,html").animate({scrollTop:0},120),!1}});$("body").append(i.hide());$(t).on("scroll",function(){var r=($(t).height(),$(this).scrollTop()),f=-45,u=n._getToolBar();r>0?i.fadeIn():i.fadeOut();r>35?(f=r-80,u.addClass("toolbar-float").removeClass("toolbar-fix")):u.removeClass("toolbar-float").addClass("toolbar-fix");u.css("margin-top",f+"px")})}if(n.ProgramId){if(r=g_ul.GetLang()||"zh-TW",n._setLang(r),n._getPageVal(),n._createPageTitle(),n.options.searchBar)var f=$("#searchbar").height(),e=$("",{"class":"fa fa-arrow-up slide-box",click:function(){$(this).hasClass("fa-arrow-up")?($(this).removeClass("fa-arrow-up").addClass("fa-arrow-down"),u.slideUp(),!n.Grid||(n.Grid.height=n.Grid.dfheight.replace("px","")*1+f+"px")):($(this).removeClass("fa-arrow-down").addClass("fa-arrow-up"),u.slideDown(),!n.Grid||(n.Grid.height=n.Grid.dfheight));!n.Grid||n.Grid.refresh();var t=$(".jsgrid-grid-body.slimscroll");t.parent().css("height",t.css("height"))}}),o=$("
",{"class":"col-sm-12 up-down-go"}).append(e),u=$("#searchbar").after(o);return n._reSetQueryPm(),n._getAuthority(n).done(function(){})}},_getAuthority:function(t){var i=this,r=i._getTopMod();return g_api.ConnectLite("Authorize","GetAuthorize",{ProgramID:i.ProgramId,TopModuleID:r},function(r){var s,f,l,a;if(r.RESULT){var v=r.DATA.rel,e=[],u={},o=null,h=i._getToolBar(),y=function(){h.ToolBar({btns:e,fncallback:i.initButtonHandler});i._transLang(h)},c=function(){$.fn.ToolBar?y():c()};$.each(v,function(n,t){if(t.AllowRight){var i=t.AllowRight.split("|");$.each(i,function(n,t){var i=$.trim(t);u[i.toLowerCase()]===undefined&&(u[i.toLowerCase()]=i)})}});u.upd||(delete u.save,delete u.readd);i.action==="upd"&&delete u.readd;i.action==="add"&&delete u.del;delete u.upd;delete u.view;for(s in u)if(f={},f.key=u[s],s==="leave")o=f,o.hotkey="ctrl + l";else{switch(s){case"qry":f.hotkey="enter";break;case"add":f.hotkey="ctrl + i";break;case"readd":f.hotkey="ctrl + r";break;case"save":f.hotkey="ctrl + s";break;case"del":f.hotkey="ctrl + d";break;case"clear":f.hotkey="ctrl + q"}e.push(f)}if(i.options.cusBtns.length>0&&e.push.apply(e,i.options.cusBtns),o&&e.push(o),c(),t.ProgramId.indexOf("_Upd")>-1)l=t._getAction(),l==="upd"&&parent.top.msgs.server.checkEdit(t.ProgramId,t.CheckId),t.form.find(":input,select").not("[data-type=select2]").change(function(){$(this).attr("data-trigger")||(n.bRequestStorage=!0)}),setTimeout(function(){t.form.find("[data-type=select2]").change(function(){$(this).attr("data-trigger")||(n.bRequestStorage=!0)})},3e3);else if(t.ProgramId.indexOf("_Qry")>-1&&parent.top.msgs.server.removeEditPrg(t.ProgramId.replace("_Qry","_Upd")),a=$("#Toolbar_Qry"),a.length>0){$("select").on("change",function(n,t){setTimeout(function(){t!=="clear"&&$("#Toolbar_Qry").click()},10)});$(':input[type="radio"],:input[type="checkbox"]').on("click",function(n,t){t!=="clear"&&$("#Toolbar_Qry").click()})}}})},_getTopMod:function(){var n=this,t="",r=g_db.GetDic("programList")||[],u=r.filter(function(t){return t.ModuleID===n.ProgramId})[0],i=function(r){var u=n._getParentMod(r);u.ParentID?i(u.ParentID):t=u.ModuleID};return i(u.ParentID),t},_getFormSerialize:function(n,t){var r=this,i={};return n=n||r.form,reFreshInput(n),i=t?n.serializeJSON():n.serializeObject(),reSetInput(n),i},_getParentMod:function(n){var i=this,t=g_db.GetDic("programList")||[];return t.filter(function(t){return t.ModuleID===n&&t.FilePath==="#"})[0]},_getPageVal:function(n){var t=this,i=n!==undefined?$("#"+n):t.form;t.currentPageValue=[];i.find(":input","textarea","select").each(function(){var n={};if(n.ID=this.id,n.Type=this.type,n.ID&&n.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":n.Value=$(this).val();break;case"checkbox":case"radio":n.Checked=this.checked;break;case"select-multiple":case"select-one":case"select":n.Value=$(this).val()||"";n.Html=$(this).html()}t.currentPageValue.push(n)}})},_getUrlParam:function(t){var r=new RegExp("(^|&)"+t+"=([^&]*)(&|$)"),i=n.location.search.substr(1).match(r);return i!==null?unescape(i[2]):null},_createPageTitle:function(){var t=this,f=$(".page-title"),i=g_db.GetItem("programList"),e="",r=[],o=function(n){var i=t._getParentMod(n);i.ModuleID&&r.unshift('
<\/span><\/a>