[IMP] web_listview_range_select: black, isort, prettier

pull/1741/head
Ernesto Tejeda 2020-11-17 15:55:41 -05:00
parent 72aaf5909f
commit d6a5c32924
5 changed files with 56 additions and 43 deletions

View File

@ -0,0 +1 @@
../../../../web_listview_range_select

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

View File

@ -2,21 +2,17 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{ {
'name': 'List Range Selection', "name": "List Range Selection",
'summary': """ "summary": """
Enables selecting a range of records using the shift key Enables selecting a range of records using the shift key
""", """,
'version': '12.0.1.0.0', "version": "12.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': [ "depends": ["web",],
'web', "data": ["templates/assets.xml"],
], "installable": True,
'data': [ "application": False,
'templates/assets.xml'
],
'installable': True,
'application': False,
} }

View File

@ -1,17 +1,17 @@
/* 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");
ListRenderer.include({ ListRenderer.include({
_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;
}, },
@ -22,10 +22,12 @@ odoo.define('web_listview_range_select', function (require) {
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).closest('tr').data('id'); var id = $(el)
.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) {
start = i; start = i;
} else { } else {
@ -42,14 +44,17 @@ odoo.define('web_listview_range_select', function (require) {
_getSelectionByRange: function(start, end) { _getSelectionByRange: function(start, end) {
var result = []; var result = [];
this.$el.find('td.o_list_record_selector input').closest('tr').each(function (i, el) { this.$el
var record_id = $(el).data('id'); .find("td.o_list_record_selector input")
if (start != null && end != null && i >= start && i <= end) { .closest("tr")
result.push(record_id); .each(function(i, el) {
} else if(start != null && end == null && start == i) { var record_id = $(el).data("id");
result.push(record_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; return result;
}, },
@ -71,22 +76,26 @@ odoo.define('web_listview_range_select', function (require) {
// Firefox shift click fix // Firefox shift click fix
if (/firefox/i.test(navigator.userAgent) && event.shiftKey) { if (/firefox/i.test(navigator.userAgent) && event.shiftKey) {
el.find('input').prop('checked', !el.find('input').prop('checked')); el.find("input").prop("checked", !el.find("input").prop("checked"));
} }
if (el.find('input').prop('checked')) { if (el.find("input").prop("checked")) {
this._pushRangeHistory(el.closest('tr').data('id')); this._pushRangeHistory(el.closest("tr").data("id"));
} }
if (event.shiftKey) { if (event.shiftKey) {
// Get selection // Get selection
var selection = this._getRangeSelection(); var selection = this._getRangeSelection();
var $rows = this.$el.find('td.o_list_record_selector input').closest('tr'); var $rows = this.$el
$rows.each(function () { .find("td.o_list_record_selector input")
.closest("tr");
$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) {
$(this).find('td.o_list_record_selector input').prop('checked', true); $(this)
.find("td.o_list_record_selector input")
.prop("checked", true);
} }
}); });
// Update selection internally // Update selection internally
@ -94,6 +103,6 @@ odoo.define('web_listview_range_select', function (require) {
this._deselectTable(); this._deselectTable();
} }
return res; return res;
} },
}); });
}); });

View File

@ -1,12 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" ?>
<!-- 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> <odoo>
<template id="assets_backend" inherit_id="web.assets_backend"> <template id="assets_backend" inherit_id="web.assets_backend">
<xpath expr="."> <xpath expr=".">
<script type="text/javascript" <script
src="/web_listview_range_select/static/src/js/web_listview_range_select.js"/> type="text/javascript"
src="/web_listview_range_select/static/src/js/web_listview_range_select.js"
/>
</xpath> </xpath>
</template> </template>
</odoo> </odoo>