From cf8fa97b53b00d76d50d1b1592462f6d6d6205d9 Mon Sep 17 00:00:00 2001 From: Nicolas ?vrard Date: Fri, 20 Feb 2015 11:30:11 +0100 Subject: [PATCH] Add loading indicator review10171002 --- src/common.js | 37 +++++++++++++++++++++++++++++++++++++ src/rpc.js | 6 +++++- src/sao.less | 7 +++++++ 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/common.js b/src/common.js index 66d3b13..f8ec2c8 100644 --- a/src/common.js +++ b/src/common.js @@ -2374,4 +2374,41 @@ } }); Sao.common.error = new Sao.common.ErrorDialog(); + + Sao.common.Processing = Sao.class_(Object, { + queries: 0, + timeout: 1000, + init: function() { + this.el = jQuery('
', { + 'id': 'processing', + 'class': 'text-center' + }); + this.el.append(jQuery('', { + 'class': 'label label-info', + 'text': 'Processing…' + })); + this.el.hide(); + jQuery(function() { + this.el.appendTo('body'); + }.bind(this)); + }, + show: function() { + return window.setTimeout(function() { + this.queries += 1; + this.el.show(); + }.bind(this), this.timeout); + }, + hide: function(timeoutID) { + window.clearTimeout(timeoutID); + if (this.queries > 0) { + this.queries -= 1; + } + if (this.queries <= 0) { + this.queries = 0; + this.hide(); + } + } + }); + Sao.common.processing = new Sao.common.Processing(); + }()); diff --git a/src/rpc.js b/src/rpc.js index 61ff57e..bb55837 100644 --- a/src/rpc.js +++ b/src/rpc.js @@ -11,6 +11,7 @@ var params = jQuery.extend([], args.params); params.push(jQuery.extend({}, session.context, params.pop())); + var timeoutID = Sao.common.processing.show(); var ajax_prm = jQuery.ajax({ 'contentType': 'application/json', 'data': JSON.stringify(Sao.rpc.prepareObject({ @@ -19,7 +20,10 @@ })), 'dataType': 'json', 'url': '/' + (session.database || ''), - 'type': 'post' + 'type': 'post', + 'complete': [function() { + Sao.common.processing.hide(timeoutID); + }] }); var ajax_success = function(data) { diff --git a/src/sao.less b/src/sao.less index 3d0e670..93db32e 100644 --- a/src/sao.less +++ b/src/sao.less @@ -96,3 +96,10 @@ text-align: right; } } + +#processing { + position: fixed; + top: 0px; + width: 100%; + z-index: 1000; +}