From 9e3fe8e471f29d3fae6fe1e96df2e707bb37a058 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 13 Sep 2011 08:31:21 +0200 Subject: [PATCH 1/6] [FIX] issues with list not being a primary action view * ViewManagerAction should always instantiate a DataSetSearch, if there's a res_id add it to the DataSet * Always define a base DataGroup (groupless) on the ListView's groups, so it can be shown() without a search (will just use default dataset parameters) lp bug: https://launchpad.net/bugs/847849 fixed bzr revid: xmo@openerp.com-20110913063121-ry2cuwiuqfo655xe --- addons/web/static/src/js/list.js | 7 +++++++ addons/web/static/src/js/views.js | 9 +++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/addons/web/static/src/js/list.js b/addons/web/static/src/js/list.js index b9df9e8e2df..cca616d0055 100644 --- a/addons/web/static/src/js/list.js +++ b/addons/web/static/src/js/list.js @@ -61,6 +61,13 @@ openerp.web.ListView = openerp.web.View.extend( /** @lends openerp.web.ListView# if (this.dataset instanceof openerp.web.DataSetStatic) { this.groups.datagroup = new openerp.web.StaticDataGroup(this.dataset); + } else { + this.groups.datagroup = new openerp.web.DataGroup( + this, this.model, + dataset.get_domain(), + dataset.get_context(), + {}); + this.groups.datagroup.sort = this.dataset._sort; } this.page = 0; diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index c4309a42e38..2ae20051853 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -302,12 +302,9 @@ openerp.web.ViewManagerAction = openerp.web.ViewManager.extend({ init: function(parent, action) { this.session = parent.session; this.action = action; - var dataset; - if (!action.res_id) { - dataset = new openerp.web.DataSetSearch(this, action.res_model, action.context, action.domain); - } else { - this.action.flags.search_view = false; - dataset = new openerp.web.DataSetStatic(this, action.res_model, action.context, [action.res_id]); + var dataset = new openerp.web.DataSetSearch(this, action.res_model, action.context, action.domain); + if (action.res_id) { + dataset.ids.push(action.res_id); dataset.index = 0; } this._super(parent, dataset, action.views); From 625c933bf6277dbb932ad7df4d76ed3cc1aa674f Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 13 Sep 2011 08:32:38 +0200 Subject: [PATCH 2/6] [FIX] issue with searchview appearing alongside non-searchable views (e.g. form) when they're the primary (initially loaded) view for an action bzr revid: xmo@openerp.com-20110913063238-hki65oukviah8u2k --- addons/web/static/src/js/views.js | 59 +++++++++++++++++++------------ 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 2ae20051853..f67b5375160 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -266,7 +266,7 @@ openerp.web.ViewManager = openerp.web.Widget.extend(/** @lends openerp.web.View /** * Sets up the current viewmanager's search view. * - * @param view_id the view to use or false for a default one + * @param {Number|false} view_id the view to use or false for a default one * @returns {jQuery.Deferred} search view startup deferred */ setup_search_view: function(view_id, search_defaults) { @@ -274,10 +274,10 @@ openerp.web.ViewManager = openerp.web.Widget.extend(/** @lends openerp.web.View if (this.searchview) { this.searchview.stop(); } - this.searchview = new openerp.web.SearchView(this, this.element_id + "_search", this.dataset, view_id, search_defaults); - if (this.flags.search_view === false) { - this.searchview.hide(); - } + this.searchview = new openerp.web.SearchView( + this, this.element_id + "_search", this.dataset, + view_id, search_defaults); + this.searchview.on_search.add(function(domains, contexts, groupbys) { var controller = self.views[self.active_view].controller; controller.do_search.call(controller, domains, contexts, groupbys); @@ -297,8 +297,15 @@ openerp.web.ViewManager = openerp.web.Widget.extend(/** @lends openerp.web.View } }); -openerp.web.ViewManagerAction = openerp.web.ViewManager.extend({ +openerp.web.ViewManagerAction = openerp.web.ViewManager.extend(/** @lends oepnerp.web.ViewManagerAction# */{ template: "ViewManagerAction", + /** + * @constructs openerp.web.ViewManagerAction + * @extends openerp.web.ViewManager + * + * @param {openerp.web.ActionManager} parent parent object/widget + * @param {Object} action descriptor for the action this viewmanager needs to manage its views. + */ init: function(parent, action) { this.session = parent.session; this.action = action; @@ -315,29 +322,35 @@ openerp.web.ViewManagerAction = openerp.web.ViewManager.extend({ this.flags.search_view = this.flags.pager = this.flags.sidebar = this.flags.action_buttons = false; } }, + /** + * Initializes the ViewManagerAction: sets up the searchview (if the + * searchview is enabled in the manager's action flags), calls into the + * parent to initialize the primary view and (if the VMA has a searchview) + * launches an initial search after both views are done rendering. + */ start: function() { - var inital_view_loaded = this._super(); - - var search_defaults = {}; - _.each(this.action.context, function (value, key) { - var match = /^search_default_(.*)$/.exec(key); - if (match) { - search_defaults[match[1]] = value; - } - }); - + var searchview_loaded; if (this.flags.search_view !== false) { + var search_defaults = {}; + _.each(this.action.context, function (value, key) { + var match = /^search_default_(.*)$/.exec(key); + if (match) { + search_defaults[match[1]] = value; + } + }); // init search view - var searchview_id = this.action.search_view_id && this.action.search_view_id[0]; + var searchview_id = this.action['search_view_id'] && this.action['search_view_id'][0]; - var searchview_loaded = this.setup_search_view( + searchview_loaded = this.setup_search_view( searchview_id || false, search_defaults); + } - // schedule auto_search - if (searchview_loaded != null && this.action['auto_search']) { - $.when(searchview_loaded, inital_view_loaded) - .then(this.searchview.do_search); - } + var main_view_loaded = this._super(); + + // schedule auto_search + if (searchview_loaded && this.action['auto_search']) { + $.when(searchview_loaded, main_view_loaded) + .then(this.searchview.do_search); } }, on_mode_switch: function (view_type) { From 7c75a5e35c639d6d6205795644da3d4c5b0440fe Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 13 Sep 2011 08:33:46 +0200 Subject: [PATCH 3/6] [IMP] cleanup fubared whitespace bzr revid: xmo@openerp.com-20110913063346-dq34na1d8ygvks1f --- addons/web/static/src/js/views.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index f67b5375160..e865ba836a5 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -158,7 +158,7 @@ openerp.web.ViewManager = openerp.web.Widget.extend(/** @lends openerp.web.View this.registry = openerp.web.views; }, render: function() { - return QWeb.render(this.template, {"prefix": this.element_id, views: this.views_src}) + return QWeb.render(this.template, {"prefix": this.element_id, views: this.views_src}) }, /** * @returns {jQuery.Deferred} initial view loading promise @@ -298,7 +298,7 @@ openerp.web.ViewManager = openerp.web.Widget.extend(/** @lends openerp.web.View }); openerp.web.ViewManagerAction = openerp.web.ViewManager.extend(/** @lends oepnerp.web.ViewManagerAction# */{ - template: "ViewManagerAction", + template:"ViewManagerAction", /** * @constructs openerp.web.ViewManagerAction * @extends openerp.web.ViewManager @@ -306,7 +306,7 @@ openerp.web.ViewManagerAction = openerp.web.ViewManager.extend(/** @lends oepner * @param {openerp.web.ActionManager} parent parent object/widget * @param {Object} action descriptor for the action this viewmanager needs to manage its views. */ - init: function(parent, action) { + init: function(parent, action) { this.session = parent.session; this.action = action; var dataset = new openerp.web.DataSetSearch(this, action.res_model, action.context, action.domain); @@ -704,7 +704,7 @@ openerp.web.View = openerp.web.Widget.extend(/** @lends openerp.web.View# */{ * Directly set a view to use instead of calling fields_view_get. This method must * be called before start(). When an embedded view is set, underlying implementations * of openerp.web.View must use the provided view instead of any other one. - * + * * @param embedded_view A view. */ set_embedded_view: function(embedded_view) { From 2f7229de36f6916217496ddaa0761e869661b66b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 13 Sep 2011 08:36:17 +0200 Subject: [PATCH 4/6] [IMP] remove redundant code in ViewManagerAction initializer bzr revid: xmo@openerp.com-20110913063617-jh69s47vgwxokba1 --- addons/web/static/src/js/views.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index e865ba836a5..e1554249ad6 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -307,7 +307,6 @@ openerp.web.ViewManagerAction = openerp.web.ViewManager.extend(/** @lends oepner * @param {Object} action descriptor for the action this viewmanager needs to manage its views. */ init: function(parent, action) { - this.session = parent.session; this.action = action; var dataset = new openerp.web.DataSetSearch(this, action.res_model, action.context, action.domain); if (action.res_id) { @@ -315,7 +314,6 @@ openerp.web.ViewManagerAction = openerp.web.ViewManager.extend(/** @lends oepner dataset.index = 0; } this._super(parent, dataset, action.views); - this.action = action; this.flags = this.action.flags || {}; if (action.res_model == 'board.board' && action.views.length == 1 && action.views) { // Not elegant but allows to avoid flickering of SearchView#do_hide From 2f05581439e09d3a85634fcb0de9ed54fa1714f2 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 13 Sep 2011 08:38:30 +0200 Subject: [PATCH 5/6] [FIX] correctly return readyness deferred from ViewManagerAction's start method bzr revid: xmo@openerp.com-20110913063830-eyyfczieq6w1b1j4 --- addons/web/static/src/js/views.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index e1554249ad6..3ccdd672a0d 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -345,11 +345,12 @@ openerp.web.ViewManagerAction = openerp.web.ViewManager.extend(/** @lends oepner var main_view_loaded = this._super(); - // schedule auto_search + var manager_ready = $.when(searchview_loaded, main_view_loaded); if (searchview_loaded && this.action['auto_search']) { - $.when(searchview_loaded, main_view_loaded) - .then(this.searchview.do_search); + // schedule auto_search + manager_ready.then(this.searchview.do_search); } + return manager_ready; }, on_mode_switch: function (view_type) { return $.when( From 4c35dde0e06e54d0ab8261aa3a8ae5c6e75b7360 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Tue, 13 Sep 2011 08:47:45 +0200 Subject: [PATCH 6/6] [FIX] reintroduce code which was not redundant after all bzr revid: xmo@openerp.com-20110913064745-xk3xgmqkmu2zh6hp --- addons/web/static/src/js/views.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 3ccdd672a0d..6c10174d109 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -307,6 +307,10 @@ openerp.web.ViewManagerAction = openerp.web.ViewManager.extend(/** @lends oepner * @param {Object} action descriptor for the action this viewmanager needs to manage its views. */ init: function(parent, action) { + // dataset initialization will take the session from ``this``, so if we + // do not have it yet (and we don't, because we've not called our own + // ``_super()``) rpc requests will blow up. + this.session = parent.session; this.action = action; var dataset = new openerp.web.DataSetSearch(this, action.res_model, action.context, action.domain); if (action.res_id) { @@ -316,7 +320,8 @@ openerp.web.ViewManagerAction = openerp.web.ViewManager.extend(/** @lends oepner this._super(parent, dataset, action.views); this.flags = this.action.flags || {}; if (action.res_model == 'board.board' && action.views.length == 1 && action.views) { - // Not elegant but allows to avoid flickering of SearchView#do_hide + // Not elegant but allows to avoid form chrome (pager, save/new + // buttons, sidebar, ...) displaying this.flags.search_view = this.flags.pager = this.flags.sidebar = this.flags.action_buttons = false; } },