summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/views/abstract_controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'addons/web/static/src/js/views/abstract_controller.js')
-rw-r--r--addons/web/static/src/js/views/abstract_controller.js78
1 files changed, 47 insertions, 31 deletions
diff --git a/addons/web/static/src/js/views/abstract_controller.js b/addons/web/static/src/js/views/abstract_controller.js
index 0bd156516fa..607f49c8031 100644
--- a/addons/web/static/src/js/views/abstract_controller.js
+++ b/addons/web/static/src/js/views/abstract_controller.js
@@ -62,7 +62,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
/**
* Simply renders and updates the url.
*
- * @returns {Deferred}
+ * @returns {Promise}
*/
start: function () {
var self = this;
@@ -70,12 +70,16 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
this.$el.addClass('o_view_controller');
return this._super.apply(this, arguments).then(function () {
+ var prom;
if (self._controlPanel) {
// render the ControlPanel elements (buttons, pager, sidebar...)
- self.controlPanelElements = self._renderControlPanelElements();
- self._controlPanel.$el.prependTo(self.$el);
+ prom = self._renderControlPanelElements().then(function (elements) {
+ self.controlPanelElements = elements;
+ self._controlPanel.$el.prependTo(self.$el);
+ });
}
-
+ return Promise.resolve(prom);
+ }).then(function () {
return self._update(self.initialState);
});
},
@@ -119,7 +123,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
*/
canBeRemoved: function () {
// AAB: get rid of this option when on_hashchange mechanism is improved
- return this.discardChanges(undefined, {readonlyIfRealDiscard: true});
+ return this.discardChanges(undefined, { readonlyIfRealDiscard: true });
},
/**
* Discards the changes made on the record associated to the given ID, or
@@ -128,15 +132,15 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
* this method on the active view to make sure it is ok to open the home
* screen (and lose all current state).
*
- * Note that it returns a deferred, because the view could choose to ask the
+ * Note that it returns a Promise, because the view could choose to ask the
* user if he agrees to discard.
*
* @param {string} [recordID]
* if not given, we consider all the changes made by the controller
- * @returns {Deferred} resolved if properly discarded, rejected otherwise
+ * @returns {Promise} resolved if properly discarded, rejected otherwise
*/
discardChanges: function (recordID) {
- return $.when();
+ return Promise.resolve();
},
/**
* Export the state of the controller containing information that is shared
@@ -155,7 +159,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
/**
* Gives the focus to the renderer
*/
- giveFocus: function() {
+ giveFocus: function () {
this.renderer.giveFocus();
},
/**
@@ -174,10 +178,11 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
* Short helper method to reload the view
*
* @param {Object} [params] This object will simply be given to the update
- * @returns {Deferred}
+ * @returns {Promise}
*/
reload: function (params) {
params = params || {};
+ var self = this;
var def;
var controllerState = params.controllerState || {};
var cpState = controllerState.cpState;
@@ -186,7 +191,9 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
params = _.extend({}, params, searchQuery);
});
}
- return $.when(def).then(this.update.bind(this, params, {}));
+ return Promise.resolve(def).then(function () {
+ return self.update(params, {});
+ });
},
/**
* For views that require a pager, this method will be called to allow the
@@ -195,16 +202,20 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
* your view does not want a pager, just let this method empty.
*
* @param {jQuery Node} $node
+ * @return {Promise}
*/
renderPager: function ($node) {
+ return Promise.resolve();
},
/**
* Same as renderPager, but for the 'sidebar' zone (the zone with the menu
* dropdown in the control panel next to the buttons)
*
* @param {jQuery Node} $node
+ * @return {Promise}
*/
renderSidebar: function ($node) {
+ return Promise.resolve();
},
/**
* This is the main entry point for the controller. Changes from the search
@@ -219,12 +230,12 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
* @param {Object} [options]
* @param {boolean} [options.reload=true] if true, the model will reload data
*
- * @returns {Deferred}
+ * @returns {Promise}
*/
update: function (params, options) {
var self = this;
var shouldReload = (options && 'reload' in options) ? options.reload : true;
- var def = shouldReload ? this.model.reload(this.handle, params) : $.when();
+ var def = shouldReload ? this.model.reload(this.handle, params) : Promise.resolve();
// we check here that the updateIndex of the control panel hasn't changed
// between the start of the update request and the moment the controller
// asks the control panel to update itself ; indeed, it could happen that
@@ -285,17 +296,17 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
* return {'html': '<h1>hello, world</h1>'}
*
* @private
- * @returns {Deferred}
+ * @returns {Promise}
*/
_renderBanner: function () {
if (this.bannerRoute !== undefined) {
var self = this;
return this.dp
- .add(this._rpc({route: this.bannerRoute}))
+ .add(this._rpc({ route: this.bannerRoute }))
.then(function (response) {
if (!response.html) {
self.$el.removeClass('o_has_banner');
- return $.when();
+ return Promise.resolve();
}
self.$el.addClass('o_has_banner');
var $banner = $(response.html);
@@ -313,22 +324,24 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
defs.push(ajax.loadJS(js.src));
js.remove();
});
- return $.when.apply($, defs).then(function () {
+ return Promise.all(defs).then(function () {
$banner.prependTo(self.$('> .o_content'));
self._$banner = $banner;
});
});
}
- return $.when();
+ return Promise.resolve();
},
/**
* Renders the control elements (buttons, pager and sidebar) of the current
* view.
*
* @private
- * @returns {Object} an object containing the control panel jQuery elements
+ * @returns {Promise<Object>} resolved with an object containing the control
+ * panel jQuery elements
*/
_renderControlPanelElements: function () {
+ var self = this;
var elements = {
$buttons: $('<div>'),
$sidebar: $('<div>'),
@@ -336,15 +349,18 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
};
this.renderButtons(elements.$buttons);
- this.renderSidebar(elements.$sidebar);
- this.renderPager(elements.$pager);
- // remove the unnecessary outer div
- elements = _.mapObject(elements, function($node) {
- return $node && $node.contents();
- });
- elements.$switch_buttons = this._renderSwitchButtons();
+ var sidebarProm = this.renderSidebar(elements.$sidebar);
+ var pagerProm = this.renderPager(elements.$pager);
+
+ return Promise.all([sidebarProm, pagerProm]).then(function () {
+ // remove the unnecessary outer div
+ elements = _.mapObject(elements, function ($node) {
+ return $node && $node.contents();
+ });
+ elements.$switch_buttons = self._renderSwitchButtons();
- return elements;
+ return elements;
+ });
},
/**
* Renders the switch buttons and binds listeners on them.
@@ -354,7 +370,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
*/
_renderSwitchButtons: function () {
var self = this;
- var views = _.filter(this.actionViews, {multiRecord: this.isMultiRecord});
+ var views = _.filter(this.actionViews, { multiRecord: this.isMultiRecord });
if (views.length <= 1) {
return $();
@@ -373,7 +389,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
var $switchButtonsFiltered = config.device.isMobile ? $switchButtons.find('button') : $switchButtons.filter('button');
$switchButtonsFiltered.click(_.debounce(function (event) {
var viewType = $(event.target).data('view-type');
- self.trigger_up('switch_view', {view_type: viewType});
+ self.trigger_up('switch_view', { view_type: viewType });
}, 200, true));
// set active view's icon as view switcher button's icon in mobile
@@ -404,7 +420,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
* @param {Object} state the state given by the model
* @param {Object} [params]
* @param {Object[]} [params.breadcrumbs]
- * @returns {Deferred}
+ * @returns {Promise}
*/
_update: function (state, params) {
// AAB: update the control panel -> this will be moved elsewhere at some point
@@ -526,7 +542,7 @@ var AbstractController = mvc.Controller.extend(ActionMixin, {
*/
_onOpenRecord: function (ev) {
ev.stopPropagation();
- var record = this.model.get(ev.data.id, {raw: true});
+ var record = this.model.get(ev.data.id, { raw: true });
this.trigger_up('switch_view', {
view_type: 'form',
res_id: record.res_id,