diff --git a/frontend/javascripts/frontend.js b/frontend/javascripts/frontend.js
index ce34904..af89ceb 100644
--- a/frontend/javascripts/frontend.js
+++ b/frontend/javascripts/frontend.js
@@ -107,8 +107,8 @@ vz.initDialogs = function() {
$('#addUUID').dialog('close');
vz.entities.loadDetails();
}
- catch (e) {
- alert(e); // TODO show error
+ catch (exception) {
+ vz.exceptionDialog(exception);
}
});
};
@@ -320,9 +320,16 @@ vz.entities.loadData = function() {
$('#plot').html('

Loading...
');
vz.entities.each(function(entity, parent) {
if (entity.active && entity.type != 'group') {
- vz.load('data', entity.uuid, { from: Math.floor(vz.options.plot.xaxis.min), to: Math.ceil(vz.options.plot.xaxis.max), tuples: vz.options.tuples }, waitAsync(function(json) {
- entity.data = json.data;
- }, vz.drawPlot, 'data'));
+ vz.load('data', entity.uuid,
+ {
+ from: Math.floor(vz.options.plot.xaxis.min),
+ to: Math.ceil(vz.options.plot.xaxis.max),
+ tuples: vz.options.tuples
+ },
+ waitAsync(function(json) {
+ entity.data = json.data;
+ }, vz.drawPlot, 'data')
+ );
}
});
};
@@ -357,7 +364,37 @@ vz.load = function(context, identifier, data, success) {
data: data,
error: function(xhr) {
json = JSON.parse(xhr.responseText);
- alert(xhr.status + ': ' + xhr.statusText + '\n' + json.exception.message);
+ vz.errorDialog(xhr.statusText, json.exception.message, xhr.status);
}
});
};
+
+/*
+ * Error & Exception handling
+ */
+
+vz.errorDialog = function(error, description, code) {
+ if (typeof code != undefined) {
+ error = code + ': ' + error;
+ }
+
+ $('')
+ .addClass('error')
+ .append($('').text(description))
+ .dialog({
+ title: error,
+ width: 450
+ });
+};
+
+vz.exceptionDialog = function(exception) {
+ vz.errorDialog(exception.type, exception.message, exception.code);
+};
+
+var Exception(type, message, code) {
+ return {
+ type: type,
+ message: message,
+ code: code
+ };
+}
diff --git a/frontend/javascripts/helper.js b/frontend/javascripts/helper.js
index b20f706..17d4566 100644
--- a/frontend/javascripts/helper.js
+++ b/frontend/javascripts/helper.js
@@ -24,6 +24,9 @@
* volkszaehler.org. If not, see .
*/
+/**
+ * Helper function to wait for multiple ajax requests to complete
+ */
function waitAsync(callback, finished, identifier) {
if (!waitAsync.counter) { waitAsync.counter = new Array(); }
if (!waitAsync.counter[identifier]) { waitAsync.counter[identifier] = 0; }
@@ -63,4 +66,4 @@ Array.prototype.contains = function(n) {
Array.prototype.clear = function() {
this.length = 0;
-}
\ No newline at end of file
+}
diff --git a/frontend/javascripts/uuid.js b/frontend/javascripts/uuid.js
index c2b11eb..733ce4f 100644
--- a/frontend/javascripts/uuid.js
+++ b/frontend/javascripts/uuid.js
@@ -45,11 +45,11 @@ vz.uuids.add = function(uuid) {
$.setCookie('vz_uuids', JSON.stringify(vz.uuids));
}
else {
- throw 'UUID already added';
+ throw new Exception('UUIDException', 'UUID already added');
}
}
else {
- throw 'Invalid UUID';
+ throw new Exception('UUIDException', 'Invalid UUID');
}
};
@@ -63,7 +63,7 @@ vz.uuids.remove = function(uuid) {
$.setCookie('vz_uuids', JSON.stringify(vz.uuids));
}
else {
- throw 'UUID unkown: ' + uuid;
+ throw new Exception('UUIDException', 'UUID unkown: ' + uuid);
}
};
@@ -72,4 +72,4 @@ vz.uuids.remove = function(uuid) {
*/
vz.uuids.validate = function(uuid) {
return uuid.match(/^[0-9a-zA-Z]{8}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{4}-[0-9a-zA-Z]{12}$/);
-};
\ No newline at end of file
+};