[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 Karl Southern
parent 48457a94e1
commit e089cdcbd2
2 changed files with 13 additions and 15 deletions

View File

@@ -6,10 +6,10 @@
"summary": """ "summary": """
Enables selecting a range of records using the shift key Enables selecting a range of records using the shift key
""", """,
"version": "13.0.1.0.0", "version": "14.0.1.0.0",
"category": "Web", "category": "Web",
"author": "Onestein, Odoo Community Association (OCA)", "author": "Onestein, Odoo Community Association (OCA)",
"website": "https://github.com/oca/web", "website": "https://github.com/OCA/web",
"license": "AGPL-3", "license": "AGPL-3",
"depends": ["web"], "depends": ["web"],
"data": ["templates/assets.xml"], "data": ["templates/assets.xml"],

View File

@@ -1,7 +1,7 @@
/* Copyright 2017 Onestein /* Copyright 2017 Onestein
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ * 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"; "use strict";
var ListRenderer = require("web.ListRenderer"); var ListRenderer = require("web.ListRenderer");
@@ -18,22 +18,20 @@ odoo.define("web_listview_range_select", function(require) {
}), }),
_range_history: [], _range_history: [],
_render: function() { _render: function () {
var res = this._super.apply(this, arguments); var res = this._super.apply(this, arguments);
this.$table = this.$el.find(".o_list_view"); this.$table = this.$el.find(".o_list_view");
return res; return res;
}, },
_getRangeSelection: function() { _getRangeSelection: function () {
var self = this; var self = this;
// Get start and end // Get start and end
var start = null, var start = null,
end = null; end = null;
this.$el.find("td.o_list_record_selector input").each(function(i, el) { this.$el.find("td.o_list_record_selector input").each(function (i, el) {
var id = $(el) var id = $(el).closest("tr").data("id");
.closest("tr")
.data("id");
var checked = self._range_history.indexOf(id) !== -1; var checked = self._range_history.indexOf(id) !== -1;
if (checked && $(el).is(":checked")) { if (checked && $(el).is(":checked")) {
if (start === null) { if (start === null) {
@@ -50,12 +48,12 @@ odoo.define("web_listview_range_select", function(require) {
return current_selection; return current_selection;
}, },
_getSelectionByRange: function(start, end) { _getSelectionByRange: function (start, end) {
var result = []; var result = [];
this.$el this.$el
.find("td.o_list_record_selector input") .find("td.o_list_record_selector input")
.closest("tr") .closest("tr")
.each(function(i, el) { .each(function (i, el) {
var record_id = $(el).data("id"); var record_id = $(el).data("id");
if (start !== null && end !== null && i >= start && i <= end) { if (start !== null && end !== null && i >= start && i <= end) {
result.push(record_id); result.push(record_id);
@@ -66,19 +64,19 @@ odoo.define("web_listview_range_select", function(require) {
return result; return result;
}, },
_pushRangeHistory: function(id) { _pushRangeHistory: function (id) {
if (this._range_history.length === 2) { if (this._range_history.length === 2) {
this._range_history = []; this._range_history = [];
} }
this._range_history.push(id); this._range_history.push(id);
}, },
_deselectTable: function() { _deselectTable: function () {
// This is needed because the checkboxes are not real checkboxes. // This is needed because the checkboxes are not real checkboxes.
window.getSelection().removeAllRanges(); window.getSelection().removeAllRanges();
}, },
_onClickSelectRecord: function(event) { _onClickSelectRecord: function (event) {
var el = $(event.currentTarget); var el = $(event.currentTarget);
// Firefox shift click fix // Firefox shift click fix
@@ -96,7 +94,7 @@ odoo.define("web_listview_range_select", function(require) {
var $rows = this.$el var $rows = this.$el
.find("td.o_list_record_selector input") .find("td.o_list_record_selector input")
.closest("tr"); .closest("tr");
$rows.each(function() { $rows.each(function () {
// Check input visual // Check input visual
var record_id = $(this).data("id"); var record_id = $(this).data("id");
if (selection.indexOf(record_id) !== -1) { if (selection.indexOf(record_id) !== -1) {