Commit 5e8b2296 by NGUYEN HOANG SON

implement dashboard setting js

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