aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-01-30 14:08:04 +0500
committerAbyss777 <abyss@fox5.ru>2017-01-30 14:08:04 +0500
commite774dedf3497f640af5a686723a0f5cf0ea42b93 (patch)
tree331507d9f02a1e25322ac9aa3af490b4b413de62
parentd1dd9f84e819d70154861ac2487f902da12885ed (diff)
downloadtrackermap-web-e774dedf3497f640af5a686723a0f5cf0ea42b93.tar.gz
trackermap-web-e774dedf3497f640af5a686723a0f5cf0ea42b93.tar.bz2
trackermap-web-e774dedf3497f640af5a686723a0f5cf0ea42b93.zip
Implement base controller for windows with EditToolbar
-rw-r--r--web/app/view/AttributeAliasesController.js36
-rw-r--r--web/app/view/AttributesController.js52
-rw-r--r--web/app/view/CalendarsController.js53
-rw-r--r--web/app/view/DevicesController.js51
-rw-r--r--web/app/view/EditToolbarController.js67
-rw-r--r--web/app/view/GeofencesController.js49
-rw-r--r--web/app/view/GroupsController.js46
-rw-r--r--web/app/view/UsersController.js37
8 files changed, 108 insertions, 283 deletions
diff --git a/web/app/view/AttributeAliasesController.js b/web/app/view/AttributeAliasesController.js
index 1cbb735f..f5348301 100644
--- a/web/app/view/AttributeAliasesController.js
+++ b/web/app/view/AttributeAliasesController.js
@@ -17,7 +17,7 @@
*/
Ext.define('Traccar.view.AttributeAliasesController', {
- extend: 'Ext.app.ViewController',
+ extend: 'Traccar.view.EditToolbarController',
alias: 'controller.attributeAliases',
requires: [
@@ -25,6 +25,10 @@ Ext.define('Traccar.view.AttributeAliasesController', {
'Traccar.model.AttributeAlias'
],
+ objectModel: 'Traccar.model.AttributeAlias',
+ objectDialog: 'Traccar.view.AttributeAliasDialog',
+ removeTitle: Strings.sharedAttributeAlias,
+
init: function () {
var manager = Traccar.app.getUser().get('admin') || Traccar.app.getUser().get('userLimit') > 0;
this.lookupReference('deviceField').setStore(manager ? 'AllDevices' : 'Devices');
@@ -49,36 +53,6 @@ Ext.define('Traccar.view.AttributeAliasesController', {
dialog.show();
},
- onEditClick: function () {
- var attributeAlias, dialog;
- attributeAlias = this.getView().getSelectionModel().getSelection()[0];
- attributeAlias.store = Ext.getStore('AttributeAliases');
- dialog = Ext.create('Traccar.view.AttributeAliasDialog');
- dialog.down('form').loadRecord(attributeAlias);
- dialog.show();
- },
-
- onRemoveClick: function () {
- var attributeAlias = this.getView().getSelectionModel().getSelection()[0];
- Ext.Msg.show({
- title: Strings.sharedAttributeAlias,
- message: Strings.sharedRemoveConfirm,
- buttons: Ext.Msg.YESNO,
- buttonText: {
- yes: Strings.sharedRemove,
- no: Strings.sharedCancel
- },
- scope: this,
- fn: function (btn) {
- var store = Ext.getStore('AttributeAliases');
- if (btn === 'yes') {
- store.remove(attributeAlias);
- store.sync();
- }
- }
- });
- },
-
onSelectionChange: function (selected) {
var disabled = !this.lookupReference('deviceField').getValue();
this.lookupReference('toolbarAddButton').setDisabled(disabled);
diff --git a/web/app/view/AttributesController.js b/web/app/view/AttributesController.js
index 918938f1..1c5f5b4b 100644
--- a/web/app/view/AttributesController.js
+++ b/web/app/view/AttributesController.js
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
*/
Ext.define('Traccar.view.AttributesController', {
- extend: 'Ext.app.ViewController',
+ extend: 'Traccar.view.EditToolbarController',
alias: 'controller.attributes',
requires: [
@@ -25,6 +25,10 @@ Ext.define('Traccar.view.AttributesController', {
'Traccar.model.Attribute'
],
+ objectModel: 'Traccar.model.Attribute',
+ objectDialog: 'Traccar.view.AttributeDialog',
+ removeTitle: Strings.stateName,
+
init: function () {
var store, propertyName, i = 0, attributes;
store = Ext.create('Traccar.store.Attributes');
@@ -67,49 +71,5 @@ Ext.define('Traccar.view.AttributesController', {
}, this);
this.getView().setStore(store);
- },
-
- onAddClick: function () {
- var attribute, dialog;
- attribute = Ext.create('Traccar.model.Attribute');
- attribute.store = this.getView().getStore();
- dialog = Ext.create('Traccar.view.AttributeDialog');
- dialog.down('form').loadRecord(attribute);
- dialog.show();
- },
-
- onEditClick: function () {
- var attribute, dialog;
- attribute = this.getView().getSelectionModel().getSelection()[0];
- dialog = Ext.create('Traccar.view.AttributeDialog');
- dialog.down('form').loadRecord(attribute);
- dialog.show();
- },
-
- onRemoveClick: function () {
- var attribute = this.getView().getSelectionModel().getSelection()[0];
- Ext.Msg.show({
- title: Strings.stateName,
- message: Strings.sharedRemoveConfirm,
- buttons: Ext.Msg.YESNO,
- buttonText: {
- yes: Strings.sharedRemove,
- no: Strings.sharedCancel
- },
- scope: this,
- fn: function (btn) {
- var store = this.getView().getStore();
- if (btn === 'yes') {
- store.remove(attribute);
- store.sync();
- }
- }
- });
- },
-
- onSelectionChange: function (selected) {
- var disabled = selected.length > 0;
- this.lookupReference('toolbarEditButton').setDisabled(disabled);
- this.lookupReference('toolbarRemoveButton').setDisabled(disabled);
}
});
diff --git a/web/app/view/CalendarsController.js b/web/app/view/CalendarsController.js
index d5ab57a5..65bee91d 100644
--- a/web/app/view/CalendarsController.js
+++ b/web/app/view/CalendarsController.js
@@ -1,6 +1,6 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
- * Copyright 2016 Andrey Kunitsyn (andrey@traccar.org)
+ * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2017 Andrey Kunitsyn (andrey@traccar.org)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,7 +17,7 @@
*/
Ext.define('Traccar.view.CalendarsController', {
- extend: 'Ext.app.ViewController',
+ extend: 'Traccar.view.EditToolbarController',
alias: 'controller.calendars',
requires: [
@@ -25,50 +25,11 @@ Ext.define('Traccar.view.CalendarsController', {
'Traccar.model.Calendar'
],
+ objectModel: 'Traccar.model.Calendar',
+ objectDialog: 'Traccar.view.CalendarDialog',
+ removeTitle: Strings.sharedCalendar,
+
init: function () {
Ext.getStore('Calendars').load();
- },
-
- onAddClick: function () {
- var calendar, dialog;
- calendar = Ext.create('Traccar.model.Calendar');
- calendar.store = this.getView().getStore();
- dialog = Ext.create('Traccar.view.CalendarDialog');
- dialog.down('form').loadRecord(calendar);
- dialog.show();
- },
-
- onEditClick: function () {
- var calendar, dialog;
- calendar = this.getView().getSelectionModel().getSelection()[0];
- dialog = Ext.create('Traccar.view.CalendarDialog');
- dialog.down('form').loadRecord(calendar);
- dialog.show();
- },
-
- onRemoveClick: function () {
- var calendar = this.getView().getSelectionModel().getSelection()[0];
- Ext.Msg.show({
- title: Strings.sharedCalendar,
- message: Strings.sharedRemoveConfirm,
- buttons: Ext.Msg.YESNO,
- buttonText: {
- yes: Strings.sharedRemove,
- no: Strings.sharedCancel
- },
- fn: function (btn) {
- var store = Ext.getStore('Calendars');
- if (btn === 'yes') {
- store.remove(calendar);
- store.sync();
- }
- }
- });
- },
-
- onSelectionChange: function (selected) {
- var disabled = selected.length > 0;
- this.lookupReference('toolbarEditButton').setDisabled(disabled);
- this.lookupReference('toolbarRemoveButton').setDisabled(disabled);
}
});
diff --git a/web/app/view/DevicesController.js b/web/app/view/DevicesController.js
index f7e4bb47..e856731c 100644
--- a/web/app/view/DevicesController.js
+++ b/web/app/view/DevicesController.js
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 - 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2015 - 2017 Anton Tananaev (anton@traccar.org)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
*/
Ext.define('Traccar.view.DevicesController', {
- extend: 'Ext.app.ViewController',
+ extend: 'Traccar.view.EditToolbarController',
alias: 'controller.devices',
requires: [
@@ -47,6 +47,10 @@ Ext.define('Traccar.view.DevicesController', {
}
},
+ objectModel: 'Traccar.model.Device',
+ objectDialog: 'Traccar.view.DeviceDialog',
+ removeTitle: Strings.sharedDevice,
+
init: function () {
var readonly, deviceReadonly;
deviceReadonly = Traccar.app.getUser().get('deviceReadonly');
@@ -57,49 +61,6 @@ Ext.define('Traccar.view.DevicesController', {
this.lookupReference('toolbarGeofencesButton').setVisible(!readonly);
},
- onAddClick: function () {
- var device, dialog;
- device = Ext.create('Traccar.model.Device');
- device.store = Ext.getStore('Devices');
- dialog = Ext.create('Traccar.view.DeviceDialog');
- dialog.down('form').loadRecord(device);
- dialog.show();
- },
-
- onEditClick: function () {
- var device, dialog;
- device = this.getView().getSelectionModel().getSelection()[0];
- dialog = Ext.create('Traccar.view.DeviceDialog');
- dialog.down('form').loadRecord(device);
- dialog.show();
- },
-
- onRemoveClick: function () {
- var device = this.getView().getSelectionModel().getSelection()[0];
- Ext.Msg.show({
- title: Strings.deviceDialog,
- message: Strings.sharedRemoveConfirm,
- buttons: Ext.Msg.YESNO,
- buttonText: {
- yes: Strings.sharedRemove,
- no: Strings.sharedCancel
- },
- fn: function (btn) {
- var store;
- if (btn === 'yes') {
- store = Ext.getStore('Devices');
- store.remove(device);
- store.sync({
- failure: function (batch) {
- store.rejectChanges();
- Traccar.app.showError(batch.exceptions[0].getError().response);
- }
- });
- }
- }
- });
- },
-
onGeofencesClick: function () {
var device = this.getView().getSelectionModel().getSelection()[0];
Ext.create('Traccar.view.BaseWindow', {
diff --git a/web/app/view/EditToolbarController.js b/web/app/view/EditToolbarController.js
new file mode 100644
index 00000000..7c392d53
--- /dev/null
+++ b/web/app/view/EditToolbarController.js
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2017 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 Andrey Kunitsyn (andrey@traccar.org)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+Ext.define('Traccar.view.EditToolbarController', {
+ extend: 'Ext.app.ViewController',
+ alias: 'controller.editToolbarController',
+
+ onAddClick: function () {
+ var dialog, objectInstance = Ext.create(this.objectModel);
+ objectInstance.store = this.getView().getStore();
+ dialog = Ext.create(this.objectDialog);
+ dialog.down('form').loadRecord(objectInstance);
+ dialog.show();
+ },
+
+ onEditClick: function () {
+ var dialog, objectInstance = this.getView().getSelectionModel().getSelection()[0];
+ dialog = Ext.create(this.objectDialog);
+ dialog.down('form').loadRecord(objectInstance);
+ dialog.show();
+ },
+
+ onRemoveClick: function () {
+ var objectInstance = this.getView().getSelectionModel().getSelection()[0];
+ Ext.Msg.show({
+ title: this.removeTitle,
+ message: Strings.sharedRemoveConfirm,
+ buttons: Ext.Msg.YESNO,
+ buttonText: {
+ yes: Strings.sharedRemove,
+ no: Strings.sharedCancel
+ },
+ fn: function (btn) {
+ var store = objectInstance.store;
+ if (btn === 'yes') {
+ store.remove(objectInstance);
+ store.sync({
+ failure: function (batch) {
+ store.rejectChanges();
+ Traccar.app.showError(batch.exceptions[0].getError().response);
+ }
+ });
+ }
+ }
+ });
+ },
+
+ onSelectionChange: function (selected) {
+ var disabled = selected.length > 0;
+ this.lookupReference('toolbarEditButton').setDisabled(disabled);
+ this.lookupReference('toolbarRemoveButton').setDisabled(disabled);
+ }
+});
diff --git a/web/app/view/GeofencesController.js b/web/app/view/GeofencesController.js
index 78389066..bf330872 100644
--- a/web/app/view/GeofencesController.js
+++ b/web/app/view/GeofencesController.js
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
*/
Ext.define('Traccar.view.GeofencesController', {
- extend: 'Ext.app.ViewController',
+ extend: 'Traccar.view.EditToolbarController',
alias: 'controller.geofences',
requires: [
@@ -29,46 +29,7 @@ Ext.define('Traccar.view.GeofencesController', {
Ext.getStore('Calendars').load();
},
- onAddClick: function () {
- var geofence, dialog;
- geofence = Ext.create('Traccar.model.Geofence');
- geofence.store = this.getView().getStore();
- dialog = Ext.create('Traccar.view.GeofenceDialog');
- dialog.down('form').loadRecord(geofence);
- dialog.show();
- },
-
- onEditClick: function () {
- var geofence, dialog;
- geofence = this.getView().getSelectionModel().getSelection()[0];
- dialog = Ext.create('Traccar.view.GeofenceDialog');
- dialog.down('form').loadRecord(geofence);
- dialog.show();
- },
-
- onRemoveClick: function () {
- var geofence = this.getView().getSelectionModel().getSelection()[0];
- Ext.Msg.show({
- title: Strings.sharedGeofence,
- message: Strings.sharedRemoveConfirm,
- buttons: Ext.Msg.YESNO,
- buttonText: {
- yes: Strings.sharedRemove,
- no: Strings.sharedCancel
- },
- fn: function (btn) {
- var store = Ext.getStore('Geofences');
- if (btn === 'yes') {
- store.remove(geofence);
- store.sync();
- }
- }
- });
- },
-
- onSelectionChange: function (selected) {
- var disabled = selected.length > 0;
- this.lookupReference('toolbarEditButton').setDisabled(disabled);
- this.lookupReference('toolbarRemoveButton').setDisabled(disabled);
- }
+ objectModel: 'Traccar.model.Geofence',
+ objectDialog: 'Traccar.view.GeofenceDialog',
+ removeTitle: Strings.sharedGeofence
});
diff --git a/web/app/view/GroupsController.js b/web/app/view/GroupsController.js
index 26b34da0..98568db5 100644
--- a/web/app/view/GroupsController.js
+++ b/web/app/view/GroupsController.js
@@ -1,5 +1,5 @@
/*
- * Copyright 2016 Anton Tananaev (anton@traccar.org)
+ * Copyright 2016 - 2017 Anton Tananaev (anton@traccar.org)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -16,7 +16,7 @@
*/
Ext.define('Traccar.view.GroupsController', {
- extend: 'Ext.app.ViewController',
+ extend: 'Traccar.view.EditToolbarController',
alias: 'controller.groups',
requires: [
@@ -26,42 +26,9 @@ Ext.define('Traccar.view.GroupsController', {
'Traccar.model.Group'
],
- onAddClick: function () {
- var group, dialog;
- group = Ext.create('Traccar.model.Group');
- group.store = this.getView().getStore();
- dialog = Ext.create('Traccar.view.GroupDialog');
- dialog.down('form').loadRecord(group);
- dialog.show();
- },
-
- onEditClick: function () {
- var group, dialog;
- group = this.getView().getSelectionModel().getSelection()[0];
- dialog = Ext.create('Traccar.view.GroupDialog');
- dialog.down('form').loadRecord(group);
- dialog.show();
- },
-
- onRemoveClick: function () {
- var group = this.getView().getSelectionModel().getSelection()[0];
- Ext.Msg.show({
- title: Strings.groupDialog,
- message: Strings.sharedRemoveConfirm,
- buttons: Ext.Msg.YESNO,
- buttonText: {
- yes: Strings.sharedRemove,
- no: Strings.sharedCancel
- },
- fn: function (btn) {
- var store = Ext.getStore('Groups');
- if (btn === 'yes') {
- store.remove(group);
- store.sync();
- }
- }
- });
- },
+ objectModel: 'Traccar.model.Group',
+ objectDialog: 'Traccar.view.GroupDialog',
+ removeTitle: Strings.groupDialog,
onGeofencesClick: function () {
var admin, group;
@@ -82,8 +49,7 @@ Ext.define('Traccar.view.GroupsController', {
onSelectionChange: function (selected) {
var disabled = selected.length > 0;
- this.lookupReference('toolbarEditButton').setDisabled(disabled);
- this.lookupReference('toolbarRemoveButton').setDisabled(disabled);
this.lookupReference('toolbarGeofencesButton').setDisabled(disabled);
+ this.callParent(arguments);
}
});
diff --git a/web/app/view/UsersController.js b/web/app/view/UsersController.js
index 68e49f83..2744be74 100644
--- a/web/app/view/UsersController.js
+++ b/web/app/view/UsersController.js
@@ -17,7 +17,7 @@
*/
Ext.define('Traccar.view.UsersController', {
- extend: 'Ext.app.ViewController',
+ extend: 'Traccar.view.EditToolbarController',
alias: 'controller.users',
requires: [
@@ -32,6 +32,10 @@ Ext.define('Traccar.view.UsersController', {
'Traccar.model.User'
],
+ objectModel: 'Traccar.model.User',
+ objectDialog: 'Traccar.view.UserDialog',
+ removeTitle: Strings.settingsUser,
+
init: function () {
Ext.getStore('Users').load();
this.lookupReference('userUsersButton').setHidden(!Traccar.app.getUser().get('admin'));
@@ -51,34 +55,6 @@ Ext.define('Traccar.view.UsersController', {
dialog.show();
},
- onEditClick: function () {
- var user, dialog;
- user = this.getView().getSelectionModel().getSelection()[0];
- dialog = Ext.create('Traccar.view.UserDialog');
- dialog.down('form').loadRecord(user);
- dialog.show();
- },
-
- onRemoveClick: function () {
- var user = this.getView().getSelectionModel().getSelection()[0];
- Ext.Msg.show({
- title: Strings.settingsUser,
- message: Strings.sharedRemoveConfirm,
- buttons: Ext.Msg.YESNO,
- buttonText: {
- yes: Strings.sharedRemove,
- no: Strings.sharedCancel
- },
- fn: function (btn) {
- var store = Ext.getStore('Users');
- if (btn === 'yes') {
- store.remove(user);
- store.sync();
- }
- }
- });
- },
-
onDevicesClick: function () {
var user = this.getView().getSelectionModel().getSelection()[0];
Ext.create('Traccar.view.BaseWindow', {
@@ -172,13 +148,12 @@ Ext.define('Traccar.view.UsersController', {
onSelectionChange: function (selection, selected) {
var disabled = selected.length === 0;
- this.lookupReference('toolbarEditButton').setDisabled(disabled);
- this.lookupReference('toolbarRemoveButton').setDisabled(disabled);
this.lookupReference('userDevicesButton').setDisabled(disabled);
this.lookupReference('userGroupsButton').setDisabled(disabled);
this.lookupReference('userGeofencesButton').setDisabled(disabled);
this.lookupReference('userNotificationsButton').setDisabled(disabled);
this.lookupReference('userCalendarsButton').setDisabled(disabled);
this.lookupReference('userUsersButton').setDisabled(disabled || selected[0].get('userLimit') === 0);
+ this.callParent(arguments);
}
});