Added new loading modal window. Phase 1.
Phase 2 will include metadata, currently it needs to be rewritten to allow it.
Also removed some redundant loading animations.
Change-Id: I1dce75460a0d61d14ec1de43b250b1cb27801c65
diff --git a/client/catalog/js/catalog.js b/client/catalog/js/catalog.js
index 5203fdc..2dfb368 100644
--- a/client/catalog/js/catalog.js
+++ b/client/catalog/js/catalog.js
@@ -377,9 +377,9 @@
} else if (resultIndex === 1) {
this.resultMenu.find('.previous').removeClass('disabled');
}
- $.scrollTo("#results", 500, {
- interrupt: true
- });
+ $('body').animate({
+ scrollTop: $("#results").offset().top
+ }, 500);
}
Atmos.prototype.getResults = function(index) {
@@ -455,19 +455,29 @@
interest.setInterestLifetimeMilliseconds(500);
interest.setMustBeFresh(true);
const face = this.face;
- async.retry(4, function(done) {
- face.expressInterest(interest, function(interest, data) {
- done();
- success(interest, data);
- }, function(interest) {
- done("Interest timed out 4 times.", interest);
+ var cancelled = false;
+ var attempt = 0;
+ openLoadingOverlay(function(update){
+ async.retry(4, function(done) {
+ face.expressInterest(interest, function(interest, data) {
+ update(true, attempt, attempt);
+ done();
+ success(interest, data);
+ }, function(interest) {
+ update(false, attempt++, attempt);
+ done("Timeout", interest);
+ });
+ }, function(err, interest) {
+ update(true, attempt, attempt);
+ if (err) {
+ console.log(err, interest);
+ failure(interest);
+ }
});
- }, function(err, interest) {
- if (err) {
- console.log(err, interest);
- failure(interest);
- }
+ }, function(){
+ cancelled = true;
});
+
}
/**
@@ -673,7 +683,8 @@
var item = $('<li><a href="#">' + name + '</a></li>');
sub.append(item);
- item.click(function() {
+ item.find('a').click(function(e) {
+ e.preventDefault();
//Click on the side menu filters
if (item.hasClass('active')) {
//Does the filter already exist?
@@ -685,7 +696,7 @@
var filter = $('<span class="label label-default"></span>');
filter.text(category + ':' + name);
scope.filters.append(filter);
- filter.click(function() {
+ filter.click(function(e) {
//Click on a filter
filter.remove();
item.removeClass('active');
@@ -694,7 +705,8 @@
});
});
//Toggle the menus. (Only respond when the immediate tab is clicked.)
- e.find('> a').click(function() {
+ e.find('> a').click(function(e) {
+ e.preventDefault();
scope.categories.find('.subnav').slideUp();
var t = $(this).siblings('.subnav');
if (!t.is(':visible')) {
diff --git a/client/catalog/js/loading-overlay.js b/client/catalog/js/loading-overlay.js
new file mode 100644
index 0000000..849524d
--- /dev/null
+++ b/client/catalog/js/loading-overlay.js
@@ -0,0 +1,78 @@
+/**
+ * This function allows the app to pass in a callback function for updating the progress and a function to call if the progress it cancelled.
+ * @param func - A function accepting two functions as parameters, the first will be called with one parameter (which is a callback function
+ * for progress updates) when the overlay is ready.
+ * @param cancel - A function to call if the overlay is cancelled.
+ *
+ * Example:
+ * openLoadingOverlay(function(update){
+ * //Begin progress, call update if progress is in chunks, otherwise ignore.
+ * }, function(){
+ * //Cancelled
+ * });
+ */
+var openLoadingOverlay = (function(){
+ "use strict";
+
+ var isOpen = false;
+
+ return function(func, cancel){
+
+ var overlay = $('#loading');
+ var progress = overlay.find('.progress-bar');
+ var cancelButton = overlay.find('#loading-cancel');
+
+ if (isOpen){
+ console.warn("Two overlays are not permitted at the same time. The second will have dummy callbacks");
+ func(function(){});
+ return;
+ }
+
+ isOpen = true;
+
+ var update = function(done, current, total){
+ if (current && total){
+ progress.text(current + '/' + total)
+ .animate({
+ width: Math.round(current/total) + '%'
+ },
+ 200,
+ 'linear',
+ function(){
+ if (done){
+ reset();
+ }
+ }
+ );
+ } else {
+ if (done){
+ reset();
+ }
+ }
+ };
+
+ var reset = function(){
+ overlay.modal('hide');
+ progress.text('Loading...').css('width', '100%');
+ overlay.removeClass('cancelled').addClass('loading');
+ cancelButton.removeClass('disabled');
+ };
+
+ cancelButton.one('click', function(){
+
+ cancelButton.addClass('disabled');
+ overlay.addClass('cancelled').removeClass('loading');
+
+ setTimeout(reset, 2000);
+ progress.text('Cancelling...').css('width', 0).animate({
+ width: '100%'
+ }, 2000);
+
+ });
+
+ overlay.modal('show');
+
+ func(update);
+
+ };
+})();