diff options
Diffstat (limited to 'web/app')
-rw-r--r-- | web/app/Application.js | 7 | ||||
-rw-r--r-- | web/app/controller/Root.js | 2 | ||||
-rw-r--r-- | web/app/model/Notification.js | 33 | ||||
-rw-r--r-- | web/app/model/User.js | 2 | ||||
-rw-r--r-- | web/app/store/AllNotifications.js | 30 | ||||
-rw-r--r-- | web/app/store/Notifications.js | 25 | ||||
-rw-r--r-- | web/app/view/Notifications.js | 68 | ||||
-rw-r--r-- | web/app/view/NotificationsController.js | 79 | ||||
-rw-r--r-- | web/app/view/SettingsMenu.js | 3 | ||||
-rw-r--r-- | web/app/view/SettingsMenuController.js | 13 | ||||
-rw-r--r-- | web/app/view/Users.js | 5 | ||||
-rw-r--r-- | web/app/view/UsersController.js | 14 |
12 files changed, 278 insertions, 3 deletions
diff --git a/web/app/Application.js b/web/app/Application.js index dbbc7a594..5911579b8 100644 --- a/web/app/Application.js +++ b/web/app/Application.js @@ -32,7 +32,8 @@ Ext.define('Traccar.Application', { 'Attribute', 'Command', 'Event', - 'Geofence' + 'Geofence', + 'Notification' ], stores: [ @@ -52,7 +53,9 @@ Ext.define('Traccar.Application', { 'Languages', 'Events', 'Geofences', - 'AllGeofences' + 'AllGeofences', + 'Notifications', + 'AllNotifications' ], controllers: [ diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js index da3e3a2a9..ba23b90bf 100644 --- a/web/app/controller/Root.js +++ b/web/app/controller/Root.js @@ -144,7 +144,7 @@ Ext.define('Traccar.controller.Root', { break; } } - text = Strings.eventCommandResult + text; + text = Strings.eventCommandResult + ": " + text; } else { typeKey = 'event' + array[i].type.charAt(0).toUpperCase() + array[i].type.slice(1); text = Strings[typeKey]; diff --git a/web/app/model/Notification.js b/web/app/model/Notification.js new file mode 100644 index 000000000..9b4d61eb4 --- /dev/null +++ b/web/app/model/Notification.js @@ -0,0 +1,33 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.model.Notification', { + extend: 'Ext.data.Model', + identifier: 'negative', + + fields: [{ + name: 'id', + type: 'int' + }, { + name: 'type', + type: 'string' + }, { + name: 'userId', + type: 'int' + }, { + name: 'attributes' + }] +}); diff --git a/web/app/model/User.js b/web/app/model/User.js index 35b849187..352acc651 100644 --- a/web/app/model/User.js +++ b/web/app/model/User.js @@ -54,6 +54,8 @@ Ext.define('Traccar.model.User', { }, { name: 'twelveHourFormat', type: 'boolean' + }, { + name: 'attributes' }], proxy: { diff --git a/web/app/store/AllNotifications.js b/web/app/store/AllNotifications.js new file mode 100644 index 000000000..fed02b260 --- /dev/null +++ b/web/app/store/AllNotifications.js @@ -0,0 +1,30 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.store.AllNotifications', { + extend: 'Ext.data.Store', + model: 'Traccar.model.Notification', + + proxy: { + type: 'rest', + url: '/api/users/notifications', + extraParams: { + all: true + } + }, + sortOnLoad: true, + sorters: { property: 'type', direction : 'ASC' } +}); diff --git a/web/app/store/Notifications.js b/web/app/store/Notifications.js new file mode 100644 index 000000000..5dc8cb614 --- /dev/null +++ b/web/app/store/Notifications.js @@ -0,0 +1,25 @@ +/* + * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.store.Notifications', { + extend: 'Ext.data.Store', + model: 'Traccar.model.Notification', + + proxy: { + type: 'rest', + url: '/api/users/notifications' + } +}); diff --git a/web/app/view/Notifications.js b/web/app/view/Notifications.js new file mode 100644 index 000000000..211e5cd15 --- /dev/null +++ b/web/app/view/Notifications.js @@ -0,0 +1,68 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.view.Notifications', { + extend: 'Ext.grid.Panel', + xtype: 'notificationsView', + + requires: [ + 'Traccar.view.NotificationsController' + ], + + controller: 'notificationsController', + store: 'AllNotifications', + + selModel: { + selType: 'cellmodel', + }, + + columns: [{ + text: Strings.notificationType, + dataIndex: 'type', + flex: 1, + renderer: function (value) { + var typeKey = 'event' + value.charAt(0).toUpperCase() + value.slice(1); + return Strings[typeKey]; + } + }, { + text: Strings.notificationWeb, + dataIndex: 'attributes.web', + xtype: 'checkcolumn', + flex: 1, + listeners: { + beforeCheckChange: 'onBeforeCheckChange', + checkChange: 'onCheckChange' + }, + renderer: function (value, metaData, record) { + var fields = this.dataIndex.split('\.',2); + return (new Ext.ux.CheckColumn()).renderer(record.get(fields[0])[fields[1]], metaData); + } + }, { + text: Strings.notificationMail, + dataIndex: 'attributes.mail', + xtype: 'checkcolumn', + flex: 1, + listeners: { + beforeCheckChange: 'onBeforeCheckChange', + checkChange: 'onCheckChange' + }, + renderer: function (value, metaData, record) { + var fields = this.dataIndex.split('\.',2); + return (new Ext.ux.CheckColumn()).renderer(record.get(fields[0])[fields[1]], metaData); + } + }], + +}); diff --git a/web/app/view/NotificationsController.js b/web/app/view/NotificationsController.js new file mode 100644 index 000000000..a7c4290ca --- /dev/null +++ b/web/app/view/NotificationsController.js @@ -0,0 +1,79 @@ +/* + * Copyright 2016 Anton Tananaev (anton.tananaev@gmail.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +Ext.define('Traccar.view.NotificationsController', { + extend: 'Ext.app.ViewController', + alias: 'controller.notificationsController', + + init: function () { + this.userId = this.getView().user.getData().id; + this.getView().getStore().load({ + scope: this, + callback: function (records, operation, success) { + var notificationsStore = Ext.create('Traccar.store.Notifications'); + notificationsStore.load({ + params: { + userId: this.userId + }, + scope: this, + callback: function (records, operation, success) { + var i, index, attributes, storeRecord; + if (success) { + for (i = 0; i < records.length; i++) { + index = this.getView().getStore().find('type', records[i].getData().type); + attributes = records[i].getData().attributes; + storeRecord = this.getView().getStore().getAt(index); + storeRecord.set('attributes', attributes); + storeRecord.commit(); + } + } + } + }); + } + }); + }, + + onBeforeCheckChange: function (column, rowIndex, checked, eOpts) { + var fields = column.dataIndex.split('\.',2); + var record = this.getView().getStore().getAt(rowIndex); + var data = record.get(fields[0]); + if (!data[fields[1]]) { + data[fields[1]] = "true"; + } else { + delete data[fields[1]]; + } + record.set(fields[0], data); + 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: { + userId: this.userId, + type: record.getData().type, + attributes: record.getData().attributes + }, + callback: function (options, success, response) { + if (!success) { + Traccar.app.showError(response); + } + } + }); + } +}); diff --git a/web/app/view/SettingsMenu.js b/web/app/view/SettingsMenu.js index 704884928..70041bd63 100644 --- a/web/app/view/SettingsMenu.js +++ b/web/app/view/SettingsMenu.js @@ -48,6 +48,9 @@ Ext.define('Traccar.view.SettingsMenu', { handler: 'onUsersClick', reference: 'settingsUsersButton' }, { + text: Strings.sharedNotifications, + handler: 'onNotificationsClick', + }, { text: Strings.loginLogout, handler: 'onLogoutClick' }] diff --git a/web/app/view/SettingsMenuController.js b/web/app/view/SettingsMenuController.js index 48ae60aa5..45b159ccb 100644 --- a/web/app/view/SettingsMenuController.js +++ b/web/app/view/SettingsMenuController.js @@ -25,6 +25,7 @@ Ext.define('Traccar.view.SettingsMenuController', { 'Traccar.view.Users', 'Traccar.view.Groups', 'Traccar.view.Geofences', + 'Traccar.view.Notifications', 'Traccar.view.BaseWindow' ], @@ -77,6 +78,18 @@ Ext.define('Traccar.view.SettingsMenuController', { }).show(); }, + onNotificationsClick: function () { + var user = Traccar.app.getUser(); + Ext.create('Traccar.view.BaseWindow', { + title: Strings.sharedNotifications, + modal: false, + items: { + xtype: 'notificationsView', + user: user + } + }).show(); + }, + onLogoutClick: function () { Ext.create('Traccar.view.LoginController').logout(); } diff --git a/web/app/view/Users.js b/web/app/view/Users.js index b6301b38b..4abfff1ef 100644 --- a/web/app/view/Users.js +++ b/web/app/view/Users.js @@ -45,6 +45,11 @@ Ext.define('Traccar.view.Users', { disabled: true, handler: 'onGeofencesClick', reference: 'userGeofencesButton' + }, { + text: Strings.sharedNotifications, + disabled: true, + handler: 'onNotificationsClick', + reference: 'userNotificationsButton' }] }, diff --git a/web/app/view/UsersController.js b/web/app/view/UsersController.js index acba66b4d..e745ee04c 100644 --- a/web/app/view/UsersController.js +++ b/web/app/view/UsersController.js @@ -23,6 +23,7 @@ Ext.define('Traccar.view.UsersController', { 'Traccar.view.UserDevices', 'Traccar.view.UserGroups', 'Traccar.view.UserGeofences', + 'Traccar.view.Notifications', 'Traccar.view.BaseWindow' ], @@ -114,6 +115,18 @@ Ext.define('Traccar.view.UsersController', { }).show(); }, + onNotificationsClick: function () { + var user = this.getView().getSelectionModel().getSelection()[0]; + Ext.create('Traccar.view.BaseWindow', { + title: Strings.sharedNotifications, + modal: false, + items: { + xtype: 'notificationsView', + user: user + } + }).show(); + }, + onSelectionChange: function (selected) { var disabled = selected.length > 0; this.lookupReference('toolbarEditButton').setDisabled(disabled); @@ -121,5 +134,6 @@ Ext.define('Traccar.view.UsersController', { this.lookupReference('userDevicesButton').setDisabled(disabled); this.lookupReference('userGroupsButton').setDisabled(disabled); this.lookupReference('userGeofencesButton').setDisabled(disabled); + this.lookupReference('userNotificationsButton').setDisabled(disabled); } }); |