mirror of https://github.com/OCA/web.git
Merge pull request #910 from multidadosti-erp/11.0-mig-web_listview_range_select
11.0 mig web_listview_range_selectpull/915/head
commit
cb1f5b3116
|
@ -0,0 +1,59 @@
|
|||
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
|
||||
:target: https://www.gnu.org/licenses/agpl
|
||||
:alt: License: AGPL-3
|
||||
|
||||
====================
|
||||
List Range Selection
|
||||
====================
|
||||
|
||||
Enables selecting a range of records using the shift key.
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
No configuration is needed.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
To use this module, you need to:
|
||||
|
||||
#. click a record;
|
||||
#. hold shift and click another record;
|
||||
#. you can repeat this operation as many times as you want.
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/162/11.0
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/OCA/162/issues>`_. In case of trouble, please
|
||||
check there if your issue has already been reported. If you spotted it first,
|
||||
help us smashing it by providing a detailed and welcomed feedback.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Dennis Sluijk <d.sluijk@onestein.nl>
|
||||
* Aldo Soares <soares_aldo@hotmail.com>
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: https://odoo-community.org
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
To contribute to this module, please visit https://odoo-community.org.
|
|
@ -0,0 +1,2 @@
|
|||
# © 2017 Onestein (<http://www.onestein.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
@ -0,0 +1,22 @@
|
|||
# © 2017 Onestein (<http://www.onestein.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
'name': 'List Range Selection',
|
||||
'summary': """
|
||||
Enables selecting a range of records using the shift key
|
||||
""",
|
||||
'version': '11.0.1.0.0',
|
||||
'category': 'Web',
|
||||
'author': 'Onestein,Odoo Community Association (OCA)',
|
||||
'website': 'https://github.com/oca/web',
|
||||
'license': 'AGPL-3',
|
||||
'depends': [
|
||||
'web',
|
||||
],
|
||||
'data': [
|
||||
'templates/assets.xml'
|
||||
],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
}
|
|
@ -0,0 +1,90 @@
|
|||
/* 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({
|
||||
_range_history: [],
|
||||
|
||||
_get_range_selection: function() {
|
||||
var self = this;
|
||||
var result = {ids: [], records: []};
|
||||
|
||||
//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).prop('checked')) {
|
||||
if (start == null)
|
||||
start = i;
|
||||
else
|
||||
end = i;
|
||||
}
|
||||
});
|
||||
|
||||
//Preserve already checked
|
||||
this.$el.find('td.o_list_record_selector input:checked').closest('tr').each(function (i, el) {
|
||||
if (i == start || i == end) return;
|
||||
var record_id = $(el).data('id')
|
||||
result.ids.push(record_id);
|
||||
result.records.push(el.attributes);
|
||||
});
|
||||
|
||||
var new_range = this.get_range_selection(start, end);
|
||||
result.records = result.records.concat(new_range.records);
|
||||
result.ids = result.ids.concat(new_range.ids);
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
get_range_selection: function(start, end) {
|
||||
var result = {ids: [], records: []};
|
||||
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.ids.push(record_id);
|
||||
result.records.push(el.attributes);
|
||||
} else if(start != null && end == null && start == i) {
|
||||
result.ids.push(record_id);
|
||||
result.records.push(el.attributes);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
},
|
||||
|
||||
push_range_history: function(id) {
|
||||
this._range_history.push(id);
|
||||
if (this._range_history.length == 3)
|
||||
this._range_history.shift();
|
||||
},
|
||||
|
||||
_onSelectRecord: function(event) {
|
||||
var res = this._super(event);
|
||||
var self = this;
|
||||
var el = $(event.currentTarget);
|
||||
if (el.find('input').prop('checked'))
|
||||
self.push_range_history(el.closest('tr').data('id'));
|
||||
|
||||
if (event.shiftKey) {
|
||||
//Get selection
|
||||
var selection = self._get_range_selection();
|
||||
this.$el.find('td.o_list_record_selector input').closest('tr').each(function () {
|
||||
//Check input visual
|
||||
var record_id = $(this).data('id');
|
||||
if (selection.ids.indexOf(record_id) != -1)
|
||||
$(this).find('td.o_list_record_selector input').prop('checked', true);
|
||||
});
|
||||
//Check input internal
|
||||
$(self).trigger(
|
||||
'selected', [selection.ids, selection.records, true]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Copyright 2017 Onestein
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
|
||||
<odoo>
|
||||
<template id="assets_backend" inherit_id="web.assets_backend">
|
||||
<xpath expr=".">
|
||||
<script type="text/javascript"
|
||||
src="/web_listview_range_select/static/src/js/web_listview_range_select.js"/>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
Loading…
Reference in New Issue