this.action_manager.stop();
this.action_manager = new openerp.web.ActionManager(this);
this.action_manager.appendTo($("#oe_app"));
- //this.action_manager.do_url_set_hash.add_last(this.do_url_set_hash);
- // if using saved actions, load the action and give it to action manager
- /*var parameters = jQuery.deparam(jQuery.param.querystring());
- if (parameters["s_action"] != undefined) {
- var key = parseInt(parameters["s_action"], 10);
- var self = this;
- this.rpc("/web/session/get_session_action", {key:key}, function(action) {
- self.action_manager.do_action(action);
- });
- } else /**/ if (openerp._modules_loaded) { // TODO: find better option than this
- //this.load_url_state()
+ if (openerp._modules_loaded) { // TODO: find better option than this
this.bind_statechange();
} else {
this.session.on_modules_loaded.add({ // XXX what about a $.Deferred ?
- //callback: $.proxy(this, 'load_url_state'),
callback: $.proxy(this, 'bind_statechange'),
unique: true,
position: 'last'
}
},
- //state_change_event: 'popstate', //statechange
state_change_event: 'hashchange',
bind_statechange: function() {
- console.log('bind', this.state_change_event);
$(window).bind(this.state_change_event, this.on_state_change);
- var self = this;
- self.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'});
- return;
- //var state = window.History.getState(false, false);
- //if (state) {
- // this.$element.trigger('statechange')
- //} else
- {
- var ds = new openerp.web.DataSetSearch(this, 'res.users');
- ds.read_ids([this.session.uid], ['action_id'], function (users) {
- var home_action = users[0].action_id;
- if (!home_action) {
- self.default_home();
- return;
- }
- self.do_action(home_action[0]);
- });
+ var state = $.bbq.getState(true);
+ if (! _.isEmpty(state)) {
+ $(window).trigger(this.state_change_event);
+ } else {
+ this.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'});
}
-
},
on_logged_out: function() {
on_state_change: 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 = window.History.getState();
- //var state = event.getState(true); // = bbq.getState, in fact only deparam the hash
- //var state = window.history.state;
- //if (!state) {
- // chrome
- // state = event.originalEvent.state;
- //}
- //var h_state = window.History.getState();
- //var hash = window.History.getHash();
- //console.log('getState+Hash', h_state, hash);
- //var state = $.deparam(hash, true);
- var state = $.deparam.fragment(true);
- console.log('onstatechange', event, state);
+ var state = event.getState(true); // = bbq.getState, in fact only deparam the hash
return this._super(state);
},
state = _.extend({}, hash, state);
}
var url = '#' + $.param(state);
- //console.log('pushstate', state, url);
- //window.History.pushState(state, '', url);
- //window.history.pushState(state, '', url);
-
- //var state = this.get_state();
- console.log('pushstate', state);
- //$.bbq.pushState(state, 0); // will set the hash, so will call on_state_change
- window.history.pushState(null, '', url);
- //window.location.hash = url;
-
- },
-
- /*
- do_replace_state: function(state) {
- //var hash = window.History.getHash();
- var hash = $.deparam.fragment(true);
- state = _.extend({}, hash, state);
- var url = '#' + $.param(state);
- //window.History.replaceState(state, '', url);
- //window.history.replaceState(state, '', url);
-
- //var state = this.get_state();
- console.log('replacestate', state);
- //$.bbq.pushState(state, 0); // FIXME cannot have the "no history" behavior
- window.history.replaceState(null, '', url);
- //window.location.hash = url;
+ $.bbq.pushState(url); // will set the hash, so will call on_state_change
},
- /*/
- /**
- * Loads state from URL if any, or checks if there is a home action and
- * loads that, assuming we're at the index
- */
- /*load_url_state: function () {
- var self = this;
- // TODO: add actual loading if there is url state to unpack, test on window.location.hash
- // not logged in
- if (!this.session.uid) { return; }
- self.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'});
- },
- */
default_home: function () {
},
/**
self.action_manager.do_action(action);
});
},
- /*/
- do_url_set_hash: function(url) {
- if(!this.url_external_hashchange) {
- this.url_internal_hashchange = true;
- jQuery.bbq.pushState(url);
- }
- },
- //*/
- /*/
- on_url_hashchange: function() {
- if(this.url_internal_hashchange) {
- this.url_internal_hashchange = false;
- } else {
- var url = jQuery.deparam.fragment();
- this.url_external_hashchange = true;
- this.action_manager.on_url_hashchange(url);
- this.url_external_hashchange = false;
- }
- },
- //*/
on_menu_action: function(action) {
this.action_manager.do_action(action);
}
},
+ handle_state: function() {
+ // Only root ActionManager handle the state
+ return this.widget_parent instanceof session.web.WebClient;
+ },
+
+ do_push_state: function(state, extend) {
+ if (this.handle_state()) {
+ this._super.apply(this, arguments);
+ }
+ },
+
on_state_change: function(state) {
- console.log(this.identifier_prefix, 'state change', 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);
+ 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;
- if (run_client) {
- this.null_action();
- this.ir_actions_client(state.client_action);
+ else if (state.client_action) {
+ var run_client = (!this.client_widget) || this.client_widget_name !== state.client_action.tag;
+ if (run_client) {
+ this.null_action();
+ this.ir_actions_client(state.client_action);
+ }
}
}
},
ir_actions_client: function (action) {
this.content_stop();
+ this.client_widget_name = action.tag;
var ClientWidget = session.web.client_actions.get_object(action.tag);
(this.client_widget = new ClientWidget(this, action.params)).appendTo(this);
- this.client_widget_name = action.tag;
var client_action = {tag: action.tag};
if (action.params) _.extend(client_action, {params: action.params});
-
this.do_push_state({client_action: client_action});
},
ir_actions_report_xml: function(action, on_closed) {
$.when(view_promise).then(function () {
self.$element.find('.oe_view_title_text:first').text(
self.display_title());
- self.do_push_state({view_type: self.active_view}, true);
});
return view_promise;
},
- on_state_change: function(state) {
- console.log(this.identifier_prefix, 'state change', state);
- if (state.view_type && state.view_type !== this.active_view) {
- this.on_mode_switch(state.view_type, true);
- }
- return this._super.apply(this, arguments);
- },
/**
* Returns to the view preceding the caller view in this manager's
} else {
$search_prefix.remove();
}
+
+ self.do_push_state({view_type: self.active_view}, true);
});
},
+
+ handle_state: function() {
+ return (this.widget_parent instanceof session.web.ActionManager) && this.widget_parent.handle_state();
+ },
+
+ do_push_state: function(state, extend) {
+ if (this.handle_state()) {
+ this._super.apply(this, arguments);
+ }
+ },
+
+ on_state_change: function(state) {
+ if (this.handle_state() && state.view_type && state.view_type !== this.active_view) {
+ this.on_mode_switch(state.view_type, true);
+ }
+ return this._super.apply(this, arguments);
+ },
+
shortcut_check : function(view) {
var self = this;
var grandparent = this.widget_parent && this.widget_parent.widget_parent;