diff --git a/web_listview_range_select/README.rst b/web_listview_range_select/README.rst index 660c184bc41e..2fe65dc15362 100644 --- a/web_listview_range_select/README.rst +++ b/web_listview_range_select/README.rst @@ -7,7 +7,7 @@ List Range Selection !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:4591ffee6ecf15cafad3e0e9b709c4e1d1f08052ac3ad668fead7edbca90a8bf + !! source digest: sha256:0cd77b1cd0e10283cbf40fbf8a67f9c5c5135d746e755cf13dddf44e0f034cdb !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png @@ -78,6 +78,7 @@ Contributors * `Tecnativa `_: * Ernesto Tejeda +* Nilesh Sheliya Maintainers ~~~~~~~~~~~ diff --git a/web_listview_range_select/__manifest__.py b/web_listview_range_select/__manifest__.py index 25521e343fb2..f4db02ecf61c 100644 --- a/web_listview_range_select/__manifest__.py +++ b/web_listview_range_select/__manifest__.py @@ -6,7 +6,7 @@ "summary": """ Enables selecting a range of records using the shift key """, - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "category": "Web", "author": "Onestein, Odoo Community Association (OCA)", "website": "https://github.com/OCA/web", @@ -16,7 +16,8 @@ "application": False, "assets": { "web.assets_backend": [ - "/web_listview_range_select/static/src/js/web_listview_range_select.js" + "web_listview_range_select/static/src/js/web_listview_range_select.esm.js", + "web_listview_range_select/static/src/xml/web_listview_range_select.xml", ], }, } diff --git a/web_listview_range_select/i18n/web_listview_range_select.pot b/web_listview_range_select/i18n/web_listview_range_select.pot index a11baf5cd77c..78d58d53fe07 100644 --- a/web_listview_range_select/i18n/web_listview_range_select.pot +++ b/web_listview_range_select/i18n/web_listview_range_select.pot @@ -3,7 +3,7 @@ # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 15.0\n" +"Project-Id-Version: Odoo Server 16.0\n" "Report-Msgid-Bugs-To: \n" "Last-Translator: \n" "Language-Team: \n" diff --git a/web_listview_range_select/readme/CONTRIBUTORS.rst b/web_listview_range_select/readme/CONTRIBUTORS.rst index 3c6f9b720837..b1d3e078c91d 100644 --- a/web_listview_range_select/readme/CONTRIBUTORS.rst +++ b/web_listview_range_select/readme/CONTRIBUTORS.rst @@ -3,3 +3,4 @@ * `Tecnativa `_: * Ernesto Tejeda +* Nilesh Sheliya diff --git a/web_listview_range_select/static/description/index.html b/web_listview_range_select/static/description/index.html index ddc1879feaff..1fedee1c3d8e 100644 --- a/web_listview_range_select/static/description/index.html +++ b/web_listview_range_select/static/description/index.html @@ -367,7 +367,7 @@

List Range Selection

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:4591ffee6ecf15cafad3e0e9b709c4e1d1f08052ac3ad668fead7edbca90a8bf +!! source digest: sha256:0cd77b1cd0e10283cbf40fbf8a67f9c5c5135d746e755cf13dddf44e0f034cdb !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

Enables selecting a range of records using the shift key.

@@ -428,6 +428,7 @@

Contributors

  • Ernesto Tejeda
  • +
  • Nilesh Sheliya <nilesh@synodica.com>
  • diff --git a/web_listview_range_select/static/src/js/web_listview_range_select.esm.js b/web_listview_range_select/static/src/js/web_listview_range_select.esm.js new file mode 100644 index 000000000000..8591171a377b --- /dev/null +++ b/web_listview_range_select/static/src/js/web_listview_range_select.esm.js @@ -0,0 +1,101 @@ +/** @odoo-module */ + +import {ListRenderer} from "@web/views/list/list_renderer"; +import {patch} from "@web/core/utils/patch"; + +export const RangeListSelector = { + setup() { + this._super(...arguments); + this.range_history = []; + }, + _getRangeSelection() { + var self = this; + // Get start and end + var start = null, + end = null; + $(".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 && $(this).is(":checked")) { + if (start === null) { + start = i; + } else { + end = i; + } + } + }); + var new_range = this._getSelectionByRange(start, end); + + var current_selection = []; + current_selection = _.uniq(current_selection.concat(new_range)); + return current_selection; + }, + _getSelectionByRange(start, end) { + var result = []; + $(".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.push(record_id); + } else if (start !== null && end === null && start === i) { + result.push(record_id); + } + }); + return result; + }, + _pushRangeHistory(id) { + if (this.range_history !== undefined) { + if (this.range_history.length === 2) { + this.range_history = []; + } + } + this.range_history.push(id); + }, + _deselectTable() { + // This is needed because the checkboxes are not real checkboxes. + window.getSelection().removeAllRanges(); + }, + _onClickSelectRecord(record, ev) { + const el = $(ev.currentTarget); + if (el.find("input").prop("checked")) { + this._pushRangeHistory(el.closest("tr").data("id")); + } + if (ev.shiftKey) { + // Get selection + var selection = this._getRangeSelection(); + var $rows = $("td.o_list_record_selector input").closest("tr"); + $rows.each(function () { + var record_id = $(this).data("id"); + if (selection.indexOf(record_id) !== -1) { + $(this) + .find("td.o_list_record_selector input") + .prop("checked", true); + } + }); + // Update selection internally + this.checkBoxSelections(selection); + this._deselectTable(); + } + }, + checkBoxSelections(selection) { + const record = this.props.list.records; + for (const line in record) { + for (const id in selection) { + if (selection[selection.length - 1] === selection[id]) { + continue; + } + if (selection[id] === record[line].id) { + record[line].selected = true; + record[line].model.trigger("update"); + continue; + } + } + } + }, +}; +patch( + ListRenderer.prototype, + "web_listview_range_select.WebListviewRangeSelect", + RangeListSelector +); diff --git a/web_listview_range_select/static/src/js/web_listview_range_select.js b/web_listview_range_select/static/src/js/web_listview_range_select.js deleted file mode 100644 index edcea8bef7c4..000000000000 --- a/web_listview_range_select/static/src/js/web_listview_range_select.js +++ /dev/null @@ -1,106 +0,0 @@ -/* Copyright 2017 Onestein - * License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ - -odoo.define("web_listview_range_select", function (require) { - "use strict"; - - var ListRenderer = require("web.ListRenderer"); - - ListRenderer.include({ - events: _.extend({}, ListRenderer.prototype.events, { - "click tbody .o_list_record_selector": "_onClickSelectRecord", - }), - _range_history: [], - - _render: function () { - var res = this._super.apply(this, arguments); - this.$table = this.$el.find(".o_list_view"); - return res; - }, - - _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).is(":checked")) { - if (start === null) { - start = i; - } else { - end = i; - } - } - }); - var new_range = this._getSelectionByRange(start, end); - - var current_selection = this.selection; - current_selection = _.uniq(current_selection.concat(new_range)); - return current_selection; - }, - - _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.push(record_id); - } else if (start !== null && end === null && start === i) { - result.push(record_id); - } - }); - return result; - }, - - _pushRangeHistory: function (id) { - if (this._range_history.length === 2) { - this._range_history = []; - } - this._range_history.push(id); - }, - - _deselectTable: function () { - // This is needed because the checkboxes are not real checkboxes. - window.getSelection().removeAllRanges(); - }, - - _onClickSelectRecord: function (event) { - var el = $(event.currentTarget); - - // 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 = 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.indexOf(record_id) !== -1) { - $(this) - .find("td.o_list_record_selector input") - .prop("checked", true); - } - }); - // Update selection internally - this._updateSelection(); - this._deselectTable(); - } - }, - }); -}); diff --git a/web_listview_range_select/static/src/xml/web_listview_range_select.xml b/web_listview_range_select/static/src/xml/web_listview_range_select.xml new file mode 100644 index 000000000000..aca87421738a --- /dev/null +++ b/web_listview_range_select/static/src/xml/web_listview_range_select.xml @@ -0,0 +1,10 @@ + + + + + (ev) => this._onClickSelectRecord(record,ev) + + +