Skip to content

Commit

Permalink
[MIG] web_listview_range_select: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Rogos committed Sep 12, 2023
1 parent 550792d commit c149113
Show file tree
Hide file tree
Showing 8 changed files with 120 additions and 111 deletions.
3 changes: 2 additions & 1 deletion web_listview_range_select/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,6 +78,7 @@ Contributors
* `Tecnativa <https://www.tecnativa.com>`_:

* Ernesto Tejeda
* Nilesh Sheliya <[email protected]>

Maintainers
~~~~~~~~~~~
Expand Down
5 changes: 3 additions & 2 deletions web_listview_range_select/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
],
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions web_listview_range_select/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
* `Tecnativa <https://www.tecnativa.com>`_:

* Ernesto Tejeda
* Nilesh Sheliya <[email protected]>
3 changes: 2 additions & 1 deletion web_listview_range_select/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">List Range Selection</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:4591ffee6ecf15cafad3e0e9b709c4e1d1f08052ac3ad668fead7edbca90a8bf
!! source digest: sha256:0cd77b1cd0e10283cbf40fbf8a67f9c5c5135d746e755cf13dddf44e0f034cdb
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<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>
<p>Enables selecting a range of records using the shift key.</p>
Expand Down Expand Up @@ -428,6 +428,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Ernesto Tejeda</li>
</ul>
</li>
<li>Nilesh Sheliya &lt;<a class="reference external" href="mailto:nilesh&#64;synodica.com">nilesh&#64;synodica.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
Original file line number Diff line number Diff line change
@@ -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
);
106 changes: 0 additions & 106 deletions web_listview_range_select/static/src/js/web_listview_range_select.js

This file was deleted.

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

0 comments on commit c149113

Please sign in to comment.