From bce607a9904826bd458f5bb15613086128dfb55a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 22 Mar 2013 17:27:25 +0100 Subject: [PATCH] Only change current view in switch_view --- src/screen.js | 35 ++++++++++++++++++----------------- src/tab.js | 11 ++++++----- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/screen.js b/src/screen.js index 8284d47a86..ee1122230e 100644 --- a/src/screen.js +++ b/src/screen.js @@ -13,9 +13,10 @@ this.view_to_load = jQuery.extend([], attributes.mode || ['tree', 'form']); this.views = []; + this.context = attributes.context || {}; + this.new_group(); this.current_view = null; this.current_record = null; - this.context = attributes.context || {}; if (!attributes.row_activate) { this.row_activate = this.default_row_activate; } else { @@ -66,8 +67,6 @@ if (this.current_view) { this.current_view.el.detach(); } - this.current_view = view_widget; - this.el.append(view_widget.el); return view_widget; }, number_of_views: function() { @@ -75,13 +74,12 @@ }, switch_view: function(view_type) { // TODO check validity - var self = this; if ((!view_type) || (!this.current_view) || (this.current_view.view_type != view_type)) { - var switch_current_view = function() { - self.current_view = self.views.slice(-1); - return self.switch_view(view_type); - }; + var switch_current_view = (function() { + this.current_view = this.views.slice(-1); + return this.switch_view(view_type); + }.bind(this)); for (var i = 0; i < this.number_of_views(); i++) { if (this.view_to_load.length) { return this.load_next_view().pipe(switch_current_view); @@ -114,17 +112,20 @@ var grp_prm = this.model.find(domain, this.attributes.offset, this.attributes.limit, this.attributes.order, this.context); - var group_setter = function(group) { - if (this.group) { - this.group.screens.splice( - this.group.screens.indexOf(this), 1); - } - group.screens.push(this); - this.group = group; - }; - grp_prm.done(group_setter.bind(this)); + grp_prm.done(this.set_group.bind(this)); return grp_prm; }, + set_group: function(group) { + if (this.group) { + this.group.screens.splice( + this.group.screens.indexOf(this), 1); + } + group.screens.push(this); + this.group = group; + }, + new_group: function() { + this.set_group(new Sao.Group(this.model, this.context, [])); + }, display: function() { if (this.views) { for (var i = 0; i < this.views.length; i++) diff --git a/src/tab.js b/src/tab.js index 56b6ddc279..05c42b5fb9 100644 --- a/src/tab.js +++ b/src/tab.js @@ -80,11 +80,12 @@ var toolbar = this.create_toolbar(); el.append(toolbar); this.el = el; - this.view_prm = this.screen.load_next_view().done(function() { - el.append(screen.el); - }).done(function() { - screen.search_filter().done(function() { - screen.display(); + this.view_prm = this.screen.load_next_view().then(function() { + screen.switch_view().done(function() { + el.append(screen.el); + screen.search_filter().done(function() { + screen.display(); + }); }); }); },