Commit 52572808 by NGUYEN HOANG SON

implement apply dashboard settings json

parent 5e8b2296
...@@ -134,19 +134,19 @@ ...@@ -134,19 +134,19 @@
<tbody> <tbody>
<tr> <tr>
<th class="fs-9 p-2 text-secondary multi-lang" data-msg="dashboardSettingNewReportTitle">新規報告</th> <th class="fs-9 p-2 text-secondary multi-lang" data-msg="dashboardSettingNewReportTitle">新規報告</th>
<td class="p-2"><div id="newReport" class="toggle ml-auto"><input type="checkbox" name="chk-new"></div></td> <td class="p-2"><div id="settingNewReport" data-key="newReport" class="toggle ml-auto"><input type="checkbox" name="chk-new"></div></td>
</tr> </tr>
<tr> <tr>
<th class="fs-9 p-2 text-secondary multi-lang" data-msg="dashboardSettingContinousWorkTitle">工程作業</th> <th class="fs-9 p-2 text-secondary multi-lang" data-msg="dashboardSettingContinousWorkTitle">工程作業</th>
<td class="p-2"><div id="continousWork" class="toggle ml-auto"><input type="checkbox" name="chk-proccess"></div></td> <td class="p-2"><div id="settingContinousWork" data-key="continousWork" class="toggle ml-auto"><input type="checkbox" name="chk-proccess"></div></td>
</tr> </tr>
<tr> <tr>
<th class="fs-9 p-2 text-secondary multi-lang" data-msg="dashboardSettingReportWarningTitle">警告を含む作業</th> <th class="fs-9 p-2 text-secondary multi-lang" data-msg="dashboardSettingReportWarningTitle">警告を含む作業</th>
<td class="p-2"><div id="reportWarning" class="toggle ml-auto"><input type="checkbox" name="chk-alert"></div></td> <td class="p-2"><div id="settingReportWarning" data-key="reportWarning" class="toggle ml-auto"><input type="checkbox" name="chk-alert"></div></td>
</tr> </tr>
<tr> <tr>
<th class="fs-9 p-2 text-secondary multi-lang" data-msg="dashboardSettingDashboardHomeTitle">ダッシュボードをホーム画面にする</th> <th class="fs-9 p-2 text-secondary multi-lang" data-msg="dashboardSettingDashboardHomeTitle">ダッシュボードをホーム画面にする</th>
<td class="p-2"><div id="dashboardHome" class="toggle ml-auto"><input type="checkbox" name="chk-home"></div></td> <td class="p-2"><div id="settingDashboardHome" data-key="dashboardHome" class="toggle ml-auto"><input type="checkbox" name="chk-home"></div></td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
......
var DashboardSetting = {}; var DashboardSetting = {};
DashboardSetting.elementItems = [ DashboardSetting.elementItems = {
{ id: 'newReport', name: 'chk-new', enabled: true }, newReport: { id: 'settingNewReport', name: 'chk-new', enabled: true },
{ id: 'continousWork', name: 'chk-proccess', enabled: true }, continousWork: { id: 'settingContinousWork', name: 'chk-proccess', enabled: true },
{ id: 'reportWarning', name: 'chk-alert', enabled: true }, reportWarning: { id: 'settingReportWarning', name: 'chk-alert', enabled: true },
{ id: 'dashboardHome', name: 'chk-home', enabled: false }, dashboardHome: { id: 'settingDashboardHome', 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/';
DashboardSetting.saveSettingApiUrl = DashboardSetting.baseApiUrl + 'saveSetting'; DashboardSetting.saveSettingApiUrl = DashboardSetting.baseApiUrl + 'saveSetting';
DashboardSetting.getSettingApiUrl = DashboardSetting.baseApiUrl + 'getAllSettingData'; DashboardSetting.getSettingApiUrl = DashboardSetting.baseApiUrl + 'getAllSettingData';
DashboardSetting.dummySettingJson = { DashboardSetting.defaultSettingJson = {
newReport: 1, newReport: 1,
continousWork: 1, continousWork: 1,
reportWarning: 1, reportWarning: 1,
...@@ -27,31 +27,35 @@ DashboardSetting.getSettingData = function (callback) { ...@@ -27,31 +27,35 @@ DashboardSetting.getSettingData = function (callback) {
} }
}, function() { }, function() {
console.log('DashboardSetting.getSettingData error'); console.log('DashboardSetting.getSettingData error');
if (callback) {
callback(DashboardSetting.defaultSettingJson);
}
}); });
}; };
DashboardSetting.applySettings = function (settings) { DashboardSetting.applySettings = function (settings) {
DashboardSetting.elementItems.forEach(function (item) { for (const key in settings) {
let enabled = settings[item.id]; const enabled = settings[key];
if (typeof enabled !== 'undefined') { if (DashboardSetting.elementItems.hasOwnProperty(key)) {
item.enabled = enabled; const elementItem = DashboardSetting.elementItems[key];
let itemElement = $('#' + item.id); elementItem.enabled = enabled;
if (item.enabled) { let element = $('#' + elementItem.id);
itemElement.addClass('checked'); if (element) {
if (enabled) {
element.addClass('checked');
} else { } else {
itemElement.removeClass('checked'); element.removeClass('checked');
}
}
} }
} }
});
}; };
//CHK_DashboardSetting.displayItemsに設定を書き込む
DashboardSetting.saveSetting = function (key, enabled) { DashboardSetting.saveSetting = function (key, enabled) {
DashboardSetting.elementItems.forEach(function (item) { if (DashboardSetting.elementItems.hasOwnProperty(key)) {
if (item.id == key) { const elementItem = DashboardSetting.elementItems[key];
item.enabled = enabled; elementItem.enabled = enabled;
} }
});
let param = {}; let param = {};
param.sid = COMMON.getSid(); param.sid = COMMON.getSid();
param[key] = enabled; param[key] = enabled;
...@@ -61,16 +65,15 @@ DashboardSetting.saveSetting = function (key, enabled) { ...@@ -61,16 +65,15 @@ DashboardSetting.saveSetting = function (key, enabled) {
}; };
//設定画面でクリックされてた時の処理 //設定画面でクリックされてた時の処理
//
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'); const key = $(this).attr('data-key');
// var enabled = false; var enabled = false;
// if ($(this).hasClass('checked')) { if ($(this).hasClass('checked')) {
// enabled = true; enabled = true;
// } }
// DashboardSetting.saveSetting(id, enabled); DashboardSetting.saveSetting(key, enabled);
}); });
}; };
......
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