[IMP] limit the hash managment to the actionmanager of the webclient (and its viewmanager and views)

bzr revid: chs@openerp.com-20111212164455-44l31w1jr1sm2mg0
This commit is contained in:
Christophe Simonis 2011-12-12 17:44:55 +01:00
parent 642c8e040a
commit 12ce718088
3 changed files with 56 additions and 72 deletions

View File

@ -1047,54 +1047,50 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie
if(this.action_manager) if(this.action_manager)
this.action_manager.stop(); this.action_manager.stop();
this.action_manager = new openerp.web.ActionManager(this); this.action_manager = new openerp.web.ActionManager(this);
this.action_manager.do_push_state.add(this.do_push_state);
this.action_manager.appendTo($("#oe_app")); this.action_manager.appendTo($("#oe_app"));
if (openerp._modules_loaded) { // TODO: find better option than this if (openerp._modules_loaded) { // TODO: find better option than this
this.bind_statechange(); this.bind_hashchange();
} else { } else {
this.session.on_modules_loaded.add({ // XXX what about a $.Deferred ? this.session.on_modules_loaded.add({ // XXX what about a $.Deferred ?
callback: $.proxy(this, 'bind_statechange'), callback: $.proxy(this, 'bind_hashchange'),
unique: true, unique: true,
position: 'last' position: 'last'
}) })
} }
}, },
state_change_event: 'hashchange', bind_hashchange: function() {
$(window).bind('hashchange', this.on_hashchange);
bind_statechange: function() {
$(window).bind(this.state_change_event, this.on_state_change);
var state = $.bbq.getState(true); var state = $.bbq.getState(true);
if (! _.isEmpty(state)) { if (! _.isEmpty(state)) {
$(window).trigger(this.state_change_event); $(window).trigger('hashchange');
} else { } else {
this.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'}); this.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'});
} }
}, },
on_logged_out: function() { on_logged_out: function() {
$(window).unbind('hashchange', this.on_hashchange);
if(this.action_manager) if(this.action_manager)
this.action_manager.stop(); this.action_manager.stop();
this.action_manager = null; this.action_manager = null;
$(window).unbind(this.state_change_event, this.on_state_change);
}, },
on_state_change: function(event) { on_hashchange: function(event) {
// as this method is bound to a event via jQuery, the argument is the jQuery Event.. we need to get the current state var state = event.getState(true);
var state = event.getState(true); // = bbq.getState, in fact only deparam the hash this.action_manager.do_load_state(state);
return this._super(state);
}, },
do_push_state: function(state, overwrite) {
if (!overwrite) {
do_push_state: function(state, extend) {
if (extend) {
var hash = $.deparam.fragment(true); var hash = $.deparam.fragment(true);
state = _.extend({}, hash, state); state = _.extend({}, hash, state);
} }
var url = '#' + $.param(state); var url = '#' + $.param(state);
$.bbq.pushState(url); // will set the hash, so will call on_state_change $.bbq.pushState(url);
}, },
default_home: function () { default_home: function () {

View File

@ -986,21 +986,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
return false; return false;
}, },
do_push_state: function(state) {
// create a new state
if (this.widget_parent) {
return this.widget_parent.do_push_state.apply(this,arguments);
}
//this.on_state_change(state);
return null;
},
on_state_change: function(state) {
_.each(this.widget_children, function(child) {
child.on_state_change(state);
});
},
rpc: function(url, data, success, error) { rpc: function(url, data, success, error) {
var def = $.Deferred().then(success, error); var def = $.Deferred().then(success, error);
var self = this; var self = this;

View File

@ -49,36 +49,28 @@ session.web.ActionManager = session.web.Widget.extend({
} }
}, },
handle_state: function() { do_push_state: function(state, overwrite) {
// Only root ActionManager handle the state
return this.widget_parent instanceof session.web.WebClient;
}, },
do_push_state: function(state, extend) { do_load_state: function(state) {
if (this.handle_state()) { if (state.action_id) {
this._super.apply(this, arguments); var run_action = (!this.inner_viewmanager) || this.inner_viewmanager.action.id !== state.action_id;
} if (run_action) {
}, this.null_action();
this.do_action(state.action_id);
on_state_change: function(state) {
if (this.handle_state()) {
if (state.action_id) {
var run_action = (!this.inner_viewmanager) || this.inner_viewmanager.action.id !== state.action_id;
if (run_action) {
this.null_action();
this.do_action(state.action_id);
}
} }
else if (state.client_action) { }
var run_client = (!this.client_widget) || this.client_widget_name !== state.client_action.tag; else if (state.client_action) {
if (run_client) { var run_client = (!this.client_widget) || this.client_widget_name !== state.client_action.tag;
this.null_action(); if (run_client) {
this.ir_actions_client(state.client_action); this.null_action();
} this.ir_actions_client(state.client_action);
} }
} }
return this._super.apply(this, arguments); if (this.inner_viewmanager) {
this.inner_viewmanager.do_load_state(state);
}
}, },
do_action: function(action, on_close) { do_action: function(action, on_close) {
@ -137,9 +129,10 @@ session.web.ActionManager = session.web.Widget.extend({
this.dialog_stop(); this.dialog_stop();
this.content_stop(); this.content_stop();
this.inner_viewmanager = new session.web.ViewManagerAction(this, action); this.inner_viewmanager = new session.web.ViewManagerAction(this, action);
this.inner_viewmanager.do_push_state.add(this.do_push_state);
this.inner_viewmanager.appendTo(this.$element); this.inner_viewmanager.appendTo(this.$element);
if (action.id) { if (action.id) {
this.do_push_state({action_id: action.id}); this.do_push_state({action_id: action.id}, true);
} }
} }
}, },
@ -166,7 +159,7 @@ session.web.ActionManager = session.web.Widget.extend({
var client_action = {tag: action.tag}; var client_action = {tag: action.tag};
if (action.params) _.extend(client_action, {params: action.params}); if (action.params) _.extend(client_action, {params: action.params});
this.do_push_state({client_action: client_action}); this.do_push_state({client_action: client_action}, true);
}, },
ir_actions_report_xml: function(action, on_closed) { ir_actions_report_xml: function(action, on_closed) {
var self = this; var self = this;
@ -283,7 +276,7 @@ session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.View
var container = $("#" + this.element_id + '_view_' + view_type); var container = $("#" + this.element_id + '_view_' + view_type);
view_promise = controller.appendTo(container); view_promise = controller.appendTo(container);
this.views[view_type].controller = controller; this.views[view_type].controller = controller;
this.views[view_type].deferred.resolve(); this.views[view_type].deferred.resolve(view_type);
$.when(view_promise).then(function() { $.when(view_promise).then(function() {
self.on_controller_inited(view_type, controller); self.on_controller_inited(view_type, controller);
if (self.searchview && view.controller.searchable !== false) { if (self.searchview && view.controller.searchable !== false) {
@ -467,6 +460,12 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner
var main_view_loaded = this._super(); var main_view_loaded = this._super();
_.each(_.keys(this.views), function(view_type) {
$.when(self.views[view_type].deferred).done(function(view_type) {
self.views[view_type].controller.do_push_state.add(self.do_push_state);
});
});
var manager_ready = $.when(searchview_loaded, main_view_loaded); var manager_ready = $.when(searchview_loaded, main_view_loaded);
this.$element.find('.oe_get_xml_view').click(function () { this.$element.find('.oe_get_xml_view').click(function () {
@ -541,25 +540,23 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner
$search_prefix.remove(); $search_prefix.remove();
} }
self.do_push_state({view_type: self.active_view}, true); self.do_push_state({view_type: self.active_view});
}); });
}, },
handle_state: function() { do_push_state: function(state, overwrite) {
return (this.widget_parent instanceof session.web.ActionManager) && this.widget_parent.handle_state();
}, },
do_push_state: function(state, extend) { do_load_state: function(state) {
if (this.handle_state()) { var self = this,
this._super.apply(this, arguments); defs = [];
} if (state.view_type && state.view_type !== this.active_view) {
}, defs.push(this.on_mode_switch(state.view_type, true));
}
on_state_change: function(state) { $.when(defs).then(function() {
if (this.handle_state() && state.view_type && state.view_type !== this.active_view) { self.views[self.active_view].controller.do_load_state(state);
this.on_mode_switch(state.view_type, true); });
}
return this._super.apply(this, arguments);
}, },
shortcut_check : function(view) { shortcut_check : function(view) {
@ -1127,6 +1124,12 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{
}, },
sidebar_context: function () { sidebar_context: function () {
return $.Deferred().resolve({}).promise(); return $.Deferred().resolve({}).promise();
},
do_push_state: function(state, overwrite) {
},
do_load_state: function(state) {
} }
}); });