Commit 1d4f9b4a authored by Efthymia Bika's avatar Efthymia Bika
Browse files

Write maps instead of lists to config files

parent 7d3e5804
......@@ -13,12 +13,12 @@
function show_cloud_msg(data) {
if(typeof clouds === 'undefined') {
if(data != "") {
clouds = JSON.parse(data).clouds;
clouds = JSON.parse(data);
} else {
clouds = [];
clouds = new Object();
}
}
if(clouds.length == 0) {
if(Object.keys(clouds).length == 0) {
$("#cloud-alert").show();
}
}
......@@ -36,12 +36,12 @@
// reading data from file
if(typeof backups === 'undefined') {
if(data != "") {
backups = JSON.parse(data).backups;
backups = JSON.parse(data);
} else {
backups = [];
backups = new Object();
}
}
if(backups.length == 0) {
if(Object.keys(backups).length == 0) {
$("#backup-alert").show();
}
var ul = $("<ul></ul>")
......
......@@ -79,9 +79,9 @@
function populate_clouds(data) {
if(typeof clouds === 'undefined') {
if(data != "") {
clouds = JSON.parse(data).clouds;
clouds = JSON.parse(data);
} else {
clouds = [];
clouds = new Object();
}
}
var cloud_sel = $("#cloud");
......
......@@ -86,16 +86,6 @@ function load_backup(backup) {
$("#backup_details").show();
}
function backup_exists(backup_name) {
var found = false;
$.each(backups, function(i, backup_set) {
if(backup_set.name == backup_name) {
found = true;
}
});
return found;
}
function save_backup_set() {
var backup_name = $("#backup-name").val().replace(/^\s+|\s+$/gm,'');
var directory = $("#directory").html();
......@@ -105,46 +95,26 @@ function save_backup_set() {
var exclude = $("#exclude").val();
var include = $("#include").val();
if(backup_exists(backup_name)) {
$.each(backups, function(i, backup_set) {
if(backup_set.name == backup_name) {
backup_set.name = backup_name;
backup_set.local_dir = directory;
backup_set.cloud = cloud;
backup_set.passphrase = passphrase;
backup_set.exclude = exclude;
backup_set.include = include;
}
});
} else {
var backup_set = {"name" : "", "local_dir" : "",
"cloud" : "", "passphrase" : "", "container" : "",
"first_backup" : "", "exclude" : "", "include" : "" };
backup_set.name = backup_name;
backup_set.local_dir = directory;
backup_set.cloud = cloud;
backup_set.passphrase = passphrase;
backup_set.container = backup_name;
container = backup_set.container;
backup_set.exclude = exclude;
backup_set.include = include;
backups.push(backup_set);
render_backup_sets("");
}
var root_backup_sets = {"backups" : "" };
root_backup_sets.backups = backups;
write_conf_file(BACKUP_CONF_FILE, root_backup_sets);
var backup_set = {};
backup_set.name = backup_name;
backup_set.local_dir = directory;
backup_set.cloud = cloud;
backup_set.passphrase = passphrase;
backup_set.container = backup_name;
container = backup_set.container;
backup_set.exclude = exclude;
backup_set.include = include;
backups[backup_name] = backup_set;
render_backup_sets("");
write_conf_file(BACKUP_CONF_FILE, backups);
activate_li("li_" + backup_name);
}
function delete_backup(backup) {
var i = backups.indexOf(backup);
backups.splice(i, 1);
delete backups[backup.name];
render_backup_sets("");
var root_backup_sets = {"backups" : "" };
root_backup_sets.backups = backups;
write_conf_file(BACKUP_CONF_FILE, root_backup_sets);
write_conf_file(BACKUP_CONF_FILE, backups);
$(".tabs").hide();
$(".tabs-content").hide();
}
......@@ -157,8 +127,6 @@ function write_first_backup() {
backup_set.first_backup = Date.now();
}
});
var root_backup_sets = {"backups" : "" };
root_backup_sets.backups = backups;
write_conf_file(BACKUP_CONF_FILE, root_backup_sets);
write_conf_file(BACKUP_CONF_FILE, backups);
}
......@@ -13,9 +13,9 @@
// reading data from file
if(typeof clouds === 'undefined') {
if(data != "") {
clouds = JSON.parse(data).clouds;
clouds = JSON.parse(data);
} else {
clouds = [];
clouds = new Object();
}
}
var ul = $("<ul></ul>")
......@@ -196,45 +196,25 @@
function edit_add_cloud() {
var cloud_name = $("#cloud-name").val().replace(/^\s+|\s+$/gm,'');
// edit existing
var url = $("#cloud-url").val().replace(/^\s+|\s+$/gm,'');
var token = $("#token").val().replace(/^\s+|\s+$/gm,'');
if($("#" + cloud_name).attr("id")) {
$.each(clouds, function(i, cloud) {
if(cloud.name == cloud_name) {
cloud.auth_url = url;
cloud.token = token;
cloud.pithos_public = pithos_public;
cloud.uuid = uuid;
}
});
// add new cloud
} else {
var cloud = {"name" : "", "auth_url" : "",
"token" : "", "pithos_public" : "", "uuid" : ""};
cloud.name = cloud_name;
cloud.auth_url = url;
cloud.token = token;
cloud.pithos_public = pithos_public;
cloud.uuid = uuid;
var cloud = {};
cloud.name = cloud_name;
cloud.auth_url = url;
cloud.token = token;
cloud.pithos_public = pithos_public;
cloud.uuid = uuid;
clouds.push(cloud);
render_clouds("");
}
var root_clouds = {"clouds" : "" };
root_clouds.clouds = clouds;
write_conf_file(CLOUDS_CONF_FILE, root_clouds);
clouds[cloud_name] = cloud;
render_clouds("");
write_conf_file(CLOUDS_CONF_FILE, clouds);
}
function delete_cloud(cloud) {
var i = clouds.indexOf(cloud);
clouds.splice(i, 1);
delete clouds[cloud.name];
render_clouds("");
var root_clouds = {"clouds" : "" };
root_clouds.clouds = clouds;
write_conf_file(CLOUDS_CONF_FILE, root_clouds);
write_conf_file(CLOUDS_CONF_FILE, clouds);
$("#cloud_details").hide();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment