[IMP] improves searchview appendTo

after some thought, the extra method insert was not really necessary.
It was at first a way to force the user to give two nodes to determine
where the searchview and the drawer were to be inserted.  However,
the second node can be omitted, a perfectly reasonable default is
to append the drawer just after the searchview.

Then, the role of insert is exactly the same as appendTo, so it makes
sense to override appendTo and remove insert.  Simpler, and the job is done.
This commit is contained in:
Géry Debongnie 2014-05-22 09:55:04 +02:00
parent 36471c3955
commit 8159f4a18c
4 changed files with 16 additions and 28 deletions

View File

@ -1889,7 +1889,7 @@ openerp.mail = function (session) {
var ds_msg = new session.web.DataSetSearch(this, 'mail.message'); var ds_msg = new session.web.DataSetSearch(this, 'mail.message');
this.searchview = new session.web.SearchView(this, ds_msg, false, defaults || {}, false); this.searchview = new session.web.SearchView(this, ds_msg, false, defaults || {}, false);
this.searchview.insert(this.$('.oe_view_manager_view_search'), this.searchview.appendTo(this.$('.oe_view_manager_view_search'),
this.$('.oe_searchview_drawer_container')) this.$('.oe_searchview_drawer_container'))
.then(function () { self.searchview.on('search_data', self, self.do_searchview_search); }); .then(function () { self.searchview.on('search_data', self, self.do_searchview_search); });
if (this.searchview.has_defaults) { if (this.searchview.has_defaults) {

View File

@ -427,15 +427,15 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
var view_manager = this.getParent(); var view_manager = this.getParent();
while (!(view_manager instanceof instance.web.ViewManager) && while (!(view_manager instanceof instance.web.ViewManager) &&
(view_manager !== undefined)) { view_manager && view_manager.getParent) {
view_manager = view_manager.getParent(); view_manager = view_manager.getParent();
} }
if (view_manager) { if (view_manager) {
view_manager.on('switch_mode', this, function (e) { view_manager.on('switch_mode', this, function (e) {
self.drawer.hide(); self.drawer.toggle(e === 'graph');
}); });
} }
return $.when(p, this.ready); return $.when(p, this.ready);
}, },
@ -783,22 +783,14 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
this.trigger('invalid_search', errors); this.trigger('invalid_search', errors);
}, },
// The method appendTo is overwrited to make sure that the search view is not // The method appendTo is overwrited to be able to insert the drawer anywhere
// appendTo'ed. Instead, the correct way to insert the searchview in the DOM appendTo: function ($searchview_parent, $searchview_drawer_node) {
// is by using insert var $searchview_drawer_node = $searchview_drawer_node || $searchview_parent;
appendTo: function () {
throw new Error("SearchView should be inserted, not appended");
},
// This is the correct way to insert the searchview in the dom. First argument return $.when(
// is for the searchview, and second is the place where the drawer should be this._super($searchview_parent),
// appended. this.drawer.appendTo($searchview_drawer_node)
insert: function ($searchview_parent, $searchview_drawer_node) { );
var parent = this.getParent(),
$searchview_drawer_node = $searchview_drawer_node || $searchview_parent,
insert_searchview = parent.appendTo.call(this, $searchview_parent),
insert_drawer = parent.appendTo.call(this.drawer, $searchview_drawer_node);
return $.when(insert_searchview, insert_drawer);
}, },
destroy: function () { destroy: function () {
@ -819,12 +811,8 @@ instance.web.SearchViewDrawer = instance.web.Widget.extend({
this.inputs = []; this.inputs = [];
}, },
toggle: function () { toggle: function (visibility) {
this.$el.toggle(); this.$el.toggle(visibility);
},
hide: function () {
this.$el.hide();
}, },
start: function() { start: function() {
@ -1011,7 +999,7 @@ instance.web.search.Widget = instance.web.Widget.extend( /** @lends instance.web
this.drawer = ancestor; this.drawer = ancestor;
} while (!(ancestor instanceof instance.web.SearchViewDrawer) } while (!(ancestor instanceof instance.web.SearchViewDrawer)
&& (ancestor = (ancestor.getParent && ancestor.getParent()))); && (ancestor = (ancestor.getParent && ancestor.getParent())));
this.view = this.drawer.searchview; this.view = this.drawer.searchview || this.drawer;
} }
}); });

View File

@ -5346,7 +5346,7 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend
}); });
}); });
}); });
this.searchview.insert(this.$(".oe_popup_search")); this.searchview.appendTo(this.$(".oe_popup_search"));
}, },
do_search: function(domains, contexts, groupbys) { do_search: function(domains, contexts, groupbys) {
var self = this; var self = this;

View File

@ -808,7 +808,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
this.searchview = new instance.web.SearchView(this, this.dataset, view_id, search_defaults, options); this.searchview = new instance.web.SearchView(this, this.dataset, view_id, search_defaults, options);
this.searchview.on('search_data', self, this.do_searchview_search); this.searchview.on('search_data', self, this.do_searchview_search);
return this.searchview.insert(this.$(".oe_view_manager_view_search"), return this.searchview.appendTo(this.$(".oe_view_manager_view_search"),
this.$(".oe_searchview_drawer_container")); this.$(".oe_searchview_drawer_container"));
}, },
do_searchview_search: function(domains, contexts, groupbys) { do_searchview_search: function(domains, contexts, groupbys) {