aboutsummaryrefslogtreecommitdiff
path: root/web/app
diff options
context:
space:
mode:
Diffstat (limited to 'web/app')
-rw-r--r--web/app/Application.js6
-rw-r--r--web/app/controller/Root.js31
-rw-r--r--web/app/model/Event.js40
-rw-r--r--web/app/store/Events.js25
4 files changed, 98 insertions, 4 deletions
diff --git a/web/app/Application.js b/web/app/Application.js
index 69ce8f891..e798a73e2 100644
--- a/web/app/Application.js
+++ b/web/app/Application.js
@@ -30,7 +30,8 @@ Ext.define('Traccar.Application', {
'Device',
'Position',
'Attribute',
- 'Command'
+ 'Command',
+ 'Event'
],
stores: [
@@ -47,7 +48,8 @@ Ext.define('Traccar.Application', {
'SpeedUnits',
'CommandTypes',
'TimeUnits',
- 'Languages'
+ 'Languages',
+ 'Events'
],
controllers: [
diff --git a/web/app/controller/Root.js b/web/app/controller/Root.js
index bb65e0048..991a2572c 100644
--- a/web/app/controller/Root.js
+++ b/web/app/controller/Root.js
@@ -94,7 +94,7 @@ Ext.define('Traccar.controller.Root', {
};
socket.onmessage = function (event) {
- var i, store, data, array, entity;
+ var i, j, store, data, array, entity, device, typeKey, text;
data = Ext.decode(event.data);
@@ -114,7 +114,7 @@ Ext.define('Traccar.controller.Root', {
}
}
- if (data.positions) {
+ if (data.positions && !data.events) {
array = data.positions;
store = Ext.getStore('LatestPositions');
for (i = 0; i < array.length; i++) {
@@ -126,6 +126,33 @@ Ext.define('Traccar.controller.Root', {
}
}
}
+
+ if (data.events) {
+ array = data.events;
+ store = Ext.getStore('Events');
+ for (i = 0; i < array.length; i++) {
+ store.add(array[i]);
+ if (array[i].type === 'commandResult' && data.positions) {
+ for (j = 0; j < data.positions.length; j++) {
+ if (data.positions[j].id == array[i].positionId) {
+ text = data.positions[j].attributes.result;
+ break;
+ }
+ }
+ text = Strings.eventCommandResult + text;
+ } else {
+ typeKey = 'event' + array[i].type.charAt(0).toUpperCase() + array[i].type.slice(1);
+ text = Strings[typeKey];
+ if (typeof text == "undefined") {
+ text = typeKey;
+ }
+ }
+ device = Ext.getStore('Devices').getById(array[i].deviceId);
+ if (typeof device != "undefined") {
+ Ext.toast(text, device.getData().name);
+ }
+ }
+ }
};
}
});
diff --git a/web/app/model/Event.js b/web/app/model/Event.js
new file mode 100644
index 000000000..4dd3ea7ff
--- /dev/null
+++ b/web/app/model/Event.js
@@ -0,0 +1,40 @@
+/*
+ * 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.model.Event', {
+ extend: 'Ext.data.Model',
+ identifier: 'negative',
+
+ fields: [{
+ name: 'id',
+ type: 'int'
+ }, {
+ name: 'type',
+ type: 'string'
+ }, {
+ name: 'serverTime',
+ type: 'date',
+ dateFormat: 'c'
+ }, {
+ name: 'deviceId',
+ type: 'int'
+ }, {
+ name: 'positionId',
+ type: 'int'
+ }, {
+ name: 'attributes'
+ }]
+});
diff --git a/web/app/store/Events.js b/web/app/store/Events.js
new file mode 100644
index 000000000..54b341d30
--- /dev/null
+++ b/web/app/store/Events.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.Events', {
+ extend: 'Ext.data.Store',
+ model: 'Traccar.model.Event',
+
+ proxy: {
+ type: 'rest',
+ url: '/api/events'
+ }
+});