Commit 47449f8f authored by Efthymia Bika's avatar Efthymia Bika

Clean code

Move cloud loading to a single function
parent d2b1d1a7
......@@ -34,17 +34,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
}
}
function populate_template_list(data) {
if(typeof templates === 'undefined') {
if(data != "") {
templates = JSON.parse(data);
} else {
templates = new Object();
}
}
$("#template_list").empty();
var ul = $("<ul></ul>")
.attr("class", "no-bullet template-list");
var li = $("<li>Load Template:</li>")
.attr("class", "template-list-title");
ul.append(li);
$.each(templates, function(i, template) {
var li = $("<li></li>");
var a = $("<a>" + template.name + "&nbsp;<i class='fa fa-arrow-circle-right'></a>")
.attr("href", "#")
.click(function() {
load_backup(template);
$("#template_list").hide();
});
li.append(a);
ul.append(li);
});
$("#template_list").append(ul);
}
if(typeof templates === 'undefined') {
load_data_from_file(TEMPLATES_FILE, populate_template_list);
} else {
populate_template_list("");
}
if(typeof clouds === 'undefined') {
load_data_from_file(CLOUDS_CONF_FILE, populate_clouds);
} else {
populate_clouds("");
}
populate_clouds("cloud", "");
if(typeof selected_backup != 'undefined' && selected_backup &&
typeof backups[selected_backup] != 'undefined') {
$("#selected-bar").html(selected_backup);
......@@ -70,16 +96,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
load_backup();
}
function activate_li(id) {
$("li").each(function(i, li) {
if($(this).is("#" + id)) {
$(this).addClass("active-li");
} else {
$(this).removeClass("active-li");
}
});
}
function check_backup_name() {
var backup_name = $('#backup-name').val().replace(/^\s+|\s+$/gm,'');
if(!backup_name) {
......@@ -123,51 +139,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
return true;
}
function populate_clouds(data) {
if(typeof clouds === 'undefined') {
if(data != "") {
clouds = JSON.parse(data);
} else {
clouds = new Object();
}
}
var cloud_sel = $("#cloud");
$.each(clouds, function(i, cloud) {
cloud_sel.append($("<option></option>")
.attr("value", cloud.name)
.text(cloud.name));
});
}
function populate_template_list(data) {
if(typeof templates === 'undefined') {
if(data != "") {
templates = JSON.parse(data);
} else {
templates = new Object();
}
}
$("#template_list").empty();
var ul = $("<ul></ul>")
.attr("class", "no-bullet template-list");
var li = $("<li>Load Template:</li>")
.attr("class", "template-list-title");
ul.append(li);
$.each(templates, function(i, template) {
var li = $("<li></li>");
var a = $("<a>" + template.name + "&nbsp;<i class='fa fa-arrow-circle-right'></a>")
.attr("href", "#")
.click(function() {
load_backup(template);
$("#template_list").hide();
});
li.append(a);
ul.append(li);
});
$("#template_list").append(ul);
}
function disable_form(disable) {
$("#backup-name").prop("disabled", disable);
$("#choose-dir").prop("disabled", disable);
......
......@@ -39,6 +39,22 @@ function toggle_error(error, msg) {
}
}
function populate_clouds(cloud_field, data) {
if(typeof clouds === 'undefined') {
if(data != "") {
clouds = JSON.parse(data);
} else {
clouds = new Object();
}
}
var cloud_sel = $("#" + cloud_field);
$.each(clouds, function(i, cloud) {
cloud_sel.append($("<option></option>")
.attr("value", cloud.name)
.text(cloud.name));
});
}
function check_directory(dir_id) {
if(!$('#' + dir_id).html()) {
$('#' + dir_id + '-error small').text(errors.dir_not_chosen);
......
......@@ -17,13 +17,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<script type="text/javascript">
$(document).ready(function() {
if(typeof clouds === 'undefined') {
load_data_from_file(CLOUDS_CONF_FILE, populate_clouds);
} else {
populate_clouds("");
}
});
populate_clouds("res-cloud", "");
hide_error_divs();
function load_field_values() {
......@@ -70,22 +64,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
return true;
}
function populate_clouds(data) {
if(typeof clouds === 'undefined') {
if(data != "") {
clouds = JSON.parse(data).clouds;
} else {
clouds = [];
}
}
var cloud_sel = $("#res-cloud");
$.each(clouds, function(i, cloud) {
cloud_sel.append($("<option></option>")
.attr("value", cloud.name)
.text(cloud.name));
});
}
function check_res_fields() {
return (check_res_backup_name()
&& check_directory("res-directory")
......
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