Commit cd4748af by NGUYEN HOANG SON

implement map response json format

parent 2fa4a9a8
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</tr> </tr>
<tr> <tr>
<th class="fs-9 p-2 text-secondary lang" lang="workWithWarningsTitle"></th> <th class="fs-9 p-2 text-secondary lang" lang="workWithWarningsTitle"></th>
<td class="p-2"><div id="settingReportWarning" data-key="reportWarning" class="toggle ml-auto"><input type="checkbox" name="chk-alert"></div></td> <td class="p-2"><div id="settingWarningReport" data-key="warningReport" class="toggle ml-auto"><input type="checkbox" name="chk-alert"></div></td>
</tr> </tr>
<tr> <tr>
<th class="fs-9 p-2 text-secondary lang" lang="makeDashboardAsHome"></th> <th class="fs-9 p-2 text-secondary lang" lang="makeDashboardAsHome"></th>
......
...@@ -8,7 +8,7 @@ var DASHBOARD = {}; ...@@ -8,7 +8,7 @@ var DASHBOARD = {};
DASHBOARD.pickupItems = [ DASHBOARD.pickupItems = [
{id: 'newReport', href: "javascript:DASHBOARD.goPickup('newReport');", count: 0, enabled: true, img: {src: '../common/img/dahboard_icon_new.svg'}, msg: 'newRegistrationTitle'}, {id: 'newReport', href: "javascript:DASHBOARD.goPickup('newReport');", count: 0, enabled: true, img: {src: '../common/img/dahboard_icon_new.svg'}, msg: 'newRegistrationTitle'},
{id: 'continousWork', href: "javascript:DASHBOARD.goPickup('continousWork');", count: 0, enabled: true, img: {src: '../common/img/dahboard_icon_proccess.svg'}, msg: 'continousWorkTitle'}, {id: 'continousWork', href: "javascript:DASHBOARD.goPickup('continousWork');", count: 0, enabled: true, img: {src: '../common/img/dahboard_icon_proccess.svg'}, msg: 'continousWorkTitle'},
{id: 'reportWarning', href: "javascript:DASHBOARD.goPickup('reportWarning');", count: 0, enabled: true, img: {src: '../common/img/dahboard_icon_alert.svg'}, msg: 'reportWarningTitle' }, {id: 'warningReport', href: "javascript:DASHBOARD.goPickup('reportWarning');", count: 0, enabled: true, img: {src: '../common/img/dahboard_icon_alert.svg'}, msg: 'reportWarningTitle' },
]; ];
/** comunication dashboard configuration */ /** comunication dashboard configuration */
...@@ -23,7 +23,7 @@ DASHBOARD.communicationItems = [ ...@@ -23,7 +23,7 @@ DASHBOARD.communicationItems = [
DASHBOARD.defaultDashboard = { DASHBOARD.defaultDashboard = {
newReport: 0, newReport: 0,
continousWork: 0, continousWork: 0,
reportWarning: 0, warningReport: 0,
pushMesage: 0, pushMesage: 0,
} }
......
...@@ -13,25 +13,51 @@ DashboardSetting.changeSettingCallback = function() {}; ...@@ -13,25 +13,51 @@ DashboardSetting.changeSettingCallback = function() {};
DashboardSetting.elementItems = { DashboardSetting.elementItems = {
newReport: { id: 'settingNewReport', name: 'chk-new', enabled: true }, newReport: { id: 'settingNewReport', name: 'chk-new', enabled: true },
continousWork: { id: 'settingContinousWork', name: 'chk-proccess', enabled: true }, continousWork: { id: 'settingContinousWork', name: 'chk-proccess', enabled: true },
reportWarning: { id: 'settingReportWarning', name: 'chk-alert', enabled: true }, warningReport: { id: 'settingWarningReport', name: 'chk-alert', enabled: true },
dashboardHome: { id: 'settingDashboardHome', 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/';
/** /**
* default setting JSON * default setting
*/ */
DashboardSetting.defaultSettingJson = { DashboardSetting.defaultSetting = {
newReport: 1, newReport: 1,
continousWork: 1, continousWork: 1,
reportWarning: 1, warningReport: 1,
dashboardHome: 0, dashboardHome: 0,
} }
/** dummy setting json reponse */
DashboardSetting.dummySettingJson = {
dashboardSettingList: [
{
"id": 1,
"settingName": "New Report",
"settingValue": 1
},
{
"id": 2,
"settingName": "Continous Work",
"settingValue": 1
},
{
"id": 3,
"settingName": "Warning Report",
"settingValue": 1
},
{
"id": 4,
"settingName": "Dashboard Home",
"settingValue": 0
}
],
}
/** /**
* get setting data from cms * get setting data from cms
* @param {function} callback * @param {function} callback - callback with settings
*/ */
DashboardSetting.getSettingData = function (callback) { DashboardSetting.getSettingData = function (callback) {
let param = { let param = {
...@@ -39,14 +65,27 @@ DashboardSetting.getSettingData = function (callback) { ...@@ -39,14 +65,27 @@ DashboardSetting.getSettingData = function (callback) {
}; };
const url = DashboardSetting.baseApiUrl; const url = DashboardSetting.baseApiUrl;
COMMON.cmsAjax(url, param, false, function (json) { COMMON.cmsAjax(url, param, false, function (json) {
let settings = {};
//map id with key when save setting
const mapKeys = {
1: 'newReport',
2: 'continousWork',
3: 'warningReport',
4: 'dashboardHome'
};
if (json && json.dashboardSettingList) {
for (const item of json.dashboardSettingList) {
if (mapKeys.hasOwnProperty(item.id)) {
const settingKey = mapKeys[item.id];
settings[settingKey] = item.settingValue;
}
}
}
if (callback) { if (callback) {
callback(json); callback(settings);
} }
}, function() { }, function() {
console.log('DashboardSetting.getSettingData error'); console.log('DashboardSetting.getSettingData error');
if (callback) {
callback(DashboardSetting.defaultSettingJson);
}
}); });
}; };
...@@ -81,7 +120,7 @@ DashboardSetting.saveSetting = function () { ...@@ -81,7 +120,7 @@ DashboardSetting.saveSetting = function () {
param.sid = COMMON.getSid(); param.sid = COMMON.getSid();
for (const key in DashboardSetting.elementItems) { for (const key in DashboardSetting.elementItems) {
const element = DashboardSetting.elementItems[key]; const element = DashboardSetting.elementItems[key];
param[key] = element.enabled; param[key] = element.enabled ? 1 : 0;
} }
const url = CONSTANT.URL.CMS.BASE + ClientData.userInfo_accountPath() + CONSTANT.URL.CMS.API.BASE + 'saveDashboardSetting/'; const url = CONSTANT.URL.CMS.BASE + ClientData.userInfo_accountPath() + CONSTANT.URL.CMS.API.BASE + 'saveDashboardSetting/';
COMMON.cmsAjax(url, param, false, function (json) { COMMON.cmsAjax(url, param, false, function (json) {
......
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