Skip to content

Commit c149113

Browse files
author
Christopher Rogos
committed
[MIG] web_listview_range_select: Migration to 16.0
1 parent 550792d commit c149113

8 files changed

+120
-111
lines changed

web_listview_range_select/README.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ List Range Selection
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:4591ffee6ecf15cafad3e0e9b709c4e1d1f08052ac3ad668fead7edbca90a8bf
10+
!! source digest: sha256:0cd77b1cd0e10283cbf40fbf8a67f9c5c5135d746e755cf13dddf44e0f034cdb
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -78,6 +78,7 @@ Contributors
7878
* `Tecnativa <https://www.tecnativa.com>`_:
7979

8080
* Ernesto Tejeda
81+
* Nilesh Sheliya <nilesh@synodica.com>
8182

8283
Maintainers
8384
~~~~~~~~~~~

web_listview_range_select/__manifest__.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"summary": """
77
Enables selecting a range of records using the shift key
88
""",
9-
"version": "15.0.1.0.0",
9+
"version": "16.0.1.0.0",
1010
"category": "Web",
1111
"author": "Onestein, Odoo Community Association (OCA)",
1212
"website": "https://github.com/OCA/web",
@@ -16,7 +16,8 @@
1616
"application": False,
1717
"assets": {
1818
"web.assets_backend": [
19-
"/web_listview_range_select/static/src/js/web_listview_range_select.js"
19+
"web_listview_range_select/static/src/js/web_listview_range_select.esm.js",
20+
"web_listview_range_select/static/src/xml/web_listview_range_select.xml",
2021
],
2122
},
2223
}

web_listview_range_select/i18n/web_listview_range_select.pot

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44
msgid ""
55
msgstr ""
6-
"Project-Id-Version: Odoo Server 15.0\n"
6+
"Project-Id-Version: Odoo Server 16.0\n"
77
"Report-Msgid-Bugs-To: \n"
88
"Last-Translator: \n"
99
"Language-Team: \n"

web_listview_range_select/readme/CONTRIBUTORS.rst

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
* `Tecnativa <https://www.tecnativa.com>`_:
44

55
* Ernesto Tejeda
6+
* Nilesh Sheliya <nilesh@synodica.com>

web_listview_range_select/static/description/index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ <h1 class="title">List Range Selection</h1>
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370-
!! source digest: sha256:4591ffee6ecf15cafad3e0e9b709c4e1d1f08052ac3ad668fead7edbca90a8bf
370+
!! source digest: sha256:0cd77b1cd0e10283cbf40fbf8a67f9c5c5135d746e755cf13dddf44e0f034cdb
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372372
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/web/tree/15.0/web_listview_range_select"><img alt="OCA/web" src="https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/web-15-0/web-15-0-web_listview_range_select"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/web&amp;target_branch=15.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>Enables selecting a range of records using the shift key.</p>
@@ -428,6 +428,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
428428
<li>Ernesto Tejeda</li>
429429
</ul>
430430
</li>
431+
<li>Nilesh Sheliya &lt;<a class="reference external" href="mailto:nilesh&#64;synodica.com">nilesh&#64;synodica.com</a>&gt;</li>
431432
</ul>
432433
</div>
433434
<div class="section" id="maintainers">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/** @odoo-module */
2+
3+
import {ListRenderer} from "@web/views/list/list_renderer";
4+
import {patch} from "@web/core/utils/patch";
5+
6+
export const RangeListSelector = {
7+
setup() {
8+
this._super(...arguments);
9+
this.range_history = [];
10+
},
11+
_getRangeSelection() {
12+
var self = this;
13+
// Get start and end
14+
var start = null,
15+
end = null;
16+
$(".o_list_record_selector input").each(function (i, el) {
17+
var id = $(el).closest("tr").data("id");
18+
var checked = self.range_history.indexOf(id) !== -1;
19+
if (checked && $(this).is(":checked")) {
20+
if (start === null) {
21+
start = i;
22+
} else {
23+
end = i;
24+
}
25+
}
26+
});
27+
var new_range = this._getSelectionByRange(start, end);
28+
29+
var current_selection = [];
30+
current_selection = _.uniq(current_selection.concat(new_range));
31+
return current_selection;
32+
},
33+
_getSelectionByRange(start, end) {
34+
var result = [];
35+
$(".o_list_record_selector input")
36+
.closest("tr")
37+
.each(function (i, el) {
38+
var record_id = $(el).data("id");
39+
if (start !== null && end !== null && i >= start && i <= end) {
40+
result.push(record_id);
41+
} else if (start !== null && end === null && start === i) {
42+
result.push(record_id);
43+
}
44+
});
45+
return result;
46+
},
47+
_pushRangeHistory(id) {
48+
if (this.range_history !== undefined) {
49+
if (this.range_history.length === 2) {
50+
this.range_history = [];
51+
}
52+
}
53+
this.range_history.push(id);
54+
},
55+
_deselectTable() {
56+
// This is needed because the checkboxes are not real checkboxes.
57+
window.getSelection().removeAllRanges();
58+
},
59+
_onClickSelectRecord(record, ev) {
60+
const el = $(ev.currentTarget);
61+
if (el.find("input").prop("checked")) {
62+
this._pushRangeHistory(el.closest("tr").data("id"));
63+
}
64+
if (ev.shiftKey) {
65+
// Get selection
66+
var selection = this._getRangeSelection();
67+
var $rows = $("td.o_list_record_selector input").closest("tr");
68+
$rows.each(function () {
69+
var record_id = $(this).data("id");
70+
if (selection.indexOf(record_id) !== -1) {
71+
$(this)
72+
.find("td.o_list_record_selector input")
73+
.prop("checked", true);
74+
}
75+
});
76+
// Update selection internally
77+
this.checkBoxSelections(selection);
78+
this._deselectTable();
79+
}
80+
},
81+
checkBoxSelections(selection) {
82+
const record = this.props.list.records;
83+
for (const line in record) {
84+
for (const id in selection) {
85+
if (selection[selection.length - 1] === selection[id]) {
86+
continue;
87+
}
88+
if (selection[id] === record[line].id) {
89+
record[line].selected = true;
90+
record[line].model.trigger("update");
91+
continue;
92+
}
93+
}
94+
}
95+
},
96+
};
97+
patch(
98+
ListRenderer.prototype,
99+
"web_listview_range_select.WebListviewRangeSelect",
100+
RangeListSelector
101+
);

web_listview_range_select/static/src/js/web_listview_range_select.js

-106
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<templates xml:space="preserve">
3+
<t t-inherit="web.ListRenderer.RecordRow" t-inherit-mode="extension">
4+
<xpath expr="//tr[@class='o_data_row']/td/CheckBox" position="attributes">
5+
<attribute
6+
name="t-on-click.capture"
7+
>(ev) => this._onClickSelectRecord(record,ev)</attribute>
8+
</xpath>
9+
</t>
10+
</templates>

0 commit comments

Comments
 (0)