[MIG] web_listview_range_select: Migration to 14.0

This commit is contained in:
Kévin Roche
2021-01-13 14:52:36 +01:00
committed by Christopher Rogos
parent 91c2757133
commit 7485491f0b
5 changed files with 22 additions and 30 deletions

View File

@@ -1,39 +1,31 @@
/* Copyright 2017 Onestein
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define("web_listview_range_select", function(require) {
odoo.define("web_listview_range_select", function (require) {
"use strict";
var ListRenderer = require("web.ListRenderer");
ListRenderer.include({
/*
I extend 'events' because in v13 Odoo catches 'change' event instead
of the 'click' event for the selector .o_list_record_selector ",
so shift + [click] is not caught.
https://github.com/OCA/OCB/blob/13.0/addons/web/static/src/js/views/list/list_renderer.js#L42:L42
*/
events: _.extend({}, ListRenderer.prototype.events, {
"click tbody .o_list_record_selector": "_onClickSelectRecord",
}),
_range_history: [],
_render: function() {
_render: function () {
var res = this._super.apply(this, arguments);
this.$table = this.$el.find(".o_list_view");
return res;
},
_getRangeSelection: function() {
_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");
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).is(":checked")) {
if (start === null) {
@@ -50,12 +42,12 @@ odoo.define("web_listview_range_select", function(require) {
return current_selection;
},
_getSelectionByRange: function(start, end) {
_getSelectionByRange: function (start, end) {
var result = [];
this.$el
.find("td.o_list_record_selector input")
.closest("tr")
.each(function(i, el) {
.each(function (i, el) {
var record_id = $(el).data("id");
if (start !== null && end !== null && i >= start && i <= end) {
result.push(record_id);
@@ -66,19 +58,19 @@ odoo.define("web_listview_range_select", function(require) {
return result;
},
_pushRangeHistory: function(id) {
_pushRangeHistory: function (id) {
if (this._range_history.length === 2) {
this._range_history = [];
}
this._range_history.push(id);
},
_deselectTable: function() {
_deselectTable: function () {
// This is needed because the checkboxes are not real checkboxes.
window.getSelection().removeAllRanges();
},
_onClickSelectRecord: function(event) {
_onClickSelectRecord: function (event) {
var el = $(event.currentTarget);
// Firefox shift click fix
@@ -96,7 +88,7 @@ odoo.define("web_listview_range_select", function(require) {
var $rows = this.$el
.find("td.o_list_record_selector input")
.closest("tr");
$rows.each(function() {
$rows.each(function () {
// Check input visual
var record_id = $(this).data("id");
if (selection.indexOf(record_id) !== -1) {