fixed bug on duplicate uuids via url parameter

adding multiple uuids per url
This commit is contained in:
Steffen Vogel 2011-01-15 21:46:01 +01:00
parent a780d9b95a
commit a6daca00f6
4 changed files with 29 additions and 16 deletions

View file

@ -50,6 +50,7 @@ vz.wui.init = function() {
$('#entity-subscribe input[type=button]').click(function() {
try {
vz.uuids.add($('#entity-subscribe input[type=text]').val());
vz.uuids.save();
$('#entity-subscribe input[type=text]').val('');
$('#entity-add').dialog('close');
vz.entities.loadDetails();
@ -312,6 +313,7 @@ vz.entities.show = function() {
.attr('alt', 'delete')
.bind('click', entity, function(event) {
vz.uuids.remove(event.data.uuid);
vz.uuids.save();
vz.entities.loadDetails();
})
);
@ -435,24 +437,26 @@ vz.load = function(context, identifier, data, success) {
/**
* Parse URL GET parameters
*/
vz.parseUrlVars = function() {
var vars = $.getUrlVars();
vz.parseUrlParams = function() {
var vars = $.getUrlParams();
for (var key in vars) {
if (vars.hasOwnProperty(key)) {
switch (key) {
case 'uuid': // add optional uuid from url
try {
vz.uuids.add(vars[key]);
} catch (exception) {
vz.wui.dialogs.exception(exception);
}
var uuids = (typeof vars[key] == 'string') ? [vars[key]] : vars[key]; // handle multiple uuids
uuids.each(function(index, uuid) {
try { vz.uuids.add(uuid); } catch (exception) { /* ignore exception */ }
});
break;
case 'from':
vz.options.plot.xaxis.min = parseInt(vars[key]);
break;
case 'to':
vz.options.plot.xaxis.max = parseInt(vars[key]);
break;
case 'debug':
$.getScript('javascripts/firebug-lite.js');
break;

View file

@ -63,7 +63,7 @@ $(document).ready(function() {
vz.definitions.load();
vz.uuids.load();
vz.options.load();
vz.parseUrlVars();
vz.parseUrlParams();
// initialize user interface
vz.wui.init();

View file

@ -29,18 +29,28 @@
* Get URL parameters
*/
$.extend( {
getUrlVars : function() {
var vars = [], hash;
getUrlParams : function() {
var vars = {}, hash;
var hashes = window.location.href.slice(
window.location.href.indexOf('?') + 1).split('&');
for (var i = 0; i < hashes.length; i++) {
hash = hashes[i].split('=');
vars[hash[0]] = hash[1];
switch (typeof vars[hash[0]]) {
case 'undefined':
vars[hash[0]] = hash[1];
break;
case 'string':
vars[hash[0]] = Array(vars[hash[0]]);
case 'object':
vars[hash[0]].push(hash[1]);
}
}
return vars;
},
getUrlVar : function(name) {
return $.getUrlVars()[name];
getUrlParam : function(name) {
return $.getUrlParams()[name];
}
});

View file

@ -31,7 +31,6 @@ vz.uuids.add = function(uuid) {
if (this.validate(uuid)) {
if (!this.contains(uuid)) {
this.push(uuid);
this.save();
}
else {
throw new Exception('UUIDException', 'UUID already added: ' + uuid);
@ -48,7 +47,6 @@ vz.uuids.add = function(uuid) {
vz.uuids.remove = function(uuid) {
if (this.contains(uuid)) {
this.splice(this.indexOf(uuid), 1); // remove uuid from array
this.save();
}
else {
throw new Exception('UUIDException', 'UUID unkown: ' + uuid);
@ -66,7 +64,8 @@ vz.uuids.validate = function(uuid) {
* Save uuids as cookie
*/
vz.uuids.save = function() {
$.setCookie('vz_uuids', this.join(';'));
var expires = new Date(new Date().getTime() + 31536e6); // expires in a year
$.setCookie('vz_uuids', this.join(';'), {expires: expires});
};
/**