From 1972191b8802f3f9295cb151202c50d115a87f0e Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Mon, 27 Jun 2016 14:34:37 +0500 Subject: Do not use plane record fields to handle attributes nested fields --- web/app/view/NotificationsController.js | 41 +++++++++++++++------------------ 1 file changed, 18 insertions(+), 23 deletions(-) (limited to 'web/app/view/NotificationsController.js') diff --git a/web/app/view/NotificationsController.js b/web/app/view/NotificationsController.js index 7a609ef19..1638e4520 100644 --- a/web/app/view/NotificationsController.js +++ b/web/app/view/NotificationsController.js @@ -36,13 +36,7 @@ Ext.define('Traccar.view.NotificationsController', { index = this.getView().getStore().find('type', records[i].getData().type); attributes = records[i].getData().attributes; storeRecord = this.getView().getStore().getAt(index); - if (typeof attributes.web != 'undefined') { - storeRecord.set('web', attributes.web); - } - if (typeof attributes.mail != 'undefined') { - storeRecord.set('mail', attributes.mail); - } - + storeRecord.set('attributes', attributes); storeRecord.commit(); } } @@ -52,32 +46,33 @@ Ext.define('Traccar.view.NotificationsController', { }); }, - onCheckChange: function (column, rowIndex, checked, eOpts) { + onBeforeCheckChange: function (column, rowIndex, checked, eOpts) { var record = this.getView().getStore().getAt(rowIndex); - var web, mail; - var data = { - userId: this.userId, - type: record.getData().type, - attributes: {} - }; - web = record.getData().web; - if (typeof web != 'undefined' && web) { - data.attributes.web = "true"; - } - mail = record.getData().mail; - if (typeof mail != 'undefined' && mail) { - data.attributes.mail = "true"; + var attributes = record.getData().attributes; + if (!attributes[column.dataIndex]) { + attributes[column.dataIndex] = "true"; + } else { + delete attributes[column.dataIndex]; } + record.set('attributes', attributes); + record.commit(); + }, + + onCheckChange: function (column, rowIndex, checked, eOpts) { + var record = this.getView().getStore().getAt(rowIndex); Ext.Ajax.request({ scope: this, url: '/api/users/notifications', - jsonData: data, + jsonData: { + userId: this.userId, + type: record.getData().type, + attributes: record.getData().attributes + }, callback: function (options, success, response) { if (!success) { Traccar.app.showError(response); } } }); - } }); -- cgit v1.2.3