From 607fa699d634d0aa4c34a8a00b8f43ff332c5a06 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Fri, 9 Dec 2011 17:31:14 +0100 Subject: [PATCH 1/7] [IMP] fire the bbq bzr revid: chs@openerp.com-20111209163114-23c0orpwbqom4js9 --- addons/web/__openerp__.py | 3 + addons/web/static/src/js/chrome.js | 114 +++++++++++++++++++++++++++-- addons/web/static/src/js/core.js | 16 ++++ addons/web/static/src/js/views.js | 81 +++++++++++--------- 4 files changed, 174 insertions(+), 40 deletions(-) diff --git a/addons/web/__openerp__.py b/addons/web/__openerp__.py index 3767072ff9d..a82759af85f 100644 --- a/addons/web/__openerp__.py +++ b/addons/web/__openerp__.py @@ -36,6 +36,9 @@ "static/lib/underscore/underscore.string.js", "static/lib/labjs/LAB.src.js", "static/lib/py.parse/lib/py.js", + #"static/lib/history.js/scripts/bundled/html4+html5/jquery.history.js", + #"static/lib/history.js/scripts/uncompressed/history.adapter.jquery.js", + #"static/lib/history.js/scripts/uncompressed/history.js", "static/src/js/boot.js", "static/src/js/core.js", "static/src/js/dates.js", diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 3c212616496..2bf7451c52a 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1011,6 +1011,7 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this.session.on_session_valid.add_last(this.header.do_update); this.session.on_session_invalid.add_last(this.header.do_update); this.session.on_session_valid.add_last(this.on_logged); + this.session.on_session_invalid.add_last(this.on_logged_out); this.menu = new openerp.web.Menu(this, "oe_menu", "oe_secondary_menu"); this.menu.on_action.add(this.on_menu_action); @@ -1047,37 +1048,131 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie 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); + //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()); + /*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() + } else /**/ if (openerp._modules_loaded) { // TODO: find better option than this + //this.load_url_state() + this.bind_statechange(); } else { - this.session.on_modules_loaded.add({ - callback: $.proxy(this, 'load_url_state'), + 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]); + }); + } + + }, + + on_logged_out: function() { + if(this.action_manager) + this.action_manager.stop(); + this.action_manager = null; + $(window).unbind(this.state_change_event, this.on_state_change); + }, + + 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); + return this._super(state); + }, + + + + do_push_state: function(state, extend) { + if (extend) { + var hash = $.deparam.fragment(true); + 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; + }, + /*/ + /** * 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 () { + /*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 () { }, /** @@ -1101,12 +1196,15 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie 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; @@ -1117,6 +1215,8 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this.url_external_hashchange = false; } }, + //*/ + on_menu_action: function(action) { this.action_manager.do_action(action); }, diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index c9255d31949..e3a32342af7 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -985,6 +985,22 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W } 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) { var def = $.Deferred().then(success, error); var self = this; diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index e11c0c20f04..13f74330a21 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -24,6 +24,7 @@ session.web.ActionManager = session.web.Widget.extend({ this.dialog = null; this.dialog_viewmanager = null; this.client_widget = null; + this.client_widget_name = null; }, render: function() { return "
"; @@ -44,37 +45,39 @@ session.web.ActionManager = session.web.Widget.extend({ if (this.client_widget) { this.client_widget.stop(); this.client_widget = null; + this.client_widget_name = null; } }, - url_update: function(action) { - var url = {}; - if(action.id) - url.action_id = action.id; - // this.url = { - // "model": action.res_model, - // "domain": action.domain, - // }; - // action.res_model - // action.domain - // action.context - // after - // action.views - // action.res_id - // mode - // menu - this.do_url_set_hash(url); - }, - do_url_set_hash: function(url) { - }, - on_url_hashchange: function(url) { - var self = this; - if(url && url.action_id) { - self.rpc("/web/action/load", { action_id: url.action_id }, function(result) { - self.do_action(result.result); - }); + + 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); + } } + 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); + } + } + + return this._super.apply(this, arguments); }, + do_action: function(action, on_close) { + if (_.isNumber(action)) { + var self = this; + self.rpc("/web/action/load", { action_id: action }, function(result) { + self.do_action(result.result, on_close); + }); + return; + } if (!action.type) { console.error("No type for action", action); return; @@ -124,14 +127,10 @@ session.web.ActionManager = session.web.Widget.extend({ this.content_stop(); this.inner_viewmanager = new session.web.ViewManagerAction(this, action); this.inner_viewmanager.appendTo(this.$element); - this.url_update(action); + if (action.id) { + this.do_push_state({action_id: action.id}); + } } - /* new window code - this.rpc("/web/session/save_session_action", { the_action : action}, function(key) { - var url = window.location.protocol + "//" + window.location.host + window.location.pathname + "?" + jQuery.param({ s_action : "" + key }); - window.open(url,'_blank'); - }); - */ }, ir_actions_act_window_close: function (action, on_closed) { if (!this.dialog && on_closed) { @@ -152,6 +151,12 @@ session.web.ActionManager = session.web.Widget.extend({ this.content_stop(); 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) { var self = this; @@ -301,9 +306,19 @@ session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.View $.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 * navigation history (the navigation history is appended to via From 642c8e040a13a1a1eec29f70415ed9d495b72a51 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 12 Dec 2011 15:20:12 +0100 Subject: [PATCH 2/7] [FIX] cleaning url managment bzr revid: chs@openerp.com-20111212142012-cb5p5oxu2fzmcil2 --- addons/web/__openerp__.py | 3 - addons/web/static/src/js/chrome.js | 112 +++-------------------------- addons/web/static/src/js/views.js | 70 +++++++++++------- 3 files changed, 54 insertions(+), 131 deletions(-) diff --git a/addons/web/__openerp__.py b/addons/web/__openerp__.py index a82759af85f..3767072ff9d 100644 --- a/addons/web/__openerp__.py +++ b/addons/web/__openerp__.py @@ -36,9 +36,6 @@ "static/lib/underscore/underscore.string.js", "static/lib/labjs/LAB.src.js", "static/lib/py.parse/lib/py.js", - #"static/lib/history.js/scripts/bundled/html4+html5/jquery.history.js", - #"static/lib/history.js/scripts/uncompressed/history.adapter.jquery.js", - #"static/lib/history.js/scripts/uncompressed/history.js", "static/src/js/boot.js", "static/src/js/core.js", "static/src/js/dates.js", diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 2bf7451c52a..cf7b9d305c1 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1048,22 +1048,11 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie 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' @@ -1071,32 +1060,17 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie } }, - //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() { @@ -1108,19 +1082,7 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie 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); }, @@ -1132,47 +1094,9 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie 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; - + $.bbq.pushState(url); // will set the hash, so will call on_state_change }, - /* - 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; - }, - /*/ - - /** - * 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 () { }, /** @@ -1196,26 +1120,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie 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); diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 13f74330a21..86aa8828caa 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -49,21 +49,32 @@ session.web.ActionManager = session.web.Widget.extend({ } }, - 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); - } + 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); } - 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); + }, + + 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; + if (run_client) { + this.null_action(); + this.ir_actions_client(state.client_action); + } } } @@ -149,13 +160,12 @@ session.web.ActionManager = session.web.Widget.extend({ }, 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) { @@ -306,18 +316,10 @@ session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.View $.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 @@ -538,8 +540,28 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner } 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; From 12ce7180882bb6aedc97ff6f1f17b0b5ea4c1929 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 12 Dec 2011 17:44:55 +0100 Subject: [PATCH 3/7] [IMP] limit the hash managment to the actionmanager of the webclient (and its viewmanager and views) bzr revid: chs@openerp.com-20111212164455-44l31w1jr1sm2mg0 --- addons/web/static/src/js/chrome.js | 30 +++++------ addons/web/static/src/js/core.js | 15 ------ addons/web/static/src/js/views.js | 83 ++++++++++++++++-------------- 3 files changed, 56 insertions(+), 72 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index cf7b9d305c1..0e332252341 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1047,54 +1047,50 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie if(this.action_manager) this.action_manager.stop(); 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")); if (openerp._modules_loaded) { // TODO: find better option than this - this.bind_statechange(); + this.bind_hashchange(); } else { this.session.on_modules_loaded.add({ // XXX what about a $.Deferred ? - callback: $.proxy(this, 'bind_statechange'), + callback: $.proxy(this, 'bind_hashchange'), unique: true, position: 'last' }) } }, - state_change_event: 'hashchange', - - bind_statechange: function() { - $(window).bind(this.state_change_event, this.on_state_change); + bind_hashchange: function() { + $(window).bind('hashchange', this.on_hashchange); var state = $.bbq.getState(true); if (! _.isEmpty(state)) { - $(window).trigger(this.state_change_event); + $(window).trigger('hashchange'); } else { this.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'}); } }, on_logged_out: function() { + $(window).unbind('hashchange', this.on_hashchange); if(this.action_manager) this.action_manager.stop(); this.action_manager = null; - $(window).unbind(this.state_change_event, this.on_state_change); }, - 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 = event.getState(true); // = bbq.getState, in fact only deparam the hash - return this._super(state); + on_hashchange: function(event) { + var state = event.getState(true); + this.action_manager.do_load_state(state); }, - - - do_push_state: function(state, extend) { - if (extend) { + do_push_state: function(state, overwrite) { + if (!overwrite) { var hash = $.deparam.fragment(true); state = _.extend({}, hash, state); } var url = '#' + $.param(state); - $.bbq.pushState(url); // will set the hash, so will call on_state_change + $.bbq.pushState(url); }, default_home: function () { diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js index e3a32342af7..1962cc440c7 100644 --- a/addons/web/static/src/js/core.js +++ b/addons/web/static/src/js/core.js @@ -986,21 +986,6 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W 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) { var def = $.Deferred().then(success, error); var self = this; diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 86aa8828caa..0c0fc74514e 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -49,36 +49,28 @@ session.web.ActionManager = session.web.Widget.extend({ } }, - handle_state: function() { - // Only root ActionManager handle the state - return this.widget_parent instanceof session.web.WebClient; + do_push_state: function(state, overwrite) { }, - do_push_state: function(state, extend) { - if (this.handle_state()) { - this._super.apply(this, arguments); - } - }, - - 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); - } + do_load_state: function(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); } } - return this._super.apply(this, arguments); + if (this.inner_viewmanager) { + this.inner_viewmanager.do_load_state(state); + } }, do_action: function(action, on_close) { @@ -137,9 +129,10 @@ session.web.ActionManager = session.web.Widget.extend({ this.dialog_stop(); this.content_stop(); 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); 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}; 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) { 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); view_promise = controller.appendTo(container); 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() { self.on_controller_inited(view_type, controller); 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(); + _.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); 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(); } - self.do_push_state({view_type: self.active_view}, true); + self.do_push_state({view_type: self.active_view}); }); }, - handle_state: function() { - return (this.widget_parent instanceof session.web.ActionManager) && this.widget_parent.handle_state(); + do_push_state: function(state, overwrite) { }, - do_push_state: function(state, extend) { - if (this.handle_state()) { - this._super.apply(this, arguments); - } - }, + do_load_state: function(state) { + var self = this, + 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) { - 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); + $.when(defs).then(function() { + self.views[self.active_view].controller.do_load_state(state); + }); }, shortcut_check : function(view) { @@ -1127,6 +1124,12 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{ }, sidebar_context: function () { return $.Deferred().resolve({}).promise(); + }, + + do_push_state: function(state, overwrite) { + }, + + do_load_state: function(state) { } }); From c14ec82eb0a5ee36edc3d52b51c43cbfabe96e5e Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 13 Dec 2011 10:35:57 +0100 Subject: [PATCH 4/7] [FIX] remove unused functions bzr revid: chs@openerp.com-20111213093557-3hab6yamep1pv9x2 --- addons/web/static/src/js/chrome.js | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 0e332252341..62c9d31de96 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1093,30 +1093,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie $.bbq.pushState(url); }, - default_home: function () { - }, - /** - * Bundles the execution of the home action - * - * @param {Number} action action id - * @param {openerp.web.DataSet} dataset action executor - */ - execute_home_action: function (action, dataset) { - var self = this; - this.rpc('/web/action/load', { - action_id: action, - context: dataset.get_context() - }, function (meh) { - var action = meh.result; - action.context = _.extend(action.context || {}, { - active_id: false, - active_ids: [false], - active_model: dataset.model - }); - self.action_manager.do_action(action); - }); - }, - on_menu_action: function(action) { this.action_manager.do_action(action); }, From e28eaa509b928ca836322db3a3957edaf81345a6 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 13 Dec 2011 11:32:32 +0100 Subject: [PATCH 5/7] [FIX] do not call hashchange event when pushing state bzr revid: chs@openerp.com-20111213103232-bhjrog6eaiaqrilu --- addons/web/static/src/js/chrome.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 62c9d31de96..af2fc110691 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1016,9 +1016,7 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this.menu = new openerp.web.Menu(this, "oe_menu", "oe_secondary_menu"); this.menu.on_action.add(this.on_menu_action); - this.url_internal_hashchange = false; - this.url_external_hashchange = false; - jQuery(window).bind('hashchange', this.on_url_hashchange); + this._current_state = null; }, start: function() { @@ -1081,7 +1079,10 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie on_hashchange: function(event) { var state = event.getState(true); - this.action_manager.do_load_state(state); + if (!_.isEqual(this._current_state, state)) { + this.action_manager.do_load_state(state); + } + this._current_state = state; }, do_push_state: function(state, overwrite) { @@ -1090,6 +1091,7 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie state = _.extend({}, hash, state); } var url = '#' + $.param(state); + this._current_state = _.clone(state); $.bbq.pushState(url); }, From 3c9a0d91f0eb922611fcce74b41db27e82d79b5a Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 13 Dec 2011 11:41:00 +0100 Subject: [PATCH 6/7] [FIX] cleanup do_load_state methods bzr revid: chs@openerp.com-20111213104100-qxvyqnr84bm1x6x5 --- addons/web/static/src/js/views.js | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 0c0fc74514e..985a75a8030 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -54,18 +54,17 @@ session.web.ActionManager = session.web.Widget.extend({ do_load_state: function(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); - } + this.null_action(); + this.do_action(state.action_id); + } + else if (state.model && state.id) { + // TODO implement it + //this.null_action(); + // 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); - } + this.null_action(); + this.ir_actions_client(state.client_action); } if (this.inner_viewmanager) { @@ -548,13 +547,8 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner }, do_load_state: function(state) { - var self = this, - defs = []; - if (state.view_type && state.view_type !== this.active_view) { - defs.push(this.on_mode_switch(state.view_type, true)); - } - - $.when(defs).then(function() { + var self = this; + $.when(this.on_mode_switch(state.view_type, true)).done(function() { self.views[self.active_view].controller.do_load_state(state); }); }, From 68914b311ba4a4e748c8c33342c3efed19a7efab Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Tue, 13 Dec 2011 11:50:09 +0100 Subject: [PATCH 7/7] [FIX] remove unused variable bzr revid: chs@openerp.com-20111213105009-otpfr3db20wakdtb --- addons/web/static/src/js/views.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 985a75a8030..9cf6d23e48e 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -24,7 +24,6 @@ session.web.ActionManager = session.web.Widget.extend({ this.dialog = null; this.dialog_viewmanager = null; this.client_widget = null; - this.client_widget_name = null; }, render: function() { return "
"; @@ -45,7 +44,6 @@ session.web.ActionManager = session.web.Widget.extend({ if (this.client_widget) { this.client_widget.stop(); this.client_widget = null; - this.client_widget_name = null; } }, @@ -152,7 +150,6 @@ session.web.ActionManager = session.web.Widget.extend({ }, 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);