Commit 8112496c by NGUYEN HOANG SON

#50278 implement dashboard setting js

parent 18699cb8
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
<script src="/abvw/common/js/constant.js?__UPDATEID__"></script> <script src="/abvw/common/js/constant.js?__UPDATEID__"></script>
<script src="/abvw/common/js/common.js?__UPDATEID__"></script> <script src="/abvw/common/js/common.js?__UPDATEID__"></script>
<script src="/abvw/common/js/footer.js"></script> <script src="/abvw/common/js/footer.js"></script>
<script src="/abvw/js/dashboardSetting/check-dashboard-setting.js"></script> <script src="/abvw/js/dashboardSetting/dashboard-setting.js"></script>
</head> </head>
<body id="dashboard" onload="CHK_DashboardSetting.init();"> <body id="dashboard" onload="DashboardSetting.init();">
<header> <header>
<nav class="navbar navbar-dark bg-primary position-fixed fixed-top w-100"> <nav class="navbar navbar-dark bg-primary position-fixed fixed-top w-100">
<a href="javascript:CHK_DashboardSetting.goBack();" class="navbar-brand category-btn lht-0"> <a href="javascript:DashboardSetting.goBack();" class="navbar-brand category-btn lht-0">
<i class="fas fa-chevron-left fs-12 p-1"></i> <i class="fas fa-chevron-left fs-12 p-1"></i>
<span class="d-none d-md-inline fs-10"> <span class="d-none d-md-inline fs-10">
戻る 戻る
......
var CHK_DashboardSetting = {}; var DashboardSetting = {};
CHK_DashboardSetting.displayItems = [ DashboardSetting.displayItems = [
{ id: 'newReport', name: 'chk-new', enabled: true, title: '新規報告', msg: 'dashboardSettingNewRegistrationTitle' }, { id: 'newReport', name: 'newReport', enabled: true, title: '新規報告', msg: 'dashboardSettingNewRegistrationTitle' },
{ id: 'continousWork', name: 'chk-proccess', enabled: true, title: '工程作業', msg: 'dashboardSettingContinousWorkTitle' }, { id: 'continousWork', name: 'continousWork', enabled: true, title: '工程作業', msg: 'dashboardSettingContinousWorkTitle' },
{ id: 'reportWarning', name: 'chk-alert', enabled: true, title: '警告を含む作業', msg: 'dashboardSettingReportWarningTitle' }, { id: 'reportWarning', name: 'reportWarning', enabled: true, title: '警告を含む作業', msg: 'dashboardSettingReportWarningTitle' },
{ id: 'dashboardHome', name: 'chk-home', enabled: false, title: 'ダッシュボードをホーム画面にする', msg: 'dashboardSettingDashboardHomeTitle' }, { id: 'dashboardHome', name: 'dashboardHome', enabled: false, title: 'ダッシュボードをホーム画面にする', msg: 'dashboardSettingDashboardHomeTitle' },
]; ];
DashboardSetting.baseApiUrl = CONSTANT.URL.CMS.BASE + ClientData.userInfo_accountPath() + CONSTANT.URL.CMS.API.BASE + 'dashboardSetting/';
DashboardSetting.saveSettingApiUrl = DashboardSetting.baseApiUrl + 'saveSetting';
DashboardSetting.getSettingApiUrl = DashboardSetting.baseApiUrl + 'getAllSettingData';
DashboardSetting.dummySettingJson = {
newReport: 1,
continousWork: 1,
reportWarning: 1,
dashboardHome: 0,
}
DashboardSetting.getSettingData = function (callback) {
let param = {
sid: COMMON.getSid(),
};
COMMON.cmsAjax(DashboardSetting.getSettingApiUrl, param, false, function (json) {
if (callback) {
callback(json);
}
}, function() {
console.log('DashboardSetting.getSettingData error');
});
};
//CHK_DashboardSetting.displayItemsに設定されている情報から✓されている項目をhtml上に設定する //CHK_DashboardSetting.displayItemsに設定されている情報から✓されている項目をhtml上に設定する
CHK_DashboardSetting.loadSettings = function () { DashboardSetting.loadSettings = function (settings) {
CHK_DashboardSetting.displayItems.forEach(function (item) { DashboardSetting.displayItems.forEach(function (item) {
let enabled = CHK.dashboardSetting[item.id]; let enabled = settings[item.id];
if (typeof enabled !== 'undefined') { if (typeof enabled !== 'undefined') {
item.enabled = enabled; item.enabled = enabled;
let itemElement = $('#' + item.id); let itemElement = $('#' + item.id);
...@@ -23,26 +47,31 @@ CHK_DashboardSetting.loadSettings = function () { ...@@ -23,26 +47,31 @@ CHK_DashboardSetting.loadSettings = function () {
}; };
//CHK_DashboardSetting.displayItemsに設定を書き込む //CHK_DashboardSetting.displayItemsに設定を書き込む
CHK_DashboardSetting.saveSetting = function (key, enabled) { DashboardSetting.saveSetting = function (key, enabled) {
CHK_DashboardSetting.displayItems.forEach(function (item) { DashboardSetting.displayItems.forEach(function (item) {
if (item.id == key) { if (item.id == key) {
item.enabled = enabled; item.enabled = enabled;
} }
}); });
CHK.saveDashboardSetting(key, enabled); let param = {};
param.sid = COMMON.getSid();
param[key] = enabled;
COMMON.cmsAjax(DashboardSetting.saveSettingApiUrl, param, false, function (json) {
});
}; };
//CHK_DashboardSetting.displayItemsからhtmlに設定画面を表示する //CHK_DashboardSetting.displayItemsからhtmlに設定画面を表示する
CHK_DashboardSetting.initDisplays = function () { DashboardSetting.initDisplays = function () {
$('#displayItems tbody').empty(); $('#displayItems tbody').empty();
CHK_DashboardSetting.displayItems.forEach(function (item) { DashboardSetting.displayItems.forEach(function (item) {
var html = CHK_DashboardSetting.initHtmlItem(item); var html = DashboardSetting.initHtmlItem(item);
$('#displayItems tbody').append(html); $('#displayItems tbody').append(html);
}); });
}; };
//設定画面に表示するhtmlを生成する //設定画面に表示するhtmlを生成する
CHK_DashboardSetting.initHtmlItem = function (item) { DashboardSetting.initHtmlItem = function (item) {
var titleDiv = '<div class="font-weight-normal text-dark multi-lang" data-msg="' + item.msg + '">' + item.title + '</div>'; var titleDiv = '<div class="font-weight-normal text-dark multi-lang" data-msg="' + item.msg + '">' + item.title + '</div>';
var toggleClass = 'toggle'; var toggleClass = 'toggle';
if (item.enabled) { if (item.enabled) {
...@@ -55,7 +84,7 @@ CHK_DashboardSetting.initHtmlItem = function (item) { ...@@ -55,7 +84,7 @@ CHK_DashboardSetting.initHtmlItem = function (item) {
//設定画面でクリックされてた時の処理 //設定画面でクリックされてた時の処理
// //
CHK_DashboardSetting.bindToggleClick = function () { DashboardSetting.bindToggleClick = function () {
$('.toggle').on('click', function () { $('.toggle').on('click', function () {
$(this).toggleClass('checked'); $(this).toggleClass('checked');
var id = $(this).attr('id'); var id = $(this).attr('id');
...@@ -63,24 +92,21 @@ CHK_DashboardSetting.bindToggleClick = function () { ...@@ -63,24 +92,21 @@ CHK_DashboardSetting.bindToggleClick = function () {
if ($(this).hasClass('checked')) { if ($(this).hasClass('checked')) {
enabled = true; enabled = true;
} }
CHK_DashboardSetting.saveSetting(id, enabled); DashboardSetting.saveSetting(id, enabled);
}); });
}; };
//設定画面の初期処理 //設定画面の初期処理
CHK_DashboardSetting.init = function () { DashboardSetting.init = function () {
CHK.initCommon(); FOOTER.initFooter();
$('#footer').load('main-footer.html', function () { DashboardSetting.getSettingData(function (settings) {
FOOTER.activeDashboardBottomNav(); DashboardSetting.loadSettings(settings);
}); DashboardSetting.initDisplays();
CHK.loadDashboardSetting(function () { DashboardSetting.bindToggleClick();
CHK_DashboardSetting.loadSettings();
CHK_DashboardSetting.initDisplays();
CHK_DashboardSetting.bindToggleClick();
}); });
}; };
//戻るボタン //戻るボタン
CHK_DashboardSetting.goBack = function () { DashboardSetting.goBack = function () {
FOOTER.goDashboard(); FOOTER.goDashboard();
}; };
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