[MERGE] view manager redo from proto-61
Full of timing bugs ;_; bzr revid: xmo@openerp.com-20110401090249-kxp4xkm92sqkxu1e
This commit is contained in:
@@ -395,6 +395,11 @@ body.openerp {
|
||||
padding-left: 10px;
|
||||
}
|
||||
|
||||
/* View Manager */
|
||||
.openerp .views_switchers {
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
/* Form */
|
||||
.openerp .required.error {
|
||||
border: 1px solid #900;
|
||||
@@ -413,6 +418,9 @@ body.openerp {
|
||||
border-radius: 3px;
|
||||
background: white;
|
||||
}
|
||||
.openerp input.field_date {
|
||||
background: url('../img/ui/field_calendar.png') no-repeat right center;
|
||||
}
|
||||
|
||||
/* Widgets */
|
||||
.openerp .separator {
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 454 B |
@@ -32,8 +32,6 @@ openerp.base.DataSet = openerp.base.Controller.extend(
|
||||
this._super(session);
|
||||
this.model = model;
|
||||
|
||||
this._fields = null;
|
||||
|
||||
this._ids = [];
|
||||
this._active_ids = null;
|
||||
this._active_id_index = 0;
|
||||
@@ -43,12 +41,6 @@ openerp.base.DataSet = openerp.base.Controller.extend(
|
||||
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 @@ openerp.base.DataSet = openerp.base.Controller.extend(
|
||||
* @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 @@ openerp.base.DataSet = openerp.base.Controller.extend(
|
||||
}, _.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 @@ openerp.base.DataSet = openerp.base.Controller.extend(
|
||||
*
|
||||
* @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 @@ openerp.base.DataSet = openerp.base.Controller.extend(
|
||||
*
|
||||
* @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 @@ openerp.base.DataSet = openerp.base.Controller.extend(
|
||||
this.on_active_id(
|
||||
record && new openerp.base.DataRecord(
|
||||
this.session, this.model,
|
||||
this._fields, record));
|
||||
fields, record));
|
||||
}, this));
|
||||
return this;
|
||||
},
|
||||
|
||||
@@ -92,6 +92,8 @@ openerp.base.FormView = openerp.base.Controller.extend({
|
||||
},
|
||||
on_saved: function() {
|
||||
// Check response for exceptions, display error
|
||||
},
|
||||
do_search: function (domains, contexts, groupbys) {
|
||||
}
|
||||
});
|
||||
|
||||
@@ -463,6 +465,10 @@ openerp.base.form.FieldDate = openerp.base.form.FieldChar.extend({
|
||||
init: function(view, node) {
|
||||
this._super(view, node);
|
||||
this.template = "FieldDate";
|
||||
},
|
||||
start: function() {
|
||||
this._super.apply(this, arguments);
|
||||
this.$element.find('input').datepicker();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -9,6 +9,9 @@ openerp.base.ListView = openerp.base.Controller.extend({
|
||||
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 = [];
|
||||
|
||||
@@ -73,6 +76,20 @@ openerp.base.ListView = openerp.base.Controller.extend({
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -8,7 +8,6 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
|
||||
// process all kind of actions
|
||||
init: function(session, element_id) {
|
||||
this._super(session, element_id);
|
||||
this.action = null;
|
||||
this.viewmanager = null;
|
||||
},
|
||||
/**
|
||||
@@ -17,8 +16,6 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
|
||||
*/
|
||||
do_action: function(action) {
|
||||
// instantiate the right controllers by understanding the action
|
||||
this.action = action;
|
||||
// TODO: handle target=new
|
||||
if(action.type == "ir.actions.act_window") {
|
||||
if (this.viewmanager) {
|
||||
this.viewmanager.stop();
|
||||
@@ -41,16 +38,27 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
|
||||
this.action = null;
|
||||
this.dataset = null;
|
||||
this.searchview = null;
|
||||
this.active_view = null;
|
||||
// this.views = { "list": { "view_id":1234, "controller": instance} }
|
||||
this.views = {};
|
||||
},
|
||||
start: function() {
|
||||
},
|
||||
on_mode_switch: function(view_type) {
|
||||
for (var type in this.views) {
|
||||
this.views[type].controller.$element.toggle(type === view_type);
|
||||
this.$element.find('#' + this.element_id + '_button_' + type)
|
||||
.attr('disabled', type === view_type);
|
||||
this.active_view = view_type;
|
||||
var view = this.views[view_type];
|
||||
if (!view.controller) {
|
||||
// Lazy loading of views
|
||||
var controller = new (openerp.base.views.get_object(view_type))(
|
||||
this.session, this.element_id + "_view_" + view_type,
|
||||
this.dataset, view.view_id);
|
||||
controller.start();
|
||||
this.views[view_type].controller = controller;
|
||||
}
|
||||
for (var i in this.views) {
|
||||
if (this.views[i].controller) {
|
||||
this.views[i].controller.$element.toggle(i === view_type);
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
@@ -76,6 +84,7 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
|
||||
* @param action the action being executed
|
||||
*/
|
||||
setup_search_view:function (action) {
|
||||
var self = this;
|
||||
if (this.searchview) {
|
||||
this.searchview.stop();
|
||||
}
|
||||
@@ -84,17 +93,13 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
|
||||
this.session, this.element_id + "_search",
|
||||
this.dataset, action.search_view_id[0] || false,
|
||||
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);
|
||||
}
|
||||
},
|
||||
do_action_window: function(action) {
|
||||
var self = this;
|
||||
var prefix_id = "#" + this.element_id;
|
||||
this.action = action;
|
||||
this.dataset = new openerp.base.DataSet(this.session, action.res_model);
|
||||
this.dataset.start();
|
||||
@@ -103,21 +108,18 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
|
||||
|
||||
this.setup_search_view(action);
|
||||
|
||||
_.each(action.views, function (view_descriptor) {
|
||||
var view_id = view_descriptor[0],
|
||||
view_type = view_descriptor[1];
|
||||
var view = new (openerp.base.views.get_object(view_type))(
|
||||
self.session, self.element_id + '_view_' + view_type,
|
||||
self.dataset, view_id);
|
||||
view.start();
|
||||
self.views[view_type] = { view_id: view_id, controller: view };
|
||||
self.$element.find(prefix_id + '_button_' + view_type).click(function () {
|
||||
self.on_mode_switch(view_type);
|
||||
});
|
||||
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 };
|
||||
});
|
||||
|
||||
if (action['auto_search']) {
|
||||
this.searchview.on_loaded.add_last(this.searchview.do_search);
|
||||
}
|
||||
// switch to the first one in sequence
|
||||
this.on_mode_switch(action.view_mode.split(',')[0]);
|
||||
this.on_mode_switch(action.views[0][1]);
|
||||
},
|
||||
// create when root, also add to parent when o2m
|
||||
on_create: function() {
|
||||
@@ -125,20 +127,6 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -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"/>
|
||||
|
||||
Reference in New Issue
Block a user