aboutsummaryrefslogtreecommitdiff
path: root/web/app/view
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-06-28 14:09:44 +1200
committerGitHub <noreply@github.com>2016-06-28 14:09:44 +1200
commit7327681f0bd2338f9c8ee3ea1b4a19dcc5f0de48 (patch)
tree0ea99ab937fbae96b35cc5dc62edbc74594af9e4 /web/app/view
parent67f46c80d3b5e34440a2644f52b81dddfbaba5fa (diff)
parent61b2486353c742afe6214f0a0c5c2e9956ea3b97 (diff)
downloadtrackermap-server-7327681f0bd2338f9c8ee3ea1b4a19dcc5f0de48.tar.gz
trackermap-server-7327681f0bd2338f9c8ee3ea1b4a19dcc5f0de48.tar.bz2
trackermap-server-7327681f0bd2338f9c8ee3ea1b4a19dcc5f0de48.zip
Merge pull request #2052 from Abyss777/master
Notifications via email
Diffstat (limited to 'web/app/view')
-rw-r--r--web/app/view/Notifications.js68
-rw-r--r--web/app/view/NotificationsController.js79
-rw-r--r--web/app/view/SettingsMenu.js3
-rw-r--r--web/app/view/SettingsMenuController.js13
-rw-r--r--web/app/view/Users.js5
-rw-r--r--web/app/view/UsersController.js14
6 files changed, 182 insertions, 0 deletions
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);
}
});