[IMP] trigger do_search on_mode_switch. Use headless searchview when hidden and when no default specified
bzr revid: fme@openerp.com-20110928151306-d7aphegy2gedjsqk
This commit is contained in:
parent
b00f4e7e1f
commit
8b55e42884
|
@ -13,25 +13,35 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
|
|||
* @param view_id
|
||||
* @param defaults
|
||||
*/
|
||||
init: function(parent, dataset, view_id, defaults) {
|
||||
init: function(parent, dataset, view_id, defaults, hidden) {
|
||||
this._super(parent);
|
||||
this.dataset = dataset;
|
||||
this.model = dataset.model;
|
||||
this.view_id = view_id;
|
||||
|
||||
this.defaults = defaults || {};
|
||||
this.has_defaults = !_.isEmpty(this.defaults);
|
||||
|
||||
this.inputs = [];
|
||||
this.enabled_filters = [];
|
||||
|
||||
this.has_focus = false;
|
||||
|
||||
this.hidden = !!hidden;
|
||||
this.headless = this.hidden && !this.has_defaults;
|
||||
|
||||
this.ready = $.Deferred();
|
||||
},
|
||||
start: function() {
|
||||
this._super();
|
||||
this.$element.hide();
|
||||
this.rpc("/web/searchview/load", {"model": this.model, "view_id":this.view_id}, this.on_loaded);
|
||||
if (this.hidden) {
|
||||
this.$element.hide();
|
||||
}
|
||||
if (this.headless) {
|
||||
this.ready.resolve();
|
||||
} else {
|
||||
this.rpc("/web/searchview/load", {"model": this.model, "view_id":this.view_id}, this.on_loaded);
|
||||
}
|
||||
return this.ready.promise();
|
||||
},
|
||||
show: function () {
|
||||
|
@ -244,10 +254,13 @@ openerp.web.SearchView = openerp.web.Widget.extend(/** @lends openerp.web.Search
|
|||
* @param e jQuery event object coming from the "Search" button
|
||||
*/
|
||||
do_search: function (e) {
|
||||
if (this.headless && !this.has_defaults) {
|
||||
return this.on_search([], [], []);
|
||||
}
|
||||
// reset filters management
|
||||
var select = this.$element.find(".oe_search-view-filters-management");
|
||||
select.val("_filters");
|
||||
|
||||
|
||||
if (e && e.preventDefault) { e.preventDefault(); }
|
||||
|
||||
var data = this.build_search_data();
|
||||
|
|
|
@ -166,7 +166,6 @@ db.web.ViewManager = db.web.Widget.extend(/** @lends db.web.ViewManager# */{
|
|||
this.model = dataset.model;
|
||||
this.dataset = dataset;
|
||||
this.searchview = null;
|
||||
this.searchview_visible = false;
|
||||
this.active_view = null;
|
||||
this.views_src = _.map(views, function(x) {return x instanceof Array? {view_id: x[0], view_type: x[1]} : x;});
|
||||
this.views = {};
|
||||
|
@ -235,12 +234,8 @@ db.web.ViewManager = db.web.Widget.extend(/** @lends db.web.ViewManager# */{
|
|||
}
|
||||
|
||||
|
||||
if (this.searchview) {
|
||||
if (this.searchview_visible === false || view.controller.searchable === false) {
|
||||
this.searchview.hide();
|
||||
} else {
|
||||
this.searchview.show();
|
||||
}
|
||||
if (this.searchview && !this.searchview.hidden) {
|
||||
this.searchview[view.controller.searchable === false ? 'hide' : 'show']();
|
||||
}
|
||||
|
||||
this.$element
|
||||
|
@ -268,27 +263,6 @@ db.web.ViewManager = db.web.Widget.extend(/** @lends db.web.ViewManager# */{
|
|||
*/
|
||||
on_controller_inited: function(view_type, view) {
|
||||
},
|
||||
/**
|
||||
* Sets up the current viewmanager's search view.
|
||||
*
|
||||
* @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) {
|
||||
var self = this;
|
||||
if (this.searchview) {
|
||||
this.searchview.stop();
|
||||
}
|
||||
this.searchview = new db.web.SearchView(
|
||||
this, 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);
|
||||
});
|
||||
return this.searchview.appendTo($("#" + this.element_id + "_search"));
|
||||
},
|
||||
/**
|
||||
* Called when one of the view want to execute an action
|
||||
*/
|
||||
|
@ -333,7 +307,7 @@ db.web.ViewManagerAction = db.web.ViewManager.extend(/** @lends oepnerp.web.View
|
|||
// buttons, sidebar, ...) displaying
|
||||
this.flags.search_view = this.flags.pager = this.flags.sidebar = this.flags.action_buttons = false;
|
||||
}
|
||||
this.searchview_visible = !!this.flags.search_view;
|
||||
this.last_search = false;
|
||||
|
||||
// setup storage for session-wise menu hiding
|
||||
if (this.session.hidden_menutips) {
|
||||
|
@ -408,10 +382,38 @@ db.web.ViewManagerAction = db.web.ViewManager.extend(/** @lends oepnerp.web.View
|
|||
return $.when(
|
||||
this._super(view_type),
|
||||
this.shortcut_check(this.views[view_type])).then(function () {
|
||||
self.do_searchview_search();
|
||||
var view_id = self.views[self.active_view].controller.fields_view.view_id;
|
||||
self.$element.find('.oe_get_xml_view span').text(view_id);
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Sets up the current viewmanager's search view.
|
||||
*
|
||||
* @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) {
|
||||
var self = this;
|
||||
if (this.searchview) {
|
||||
this.searchview.stop();
|
||||
}
|
||||
this.searchview = new db.web.SearchView(
|
||||
this, this.dataset,
|
||||
view_id, search_defaults, this.flags.search_view === false);
|
||||
|
||||
this.searchview.on_search.add(this.do_searchview_search);
|
||||
return this.searchview.appendTo($("#" + this.element_id + "_search"));
|
||||
},
|
||||
do_searchview_search: function(domains, contexts, groupbys) {
|
||||
if (domains) {
|
||||
this.last_search = [domains, contexts, groupbys];
|
||||
}
|
||||
if (this.last_search) {
|
||||
var controller = this.views[this.active_view].controller;
|
||||
controller.do_search.apply(controller, this.last_search);
|
||||
}
|
||||
},
|
||||
shortcut_check : function(view) {
|
||||
var self = this;
|
||||
var grandparent = this.widget_parent && this.widget_parent.widget_parent;
|
||||
|
|
Loading…
Reference in New Issue