Commit af007d1b by Takumi Imai

#49764 ファイル整理

parent ec36c21c
/**
* common js of app(web).
* The following is written.
* 1.language
* 2.loading
* 3.alert
* 4.url
* 5.cms communication
* 6.check if user is logged in
*
* @since cms:1.4.3.2&1.4.3.3 web:1.0
*/
var CHK_Common = {};
CHK_Common.lang;
/**
* get lang code in local storage
* web gets lang form local storage
* but app gets lnag from session storage
*/
CHK_Common.setLangCodeWeb = function () {
let lang = CHK_Common.getLangWeb();
if (lang.split('-')[0] == CONSTANT.LANG.English) {
lang = CONSTANT.LANG.ENGLISH;
} else if (lang.split('-')[0] == CONSTANT.LANG.KOREA) {
lang = CONSTANT.LANG.KOREA;
} else {
lang = CONSTANT.LANG.JAPAN;
}
CHK_Common.lang = lang;
};
/**
* get lang in local storage
*
* @returns String pageLang
*/
CHK_Common.getLangWeb = function () {
if (!CHK_Common.lang) {
let pageLang;
if (localStorage[CONSTANT.LANG.SAVE_NAME]) {
pageLang = localStorage[CONSTANT.LANG.SAVE_NAME];
} else {
pageLang = (window.navigator.languages && window.navigator.languages[0]) || window.navigator.language || window.navigator.userLanguage || window.navigator.browserLanguage;
localStorage[CONSTANT.LANG.SAVE_NAME] = pageLang;
}
return pageLang;
} else {
return CHK_Common.lang;
}
return pageLang;
};
/**
* change lang of html
*/
CHK_Common.updateLang = function () {
$('.multi-lang').each(function () {
const key = $(this).attr('data-msg');
if (key) {
if ($(this).prop('tagName').toLowerCase() == 'input' && ($(this).attr('type') == 'text' || $(this).attr('type') == 'search')) {
const attr = $(this).attr('placeholder');
if (typeof attr !== 'undefined' && attr !== false) {
$(this).attr('placeholder', CHK_Common.getMsg(key));
} else {
$(this).val(CHK_Common.getMsg(key));
}
} else {
$(this).html(CHK_Common.getMsg(key));
}
}
});
};
/**
* get any lang msg from CHK_Common.msgMap
*
* @param String key
* @returns String msg
*/
CHK_Common.getMsg = function (key) {
const msg = CONSTANT.MSG_MAP[key];
if (!msg) {
return '';
}
return msg[CHK_Common.lang];
};
/**
* show loading dialog
* show msg by key
*
* @param {String} key
*/
CHK_Common.showLoading = function () {
$('#check_loading').dialog({
dialogClass: 'noTitleDialog ui-dialog-titlebar dialogNoBorder', //cssを追加する必要がある
autoOpen: false,
resizable: false,
modal: true,
width: '100%',
title: ' ',
open: function (e) {
$(e.target).parent().css('background-color', 'rgba(128,128,128)');
$(e.target).parent().css('position', 'absolute');
$(e.target).parent().css('left', '50%');
$(e.target).parent().css('top', '25vh');
$(e.target).parent().css('transform', 'translateX(-50%)');
$(e.target).parent().css('-webkit- transform', 'translateY(-50%) translateX(-50%)');
$(e.target).parent().children('.ui-dialog-buttonpane').css('background-color', 'rgba(128,128,128)').css('border', 'none');
},
close: function () {},
});
$('#check_loading').dialog('open');
};
/**
* close loading
*/
CHK_Common.closeLoading = function () {
if ($('#check_loading').hasClass('ui-dialog-content')) {
$('#check_loading').dialog('close');
}
};
/**
* show alert
*
* @param {String} msgCode
*/
CHK_Common.displayAlert = function (msgCode, title) {
$('#alertMsg').html(CHK_Common.getMsg(msgCode));
$('.alert-overlay').removeClass('d-none');
$('.alert-area').removeClass('d-none');
const positionY = $(document).scrollTop() + screen.height / 8;
const height = screen.height / 4;
$('.alert-overlay').css('height', screen.height);
$('.alert-area').css('top', positionY);
$('.alert-area').css('min-height', height);
$('body').css('overflow', 'hidden');
};
/**
* close alert
*/
CHK_Common.alertClose = function () {
$('.alert-overlay').addClass('d-none');
$('.alert-area').addClass('d-none');
$('body').css('overflow', 'visible');
};
/**
* go Url page With Current Params
*
* ios will remove all web types data when reopen webview
* need add common parameters: app, lang, debug, mobile_flg, isChat, ...
*
* @param {String} url
* @param {Object} params
*/
CHK_Common.goUrlWithCurrentParams = function (url, params) {
if (!params) {
location.href = CONSTANT.URL.BASE_WEB + url;
}
const mixParams = Object.assign(CHK_Common.getUrlParameter(), params);
if (url.includes('?')) {
location.href = url + '&' + new URLSearchParams(mixParams);
} else {
location.href = url + '?' + new URLSearchParams(mixParams);
}
};
/**
* get url parameter
*
*/
CHK_Common.getUrlParameter = function () {
var ret = {};
if (location.search) {
var param = {};
location.search
.substring(1)
.split('&')
.forEach(function (val) {
var kv = val.split('=');
param[kv[0]] = kv[1];
});
ret = param;
}
console.log({ ret: ret });
return ret;
};
/**
* get sid in local Storage
*
* @returns sid
*/
CHK_Common.getSid = function () {
return ClientData.userInfo_sid();
};
/**
* cms communication
*
* @param {String} url
* @param {Json} param
* @param {boolean} async
* @param {Object} callback
* @param {Object} errorCallback
*/
CHK_Common.cmsAjax = function (url, param, async = true, callback, errorCallback) {
var sysSettings = AVWEB.avwSysSetting();
if (url) {
$.ajax({
type: 'post',
url: url,
data: param,
dataType: 'json',
cache: false,
async: async,
crossDomain: true,
beforeSend: function (xhr) {
xhr.setRequestHeader('X-AGT-AppId', sysSettings.appName);
xhr.setRequestHeader('X-AGT-AppVersion', sysSettings.appVersion);
},
success: function (result) {
if (result.httpStatus == '200') {
if (callback) callback(result);
} else if (errorCallback) {
errorCallback();
} else if (result.httpStatus == '401') {
CHK_Common.goUrlWithCurrentParams(CONSTANT.PAGE_NAME.LOGIN);
} else if (result.httpStatus == '403') {
CHK_Common.closeLoading();
CHK_Common.displayAlert('errorOccurred');
} else {
CHK_Common.closeLoading();
CHK_Common.displayAlert(result.message);
}
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
if (errorCallback) {
errorCallback();
} else {
CHK_Common.closeLoading();
CHK_Common.displayAlert('errorCommunicationFailed');
}
},
});
} else {
if (errorCallback) {
errorCallback();
} else {
CHK_Common.closeLoading();
CHK_Common.displayAlert('errorOccurred');
}
}
};
/**
* Communicate with cms and post
*
* @param {String} url
* @param {Object} params
* @param {String} method
*/
CHK_Common.postCommunication = function (url, params, method = 'post') {
const form = document.createElement('form');
form.method = method;
form.action = url;
for (const key in params) {
if (params.hasOwnProperty(key)) {
const hiddenField = document.createElement('input');
hiddenField.type = 'hidden';
hiddenField.name = key;
hiddenField.value = params[key];
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
};
/**
* Check if user is logged in
*
* @param {boolean} async
*/
CHK_Common.checkAuth = function (async = true) {
let params = {};
params.sid = CHK_Common.getSid;
var urlPath = ClientData.userInfo_accountPath();
const url = CONSTANT.URL.BASE_CMS + urlPath + CONSTANT.URL.BASE_CHECKAPI + CONSTANT.URL.AUTH_SESSION;
CHK_Common.cmsAjax(url, params, async, null, function () {
CHK_Common.goUrlWithCurrentParams(CONSTANT.PAGE_NAME.LOGIN);
});
};
/**
* Common js for footer.
* ※Code is written mainly for dashboard and operationList.
*
* @since cms:1.4.3.2&1.4.3.3 web:1.0
*/
var FOOTER = {};
/**
* Change specific footer bottom to active.
*
* @param {String} bottomNavId
*/
FOOTER.activeBottomNav = function (bottomNavId) {
let elm = $('#' + bottomNavId);
if (typeof elm !== 'object') {
console.log('FOOTER.activeBottomNav:elm !== object:' + bottomNavId);
return;
}
elm.removeClass('text-secondary');
elm.addClass('text-primary');
let img = elm.find('img')[0];
if (img && img.getAttribute('data-src')) {
img.src = img.getAttribute('data-src');
}
};
/**
* change inactive all footer bottom
*/
FOOTER.inactiveAllBottomNav = function () {
let navs = document.getElementsByClassName('bottom-nav');
for (i = 0; i < navs.length; i++) {
navs[i].className = navs[i].className.replace('text-primary', 'text-secondary');
let img = navs[i].querySelector('img');
if (img && img.getAttribute('data-inactive-src')) {
img.src = img.getAttribute('data-inactive-src');
}
}
};
/**
* Go page of index.html.
* Store tab id in session for want to show display.
*
* @param {String} tabId
*/
FOOTER.goIndexPage = function (tabId) {
sessionStorage.activeTab = tabId;
COMMON.goUrlWithCurrentParams(DAFAULT_PAGE);
};
/**
* is the url index.html?
*/
FOOTER.isIndexPage = function () {
if (typeof location === 'object' && typeof location.pathname === 'string') {
if (location.pathname.includes(CONSTANT.PAGE_NAME.DEFAULT) == true) {
return true;
}
}
return false;
};
/**
* Initialize with any navigation
*
* @param {String} bottomNav
*/
FOOTER.activeInitBottomNav = function (bottomNav) {
FOOTER.inactiveAllBottomNav();
FOOTER.activeBottomNav(bottomNav);
};
/**
* Go page of dashboard
*/
FOOTER.goDashboard = function () {
sessionStorage.activeTab = CONSTANT.PAGE_TAB.DASHBOARD;
FOOTER.activeInitBottomNav('dashboardBottomNav');
if (FOOTER.isIndexPage()) {
CHK_TOP.showPage(CONSTANT.PAGE_NAME.DASHBOARD);
return;
}
FOOTER.goIndexPage(CONSTANT.PAGE_NAME.DASHBOARD);
};
/**
* Go page of operationList
*/
FOOTER.goOperationList = function () {
sessionStorage.activeTab = CONSTANT.PAGE_TAB.OPERATION_LIST;
FOOTER.activeInitBottomNav('operationListBottomNav');
if (FOOTER.isIndexPage()) {
CHK_TOP.showPage(CONSTANT.PAGE_NAME.OPERATION_LIST);
return;
}
FOOTER.goIndexPage(CONSTANT.PAGE_NAME.OPERATION_LIST);
};
/**
* Go to active tab when footer was loaded.
* If it is no active tab, go to page in settings.
*/
FOOTER.initFooter = function () {
$('#footer').load(CONSTANT.PAGE_NAME.FOOTER, function () {
if (typeof sessionStorage != 'undefined' && typeof sessionStorage.activeTab != 'undefined') {
if (sessionStorage.activeTab == CONSTANT.PAGE_TAB.DASHBOARD) {
FOOTER.goDashboard();
} else {
FOOTER.goOperationList();
}
return;
}
FOOTER.goOperationList();
// CHK.loadDashboardSetting(function() {
// if (CHK.dashboardSetting.dashboardHome) {
// FOOTER.goDashboard();
// } else {
// FOOTER.goOperationList();
// }
// });
});
};
...@@ -244,13 +244,13 @@ COMMON.cmsAjax = function (url, param, async = true, callback, errorCallback) { ...@@ -244,13 +244,13 @@ COMMON.cmsAjax = function (url, param, async = true, callback, errorCallback) {
} else if (errorCallback) { } else if (errorCallback) {
errorCallback(); errorCallback();
} else if (result.httpStatus == '401') { } else if (result.httpStatus == '401') {
CHK_Common.goUrlWithCurrentParams(CONSTANT.PAGE_NAME.LOGIN); COMMON.goUrlWithCurrentParams(CONSTANT.PAGE_NAME.LOGIN);
} else if (result.httpStatus == '403') { } else if (result.httpStatus == '403') {
CHK_Common.closeLoading(); COMMON.closeLoading();
CHK_Common.displayAlert('errorOccurred'); COMMON.displayAlert('errorOccurred');
} else { } else {
CHK_Common.closeLoading(); COMMON.closeLoading();
CHK_Common.displayAlert(result.message); COMMON.displayAlert(result.message);
} }
}, },
error: function (XMLHttpRequest, textStatus, errorThrown) { error: function (XMLHttpRequest, textStatus, errorThrown) {
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
<script src="/abvw/js/dashboardSetting/check-dashboard-setting.js?__UPDATEID__"></script> <script src="/abvw/js/dashboardSetting/check-dashboard-setting.js?__UPDATEID__"></script>
<script src="/abvw/js/dashboard/check-dashboard.js?__UPDATEID__"></script> <script src="/abvw/js/dashboard/check-dashboard.js?__UPDATEID__"></script>
<script src="/abvw/common/js/footer.js?__UPDATEID__"></script> <script src="/abvw/common/js/footer.js?__UPDATEID__"></script>
<script src="/abvw/common/js/appCommon/app.js?__UPDATEID__" defer></script> <script src="/abvw/common/js/app.js?__UPDATEID__" defer></script>
</head> </head>
......
...@@ -198,7 +198,7 @@ OL.createBreadcrumbList = function () { ...@@ -198,7 +198,7 @@ OL.createBreadcrumbList = function () {
$('#groupMasterPath').empty(); $('#groupMasterPath').empty();
if (typeof OL.operationGroupMasterId == 'undefined' || OL.operationGroupMasterId == 0) { if (typeof OL.operationGroupMasterId == 'undefined' || OL.operationGroupMasterId == 0) {
$('#groupMasterPath').append('<li class="breadcrumb-item"><a href="#" class="text-decoration-none text-dark">' + CHK_Common.getMsg('all') + '</a></li>'); $('#groupMasterPath').append('<li class="breadcrumb-item"><a href="#" class="text-decoration-none text-dark">' + COMMON.getMsg('all') + '</a></li>');
} else { } else {
let treeList = []; let treeList = [];
OL.createBreadcrumbTree(treeList, OL.operationGroupMasterId); OL.createBreadcrumbTree(treeList, OL.operationGroupMasterId);
...@@ -249,7 +249,7 @@ OL.createCategoryList = function () { ...@@ -249,7 +249,7 @@ OL.createCategoryList = function () {
}); });
//common //common
const noCategory = $("<dl id='groupMasterId_0' class='group-category-list'><dt><a onclick='OL.changeOperationGroupMaster(0);'>" + CHK_Common.getMsg('all') + '</a></dt></dl>'); const noCategory = $("<dl id='groupMasterId_0' class='group-category-list'><dt><a onclick='OL.changeOperationGroupMaster(0);'>" + COMMON.getMsg('all') + '</a></dt></dl>');
$('#category-menu').append(noCategory); $('#category-menu').append(noCategory);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment