diff options
Diffstat (limited to 'addons/web/static/src/js/widgets/loading.js')
| -rw-r--r-- | addons/web/static/src/js/widgets/loading.js | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/addons/web/static/src/js/widgets/loading.js b/addons/web/static/src/js/widgets/loading.js new file mode 100644 index 00000000000..75ac1a8b4b8 --- /dev/null +++ b/addons/web/static/src/js/widgets/loading.js @@ -0,0 +1,66 @@ +odoo.define('web.Loading', ['web.core', 'web.framework', 'web.session', 'web.Widget'], function (require) { +"use strict"; + +var core = require('web.core'); +var framework = require('web.framework'); +var session = require('web.session'); +var Widget = require('web.Widget'); + +var _t = core._t; + +var Loading = Widget.extend({ + template: _t("Loading"), + init: function(parent) { + this._super(parent); + this.count = 0; + this.blocked_ui = false; + session.on("request", this, this.request_call); + session.on("response", this, this.response_call); + session.on("response_failed", this, this.response_call); + }, + destroy: function() { + this.on_rpc_event(-this.count); + this._super(); + }, + request_call: function() { + this.on_rpc_event(1); + }, + response_call: function() { + this.on_rpc_event(-1); + }, + on_rpc_event : function(increment) { + var self = this; + if (!this.count && increment === 1) { + // Block UI after 3s + this.long_running_timer = setTimeout(function () { + self.blocked_ui = true; + framework.blockUI(); + }, 3000); + } + + this.count += increment; + if (this.count > 0) { + if (session.debug) { + this.$el.text(_.str.sprintf( _t("Loading (%d)"), this.count)); + } else { + this.$el.text(_t("Loading")); + } + this.$el.show(); + this.getParent().$el.addClass('oe_wait'); + } else { + this.count = 0; + clearTimeout(this.long_running_timer); + // Don't unblock if blocked by somebody else + if (self.blocked_ui) { + this.blocked_ui = false; + framework.unblockUI(); + } + this.$el.fadeOut(); + this.getParent().$el.removeClass('oe_wait'); + } + } +}); + +return Loading; +}); + |
