[FIX] Kanban view: add limit + "Show more" button
lp bug: https://launchpad.net/bugs/925532 fixed lp bug: https://launchpad.net/bugs/922026 fixed bzr revid: fme@openerp.com-20120209175902-od0rp2a3ps3jl8yz
This commit is contained in:
parent
50e57e2242
commit
a5c4983666
|
@ -41,7 +41,21 @@
|
|||
position: absolute;
|
||||
top: 10px;
|
||||
}
|
||||
|
||||
.openerp .oe_kanban_show_more {
|
||||
clear: both;
|
||||
text-align: center;
|
||||
}
|
||||
.openerp .oe_kanban_grouped .oe_kanban_show_more .oe_button {
|
||||
width: 100%;
|
||||
}
|
||||
.openerp .oe_kanban_ungrouped .oe_kanban_record {
|
||||
float: left;
|
||||
width: 33%;
|
||||
padding: 2px;
|
||||
box-sizing: border-box;
|
||||
-moz-box-sizing: border-box;
|
||||
-webkit-box-sizing: border-box;
|
||||
}
|
||||
.openerp .oe_kanban_fold_icon {
|
||||
cursor: pointer;
|
||||
float: left;
|
||||
|
|
|
@ -32,6 +32,7 @@ openerp.web_kanban.KanbanView = openerp.web.View.extend({
|
|||
this.has_been_loaded = $.Deferred();
|
||||
this.search_domain = this.search_context = this.search_group_by = null;
|
||||
this.currently_dragging = {};
|
||||
this.limit = options.limit || 80;
|
||||
},
|
||||
start: function() {
|
||||
this._super();
|
||||
|
@ -151,22 +152,12 @@ openerp.web_kanban.KanbanView = openerp.web.View.extend({
|
|||
remaining = groups.length - 1,
|
||||
groups_array = [];
|
||||
_.each(groups, function (group, index) {
|
||||
var group_name = group.value,
|
||||
group_value = group.value,
|
||||
group_aggregates = {};
|
||||
if (group.value instanceof Array) {
|
||||
group_name = group.value[1];
|
||||
group_value = group.value[0];
|
||||
}
|
||||
_.each(self.aggregates, function(value, key) {
|
||||
group_aggregates[value] = group.aggregates[key];
|
||||
});
|
||||
var dataset = new openerp.web.DataSetSearch(self, self.dataset.model, group.context, group.domain);
|
||||
dataset.read_slice(self.fields_keys.concat(['__last_update']), {'domain': group.domain, 'context': group.context}).then(function(records) {
|
||||
dataset.read_slice(self.fields_keys.concat(['__last_update']), { 'limit': self.limit }).then(function(records) {
|
||||
self.dataset.ids.push.apply(self.dataset.ids, dataset.ids);
|
||||
groups_array[index] = new openerp.web_kanban.KanbanGroup(self, records, group_value, group_name, group_aggregates);
|
||||
groups_array[index] = new openerp.web_kanban.KanbanGroup(self, records, group, dataset);
|
||||
if (!remaining--) {
|
||||
self.dataset.index = self.dataset.ids.length ? 0 : null;
|
||||
self.dataset.index = self.dataset.size() ? 0 : null;
|
||||
self.do_add_groups(groups_array);
|
||||
}
|
||||
});
|
||||
|
@ -175,20 +166,9 @@ openerp.web_kanban.KanbanView = openerp.web.View.extend({
|
|||
do_process_dataset: function(dataset) {
|
||||
var self = this;
|
||||
this.do_clear_groups();
|
||||
this.dataset.read_slice(this.fields_keys.concat(['__last_update'])).then(function(records) {
|
||||
var groups = [];
|
||||
while (records.length) {
|
||||
for (var i = 0; i < self.default_nr_columns; i++) {
|
||||
if (!groups[i]) {
|
||||
groups[i] = [];
|
||||
}
|
||||
groups[i].push(records.shift());
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < groups.length; i++) {
|
||||
groups[i] = new openerp.web_kanban.KanbanGroup(self, _.compact(groups[i]));
|
||||
}
|
||||
self.do_add_groups(groups);
|
||||
this.dataset.read_slice(this.fields_keys.concat(['__last_update']), { 'limit': self.limit }).then(function(records) {
|
||||
var kgroup = new openerp.web_kanban.KanbanGroup(self, records, null, self.dataset);
|
||||
self.do_add_groups([kgroup]);
|
||||
});
|
||||
},
|
||||
do_reload: function() {
|
||||
|
@ -240,6 +220,8 @@ openerp.web_kanban.KanbanView = openerp.web.View.extend({
|
|||
},
|
||||
on_record_moved : function(record, old_group, old_index, new_group, new_index) {
|
||||
var self = this;
|
||||
$.fn.tipsy.clear();
|
||||
$(old_group.$element).add(new_group.$element).find('.oe_kanban_aggregates, .oe_kanban_group_length').hide();
|
||||
if (old_group === new_group) {
|
||||
new_group.records.splice(old_index, 1);
|
||||
new_group.records.splice(new_index, 0, record);
|
||||
|
@ -281,18 +263,33 @@ openerp.web_kanban.KanbanView = openerp.web.View.extend({
|
|||
|
||||
openerp.web_kanban.KanbanGroup = openerp.web.OldWidget.extend({
|
||||
template: 'KanbanView.group_header',
|
||||
init: function (parent, records, value, title, aggregates) {
|
||||
init: function (parent, records, group, dataset) {
|
||||
var self = this;
|
||||
this._super(parent);
|
||||
this.$has_been_started = $.Deferred();
|
||||
this.view = parent;
|
||||
this.value = value;
|
||||
this.title = title;
|
||||
if (title === false) {
|
||||
this.group = group;
|
||||
this.dataset = dataset;
|
||||
this.dataset_offset = 0;
|
||||
this.aggregates = {};
|
||||
this.value = this.title = null;
|
||||
if (this.group) {
|
||||
this.value = group.value;
|
||||
this.title = group.value;
|
||||
if (this.value instanceof Array) {
|
||||
this.title = this.value[1];
|
||||
this.value = this.value[0];
|
||||
}
|
||||
_.each(this.view.aggregates, function(value, key) {
|
||||
self.aggregates[value] = group.aggregates[key];
|
||||
});
|
||||
}
|
||||
|
||||
if (this.title === false) {
|
||||
this.title = _t('Undefined');
|
||||
this.undefined_title = true;
|
||||
}
|
||||
this.aggregates = aggregates || {};
|
||||
var key = this.view.group_by + '-' + value;
|
||||
var key = this.view.group_by + '-' + this.value;
|
||||
if (!this.view.state.groups[key]) {
|
||||
this.view.state.groups[key] = {
|
||||
folded: false
|
||||
|
@ -300,8 +297,10 @@ openerp.web_kanban.KanbanGroup = openerp.web.OldWidget.extend({
|
|||
}
|
||||
this.state = this.view.state.groups[key];
|
||||
this.$records = null;
|
||||
this.records = _.map(records, function(record) {
|
||||
return new openerp.web_kanban.KanbanRecord(self, record);
|
||||
|
||||
this.records = [];
|
||||
this.$has_been_started.then(function() {
|
||||
self.do_add_records(records);
|
||||
});
|
||||
},
|
||||
start: function() {
|
||||
|
@ -309,19 +308,18 @@ openerp.web_kanban.KanbanGroup = openerp.web.OldWidget.extend({
|
|||
def = this._super();
|
||||
this.$records = $(QWeb.render('KanbanView.group_records_container', { widget : this}));
|
||||
this.$records.appendTo(this.view.$element.find('.oe_kanban_groups_records'));
|
||||
_.each(this.records, function(record) {
|
||||
record.appendTo(self.$records);
|
||||
});
|
||||
this.$element.find(".oe_kanban_fold_icon").click(function() {
|
||||
self.do_toggle_fold();
|
||||
self.view.compute_groups_width();
|
||||
return false;
|
||||
});
|
||||
this.$records.find('.oe_kanban_show_more').click(this.do_show_more);
|
||||
if (this.state.folded) {
|
||||
this.do_toggle_fold();
|
||||
}
|
||||
this.$element.data('widget', this);
|
||||
this.$records.data('widget', this);
|
||||
this.$has_been_started.resolve();
|
||||
return def;
|
||||
},
|
||||
stop: function() {
|
||||
|
@ -330,6 +328,23 @@ openerp.web_kanban.KanbanGroup = openerp.web.OldWidget.extend({
|
|||
this.$records.remove();
|
||||
}
|
||||
},
|
||||
do_show_more: function(evt) {
|
||||
var self = this;
|
||||
this.dataset.read_slice(this.view.fields_keys.concat(['__last_update']), {
|
||||
'limit': self.view.limit,
|
||||
'offset': self.dataset_offset += self.view.limit
|
||||
}).then(this.do_add_records);
|
||||
},
|
||||
do_add_records: function(records) {
|
||||
var self = this;
|
||||
_.each(records, function(record) {
|
||||
var rec = new openerp.web_kanban.KanbanRecord(self, record);
|
||||
rec.insertBefore(self.$records.find('.oe_kanban_show_more'));
|
||||
self.records.push(rec);
|
||||
});
|
||||
this.$records.find('.oe_kanban_show_more').toggle(this.records.length < this.dataset.size())
|
||||
.find('.oe_kanban_remaining').text(this.dataset.size() - this.records.length);
|
||||
},
|
||||
remove_record: function(id, remove_from_dataset) {
|
||||
for (var i = 0, ii = this.records.length; i < ii; i++) {
|
||||
if (this.records[i]['id'] === id) {
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
<div class="oe_fold_column">
|
||||
<div t-attf-class="oe_kanban_group_title #{widget.undefined_title ? 'oe_kanban_group_title_undefined' : ''}">
|
||||
<t t-esc="widget.title"/>
|
||||
<span class="oe_kanban_group_length">(<t t-esc="widget.group.length"/>)</span>
|
||||
</div>
|
||||
<ul class="oe_kanban_aggregates">
|
||||
<li t-foreach="widget.aggregates" t-as="aggregate">
|
||||
|
@ -35,7 +36,10 @@
|
|||
</td>
|
||||
</t>
|
||||
<t t-name="KanbanView.group_records_container">
|
||||
<td class="oe_kanban_column">
|
||||
<td t-attf-class="oe_kanban_column #{widget.group ? 'oe_kanban_grouped' : 'oe_kanban_ungrouped'}">
|
||||
<div class="oe_kanban_show_more">
|
||||
<button class="oe_button">Show more... (<span class="oe_kanban_remaining"></span> remaining)</button>
|
||||
</div>
|
||||
</td>
|
||||
</t>
|
||||
<t t-name="KanbanView.record">
|
||||
|
|
Loading…
Reference in New Issue