From b53ee6fe2074fbbd7dc6932554631a5b3fbec185 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Wed, 14 Dec 2011 17:09:58 +0100 Subject: [PATCH 1/2] [WIP] better url management, only views are allowed to call this.do_push_state bzr revid: chs@openerp.com-20111214160958-xrtdubgh6jqn3mq3 --- addons/web/static/src/js/chrome.js | 10 ++----- addons/web/static/src/js/view_form.js | 3 ++ addons/web/static/src/js/views.js | 43 ++++++++++++++------------- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 8c8c3b5f7d6..4b41d3adc54 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1061,7 +1061,6 @@ 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 @@ -1076,7 +1075,7 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie }, on_logged_out: function() { $(window).unbind('hashchange', this.on_hashchange); - this.do_push_state({},true); + this.do_push_state({}); if(this.action_manager) this.action_manager.stop(); this.action_manager = null; @@ -1098,11 +1097,8 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie } this._current_state = state; }, - do_push_state: function(state, overwrite) { - if (!overwrite) { - var hash = $.deparam.fragment(true); - state = _.extend({}, hash, state); - } + do_push_state: function(state) { + console.log('dopushstate', state); var url = '#' + $.param(state); this._current_state = _.clone(state); $.bbq.pushState(url); diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 0ac70e64a67..b961b0089e3 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -175,6 +175,9 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView# if (self.default_focus_field && !self.embedded_view) { self.default_focus_field.focus(); } + if (record.id) { + self.do_push_state({id:record.id}); + } }); }, on_form_changed: function() { diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index fcc8a4cc06c..af0f0f47aba 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -20,6 +20,7 @@ session.web.ActionManager = session.web.Widget.extend({ identifier_prefix: "actionmanager", init: function(parent) { this._super(parent); + this.action = null; this.inner_viewmanager = null; this.dialog = null; this.dialog_viewmanager = null; @@ -47,7 +48,15 @@ session.web.ActionManager = session.web.Widget.extend({ } }, - do_push_state: function(state, overwrite) { + do_push_state: function(state) { + if (this.wiget_parent && this.widget_parent.do_push_state) { + if (this.action.id) { + state = _.extend({}, state || {}, { + action_id: this.action.id, + }); + } + this.widget_parent.do_push_state(state); + } }, do_load_state: function(state) { @@ -95,6 +104,7 @@ session.web.ActionManager = session.web.Widget.extend({ console.error("Action manager can't handle action of type " + action.type, action); return; } + this.action = action; return this[type](action, on_close); }, null_action: function() { @@ -128,10 +138,6 @@ session.web.ActionManager = session.web.Widget.extend({ this.content_stop(); this.inner_action = action; this.inner_viewmanager = new session.web.ViewManagerAction(this, action); - this.inner_viewmanager.do_push_state.add(function(state,overwrite) { - state['action_id'] = action.id; - self.do_push_state(state,true); - }); this.inner_viewmanager.appendTo(this.$element); } }, @@ -154,10 +160,6 @@ 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); - - var client_action = {tag: action.tag}; - if (action.params) _.extend(client_action, {params: action.params}); - this.do_push_state({client_action: client_action}, true); }, ir_actions_report_xml: function(action, on_closed) { var self = this; @@ -466,12 +468,6 @@ 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_debug_view').change(this.on_debug_changed); @@ -584,12 +580,16 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner } else { $search_prefix.remove(); } - - self.do_push_state({view_type: self.active_view}); }); }, - do_push_state: function(state, overwrite) { + do_push_state: function(state) { + if (this.wiget_parent && this.widget_parent.do_push_state) { + state = _.extend({}, state || {}, { + view_type: this.active_view + }); + this.widget_parent.do_push_state(state); + } }, do_load_state: function(state) { @@ -1146,11 +1146,12 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{ return $.Deferred().resolve({}).promise(); }, - do_push_state: function(state, overwrite) { + do_push_state: function(state) { + if (this.wiget_parent && this.widget_parent.do_push_state) { + this.widget_parent.do_push_state(state); + } }, - do_load_state: function(state) { - } }); session.web.json_node_to_xml = function(node, human_readable, indent) { From cb4dbede99065b6e0bfa10163ce51579d77ec2e3 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Wed, 14 Dec 2011 19:04:42 +0100 Subject: [PATCH 2/2] [FIX] working urls bzr revid: al@openerp.com-20111214180442-gd1j369la1kss2wj --- addons/web/static/src/js/chrome.js | 1 - addons/web/static/src/js/view_form.js | 2 +- addons/web/static/src/js/views.js | 39 ++++++++++++--------------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index e4bbf5f2503..0d0454c08e4 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -1098,7 +1098,6 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie this._current_state = state; }, do_push_state: function(state) { - console.log('dopushstate', state); var url = '#' + $.param(state); this._current_state = _.clone(state); $.bbq.pushState(url); diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 502778d0f28..eb5a310e154 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -125,7 +125,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView# } else { promise = this.dataset.read_index(_.keys(this.fields_view.fields)).pipe(this.on_record_loaded); } - this._super(); + this.$element.show(); if (this.sidebar) { this.sidebar.$element.show(); } diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index e29d7761196..f97a09dee94 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -20,7 +20,7 @@ session.web.ActionManager = session.web.Widget.extend({ identifier_prefix: "actionmanager", init: function(parent) { this._super(parent); - this.action = null; + this.inner_action = null; this.inner_viewmanager = null; this.dialog = null; this.dialog_viewmanager = null; @@ -47,18 +47,14 @@ session.web.ActionManager = session.web.Widget.extend({ this.client_widget = null; } }, - do_push_state: function(state) { - if (this.wiget_parent && this.widget_parent.do_push_state) { - if (this.action.id) { - state = _.extend({}, state || {}, { - action_id: this.action.id, - }); + if (this.widget_parent && this.widget_parent.do_push_state) { + if (this.inner_action && this.inner_action.id) { + state['action_id'] = this.inner_action.id; } this.widget_parent.do_push_state(state); } }, - do_load_state: function(state) { if (state.action_id) { this.null_action(); @@ -78,7 +74,6 @@ session.web.ActionManager = session.web.Widget.extend({ this.inner_viewmanager.do_load_state(state); } }, - do_action: function(action, on_close) { if (_.isNumber(action)) { var self = this; @@ -104,7 +99,6 @@ session.web.ActionManager = session.web.Widget.extend({ console.error("Action manager can't handle action of type " + action.type, action); return; } - this.action = action; return this[type](action, on_close); }, null_action: function() { @@ -317,8 +311,6 @@ session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.View }); return view_promise; }, - - /** * Returns to the view preceding the caller view in this manager's * navigation history (the navigation history is appended to via @@ -394,7 +386,8 @@ session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.View /** * Called by children view after executing an action */ - on_action_executed: function () {}, + on_action_executed: function () { + }, display_title: function () { var view = this.views[this.active_view]; if (view) { @@ -583,23 +576,18 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner } }); }, - do_push_state: function(state) { - if (this.wiget_parent && this.widget_parent.do_push_state) { - state = _.extend({}, state || {}, { - view_type: this.active_view - }); + if (this.widget_parent && this.widget_parent.do_push_state) { + state["view_type"] = this.active_view; this.widget_parent.do_push_state(state); } }, - do_load_state: function(state) { var self = this; $.when(this.on_mode_switch(state.view_type, true)).done(function() { self.views[self.active_view].controller.do_load_state(state); }); }, - shortcut_check : function(view) { var self = this; var grandparent = this.widget_parent && this.widget_parent.widget_parent; @@ -1067,10 +1055,18 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{ }, do_show: function () { this.$element.show(); + this.do_push_state({}); }, do_hide: function () { this.$element.hide(); }, + do_push_state: function(state) { + if (this.widget_parent && this.widget_parent.do_push_state) { + this.widget_parent.do_push_state(state); + } + }, + do_load_state: function(state) { + }, /** * Switches to a specific view type * @@ -1152,8 +1148,7 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{ }, sidebar_context: function () { return $.Deferred().resolve({}).promise(); - }, - }, + } }); session.web.json_node_to_xml = function(node, human_readable, indent) {