-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] web_listview_range_select: Migration to 16.0
- Loading branch information
Christopher Rogos
committed
Sep 12, 2023
1 parent
d897995
commit 76dab23
Showing
8 changed files
with
120 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <https://www.tecnativa.com>`_: | ||
|
||
* Ernesto Tejeda | ||
* Nilesh Sheliya <[email protected]> | ||
|
||
Maintainers | ||
~~~~~~~~~~~ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* Ernesto Tejeda | ||
* Nilesh Sheliya <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
web_listview_range_select/static/src/js/web_listview_range_select.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
106
web_listview_range_select/static/src/js/web_listview_range_select.js
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
web_listview_range_select/static/src/xml/web_listview_range_select.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |