Commit 030ec847 authored by Efthymia Bika's avatar Efthymia Bika
Browse files

Merge toggle messages functions

parent e6bde7a5
...@@ -238,7 +238,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. ...@@ -238,7 +238,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<ul class="tabs" data-tab> <ul class="tabs" data-tab>
<li class="tab-title radius" id="backup_details_tab"> <li class="tab-title radius" id="backup_details_tab">
<a href="#backup_details" <a href="#backup_details"
onclick="$('#backup_details').show()" onclick="$('#backup_details').show();
toggle_msgs(false, 'msg', false)"
id="backup_details_link">Settings</a> id="backup_details_link">Settings</a>
</li> </li>
<li class="tab-title"> <li class="tab-title">
......
...@@ -28,14 +28,21 @@ var errors = { ...@@ -28,14 +28,21 @@ var errors = {
remove_all_time_empty: 'Provide a valid timestamp' remove_all_time_empty: 'Provide a valid timestamp'
}; };
function toggle_error(error, msg) { function toggle_msgs(data, msgDiv, append) {
if(error) { if(data) {
$("#msg").html(msg); if(append) {
$("#msg").addClass("panel"); $("#" + msgDiv).append(data);
$("html,body").animate({scrollTop: $("#msg").offset().top}, "slow"); $("#" + msgDiv).animate({scrollTop: "+=300px"}, "slow");
} else {
$("#" + msgDiv).html(data);
}
$("#" + msgDiv).addClass("panel");
$("html,body").animate({scrollTop:
$("#" + msgDiv).offset().top}, "slow");
} else { } else {
$("#msg").html(""); $("#" + msgDiv).html("");
$("#msg").removeClass("panel"); $("#" + msgDiv).removeClass("panel");
if($("#error-alert")) $("#error-alert").hide();
} }
} }
...@@ -90,7 +97,7 @@ function load_backup(backup) { ...@@ -90,7 +97,7 @@ function load_backup(backup) {
$("#time-dates").html(""); $("#time-dates").html("");
$("#time-contents").html(""); $("#time-contents").html("");
$("#time-path").val("/"); $("#time-path").val("/");
toggle_error(false, ""); toggle_msgs(false, "msg", false);
hide_error_divs(); hide_error_divs();
......
...@@ -71,7 +71,7 @@ function build_win_commands() { ...@@ -71,7 +71,7 @@ function build_win_commands() {
"export SWIFT_PREAUTHTOKEN=" + env_values[2] + ";"; "export SWIFT_PREAUTHTOKEN=" + env_values[2] + ";";
} }
function show_cloud_error() { function show_cloud_error() {
toggle_error(false, ""); toggle_msgs(false, "msg", false);
show_alert_box("A problem occured.<br>" + show_alert_box("A problem occured.<br>" +
"Please check your <a href='#' " + "Please check your <a href='#' " +
"onclick=$('#cloud-settings-link').trigger('click')>" + "onclick=$('#cloud-settings-link').trigger('click')>" +
...@@ -94,7 +94,7 @@ function build_extra_args(field_value, type, params) { ...@@ -94,7 +94,7 @@ function build_extra_args(field_value, type, params) {
function check_restore_errors(code) { function check_restore_errors(code) {
if(code == DUP_ERR_CODES.RESTORE_DIR_EXISTS) { if(code == DUP_ERR_CODES.RESTORE_DIR_EXISTS) {
toggle_error(false, ""); toggle_msgs(false, "msg", false);
$("#modal-confirm").foundation("reveal", "open"); $("#modal-confirm").foundation("reveal", "open");
var i = 0; var i = 0;
$("#modal-confirm").on('close.fndtn.reveal', $("#modal-confirm").on('close.fndtn.reveal',
...@@ -112,44 +112,36 @@ function check_restore_errors(code) { ...@@ -112,44 +112,36 @@ function check_restore_errors(code) {
}); });
} }
); );
} else if(code == DUP_ERR_CODES.GPG_FAILED) { return true;
toggle_error(false, ""); }
if(code == DUP_ERR_CODES.GPG_FAILED) {
toggle_msgs(false, "msg", false);
$('#res-passphrase-error small'). $('#res-passphrase-error small').
text(errors.passphrase_wrong); text(errors.passphrase_wrong);
$('#res-passphrase-error small').show(); $('#res-passphrase-error small').show();
return true;
} }
} return false;
function toggle_msgs(data, msgDiv) {
if(data) {
$("#" + msgDiv).addClass("panel");
$("#" + msgDiv).append(data.toString());
$("#" + msgDiv).animate({scrollTop: "+=300px"}, "slow");
} else {
$("#" + msgDiv).removeClass("panel");
$("#" + msgDiv).html("");
if($("#error-alert")) $("#error-alert").hide();
}
} }
function load_status() { function load_status() {
$('#backup_details').hide(); $('#backup_details').hide();
$("#loader").show(); $("#loader").show();
toggle_msgs(null, "msg"); toggle_msgs(false, "msg", false);
$("#status_contents").html(""); $("#status_contents").html("");
call_duplicity("status", get_backup_set(), false); call_duplicity("status", get_backup_set(), false);
} }
function remove_all(force) { function remove_all(force) {
$("#loader").show(); $("#loader").show();
toggle_msgs(null, "msg"); toggle_msgs(false, "msg", false);
call_duplicity("remove", get_backup_set(), force); call_duplicity("remove", get_backup_set(), force);
} }
function load_timeview() { function load_timeview() {
$('#backup_details').hide(); $('#backup_details').hide();
$("#loader").show(); $("#loader").show();
toggle_msgs(null, "msg"); toggle_msgs(false, "msg", false);
call_duplicity("timeview", get_backup_set(), false); call_duplicity("timeview", get_backup_set(), false);
} }
...@@ -161,7 +153,7 @@ function array_to_str(args) { ...@@ -161,7 +153,7 @@ function array_to_str(args) {
return str; return str;
} }
function call_duplicity(mode, backup_set, force) { function call_duplicity(mode, backup_set, force) {
toggle_error(false, ""); toggle_msgs(false, "msg", false);
var win_cmd = ""; var win_cmd = "";
var args = []; var args = [];
...@@ -198,7 +190,7 @@ function call_duplicity(mode, backup_set, force) { ...@@ -198,7 +190,7 @@ function call_duplicity(mode, backup_set, force) {
fs.stat(local_dir, function (err, stats) { fs.stat(local_dir, function (err, stats) {
if(err) { if(err) {
try { mkdirp.sync(local_dir); } try { mkdirp.sync(local_dir); }
catch(e) { toggle_error(e, e); } catch(e) { toggle_msgs(e, "msg", false); }
} }
}); });
} else { } else {
...@@ -257,9 +249,9 @@ function call_duplicity(mode, backup_set, force) { ...@@ -257,9 +249,9 @@ function call_duplicity(mode, backup_set, force) {
var output_str = ""; var output_str = "";
function dup_call_out(data) { function dup_call_out(data) {
if(mode == "status") { if(mode == "status") {
toggle_msgs(data, "status_contents"); toggle_msgs(data.toString(), "status_contents", true);
} else if(mode == "remove") { } else if(mode == "remove") {
toggle_msgs(data, "cleanup-msg"); toggle_msgs(data.toString(), "cleanup-msg", true);
var nothing_to_del = new RegExp( var nothing_to_del = new RegExp(
"No old backup sets found, nothing deleted").exec(data); "No old backup sets found, nothing deleted").exec(data);
if(nothing_to_del) { if(nothing_to_del) {
...@@ -275,7 +267,7 @@ function call_duplicity(mode, backup_set, force) { ...@@ -275,7 +267,7 @@ function call_duplicity(mode, backup_set, force) {
} else if(mode == "timeview") { } else if(mode == "timeview") {
output_str += data.toString(); output_str += data.toString();
} else { } else {
toggle_msgs(data, "msg"); toggle_msgs(data.toString(), "msg", true);
if(mode == "backup") { if(mode == "backup") {
backup_set.last_status = "Running"; backup_set.last_status = "Running";
} }
...@@ -284,10 +276,10 @@ function call_duplicity(mode, backup_set, force) { ...@@ -284,10 +276,10 @@ function call_duplicity(mode, backup_set, force) {
function dup_call_err(data) { function dup_call_err(data) {
if(mode == "remove") { if(mode == "remove") {
toggle_msgs(data, "cleanup-msg"); toggle_msgs(data.toString(), "cleanup-msg", true);
$("#force-delete").hide(); $("#force-delete").hide();
} else { } else {
toggle_msgs(data, "msg"); toggle_msgs(data.toString(), "msg", true);
} }
} }
...@@ -325,8 +317,9 @@ function call_duplicity(mode, backup_set, force) { ...@@ -325,8 +317,9 @@ function call_duplicity(mode, backup_set, force) {
show_alert_box("Successfully completed", "success", true); show_alert_box("Successfully completed", "success", true);
} else if(code == DUP_ERR_CODES.CONNECTION_FAILED) { } else if(code == DUP_ERR_CODES.CONNECTION_FAILED) {
show_cloud_error(); show_cloud_error();
} else { } else if(!check_restore_errors(code)) {
check_restore_errors(code); show_alert_box("A problem occured during restoring",
"error", false);
} }
} else if(mode == "timeview") { } else if(mode == "timeview") {
if(code == 0) { if(code == 0) {
......
...@@ -31,7 +31,7 @@ function escape_illegal_chars(s) { ...@@ -31,7 +31,7 @@ function escape_illegal_chars(s) {
} }
function show_contents_by_date(error, stdout, stderr) { function show_contents_by_date(error, stdout, stderr) {
toggle_error(error, stderr); toggle_msgs(stderr, "msg", false);
$("#time-contents").empty(); $("#time-contents").empty();
if(!error) { if(!error) {
......
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