[IMP] better architecture for searchview/drawer
Before, the searchview and the searchview drawer had to be instantiated by the user and appended separately to their correct place. Now, the searchview is responsible for creating/destroying the drawer, and the user is responsible for correctly using the insert method with the node where the searchview/drawer are to be inserted.
This commit is contained in:
parent
2c8dec5daa
commit
7c6c720425
|
@ -1888,10 +1888,9 @@ openerp.mail = function (session) {
|
|||
var self = this;
|
||||
var ds_msg = new session.web.DataSetSearch(this, 'mail.message');
|
||||
this.searchview = new session.web.SearchView(this, ds_msg, false, defaults || {}, false);
|
||||
this.searchview_drawer = new session.web.SearchViewDrawer(this, this.searchview);
|
||||
|
||||
$.when(this.searchview.appendTo(this.$('.oe_view_manager_view_search')),
|
||||
this.searchview_drawer.appendTo(this.$('.oe_searchview_drawer_container')))
|
||||
this.searchview.insert(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) {
|
||||
this.searchview.ready.then(this.searchview.do_search);
|
||||
|
|
|
@ -391,6 +391,8 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
|
|||
this.ready = $.Deferred();
|
||||
this.drawer_ready = $.Deferred();
|
||||
this.fields_view_get = $.Deferred();
|
||||
this.drawer = new instance.web.SearchViewDrawer(parent, this);
|
||||
|
||||
},
|
||||
start: function() {
|
||||
var self = this;
|
||||
|
@ -424,13 +426,16 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
|
|||
}
|
||||
|
||||
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.on('switch_mode', this, function (e) {
|
||||
self.drawer.hide();
|
||||
})
|
||||
|
||||
if (view_manager) {
|
||||
view_manager.on('switch_mode', this, function (e) {
|
||||
self.drawer.hide();
|
||||
});
|
||||
}
|
||||
return $.when(p, this.ready);
|
||||
},
|
||||
|
||||
|
@ -776,6 +781,29 @@ instance.web.SearchView = instance.web.Widget.extend(/** @lends instance.web.Sea
|
|||
on_invalid: function (errors) {
|
||||
this.do_notify(_t("Invalid Search"), _t("triggered from search view"));
|
||||
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");
|
||||
},
|
||||
|
||||
// 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);
|
||||
},
|
||||
|
||||
destroy: function () {
|
||||
this.drawer.destroy();
|
||||
this.getParent().destroy.call(this);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -5346,8 +5346,7 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend
|
|||
});
|
||||
});
|
||||
});
|
||||
this.searchview.appendTo($(".oe_popup_search", self.$el));
|
||||
this.searchview_drawer.appendTo($(".oe_popup_search", self.$el));
|
||||
this.searchview.insert(this.$(".oe_popup_search"));
|
||||
},
|
||||
do_search: function(domains, contexts, groupbys) {
|
||||
var self = this;
|
||||
|
|
|
@ -553,7 +553,6 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
|||
this.model = dataset ? dataset.model : undefined;
|
||||
this.dataset = dataset;
|
||||
this.searchview = null;
|
||||
this.searchview_drawer = null;
|
||||
this.active_view = null;
|
||||
this.views_src = _.map(views, function(x) {
|
||||
if (x instanceof Array) {
|
||||
|
@ -801,20 +800,16 @@ instance.web.ViewManager = instance.web.Widget.extend({
|
|||
if (this.searchview) {
|
||||
this.searchview.destroy();
|
||||
}
|
||||
if (this.searchview_drawer) {
|
||||
this.searchview_drawer.destroy();
|
||||
}
|
||||
|
||||
var options = {
|
||||
hidden: this.flags.search_view === false,
|
||||
disable_custom_filters: this.flags.search_disable_custom_filters,
|
||||
};
|
||||
this.searchview = new instance.web.SearchView(this, this.dataset, view_id, search_defaults, options);
|
||||
this.searchview_drawer = new instance.web.SearchViewDrawer(this, this.searchview);
|
||||
|
||||
this.searchview.on('search_data', self, this.do_searchview_search);
|
||||
return $.when(this.searchview.appendTo(this.$el.find(".oe_view_manager_view_search")),
|
||||
this.searchview_drawer.appendTo(this.$(".oe_searchview_drawer_container")));
|
||||
return this.searchview.insert(this.$(".oe_view_manager_view_search"),
|
||||
this.$(".oe_searchview_drawer_container"));
|
||||
},
|
||||
do_searchview_search: function(domains, contexts, groupbys) {
|
||||
var self = this,
|
||||
|
|
Loading…
Reference in New Issue