improved export dropdown (fixes #66)

improved behaviour after deleting entities
This commit is contained in:
Steffen Vogel 2011-07-22 15:44:20 +02:00
parent 6c8942c904
commit 4828004746
5 changed files with 95 additions and 44 deletions

View file

@ -38,9 +38,16 @@
<div id="content">
<div id="headline">
<h2 id="title"></h2>
<div id="links">
<button id="snapshot"><img src="images/image.png" alt="snaptshot" /> Snapshot</button>
<button id="permalink"><img src="images/link.png" alt="permalink" /> Permalink</button>
<div id="export">
<img alt="export" src="images/export.png" />
<select>
<option value="default" style="background-image: url(images/export.png)" selected="selected">Export...</option>
<option value="permalink" style="background-image: url(images/link.png)" >Permalink</option>
<option value="png" style="background-image: url(images/image.png)" disabled="disabled" >Snapshot</option>
<option value="csv" style="background-image: url(images/table.png)" >CSV</option>
<option value="xml" style="background-image: url(images/xml.png)" >XML</option>
</select>
</div>
<br style="clear: both" />
</div>
@ -151,7 +158,7 @@
<form method="get" target="_blank">
<table>
<tr class="property"><th>Eigenschaft</th><th>Wert</th></tr>
<tr class="property"><td>Middleware:></td><td><input type="text" id="entity-create-middleware" /></td></tr>
<tr class="property"><td>Middleware:</td><td><input type="text" id="entity-create-middleware" /></td></tr>
<tr class="property"><td>Typ:</td><td><select id="enti"name="type" size="1"></select></td></tr>
<tr class="property"><td>&Ouml;ffentlich:</td><td><input type="radio" name="public" value="1"> ja&nbsp;&nbsp;<input type="radio" name="public" value="0"> nein</td></tr>
<tr class="property"><td>Titel:</td><td><input type="text" name="title" value="K&uuml;hlschrank" /></td></tr>

View file

@ -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');
}

View file

@ -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
}
}

View file

@ -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;

View file

@ -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(
$('<option>').html(entity.title).val(entity.uuid).data('entity', entity)
);
});
public.sort(Entity.compare);
vz.middleware[0].public = public;
vz.middleware[0].public = entities; /* store */
$('#entity-public-entity').empty();
public.each(function(index, entity) {
$('#entity-public-entity').append(
$('<option>').html(entity.title).val(entity.uuid).data('entity', entity)
);
});
}
});
}
});
@ -168,7 +187,7 @@ vz.wui.dialogs.init = function() {
});
$('#entity-create form').submit(function() {
$(this).attr('action', $('#entity-create-middlware').val() + '/channel.json');
$(this).attr('action', $('#entity-create-middleware').val() + '/channel.json');
$('#entity-add').dialog('close');
});
@ -206,15 +225,17 @@ vz.wui.getPermalink = function() {
*
* @return string url
*/
vz.wui.getSnaplink = function() {
var uuids = new Array;
vz.wui.getLink = function(format) {
var entities = new Array;
vz.entities.each(function(entity, parent) {
if (entity.active) {
uuids.push(entity.uuid);
entities.push(entity);
}
}, true); // recursive!
return vz.options.middlewareUrl + '/data/' + uuids[0] + '.png?' + $.param({
var entity = entities[0]; // TODO handle other entities
return entity.middleware + '/data/' + entity.uuid + '.' + format + '?' + $.param({
from: Math.floor(vz.options.plot.xaxis.min),
to: Math.ceil(vz.options.plot.xaxis.max)
});