diff options
Diffstat (limited to 'web/app/view')
-rw-r--r-- | web/app/view/Notifications.js | 8 | ||||
-rw-r--r-- | web/app/view/NotificationsController.js | 41 |
2 files changed, 26 insertions, 23 deletions
diff --git a/web/app/view/Notifications.js b/web/app/view/Notifications.js index 8efebd038..2ae980afe 100644 --- a/web/app/view/Notifications.js +++ b/web/app/view/Notifications.js @@ -43,7 +43,11 @@ Ext.define('Traccar.view.Notifications', { xtype: 'checkcolumn', flex: 1, listeners: { + beforeCheckChange: 'onBeforeCheckChange', checkChange: 'onCheckChange' + }, + renderer: function (value, metaData, record) { + return (new Ext.ux.CheckColumn()).renderer(record.getData().attributes.web, metaData); } }, { text: Strings.notificationMail, @@ -51,7 +55,11 @@ Ext.define('Traccar.view.Notifications', { xtype: 'checkcolumn', flex: 1, listeners: { + beforeCheckChange: 'onBeforeCheckChange', checkChange: 'onCheckChange' + }, + renderer: function (value, metaData, record) { + return (new Ext.ux.CheckColumn()).renderer(record.getData().attributes.mail, metaData); } }], 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); } } }); - } }); |