[MERGE] fme viewmanager updates
bzr revid: al@openerp.com-20110331172258-vzrkxqeo4rk2lsvx
This commit is contained in:
commit
0d9a590970
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -91,6 +91,8 @@ openerp.base.FormView = openerp.base.Controller.extend({
|
|||
},
|
||||
on_saved: function() {
|
||||
// Check response for exceptions, display error
|
||||
},
|
||||
do_search: function (domains, contexts, groupbys) {
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -8,6 +8,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 = [];
|
||||
|
||||
|
@ -72,6 +75,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,7 +16,6 @@ openerp.base.ActionManager = openerp.base.Controller.extend({
|
|||
*/
|
||||
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 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
|
|||
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 @@ openerp.base.ViewManager = openerp.base.Controller.extend({
|
|||
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 @@ 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"></div>
|
||||
|
|
Loading…
Reference in New Issue