openerp-dev-web team mailing list archive
-
openerp-dev-web team
-
Mailing list archive
-
Message #04873
lp:~openerp-dev/openobject-client-web/trunk-proto61-decentralized-search into lp:~openerp-dev/openobject-client-web/trunk-proto61
Fabien Meghazi (OpenERP) has proposed merging lp:~openerp-dev/openobject-client-web/trunk-proto61-decentralized-search into lp:~openerp-dev/openobject-client-web/trunk-proto61.
Requested reviews:
Antony Lesuisse (al-openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-client-web/trunk-proto61-decentralized-search/+merge/55768
- Decentralised searches
- Lazy loading of views
- Fields are no more inherent to DataSet
--
https://code.launchpad.net/~openerp-dev/openobject-client-web/trunk-proto61-decentralized-search/+merge/55768
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-client-web/trunk-proto61.
=== modified file 'addons/base/static/src/css/base.css'
--- addons/base/static/src/css/base.css 2011-03-30 14:44:36 +0000
+++ addons/base/static/src/css/base.css 2011-03-31 15:26:23 +0000
@@ -395,6 +395,11 @@
padding-left: 10px;
}
+/* View Manager */
+.openerp .views_switchers {
+ text-align: right;
+}
+
/* Form */
.openerp .required.error {
border: 1px solid #900;
=== modified file 'addons/base/static/src/js/data.js'
--- addons/base/static/src/js/data.js 2011-03-31 12:05:15 +0000
+++ addons/base/static/src/js/data.js 2011-03-31 15:26:23 +0000
@@ -32,8 +32,6 @@
this._super(session);
this.model = model;
- this._fields = null;
-
this._ids = [];
this._active_ids = null;
this._active_id_index = 0;
@@ -43,12 +41,6 @@
this._context = {};
},
start: function() {
- // TODO: fields_view_get fields selection?
- this.rpc("/base/dataset/fields", {"model":this.model}, this.on_fields);
- },
- on_fields: function(result) {
- this._fields = result.fields;
- this.on_ready();
},
/**
@@ -63,12 +55,11 @@
* @param {Number} [limit=null] The maximum number of records to return
* @returns itself
*/
- fetch: function (offset, limit) {
+ fetch: function (fields, offset, limit) {
offset = offset || 0;
- limit = limit || null;
this.rpc('/base/dataset/find', {
model: this.model,
- fields: this._fields,
+ fields: fields,
domain: this._domain,
context: this._context,
sort: this._sort,
@@ -77,9 +68,7 @@
}, _.bind(function (records) {
var data_records = _.map(
records, function (record) {
- return new openerp.base.DataRecord(
- this.session, this.model,
- this._fields, record);
+ return new openerp.base.DataRecord(this.session, this.model, fields, record);
}, this);
this.on_fetch(data_records, {
@@ -116,16 +105,14 @@
*
* @returns itself
*/
- active_ids: function () {
+ active_ids: function (fields) {
this.rpc('/base/dataset/get', {
ids: this.get_active_ids(),
model: this.model
}, _.bind(function (records) {
this.on_active_ids(_.map(
records, function (record) {
- return new openerp.base.DataRecord(
- this.session, this.model,
- this._fields, record);
+ return new openerp.base.DataRecord(this.session, this.model, fields, record);
}, this));
}, this));
return this;
@@ -149,7 +136,7 @@
*
* @returns itself
*/
- active_id: function () {
+ active_id: function (fields) {
this.rpc('/base/dataset/get', {
ids: [this.get_active_id()],
model: this.model
@@ -158,7 +145,7 @@
this.on_active_id(
record && new openerp.base.DataRecord(
this.session, this.model,
- this._fields, record));
+ fields, record));
}, this));
return this;
},
=== modified file 'addons/base/static/src/js/form.js'
--- addons/base/static/src/js/form.js 2011-03-31 10:57:51 +0000
+++ addons/base/static/src/js/form.js 2011-03-31 15:26:23 +0000
@@ -91,6 +91,8 @@
},
on_saved: function() {
// Check response for exceptions, display error
+ },
+ do_search: function (domains, contexts, groupbys) {
}
});
=== modified file 'addons/base/static/src/js/list.js'
--- addons/base/static/src/js/list.js 2011-03-30 14:35:56 +0000
+++ addons/base/static/src/js/list.js 2011-03-31 15:26:23 +0000
@@ -8,6 +8,9 @@
this.model = dataset.model;
this.view_id = view_id;
this.name = "";
+ // TODO: default to action.limit
+ // TODO: decide if limit is a property of DataSet and thus global to all views (calendar ?)
+ this.limit = 80;
this.cols = [];
@@ -72,6 +75,20 @@
return record.values;
}));
+ },
+ do_search: function (domains, contexts, groupbys) {
+ var self = this;
+ this.rpc('/base/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.set({
+ context: results.context,
+ domain: results.domain
+ }).fetch(self.fields_view.fields, 0, self.limit);
+ });
}
});
=== modified file 'addons/base/static/src/js/views.js'
--- addons/base/static/src/js/views.js 2011-03-31 08:03:35 +0000
+++ addons/base/static/src/js/views.js 2011-03-31 15:26:23 +0000
@@ -8,7 +8,6 @@
// process all kind of actions
init: function(session, element_id) {
this._super(session, element_id);
- this.action = null;
this.viewmanager = null;
},
/**
@@ -17,7 +16,6 @@
*/
do_action: function(action) {
// instantiate the right controllers by understanding the action
- this.action = action;
if(action.type == "ir.actions.act_window") {
this.viewmanager = new openerp.base.ViewManager(this.session,this.element_id);
this.viewmanager.do_action_window(action);
@@ -35,14 +33,44 @@
this.searchview_id = false;
this.searchview = null;
this.search_visible = true;
+ this.active_view = null;
+ this.auto_search = false;
// this.views = { "list": { "view_id":1234, "controller": instance} }
this.views = {};
},
start: function() {
},
on_mode_switch: function(view_type) {
+ this.active_view = view_type;
+ var view = this.views[view_type];
+ if (!view.controller) {
+ // Lazy loading of views
+ var controller;
+ switch (view_type) {
+ case 'tree':
+ controller = new openerp.base.ListView(this.session, this.element_id + "_view_tree", this.dataset, view.view_id);
+ break;
+ case 'form':
+ controller = new openerp.base.FormView(this.session, this.element_id + "_view_form", this.dataset, view.view_id);
+ break;
+ case 'calendar':
+ controller = new openerp.base.CalendarView(this.session, this.element_id + "_view_calendar", this.dataset, view.view_id);
+ break;
+ case 'gantt':
+ controller = new openerp.base.GanttView(this.session, this.element_id + "_view_gantt", this.dataset, view.view_id);
+ break;
+ }
+ controller.start();
+ this.views[view_type].controller = controller;
+ if (this.auto_search) {
+ this.searchview.on_loaded.add_last(this.searchview.do_search);
+ this.auto_search = false;
+ }
+ }
for (var i in this.views) {
- this.views[i].controller.$element.toggle(i === view_type);
+ if (this.views[i].controller) {
+ this.views[i].controller.$element.toggle(i === view_type);
+ }
}
},
/**
@@ -72,41 +100,27 @@
this.$element.html(QWeb.render("ViewManager", {"prefix": this.element_id, views: action.views}));
this.searchview_id = false;
- if(this.search_visible && action.search_view_id) {
+ if (this.search_visible && action.search_view_id) {
this.searchview_id = action.search_view_id[0];
var searchview = this.searchview = new openerp.base.SearchView(
this.session, this.element_id + "_search",
this.dataset, this.searchview_id,
this.search_defaults());
- searchview.on_search.add(this.do_search);
+ searchview.on_search.add(function() {
+ self.views[self.active_view].controller.do_search.apply(self, arguments);
+ });
searchview.start();
- if (action['auto_search']) {
- searchview.on_loaded.add_last(
- searchview.do_search);
- }
- }
- for(var i = 0; i < action.views.length; i++) {
- var view_id, controller;
- view_id = action.views[i][0];
- if(action.views[i][1] == "tree") {
- controller = new openerp.base.ListView(this.session, this.element_id + "_view_tree", this.dataset, view_id);
- controller.start();
- this.views.tree = { view_id: view_id, controller: controller };
- this.$element.find(prefix_id + "_button_tree").bind('click',function(){
- self.on_mode_switch("tree");
- });
- } else if(action.views[i][1] == "form") {
- controller = new openerp.base.FormView(this.session, this.element_id + "_view_form", this.dataset, view_id);
- controller.start();
- this.views.form = { view_id: view_id, controller: controller };
- this.$element.find(prefix_id + "_button_form").bind('click',function(){
- self.on_mode_switch("form");
- });
- }
- }
+ this.auto_search = action.auto_search;
+ }
+ this.$element.find('.views_switchers button').click(function() {
+ self.on_mode_switch($(this).data('view-type'));
+ });
+ _.each(action.views, function(view) {
+ self.views[view[1]] = { view_id: view[0], controller: null };
+ });
// switch to the first one in sequence
- this.on_mode_switch("tree");
+ this.on_mode_switch(action.views[0][1]);
},
// create when root, also add to parent when o2m
on_create: function() {
@@ -114,20 +128,6 @@
on_remove: function() {
},
on_edit: function() {
- },
- do_search: function (domains, contexts, groupbys) {
- var self = this;
- this.rpc('/base/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.set({
- context: results.context,
- domain: results.domain
- }).fetch(0, self.action.limit);
- });
}
});
=== modified file 'addons/base/static/src/xml/base.xml'
--- addons/base/static/src/xml/base.xml 2011-03-31 12:00:10 +0000
+++ addons/base/static/src/xml/base.xml 2011-03-31 15:26:23 +0000
@@ -126,12 +126,11 @@
</t>
<t t-name="ViewManager">
<!-- TODO prefix id with the element_id of the controller t-attf-id="#{prefix}_localid" -->
- <div style="text-align:right;">
- <!--
- <input t-foreach="views" t-as="view" t-att-id="" t-att-value="view[1]"/>
- -->
+ <div class="views_switchers">
<t t-foreach="views" t-as="view">
- <input t-attf-id="#{prefix}_button_#{view[1]}" type="button" t-att-value="view[1]"/>
+ <button type="button" t-att-data-view-type="view[1]">
+ <t t-esc="view[1]"/>
+ </button>
</t>
</div>
<div t-attf-id="#{prefix}_search"></div>
Follow ups