Fabien Meghazi (OpenERP) has proposed merging
lp:~openerp-dev/openerp-web/trunk-search2-fme into lp:openerp-web.
Requested reviews:
OpenERP R&D Web Team (openerp-dev-web)
For more details, see:
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-search2-fme/+merge/77519
With this branch, controller's do_search method are called at each
on_mode_switch.
The view doesn't have to do inital search anymore neither an eval domain and
context.
the last search evaluated domain and contexts are cached in the viewmanager
itself.
All views are fixed in order to support this new do_search already evaluated
arguments.
The gantt view need refactoring because it messes up with the dataset's own
domain and context.
--
https://code.launchpad.net/~openerp-dev/openerp-web/trunk-search2-fme/+merge/77519
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openerp-web/trunk-search2-fme.
=== modified file 'addons/web/static/src/js/search.js'
--- addons/web/static/src/js/search.js 2011-09-21 12:04:34 +0000
+++ addons/web/static/src/js/search.js 2011-09-29 12:45:56 +0000
@@ -13,24 +13,35 @@
* @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.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 () {
@@ -137,10 +148,7 @@
'defaults': this.defaults
});
- // We don't understand why the following commented line does not work in Chrome but
- // the non-commented line does. As far as we investigated, only God knows.
- //this.$element.html(render);
- jQuery(render).appendTo(this.$element);
+ this.$element.html(render);
this.$element.find(".oe_search-view-custom-filter-btn").click(ext.on_activate);
var f = this.$element.find('form');
@@ -246,10 +254,13 @@
* @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();
=== modified file 'addons/web/static/src/js/view_form.js'
--- addons/web/static/src/js/view_form.js 2011-09-28 16:44:28 +0000
+++ addons/web/static/src/js/view_form.js 2011-09-29 12:45:56 +0000
@@ -444,9 +444,6 @@
return $.Deferred().then(success).resolve(_.extend(r, {created: true}));
}
},
- do_search: function (domains, contexts, groupbys) {
- console.debug("Searching form");
- },
on_action: function (action) {
console.debug('Executing action', action);
},
=== modified file 'addons/web/static/src/js/view_list.js'
--- addons/web/static/src/js/view_list.js 2011-09-21 07:45:09 +0000
+++ addons/web/static/src/js/view_list.js 2011-09-29 12:45:56 +0000
@@ -353,9 +353,6 @@
if (this.sidebar) {
this.sidebar.$element.show();
}
- if (!_(this.dataset.ids).isEmpty()) {
- this.reload_content();
- }
},
do_hide: function () {
this.$element.hide();
@@ -405,40 +402,21 @@
}));
},
/**
- * Event handler for a search, asks for the computation/folding of domains
- * and contexts (and group-by), then reloads the view's content.
- *
- * @param {Array} domains a sequence of literal and non-literal domains
- * @param {Array} contexts a sequence of literal and non-literal contexts
- * @param {Array} groupbys a sequence of literal and non-literal group-by contexts
- * @returns {$.Deferred} fold request evaluation promise
- */
- do_search: function (domains, contexts, groupbys) {
- return this.rpc('/web/session/eval_domain_and_context', {
- domains: _([this.dataset.get_domain()].concat(domains)).compact(),
- contexts: _([this.dataset.get_context()].concat(contexts)).compact(),
- group_by_seq: groupbys
- }, $.proxy(this, 'do_actual_search'));
- },
- /**
* Handler for the result of eval_domain_and_context, actually perform the
* searching
*
* @param {Object} results results of evaluating domain and process for a search
*/
- do_actual_search: function (results) {
+ do_search: function (domain, context, group_by) {
this.groups.datagroup = new openerp.web.DataGroup(
- this, this.model,
- results.domain,
- results.context,
- results.group_by);
+ this, this.model, domain, context, group_by);
this.groups.datagroup.sort = this.dataset._sort;
- if (_.isEmpty(results.group_by) && !results.context['group_by_no_leaf']) {
- results.group_by = null;
+ if (_.isEmpty(group_by) && !context['group_by_no_leaf']) {
+ group_by = null;
}
- this.reload_view(!!results.group_by, results.context).then(
+ this.reload_view(!!group_by, context).then(
$.proxy(this, 'reload_content'));
},
/**
=== modified file 'addons/web/static/src/js/view_list_editable.js'
--- addons/web/static/src/js/view_list_editable.js 2011-09-20 14:58:23 +0000
+++ addons/web/static/src/js/view_list_editable.js 2011-09-29 12:45:56 +0000
@@ -56,11 +56,11 @@
|| this.defaults.editable);
},
/**
- * Replace do_actual_search to handle editability process
+ * Replace do_search to handle editability process
*/
- do_actual_search: function (results) {
- this.set_editable(results.context['set_editable']);
- this._super(results);
+ do_search: function(domain, context, group_by) {
+ this.set_editable(context['set_editable']);
+ this._super.apply(this, arguments);
},
/**
* Replace do_add_record to handle editability (and adding new record
=== modified file 'addons/web/static/src/js/views.js'
--- addons/web/static/src/js/views.js 2011-09-28 15:16:13 +0000
+++ addons/web/static/src/js/views.js 2011-09-29 12:45:56 +0000
@@ -166,6 +166,7 @@
this.model = dataset ? dataset.model : undefined;
this.dataset = dataset;
this.searchview = null;
+ this.last_search = 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 = {};
@@ -224,35 +225,21 @@
controller.set_embedded_view(view.embedded_view);
}
controller.do_switch_view.add_last(this.on_mode_switch);
- if (view_type === 'list' && this.flags.search_view === false && this.action && this.action['auto_search']) {
- // In case the search view is not instantiated: manually call ListView#search
- var domains = !_(self.action.domain).isEmpty()
- ? [self.action.domain] : [],
- contexts = !_(self.action.context).isEmpty()
- ? [self.action.context] : [];
- controller.on_loaded.add({
- callback: function () {
- controller.do_search(domains, contexts, []);
- },
- position: 'last',
- unique: true
- });
- }
var container = $("#" + this.element_id + '_view_' + view_type);
view_promise = controller.appendTo(container);
+ this.views[view_type].controller = controller;
$.when(view_promise).then(function() {
self.on_controller_inited(view_type, controller);
+ if (self.searchview && view.controller.searchable !== false) {
+ self.do_searchview_search();
+ }
});
- this.views[view_type].controller = controller;
+ } else if (this.searchview && view.controller.searchable !== false) {
+ self.do_searchview_search();
}
-
if (this.searchview) {
- if (view.controller.searchable === false) {
- this.searchview.hide();
- } else {
- this.searchview.show();
- }
+ this.searchview[view.controller.searchable === false || this.searchview.hidden ? 'hide' : 'show']();
}
this.$element
@@ -273,14 +260,6 @@
return view_promise;
},
/**
- * Event launched when a controller has been inited.
- *
- * @param {String} view_type type of view
- * @param {String} view the inited controller
- */
- 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
@@ -293,14 +272,36 @@
}
this.searchview = new db.web.SearchView(
this, this.dataset,
- view_id, search_defaults);
+ view_id, search_defaults, this.flags.search_view === false);
- 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);
- });
+ this.searchview.on_search.add(this.do_searchview_search);
return this.searchview.appendTo($("#" + this.element_id + "_search"));
},
+ do_searchview_search: function(domains, contexts, groupbys) {
+ var self = this,
+ controller = this.views[this.active_view].controller;
+ if (domains || contexts) {
+ //if ((!domains || !domains.length) && (!contexts || !contexts.length) && (!groupbys || !groupbys.length) { }
+ this.rpc('/web/session/eval_domain_and_context', {
+ domains: [this.dataset.get_domain()].concat(domains || []),
+ contexts: [this.dataset.get_context()].concat(contexts || []),
+ group_by_seq: groupbys || []
+ }, function (results) {
+ controller.do_search(results.domain, results.context, results.group_by);
+ self.last_search = [results.domain, results.context, results.group_by];
+ });
+ } else if (this.last_search) {
+ controller.do_search.apply(controller, this.last_search);
+ }
+ },
+ /**
+ * Event launched when a controller has been inited.
+ *
+ * @param {String} view_type type of view
+ * @param {String} view the inited controller
+ */
+ on_controller_inited: function(view_type, view) {
+ },
/**
* Called when one of the view want to execute an action
*/
@@ -360,23 +361,19 @@
* launches an initial search after both views are done rendering.
*/
start: function() {
- var self = this;
-
- var searchview_loaded;
- if (this.flags.search_view !== false) {
- var search_defaults = {};
- _.each(this.action.context, function (value, key) {
- var match = /^search_default_(.*)$/.exec(key);
- if (match) {
- search_defaults[match[1]] = value;
- }
- });
- // init search view
- var searchview_id = this.action['search_view_id'] && this.action['search_view_id'][0];
-
- searchview_loaded = this.setup_search_view(
- searchview_id || false, search_defaults);
- }
+ var self = this,
+ searchview_loaded,
+ search_defaults = {};
+ _.each(this.action.context, function (value, key) {
+ var match = /^search_default_(.*)$/.exec(key);
+ if (match) {
+ search_defaults[match[1]] = value;
+ }
+ });
+ // init search view
+ var searchview_id = this.action['search_view_id'] && this.action['search_view_id'][0];
+
+ searchview_loaded = this.setup_search_view(searchview_id || false, search_defaults);
var main_view_loaded = this._super();
@@ -816,6 +813,8 @@
},
do_switch_view: function(view) {
},
+ do_search: function(view) {
+ },
set_common_sidebar_sections: function(sidebar) {
sidebar.add_section('customize', "Customize", [
{
=== modified file 'addons/web_calendar/static/src/js/calendar.js'
--- addons/web_calendar/static/src/js/calendar.js 2011-09-28 15:16:13 +0000
+++ addons/web_calendar/static/src/js/calendar.js 2011-09-29 12:45:56 +0000
@@ -13,6 +13,7 @@
this.set_default_options(options);
this.dataset = dataset;
this.model = dataset.model;
+ this.fields_view = {};
this.view_id = view_id;
this.domain = this.dataset.domain || [];
this.context = this.dataset.context || {};
@@ -92,9 +93,6 @@
this.init_scheduler();
this.has_been_loaded.resolve();
- if (this.dataset.ids.length) {
- this.dataset.read_ids(this.dataset.ids, _.keys(this.fields), this.on_events_loaded);
- }
},
init_scheduler: function() {
var self = this;
@@ -293,26 +291,21 @@
}
return data;
},
- do_search: function(domains, contexts, groupbys) {
+ do_search: function(domain, context, group_by) {
var self = this;
scheduler.clearAll();
$.when(this.has_been_loaded).then(function() {
- self.rpc('/web/session/eval_domain_and_context', {
- domains: domains,
- contexts: contexts,
- group_by_seq: groupbys
- }, function (results) {
- // TODO: handle non-empty results.group_by with read_group
- self.dataset.context = self.context = results.context;
- self.dataset.domain = self.domain = results.domain;
- self.dataset.read_slice(_.keys(self.fields), {
- offset:0,
- limit: self.limit
- }, function(events) {
- self.dataset_events = events;
- self.on_events_loaded(events);
- }
- );
+ // TODO: handle non-empty results.group_by with read_group
+ self.context = context;
+ self.domain = domain;
+ self.dataset.read_slice(_.keys(self.fields), {
+ offset: 0,
+ context: context,
+ domain: domain,
+ limit: self.limit
+ }, function(events) {
+ self.dataset_events = events;
+ self.on_events_loaded(events);
});
});
},
=== modified file 'addons/web_graph/static/src/js/graph.js'
--- addons/web_graph/static/src/js/graph.js 2011-09-29 08:30:13 +0000
+++ addons/web_graph/static/src/js/graph.js 2011-09-29 12:45:56 +0000
@@ -29,7 +29,6 @@
this.group_field = null;
},
do_show: function () {
- // TODO: re-trigger search
this.$element.show();
},
do_hide: function () {
@@ -79,9 +78,6 @@
}
}, this);
this.ordinate = this.columns[0].name;
-
- this.dataset.read_slice(
- this.list_fields(), {}, $.proxy(this, 'schedule_chart'));
},
schedule_chart: function(results) {
var self = this;
@@ -366,24 +362,17 @@
});
},
- do_search: function(domains, contexts, groupbys) {
- var self = this;
- this.rpc('/web/session/eval_domain_and_context', {
- domains: domains,
- contexts: contexts,
- group_by_seq: groupbys
- }, function (results) {
- // TODO: handle non-empty results.group_by with read_group?
- if(!_(results.group_by).isEmpty()){
- self.abscissa = results.group_by[0];
- } else {
- self.abscissa = self.first_field;
- }
- self.dataset.read_slice(self.list_fields(), {
- context: results.context,
- domain: results.domain
- }, $.proxy(self, 'schedule_chart'));
- });
+ do_search: function(domain, context, group_by) {
+ // TODO: handle non-empty group_by with read_group?
+ if (!_(group_by).isEmpty()) {
+ this.abscissa = group_by[0];
+ } else {
+ this.abscissa = this.first_field;
+ }
+ this.dataset.read_slice(this.list_fields(), {
+ context: context,
+ domain: domain
+ }, $.proxy(this, 'schedule_chart'));
}
});
};
=== modified file 'addons/web_kanban/static/src/js/kanban.js'
--- addons/web_kanban/static/src/js/kanban.js 2011-09-27 08:33:11 +0000
+++ addons/web_kanban/static/src/js/kanban.js 2011-09-29 12:45:56 +0000
@@ -9,8 +9,6 @@
this.set_default_options(options);
this.dataset = dataset;
this.model = dataset.model;
- this.domain = dataset.domain;
- this.context = dataset.context;
this.view_id = view_id;
this.fields_view = {};
this.group_by = [];
@@ -33,9 +31,6 @@
var self = this;
this.fields_view = data;
this.add_qweb_template();
- if (this.qweb.has_template('kanban-box')) {
- this.do_actual_search();
- }
},
add_qweb_template: function() {
var group_operator = ["avg", "max", "min", "sum", "count"]
@@ -294,7 +289,7 @@
this.do_execute_action(
button_attrs, dataset,
record_id, function () {
- self.do_actual_search();
+ self.on_reload_record(record_id);
}
);
},
@@ -427,28 +422,18 @@
});
return new_record;
},
- do_search: function (domains, contexts, group_by) {
+ do_search: function (domain, context, group_by) {
var self = this;
- this.rpc('/web/session/eval_domain_and_context', {
- domains: [this.dataset.get_domain()].concat(domains),
- contexts: [this.dataset.get_context()].concat(contexts),
- group_by_seq: group_by
- }, function (results) {
- self.domain = results.domain;
- self.context = results.context;
- self.group_by = results.group_by;
- self.do_actual_search();
- });
- },
- do_actual_search : function () {
+ self.group_by = group_by;
var self = this,
group_by = self.group_by;
if (!group_by.length && this.fields_view.arch.attrs.default_group_by) {
group_by = [this.fields_view.arch.attrs.default_group_by];
self.group_by = group_by;
}
- self.datagroup = new openerp.web.DataGroup(self, self.model, self.domain, self.context, group_by);
- self.datagroup.list(_.keys(self.fields_view.fields),
+ self.datagroup = new openerp.web.DataGroup(self, self.model, domain, context, group_by);
+ self.datagroup.list(
+ _.keys(self.fields_view.fields),
function (groups) {
self.groups = groups;
if (groups.length) {
@@ -461,9 +446,15 @@
},
function (dataset) {
self.groups = [];
- self.dataset.read_slice([], {'domain': self.domain, 'context': self.context}, function(records) {
- if (records.length) self.all_display_data = [{'records': records, 'value':false, 'header' : false, 'ids': self.dataset.ids}];
- else self.all_display_data = [];
+ self.dataset.read_slice([], {
+ domain: domain,
+ context: context
+ }, function(records) {
+ if (records.length) {
+ self.all_display_data = [{'records': records, 'value':false, 'header' : false, 'ids': self.dataset.ids}];
+ } else {
+ self.all_display_data = [];
+ }
self.$element.find(".oe_kanban_view").remove();
self.on_show_data();
});
@@ -487,7 +478,7 @@
_.each(self.aggregates, function(value, key) {
group_aggregates[value] = group.aggregates[key];
});
- self.dataset.read_slice([], {'domain': group.domain, 'context': group.context}, function(records) {
+ self.dataset.read_slice([], {'domain': group.domain, 'conext': group.context}, function(records) {
self.all_display_data.push({"value" : group_value, "records": records, 'header':group_name, 'ids': self.dataset.ids, 'aggregates': group_aggregates});
if (datagroups.length == self.all_display_data.length) {
self.$element.find(".oe_kanban_view").remove();
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp