summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js/chrome/abstract_web_client.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-11-17 13:14:02 +0100
committerAaron Bohy <aab@odoo.com>2018-01-16 20:49:19 +0100
commit32b8cec5361174c92c45a4975d4e02f1fb448aa2 (patch)
tree110bd6986c2da1ed5047002b7ea40c91ea9fa5ed /addons/web/static/src/js/chrome/abstract_web_client.js
parent9bee25a9df65f657fef0f2f32a7ad823fdc7d4e1 (diff)
[REF] web,*: ActionManager/ViewManager refactoring
This rev. is the first part (out of 3) of the refactoring of the ActionManager and ViewManager layer of the webclient. The main changes are: - there is no ViewManager anymore, its work is now handled by the ActionManager itself, but isolated in a specific file ; this eases a lot of things, as the breadcrumbs handling for example. - the ActionManager code is converted to the new coding principles and guidelines ; mainly, children widgets communicate with it by triggering events up, and not by function calls anymore. - the ActionManager layer is now testable, and a lot of tests have already been written. - the code in other addons has been adapted consequently. What's coming next: - introduce the 'AbstractAction' Widget, and make client actions and view controllers inherit from it ; this widget will implement a common API that could be used uniformly by the ActionManager (e.g. restore(), canBeLeft(), renderButtons(), getTitle()...). - move the ControlPanel handling from the ActionManager to the AbstractAction.
Diffstat (limited to 'addons/web/static/src/js/chrome/abstract_web_client.js')
-rw-r--r--addons/web/static/src/js/chrome/abstract_web_client.js55
1 files changed, 39 insertions, 16 deletions
diff --git a/addons/web/static/src/js/chrome/abstract_web_client.js b/addons/web/static/src/js/chrome/abstract_web_client.js
index 45a2b0b1e8c..c491297abfc 100644
--- a/addons/web/static/src/js/chrome/abstract_web_client.js
+++ b/addons/web/static/src/js/chrome/abstract_web_client.js
@@ -36,8 +36,8 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, {
toggle_fullscreen: function (event) {
this.toggle_fullscreen(event.data.fullscreen);
},
- current_action_updated: function (e) {
- this.current_action_updated(e.data.action);
+ current_action_updated: function (ev) {
+ this.current_action_updated(ev.data.action, ev.data.controller);
},
// GENERIC SERVICES
// the next events are dedicated to generic services required by
@@ -51,6 +51,7 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, {
}
},
warning: '_onDisplayWarning',
+ load_action: '_onLoadAction',
load_views: function (event) {
var params = {
model: event.data.modelName,
@@ -66,6 +67,7 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, {
.load_filters(event.data.dataset, event.data.action_id)
.then(event.data.on_success);
},
+ push_state: '_onPushState',
show_effect: '_onShowEffect',
// session
get_session: function (event) {
@@ -199,7 +201,7 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, {
};
},
set_action_manager: function () {
- this.action_manager = new ActionManager(this, {webclient: this});
+ this.action_manager = new ActionManager(this, session.user_context);
return this.action_manager.appendTo(this.$('.o_main_content'));
},
set_notification_manager: function () {
@@ -213,11 +215,7 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, {
show_application: function () {
},
clear_uncommitted_changes: function () {
- var def = $.Deferred().resolve();
- core.bus.trigger('clear_uncommitted_changes', function chain_callbacks(callback) {
- def = def.then(callback);
- });
- return def;
+ return this.action_manager.clearUncommittedChanges();
},
destroy_content: function () {
_.each(_.clone(this.getChildren()), function (el) {
@@ -264,7 +262,7 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, {
* This allows to widgets that are not inside the ActionManager to perform do_action
*/
do_action: function () {
- return this.action_manager.do_action.apply(this, arguments);
+ return this.action_manager.doAction.apply(this.action_manager, arguments);
},
do_reload: function () {
var self = this;
@@ -274,6 +272,9 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, {
});
},
do_push_state: function (state) {
+ if (!state.menu_id && this.menu) { // this.menu doesn't exist in the POS
+ state.menu_id = this.menu.getCurrentPrimaryMenu();
+ }
if ('title' in state) {
this.set_title(state.title);
delete state.title;
@@ -304,13 +305,14 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, {
this.connection_notification = false;
}
},
- // Handler to be overwritten
- current_action_updated: function () {
- },
- // --------------------------------------------------------------
- // Scrolltop handling
- // --------------------------------------------------------------
- getScrollTop: function () {
+ /**
+ * Handler to be overridden, called each time the UI is updated by the
+ * ActionManager.
+ *
+ * @param {Object} action the action of the currently displayed controller
+ * @param {Object} controller the currently displayed controller
+ */
+ current_action_updated: function (action, controller) {
},
//--------------------------------------------------------------
// Misc.
@@ -347,6 +349,27 @@ var AbstractWebClient = Widget.extend(mixins.ServiceProvider, {
}
},
/**
+ * Loads an action from the database given its ID.
+ *
+ * @private
+ * @param {OdooEvent} event
+ * @param {integer} event.data.actionID
+ * @param {Object} event.data.context
+ * @param {function} event.data.on_success
+ */
+ _onLoadAction: function (event) {
+ data_manager
+ .load_action(event.data.actionID, event.data.context)
+ .then(event.data.on_success);
+ },
+ /**
+ * @private
+ * @param {OdooEvent} e
+ */
+ _onPushState: function (e) {
+ this.do_push_state(e.data.state);
+ },
+ /**
* Displays a visual effect (for example, a rainbowman0
*
* @private