Permalink
Browse files

use rcloud.prevent_progress_modal and rcloud.allow_progress_modal to …

…control appearance of progress modal
  • Loading branch information...
1 parent 1a989dc commit 8f7dc0b0bd9a732da16eac6c3252700aa4155ec9 Carlos Scheidegger committed Nov 13, 2013
Showing with 85 additions and 25 deletions.
  1. +41 −12 htdocs/js/rcloud.js
  2. +41 −12 htdocs/js/rcloud_bundle.js
  3. +1 −1 htdocs/js/rcloud_bundle.min.js
  4. +2 −0 rcloud.support/inst/javascript/password.js
View
@@ -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;
@@ -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;
};
View
@@ -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;
@@ -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;
};

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -5,6 +5,7 @@
function done() {
result = password.val();
dialog.modal('hide');
+ rcloud.allow_progress_modal();
}
function create_password_dialog() {
@@ -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.