summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/apps.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/apps.js')
-rw-r--r--addons/web/static/src/js/apps.js173
1 files changed, 90 insertions, 83 deletions
diff --git a/addons/web/static/src/js/apps.js b/addons/web/static/src/js/apps.js
index 156fe9e10b7..5dd5b576fc4 100644
--- a/addons/web/static/src/js/apps.js
+++ b/addons/web/static/src/js/apps.js
@@ -1,4 +1,4 @@
-odoo.define('base.apps', function (require) {
+odoo.define('web.Apps', function (require) {
"use strict";
var core = require('web.core');
@@ -9,10 +9,9 @@ var web_client = require('web.web_client');
var Widget = require('web.Widget');
var _t = core._t;
-var qweb = core.qweb;
var apps_client = null;
-
+var qweb = core.qweb;
var Apps = Widget.extend({
template: 'EmptyComponent',
@@ -106,92 +105,98 @@ var Apps = Widget.extend({
}
},
- start: function() {
+ _on_update_count: function(m) {
var self = this;
- return self.get_client().
- done(function(client) {
- self.client = client;
-
- var qs = (session.debug ? 'debug&' : '') + 'db=' + client.dbname;
- var u = client.origin + '/apps/embed/client?' + qs;
- var css = {width: '100%', height: '400px'};
- self.$ifr = $('<iframe>').attr('src', u);
-
- $(window).on("message.apps", self.proxy('_on_message'));
-
- self.on('message:ready', self, function(m) {
- var w = this.$ifr[0].contentWindow;
- var act = {
- type: 'ir.actions.client',
- tag: this.remote_action_tag,
- params: _.extend({}, this.params, {
- db: this.session.db,
- origin: this.session.origin,
- })
- };
- w.postMessage({type:'action', action: act}, client.origin);
+ var count = m.count;
+ var get_upd_menu_id = function() {
+ if (_.isUndefined(self._upd_menu_id)) {
+ var IMD = new Model('ir.model.data');
+ return IMD.call('get_object_reference', ['base', 'menu_module_updates']).then(function(r) {
+ var mid = r[1];
+ if(r[0] !== 'ir.ui.menu') {
+ // invalid reference, return null
+ mid = null;
+ }
+ self._upd_menu_id = mid;
+ return mid;
});
+ } else {
+ return $.Deferred().resolve(self._upd_menu_id).promise();
+ }
+ };
- self.on('message:set_height', self, function(m) {
- this.$ifr.height(m.height);
- });
+ $.when(get_upd_menu_id()).done(function(menu_id) {
+ if (_.isNull(menu_id)) {
+ return;
+ }
+ var $menu = web_client.menu.$secondary_menus.find(_.str.sprintf('a[data-menu=%s]', menu_id));
+ if ($menu.length === 0) {
+ return;
+ }
+ if (_.isUndefined(count)) {
+ count = 0;
+ }
+ var needupdate = $menu.find('#menu_counter');
+ if (needupdate && needupdate.length !== 0) {
+ if (count > 0) {
+ needupdate.text(count);
+ } else {
+ needupdate.remove();
+ }
+ } else if (count > 0) {
+ $menu.append(qweb.render("Menu.needaction_counter", {widget: {needaction_counter: count}}));
+ }
+ });
+ },
- self.on('message:update_count', self, function(m) {
- var count = m.count;
- var get_upd_menu_id = function() {
- if (_.isUndefined(self._upd_menu_id)) {
- var IMD = new Model('ir.model.data');
- return IMD.call('get_object_reference', ['base', 'menu_module_updates']).then(function(r) {
- var mid = r[1];
- if(r[0] !== 'ir.ui.menu') {
- // invalid reference, return null
- mid = null;
- }
- self._upd_menu_id = mid;
- return mid;
- });
- } else {
- return $.Deferred().resolve(self._upd_menu_id).promise();
- }
- };
-
- $.when(get_upd_menu_id()).done(function(menu_id) {
- if (_.isNull(menu_id)) {
- return;
- }
- var $menu = web_client.menu.$secondary_menus.find(_.str.sprintf('a[data-menu=%s]', menu_id));
- if ($menu.length === 0) {
- return;
- }
- if (_.isUndefined(count)) {
- count = 0;
- }
- var needupdate = $menu.find('#menu_counter');
- if (needupdate && needupdate.length !== 0) {
- if (count > 0) {
- needupdate.text(count);
- } else {
- needupdate.remove();
- }
- } else if (count > 0) {
- $menu.append(qweb.render("Menu.needaction_counter", {widget: {needaction_counter: count}}));
- }
- });
- });
+ start: function() {
+ var self = this;
+ var def = $.Deferred();
+ self.get_client().then(function(client) {
+ self.client = client;
+
+ var qs = (session.debug ? 'debug&' : '') + 'db=' + client.dbname;
+ var u = client.origin + '/apps/embed/client?' + qs;
+ var css = {width: '100%', height: '400px'};
+ self.$ifr = $('<iframe>').attr('src', u);
+
+ $(window).on("message.apps", self.proxy('_on_message'));
+
+ self.on('message:ready', self, function(m) {
+ var w = this.$ifr[0].contentWindow;
+ var act = {
+ type: 'ir.actions.client',
+ tag: this.remote_action_tag,
+ params: _.extend({}, this.params, {
+ db: this.session.db,
+ origin: this.session.origin,
+ })
+ };
+ w.postMessage({type:'action', action: act}, client.origin);
+ });
- self.on('message:blockUI', self, function() { framework.blockUI(); });
- self.on('message:unblockUI', self, function() { framework.unblockUI(); });
- self.on('message:warn', self, function(m) {self.do_warn(m.title, m.message, m.sticky); });
-
- self.$ifr.appendTo(self.$el).css(css).addClass('apps-client');
- }).
- fail(function(client) {
- self.do_warn(_t('Odoo Apps will be available soon'), _t('Showing locally available modules'), true);
- self.rpc('/web/action/load', {action_id: self.failback_action_id}).done(function(action) {
- self.do_action(action);
- web_client.menu.open_action(action.id);
- });
+ self.on('message:set_height', self, function(m) {
+ this.$ifr.height(m.height);
+ });
+
+ self.on('message:update_count', self, self._on_update_count);
+
+ self.on('message:blockUI', self, function() { framework.blockUI(); });
+ self.on('message:unblockUI', self, function() { framework.unblockUI(); });
+ self.on('message:warn', self, function(m) {self.do_warn(m.title, m.message, m.sticky); });
+
+ self.$ifr.appendTo(self.$el).css(css).addClass('apps-client');
+
+ def.resolve();
+ }, function() {
+ self.do_warn(_t('Odoo Apps will be available soon'), _t('Showing locally available modules'), true);
+ return session.rpc('/web/action/load', {action_id: self.failback_action_id}).then(function(action) {
+ return self.do_action(action);
+ }).always(function () {
+ def.reject();
});
+ });
+ return def;
},
});
@@ -202,4 +207,6 @@ var AppsUpdates = Apps.extend({
core.action_registry.add("apps", Apps);
core.action_registry.add("apps.updates", AppsUpdates);
+return Apps;
+
});