diff --git a/frontend/javascripts/functions.js b/frontend/javascripts/functions.js index 095450b..00f5277 100644 --- a/frontend/javascripts/functions.js +++ b/frontend/javascripts/functions.js @@ -82,6 +82,34 @@ function showChart() { }); } +/* + * Cookie & UUID related functions + */ +function getUUIDs() { + if ($.getCookie('uuids')) { + return JSON.parse($.getCookie('uuids')); + } + else { + return new Array; + } +} + +function addUUID(uuid) { + if (!uuids.contains(uuid)) { + uuids.push(uuid); + $.setCookie('uuids', JSON.stringify(uuids)); + } +} + +function removeUUID(uuid) { + if (uuids.contains(uuid)) { + uuids.filter(function(value) { + return value != uuid; + }); + $.setCookie('uuids', JSON.stringify(uuids)); + } +} + /* * Entity list related functions */ @@ -128,7 +156,7 @@ function showEntities() { .attr('type', 'image') .attr('src', 'images/delete.png') .attr('alt', 'delete') - .bind('click', entity, function(event) { alert('delete: ' + event.data.uuid); }) + .bind('click', entity, function(event) { removeUUID(event.data.uuid); }) ) ) .append($('') diff --git a/frontend/javascripts/script.js b/frontend/javascripts/script.js index 30104fd..98e4eb7 100644 --- a/frontend/javascripts/script.js +++ b/frontend/javascripts/script.js @@ -91,14 +91,14 @@ var myWindowStart = myWindowEnd - 24*60*60*1000; // executed on document loaded complete // this is where it all starts... $(document).ready(function() { - // parse uuids from cookie and url + // parse uuids from cookie uuids = getUUIDs(); - var uuid; - if($.getUrlVar('uuid') && !uuids.contains($.getUrlVar('uuid'))) { - uuids.push($.getUrlVar('uuid')); - $.setCookie('uuids', JSON.stringify(uuids)); + // add optional uuid from url + if($.getUrlVar('uuid')) { + addUUID($.getUrlVar('uuid')); } + console.log('cookie uuids', uuids); // start auto refresh timer window.setInterval(refreshWindow, 5000);