2010-10-03 21:51:02 +02:00
|
|
|
/**
|
|
|
|
* UUID handling
|
|
|
|
*
|
|
|
|
* @author Florian Ziegler <fz@f10-home.de>
|
|
|
|
* @author Justin Otherguy <justin@justinotherguy.org>
|
|
|
|
* @author Steffen Vogel <info@steffenvogel.de>
|
|
|
|
* @copyright Copyright (c) 2010, The volkszaehler.org project
|
|
|
|
* @package default
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* This file is part of volkzaehler.org
|
|
|
|
*
|
|
|
|
* volkzaehler.org is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the Free
|
|
|
|
* Software Foundation, either version 3 of the License, or any later version.
|
|
|
|
*
|
|
|
|
* volkzaehler.org is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
* details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* volkszaehler.org. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cookie & UUID related functions
|
|
|
|
*/
|
2010-10-04 21:10:58 +02:00
|
|
|
vz.uuids.parseCookie = function() {
|
2010-10-03 21:51:02 +02:00
|
|
|
if ($.getCookie('uuids')) {
|
2010-10-04 21:10:58 +02:00
|
|
|
$.each(JSON.parse($.getCookie('uuids')), function(index, uuid) {
|
|
|
|
vz.uuids.push(uuid);
|
|
|
|
});
|
2010-10-03 21:51:02 +02:00
|
|
|
}
|
2010-10-04 21:10:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
vz.uuids.add = function(uuid) {
|
|
|
|
if (vz.uuids.validate(uuid)) {
|
|
|
|
if (!vz.uuids.contains(uuid)) {
|
|
|
|
vz.uuids.push(uuid);
|
|
|
|
$.setCookie('uuids', JSON.stringify(vz.uuids));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
throw 'UUID already added';
|
|
|
|
}
|
2010-10-03 21:51:02 +02:00
|
|
|
}
|
2010-10-04 21:10:58 +02:00
|
|
|
else {
|
|
|
|
throw 'Invalid UUID';
|
2010-10-03 21:51:02 +02:00
|
|
|
}
|
2010-10-04 21:10:58 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
vz.uuids.remove = function(uuid) {
|
2010-10-04 03:29:12 +02:00
|
|
|
if (vz.uuids.contains(uuid)) {
|
|
|
|
vz.uuids.remove(uuid);
|
|
|
|
$.setCookie('uuids', JSON.stringify(vz.uuids));
|
2010-10-03 21:51:02 +02:00
|
|
|
}
|
2010-10-04 21:10:58 +02:00
|
|
|
else {
|
|
|
|
throw 'UUID unkown: ' + uuid;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
vz.uuids.validate = function(uuid) {
|
|
|
|
return new Boolean(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}$/));
|
|
|
|
};
|