mirror of
https://github.com/OCA/web.git
synced 2025-02-22 13:21:25 +02:00
[MIG] web_listview_range_select: Migration to 12.0
[FIX] Firefox shift click [REM] Removed unnecessary configure section [ADD] Roadmap with new features
This commit is contained in:
@@ -9,80 +9,89 @@ odoo.define('web_listview_range_select', function (require) {
|
||||
ListRenderer.include({
|
||||
_range_history: [],
|
||||
|
||||
_get_range_selection: function() {
|
||||
var self = this;
|
||||
var result = {ids: [], records: []};
|
||||
_render: function() {
|
||||
var res = this._super.apply(this, arguments);
|
||||
this.$table = this.$el.find('.o_list_view');
|
||||
return res;
|
||||
},
|
||||
|
||||
//Get start and end
|
||||
_getRangeSelection: function() {
|
||||
var self = this;
|
||||
|
||||
// Get start and end
|
||||
var start = null,
|
||||
end = null;
|
||||
|
||||
this.$el.find('td.o_list_record_selector input').each(function (i, el) {
|
||||
var id = $(el).closest('tr').data('id');
|
||||
var checked = self._range_history.indexOf(id) != -1;
|
||||
if (checked && $(el).prop('checked')) {
|
||||
if (start == null)
|
||||
var checked = self._range_history.indexOf(id) !== -1;
|
||||
if (checked && $(el).is(':checked')) {
|
||||
if (start == null) {
|
||||
start = i;
|
||||
else
|
||||
} else {
|
||||
end = i;
|
||||
}
|
||||
}
|
||||
});
|
||||
var new_range = this._getSelectionByRange(start, end);
|
||||
|
||||
//Preserve already checked
|
||||
this.$el.find('td.o_list_record_selector input:checked').closest('tr').each(function (i, el) {
|
||||
if (i == start || i == end) return;
|
||||
var record_id = $(el).data('id')
|
||||
result.ids.push(record_id);
|
||||
result.records.push(el.attributes);
|
||||
});
|
||||
|
||||
var new_range = this.get_range_selection(start, end);
|
||||
result.records = result.records.concat(new_range.records);
|
||||
result.ids = result.ids.concat(new_range.ids);
|
||||
|
||||
return result;
|
||||
var current_selection = this.selection;
|
||||
current_selection = _.uniq(current_selection.concat(new_range));
|
||||
return current_selection;
|
||||
},
|
||||
|
||||
get_range_selection: function(start, end) {
|
||||
var result = {ids: [], records: []};
|
||||
_getSelectionByRange: function(start, end) {
|
||||
var result = [];
|
||||
this.$el.find('td.o_list_record_selector input').closest('tr').each(function (i, el) {
|
||||
var record_id = $(el).data('id');
|
||||
if (start != null && end != null && i >= start && i <= end) {
|
||||
result.ids.push(record_id);
|
||||
result.records.push(el.attributes);
|
||||
result.push(record_id);
|
||||
} else if(start != null && end == null && start == i) {
|
||||
result.ids.push(record_id);
|
||||
result.records.push(el.attributes);
|
||||
result.push(record_id);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
},
|
||||
|
||||
push_range_history: function(id) {
|
||||
_pushRangeHistory: function(id) {
|
||||
if (this._range_history.length === 2) {
|
||||
this._range_history = [];
|
||||
}
|
||||
this._range_history.push(id);
|
||||
if (this._range_history.length == 3)
|
||||
this._range_history.shift();
|
||||
},
|
||||
|
||||
_deselectTable: function() {
|
||||
// This is needed because the checkboxes are not real checkboxes.
|
||||
window.getSelection().removeAllRanges();
|
||||
},
|
||||
|
||||
_onSelectRecord: function(event) {
|
||||
var res = this._super(event);
|
||||
var self = this;
|
||||
var el = $(event.currentTarget);
|
||||
if (el.find('input').prop('checked'))
|
||||
self.push_range_history(el.closest('tr').data('id'));
|
||||
var res = this._super(event);
|
||||
|
||||
// Firefox shift click fix
|
||||
if (/firefox/i.test(navigator.userAgent) && event.shiftKey) {
|
||||
el.find('input').prop('checked', !el.find('input').prop('checked'));
|
||||
}
|
||||
|
||||
if (el.find('input').prop('checked')) {
|
||||
this._pushRangeHistory(el.closest('tr').data('id'));
|
||||
}
|
||||
|
||||
if (event.shiftKey) {
|
||||
//Get selection
|
||||
var selection = self._get_range_selection();
|
||||
this.$el.find('td.o_list_record_selector input').closest('tr').each(function () {
|
||||
//Check input visual
|
||||
// Get selection
|
||||
var selection = this._getRangeSelection();
|
||||
var $rows = this.$el.find('td.o_list_record_selector input').closest('tr');
|
||||
$rows.each(function () {
|
||||
// Check input visual
|
||||
var record_id = $(this).data('id');
|
||||
if (selection.ids.indexOf(record_id) != -1)
|
||||
if (selection.indexOf(record_id) !== -1) {
|
||||
$(this).find('td.o_list_record_selector input').prop('checked', true);
|
||||
}
|
||||
});
|
||||
//Check input internal
|
||||
$(self).trigger(
|
||||
'selected', [selection.ids, selection.records, true]);
|
||||
// Update selection internally
|
||||
this._updateSelection();
|
||||
this._deselectTable();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user