[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:
parent
36471c3955
commit
8159f4a18c
|
@ -1889,7 +1889,7 @@ openerp.mail = function (session) {
|
|||
var ds_msg = new session.web.DataSetSearch(this, 'mail.message');
|
||||
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'))
|
||||
.then(function () { self.searchview.on('search_data', self, self.do_searchview_search); });
|
||||
if (this.searchview.has_defaults) {
|
||||
|
|
|
@ -427,15 +427,15 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
|
|||
|
||||
var view_manager = this.getParent();
|
||||
while (!(view_manager instanceof instance.web.ViewManager) &&
|
||||
(view_manager !== undefined)) {
|
||||
view_manager && view_manager.getParent) {
|
||||
view_manager = view_manager.getParent();
|
||||
}
|
||||
|
||||
if (view_manager) {
|
||||
view_manager.on('switch_mode', this, function (e) {
|
||||
self.drawer.hide();
|
||||
self.drawer.toggle(e === 'graph');
|
||||
});
|
||||
}
|
||||
}
|
||||
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);
|
||||
},
|
||||
|
||||
// The method appendTo is overwrited to make sure that the search view is not
|
||||
// appendTo'ed. Instead, the correct way to insert the searchview in the DOM
|
||||
// is by using insert
|
||||
appendTo: function () {
|
||||
throw new Error("SearchView should be inserted, not appended");
|
||||
},
|
||||
// The method appendTo is overwrited to be able to insert the drawer anywhere
|
||||
appendTo: function ($searchview_parent, $searchview_drawer_node) {
|
||||
var $searchview_drawer_node = $searchview_drawer_node || $searchview_parent;
|
||||
|
||||
// This is the correct way to insert the searchview in the dom. First argument
|
||||
// is for the searchview, and second is the place where the drawer should be
|
||||
// appended.
|
||||
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);
|
||||
return $.when(
|
||||
this._super($searchview_parent),
|
||||
this.drawer.appendTo($searchview_drawer_node)
|
||||
);
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
|
@ -819,12 +811,8 @@ instance.web.SearchViewDrawer = instance.web.Widget.extend({
|
|||
this.inputs = [];
|
||||
},
|
||||
|
||||
toggle: function () {
|
||||
this.$el.toggle();
|
||||
},
|
||||
|
||||
hide: function () {
|
||||
this.$el.hide();
|
||||
toggle: function (visibility) {
|
||||
this.$el.toggle(visibility);
|
||||
},
|
||||
|
||||
start: function() {
|
||||
|
@ -1011,7 +999,7 @@ instance.web.search.Widget = instance.web.Widget.extend( /** @lends instance.web
|
|||
this.drawer = ancestor;
|
||||
} while (!(ancestor instanceof instance.web.SearchViewDrawer)
|
||||
&& (ancestor = (ancestor.getParent && ancestor.getParent())));
|
||||
this.view = this.drawer.searchview;
|
||||
this.view = this.drawer.searchview || this.drawer;
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -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) {
|
||||
var self = this;
|
||||
|
|
|
@ -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.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"));
|
||||
},
|
||||
do_searchview_search: function(domains, contexts, groupbys) {
|
||||
|
|
Loading…
Reference in New Issue