Navigation Menu

Skip to content

Commit

Permalink
use rcloud.prevent_progress_modal and rcloud.allow_progress_modal to …
Browse files Browse the repository at this point in the history
…control appearance of progress modal
  • Loading branch information
Carlos Scheidegger committed Nov 13, 2013
1 parent 1a989dc commit 8f7dc0b
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 25 deletions.
53 changes: 41 additions & 12 deletions htdocs/js/rcloud.js
Expand Up @@ -268,15 +268,18 @@ RCloud.create = function(rcloud_ocaps) {
if (rcloud.authenticated)
setup_authenticated_ocaps();

//////////////////////////////////////////////////////////////////////////
// Progress indication

// FIXME this doesn't feel like it belongs on rcloud, but then again,
// where would it?
//
// Progress indication

var progress_dialog;
var progress_counter = 0;

var allowed = 1;
var curtains_on = false;
function show_progress_curtain() {

function set_curtain() {
if (curtains_on)
return;
curtains_on = true;
Expand All @@ -286,32 +289,58 @@ RCloud.create = function(rcloud_ocaps) {
}
progress_dialog.modal({keyboard: true});
}
function hide_progress_curtain() {
function clear_curtain() {
if (!curtains_on)
return;
curtains_on = false;
progress_dialog.modal('hide');
}
rcloud.with_progress = function(thunk, delay) {
if (_.isUndefined(delay))
delay = 2000;
function set_cursor() {
_.delay(function() {
document.body.style.cursor = "wait";
}, 0);
}
function clear_cursor() {
_.delay(function() {
document.body.style.cursor = '';
}, 0);
}
rcloud.with_progress = function(thunk, delay) {
if (_.isUndefined(delay))
delay = 2000;
set_cursor();
function done() {
progress_counter -= 1;
if (progress_counter === 0) {
document.body.style.cursor = '';
hide_progress_curtain();
clear_cursor();
clear_curtain();
}
}
_.delay(function() {
if (progress_counter > 0)
show_progress_curtain();
if (progress_counter > 0 && allowed > 0)
set_curtain();
}, delay);
progress_counter += 1;
thunk(done);
};
rcloud.prevent_progress_modal = function() {
if (allowed === 1) {
if (progress_counter > 0) {
clear_cursor();
clear_curtain();
}
}
allowed -= 1;
};
rcloud.allow_progress_modal = function() {
if (allowed === 0) {
if (progress_counter > 0) {
set_cursor();
set_curtain();
}
}
allowed += 1;
};

return rcloud;
};
53 changes: 41 additions & 12 deletions htdocs/js/rcloud_bundle.js
Expand Up @@ -384,15 +384,18 @@ RCloud.create = function(rcloud_ocaps) {
if (rcloud.authenticated)
setup_authenticated_ocaps();

//////////////////////////////////////////////////////////////////////////
// Progress indication

// FIXME this doesn't feel like it belongs on rcloud, but then again,
// where would it?
//
// Progress indication

var progress_dialog;
var progress_counter = 0;

var allowed = 1;
var curtains_on = false;
function show_progress_curtain() {

function set_curtain() {
if (curtains_on)
return;
curtains_on = true;
Expand All @@ -402,32 +405,58 @@ RCloud.create = function(rcloud_ocaps) {
}
progress_dialog.modal({keyboard: true});
}
function hide_progress_curtain() {
function clear_curtain() {
if (!curtains_on)
return;
curtains_on = false;
progress_dialog.modal('hide');
}
rcloud.with_progress = function(thunk, delay) {
if (_.isUndefined(delay))
delay = 2000;
function set_cursor() {
_.delay(function() {
document.body.style.cursor = "wait";
}, 0);
}
function clear_cursor() {
_.delay(function() {
document.body.style.cursor = '';
}, 0);
}
rcloud.with_progress = function(thunk, delay) {
if (_.isUndefined(delay))
delay = 2000;
set_cursor();
function done() {
progress_counter -= 1;
if (progress_counter === 0) {
document.body.style.cursor = '';
hide_progress_curtain();
clear_cursor();
clear_curtain();
}
}
_.delay(function() {
if (progress_counter > 0)
show_progress_curtain();
if (progress_counter > 0 && allowed > 0)
set_curtain();
}, delay);
progress_counter += 1;
thunk(done);
};
rcloud.prevent_progress_modal = function() {
if (allowed === 1) {
if (progress_counter > 0) {
clear_cursor();
clear_curtain();
}
}
allowed -= 1;
};
rcloud.allow_progress_modal = function() {
if (allowed === 0) {
if (progress_counter > 0) {
set_cursor();
set_curtain();
}
}
allowed += 1;
};

return rcloud;
};
Expand Down
2 changes: 1 addition & 1 deletion htdocs/js/rcloud_bundle.min.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions rcloud.support/inst/javascript/password.js
Expand Up @@ -5,6 +5,7 @@
function done() {
result = password.val();
dialog.modal('hide');
rcloud.allow_progress_modal();
}

function create_password_dialog() {
Expand Down Expand Up @@ -49,6 +50,7 @@
if(!dialog.length)
dialog = create_password_dialog();
password = dialog.find("#password-input");
rcloud.prevent_progress_modal();
dialog.modal({keyboard: true});
}
})

0 comments on commit 8f7dc0b

Please sign in to comment.