[ADD] Partial pager in form view

bzr revid: fme@openerp.com-20110404160936-4uk9pywwdbv6qj9f
This commit is contained in:
Fabien Meghazi 2011-04-04 18:09:36 +02:00
parent 04969e8bf1
commit e9b3548c11
3 changed files with 22 additions and 11 deletions

View File

@ -67,8 +67,8 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
limit: limit
}, function (records) {
var r = [];
this.offset = offset;
this.count = records.length; // TODO: get real count
self.offset = offset;
self.count = records.length; // TODO: get real count
for (var i=0; i < records.length; i++ ) {
self.ids.push(records[i].id);
r.push(new openerp.base.DataRecord(self.session, self.model, fields, records[i]));
@ -90,8 +90,12 @@ openerp.base.DataSet = openerp.base.Controller.extend( /** @lends openerp.base.
});
},
fetch_index: function (fields, callback) {
fields = fields || false;
this.fetch_ids([this.ids[this.index]], fields, callback);
if (_.isEmpty(this.ids)) {
callback([]);
} else {
fields = fields || false;
this.fetch_ids([this.ids[this.index]], fields, callback);
}
},
/**

View File

@ -41,16 +41,18 @@ openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base
_.each(this.widgets, function(w) {
w.start();
});
this.$element.find('button.pager_previous').click(this.on_previous);
this.$element.find('button.pager_next').click(this.on_next);
this.$element.find('button.form_save').click(this.do_save);
},
on_previous: function() {
this.dataset.previous();
this.dataset.fetch_index(this.fields_view.fields, this.on_record_loaded);
},
on_next: function() {
this.dataset.next();
this.dataset.fetch_index(this.fields_view.fields, this.on_record_loaded);
},
on_prev: function() {
this.dataset.prev();
this.dataset.fetch_index(this.fields_view.fields, this.on_record_loaded);
},
on_record_loaded: function(record) {
if (record.length) {
this.datarecord = record[0];
@ -60,6 +62,7 @@ openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base
this.on_form_changed();
this.ready = true;
}
this.do_update_pager();
},
on_form_changed: function(widget) {
for (var w in this.widgets) {
@ -126,6 +129,10 @@ openerp.base.FormView = openerp.base.Controller.extend( /** @lends openerp.base
do_hide: function () {
this.$element.hide();
},
do_update_pager: function() {
this.$element.find('span.dataset_index').html(this.dataset.index + 1);
this.$element.find('span.dataset_count').html(this.dataset.count);
},
on_invalid: function() {
},
on_saved: function() {

View File

@ -155,9 +155,9 @@
<h3 class="title"><t t-esc="view.fields_view.arch.attrs.string"/></h3>
<div style="text-align:right;">
<input type="button" value="First"/>
<input type="button" value="&lt;&lt;"/>
0 / 0
<input type="button" value="&gt;&gt;"/>
<button type="button" class="pager_previous">&lt;&lt;</button>
<span class="dataset_index">0</span> / <span class="dataset_count">0</span>
<button type="button" class="pager_next">&gt;&gt;</button>
<input type="button" value="Last"/>
</div>
<t t-raw="frame.render()"/>