Commit 5e8b2296 by NGUYEN HOANG SON

implement dashboard setting js

parent 9a266c6c
......@@ -26,7 +26,7 @@
<script type="text/javascript" src="../js/dashboard/dashboard.js"></script>
</head>
<body>
<body onload="DASHBOARD.init();">
<!-- header -->
<?php include('common/header.html');?>
......@@ -152,7 +152,7 @@
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary multi-lang" data-msg="dashboardSettingSaveButton" onclick="DashboardSetting.save();">保存</button>
<button type="button" class="btn btn-primary multi-lang" data-msg="dashboardSettingSaveButton" onclick="DashboardSetting.onClickSave();">保存</button>
<button type="button" class="btn btn-tertiary multi-lang" data-msg="dashboardSettingCancelButton" data-dismiss="modal">キャンセル</button>
</div>
</div>
......
var DashboardSetting = {};
DashboardSetting.displayItems = [
{ id: 'newReport', name: 'newReport', enabled: true, title: '新規報告', msg: 'dashboardSettingNewRegistrationTitle' },
{ id: 'continousWork', name: 'continousWork', enabled: true, title: '工程作業', msg: 'dashboardSettingContinousWorkTitle' },
{ id: 'reportWarning', name: 'reportWarning', enabled: true, title: '警告を含む作業', msg: 'dashboardSettingReportWarningTitle' },
{ id: 'dashboardHome', name: 'dashboardHome', enabled: false, title: 'ダッシュボードをホーム画面にする', msg: 'dashboardSettingDashboardHomeTitle' },
DashboardSetting.elementItems = [
{ id: 'newReport', name: 'chk-new', enabled: true },
{ id: 'continousWork', name: 'chk-proccess', enabled: true },
{ id: 'reportWarning', name: 'chk-alert', enabled: true },
{ id: 'dashboardHome', name: 'chk-home', enabled: false },
];
DashboardSetting.baseApiUrl = CONSTANT.URL.CMS.BASE + ClientData.userInfo_accountPath() + CONSTANT.URL.CMS.API.BASE + 'dashboardSetting/';
......@@ -30,9 +30,8 @@ DashboardSetting.getSettingData = function (callback) {
});
};
//CHK_DashboardSetting.displayItemsに設定されている情報から✓されている項目をhtml上に設定する
DashboardSetting.loadSettings = function (settings) {
DashboardSetting.displayItems.forEach(function (item) {
DashboardSetting.applySettings = function (settings) {
DashboardSetting.elementItems.forEach(function (item) {
let enabled = settings[item.id];
if (typeof enabled !== 'undefined') {
item.enabled = enabled;
......@@ -48,7 +47,7 @@ DashboardSetting.loadSettings = function (settings) {
//CHK_DashboardSetting.displayItemsに設定を書き込む
DashboardSetting.saveSetting = function (key, enabled) {
DashboardSetting.displayItems.forEach(function (item) {
DashboardSetting.elementItems.forEach(function (item) {
if (item.id == key) {
item.enabled = enabled;
}
......@@ -61,56 +60,28 @@ DashboardSetting.saveSetting = function (key, enabled) {
});
};
//CHK_DashboardSetting.displayItemsからhtmlに設定画面を表示する
DashboardSetting.initDisplays = function () {
$('#displayItems tbody').empty();
DashboardSetting.displayItems.forEach(function (item) {
var html = DashboardSetting.initHtmlItem(item);
$('#displayItems tbody').append(html);
});
};
//設定画面に表示するhtmlを生成する
DashboardSetting.initHtmlItem = function (item) {
var titleDiv = '<div class="font-weight-normal text-dark multi-lang" data-msg="' + item.msg + '">' + item.title + '</div>';
var toggleClass = 'toggle';
if (item.enabled) {
toggleClass += ' checked';
}
var toggleDiv = '<div id="' + item.id + '" class="' + toggleClass + '"><input type="checkbox" name="' + item.name + '" /></div>';
var html = $('<tr>' + '<th>' + titleDiv + '</th>' + '<td>' + toggleDiv + '</td>' + '</tr>');
return html;
};
//設定画面でクリックされてた時の処理
//
DashboardSetting.bindToggleClick = function () {
$('.toggle').on('click', function () {
$(this).toggleClass('checked');
var id = $(this).attr('id');
var enabled = false;
if ($(this).hasClass('checked')) {
enabled = true;
}
DashboardSetting.saveSetting(id, enabled);
// var id = $(this).attr('id');
// var enabled = false;
// if ($(this).hasClass('checked')) {
// enabled = true;
// }
// DashboardSetting.saveSetting(id, enabled);
});
};
//設定画面の初期処理
DashboardSetting.init = function () {
FOOTER.initFooter();
DashboardSetting.getSettingData(function (settings) {
DashboardSetting.loadSettings(settings);
DashboardSetting.initDisplays();
DashboardSetting.bindToggleClick();
DashboardSetting.applySettings(settings);
});
DashboardSetting.bindToggleClick();
};
//戻るボタン
DashboardSetting.goBack = function () {
FOOTER.goDashboard();
};
DashboardSetting.save = function () {
DashboardSetting.onClickSave = function () {
console.log("DashboardSetting.save");
};
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