diff --git a/htdocs/frontend/index.html b/htdocs/frontend/index.html index 64559dd..e9bb849 100644 --- a/htdocs/frontend/index.html +++ b/htdocs/frontend/index.html @@ -38,9 +38,16 @@

- @@ -151,7 +158,7 @@
- + diff --git a/htdocs/frontend/javascripts/entities.js b/htdocs/frontend/javascripts/entities.js index 0287d92..2c47eab 100644 --- a/htdocs/frontend/javascripts/entities.js +++ b/htdocs/frontend/javascripts/entities.js @@ -81,7 +81,7 @@ vz.entities.each = function(cb, recursive) { for (var i = 0; i < this.length; i++) { cb(this[i]); - if (recursive) { + if (recursive && this[i] !== undefined) { this[i].each(cb, true); } } @@ -151,7 +151,7 @@ vz.entities.showTable = function() { } finally { $.when(queue).done(function() { // wait for middleware - $.when(from.loadDetails(), to.loadDetails).done(vz.entities.showDetails); + $.when(from.loadDetails(), to.loadDetails).done(vz.entities.showTable); }); $(this).dialog('close'); } diff --git a/htdocs/frontend/javascripts/entity.js b/htdocs/frontend/javascripts/entity.js index 0f40663..843541c 100644 --- a/htdocs/frontend/javascripts/entity.js +++ b/htdocs/frontend/javascripts/entity.js @@ -83,7 +83,7 @@ Entity.prototype.loadData = function() { success: function(json) { this.data = json.data; - if (this.data.tuples.length > 0) { + if (this.data.tuples && this.data.tuples.length > 0) { if (this.data.min[1] < vz.options.plot.yaxis.min) { // allow negative values for temperature sensors vz.options.plot.yaxis.min = null; } @@ -112,16 +112,22 @@ Entity.prototype.showDetails = function() { $(this).dialog('close'); }, 'Löschen' : function() { - vz.load({ // TODO encapsulate in own method - controller: 'entity', - context: this, - identifier: entity.uuid, - url: entity.middleware, - type: 'DELETE', - success: function() { - $(this).dialog('close'); - } + entity.cookie = false; + vz.entities.saveCookie(); + + entity.delete().done(function() { + vz.entities.each(function(it, parent) { + if (entity == it) { + var array = (parent) ? parent.children : vz.entities; + array.remove(it); + } + }, true); + + vz.entities.showTable(); + vz.wui.drawPlot(); }); + + $(this).dialog('close'); } } }); @@ -330,6 +336,19 @@ Entity.prototype.updateDOMRow = function() { } }; +/** + * Permanently deletes this entity and its data from the middleware + */ +Entity.prototype.delete = function() { + return vz.load({ + controller: 'entity', + context: this, + identifier: this.uuid, + url: this.middleware, + type: 'DELETE' + }); +} + /** * Add entity as child */ @@ -345,7 +364,7 @@ Entity.prototype.addChild = function(child) { data: { uuid: child.uuid }, - type: 'post' + type: 'POST' }); } @@ -353,13 +372,17 @@ Entity.prototype.addChild = function(child) { * Remove entity from children */ Entity.prototype.removeChild = function(child) { + if (this.definition.model != 'Volkszaehler\\Model\\Aggregator') { + throw new Exception('EntityException', 'Entity is not an Aggregator'); + } + return vz.load({ controller: 'group', identifier: this.uuid, url: this.middleware, data: { uuid: child.uuid, - operation: 'delete' + type: 'DELETE' } }); }; @@ -374,7 +397,7 @@ Entity.prototype.each = function(cb, recursive) { for (var i = 0; i < this.children.length; i++) { cb(this.children[i], this); - if (recursive) { + if (recursive && this.children[i] !== undefined) { this.children[i].each(cb, true); // call recursive } } diff --git a/htdocs/frontend/javascripts/init.js b/htdocs/frontend/javascripts/init.js index 8d16f18..23d7c32 100644 --- a/htdocs/frontend/javascripts/init.js +++ b/htdocs/frontend/javascripts/init.js @@ -84,7 +84,7 @@ $(document).ready(function() { // chaining ajax request with jquery deferred object vz.capabilities.load().done(function() { if (vz.capabilities.formats.contains('png')) { - $('#snapshot').show(); + $('#export option[value=png]').removeAttr('disabled'); } var queue = new Array; diff --git a/htdocs/frontend/javascripts/wui.js b/htdocs/frontend/javascripts/wui.js index adffbfd..35abb8a 100644 --- a/htdocs/frontend/javascripts/wui.js +++ b/htdocs/frontend/javascripts/wui.js @@ -41,8 +41,21 @@ vz.wui.init = function() { $('button, input[type=button],[type=image],[type=submit]').button(); $('button[name=options-save]').click(vz.options.saveCookies); $('button[name=entity-add]').click(this.dialogs.init); - $('#permalink').click(function() { window.location = vz.wui.getPermalink(); }); - $('#snapshot').click(function() { window.location = vz.wui.getSnaplink(); }).hide(); + + $('#export select').change(function(event) { + switch ($(this).val()) { + case 'permalink': + window.location = vz.wui.getPermalink(); + break; + case 'png': + case 'csv': + case 'xml': + window.location = vz.wui.getLink($(this).val()); + break; + + } + $('#export option[value=default]').attr('selected', true); + }); // bind plot actions $('#controls button').click(this.handleControls); @@ -83,25 +96,31 @@ vz.wui.dialogs.init = function() { width: 530, resizable: false }); - $('#entity-add.dialog > div').tabs(); - - // load public entities - vz.load({ - controller: 'entity', - success: function(json) { - var entities = new Array; - json.entities.each(function(index, json) { - entities.push(new Entity(json)); - }); + $('#entity-add.dialog > div').tabs({ + show: function(event, ui) { // lazy loading public entities + if (ui.index != 1) { + return; // abort, we are not in public tab + } + + vz.load({ + controller: 'entity', + success: function(json) { + var public = new Array; + json.entities.each(function(index, json) { + public.push(new Entity(json)); + }); - entities.sort(Entity.compare); - entities.each(function(index, entity) { - $('#entity-public-entity').append( - $('
EigenschaftWert
Middleware:>
Middleware:
Typ:
Öffentlich: ja   nein
Titel: