Commit 280de0b5 by NGUYEN HOANG SON

refactor code : dashboard setting js

parent 4126f0f5
/**
* Dashboard Setting js in dashboard.html
*
* @since 1.0 check web
*/
var DashboardSetting = {}; var DashboardSetting = {};
DashboardSetting.elementItems = { DashboardSetting.elementItems = {
newReport: { id: 'settingNewReport', name: 'chk-new', enabled: true }, newReport: { id: 'settingNewReport', name: 'chk-new', enabled: true },
...@@ -7,8 +12,6 @@ DashboardSetting.elementItems = { ...@@ -7,8 +12,6 @@ DashboardSetting.elementItems = {
}; };
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.getSettingApiUrl = DashboardSetting.baseApiUrl + 'getAllSettingData';
DashboardSetting.defaultSettingJson = { DashboardSetting.defaultSettingJson = {
newReport: 1, newReport: 1,
...@@ -21,7 +24,8 @@ DashboardSetting.getSettingData = function (callback) { ...@@ -21,7 +24,8 @@ DashboardSetting.getSettingData = function (callback) {
let param = { let param = {
sid: COMMON.getSid(), sid: COMMON.getSid(),
}; };
COMMON.cmsAjax(DashboardSetting.getSettingApiUrl, param, false, function (json) { const url = DashboardSetting.baseApiUrl + 'getAllSettingData';
COMMON.cmsAjax(url, param, false, function (json) {
if (callback) { if (callback) {
callback(json); callback(json);
} }
...@@ -37,7 +41,7 @@ DashboardSetting.applySettings = function (settings) { ...@@ -37,7 +41,7 @@ DashboardSetting.applySettings = function (settings) {
for (const key in settings) { for (const key in settings) {
const enabled = settings[key]; const enabled = settings[key];
if (DashboardSetting.elementItems.hasOwnProperty(key)) { if (DashboardSetting.elementItems.hasOwnProperty(key)) {
const elementItem = DashboardSetting.elementItems[key]; let elementItem = DashboardSetting.elementItems[key];
elementItem.enabled = enabled; elementItem.enabled = enabled;
let element = $('#' + elementItem.id); let element = $('#' + elementItem.id);
if (element) { if (element) {
...@@ -58,7 +62,8 @@ DashboardSetting.saveSetting = function () { ...@@ -58,7 +62,8 @@ DashboardSetting.saveSetting = function () {
const element = DashboardSetting.elementItems[key]; const element = DashboardSetting.elementItems[key];
param[key] = element.enabled; param[key] = element.enabled;
} }
COMMON.cmsAjax(DashboardSetting.saveSettingApiUrl, param, false, function (json) { const url = DashboardSetting.baseApiUrl + 'saveSetting';
COMMON.cmsAjax(url, param, false, function (json) {
DashboardSetting.closeModal(); DashboardSetting.closeModal();
}, function() { }, function() {
console.log('DashboardSetting.saveSetting error'); console.log('DashboardSetting.saveSetting error');
...@@ -66,7 +71,6 @@ DashboardSetting.saveSetting = function () { ...@@ -66,7 +71,6 @@ DashboardSetting.saveSetting = function () {
}); });
}; };
//設定画面でクリックされてた時の処理
DashboardSetting.bindToggleClick = function () { DashboardSetting.bindToggleClick = function () {
$('.toggle').on('click', function () { $('.toggle').on('click', function () {
$(this).toggleClass('checked'); $(this).toggleClass('checked');
...@@ -82,7 +86,6 @@ DashboardSetting.bindToggleClick = function () { ...@@ -82,7 +86,6 @@ DashboardSetting.bindToggleClick = function () {
}); });
}; };
//設定画面の初期処理
DashboardSetting.init = function () { DashboardSetting.init = function () {
DashboardSetting.getSettingData(function (settings) { DashboardSetting.getSettingData(function (settings) {
DashboardSetting.applySettings(settings); DashboardSetting.applySettings(settings);
......
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