tarteo
8 years ago
committed by
Pedro M. Baeza
6 changed files with 218 additions and 0 deletions
-
58web_listview_range_select/README.rst
-
3web_listview_range_select/__init__.py
-
23web_listview_range_select/__manifest__.py
-
61web_listview_range_select/static/src/js/web_listview_multi_select.js
-
61web_listview_range_select/static/src/js/web_listview_range_select.js
-
12web_listview_range_select/templates/assets.xml
@ -0,0 +1,58 @@ |
|||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
||||
|
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html |
||||
|
: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/10.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> |
||||
|
|
||||
|
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,3 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2017 Onestein (<http://www.onestein.eu>) |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
@ -0,0 +1,23 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 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': '10.0.1.0.0', |
||||
|
'category': 'Web', |
||||
|
'author': 'Onestein,Odoo Community Association (OCA)', |
||||
|
'website': 'http://www.onestein.eu', |
||||
|
'license': 'AGPL-3', |
||||
|
'depends': [ |
||||
|
'web', |
||||
|
], |
||||
|
'data': [ |
||||
|
'templates/assets.xml' |
||||
|
], |
||||
|
'installable': True, |
||||
|
'application': False, |
||||
|
} |
@ -0,0 +1,61 @@ |
|||||
|
/* Copyright 2017 Onestein |
||||
|
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
|
||||
|
|
||||
|
odoo.define('web_listview_multi_select', function (require) { |
||||
|
"use strict"; |
||||
|
var core = require('web.core'), |
||||
|
_t = core._t, |
||||
|
listview = require('web.ListView'); |
||||
|
|
||||
|
listview.List.include({ |
||||
|
get_range_selection: function() { |
||||
|
var result = {ids: [], records: []}; |
||||
|
if (!this.options.selectable) { |
||||
|
return result; |
||||
|
} |
||||
|
var records = this.records; |
||||
|
var start = null, |
||||
|
end = null; |
||||
|
|
||||
|
//Get start and end;
|
||||
|
this.$current.find('td.o_list_record_selector input').each(function (i, el) { |
||||
|
var checked = $(el).prop('checked'); |
||||
|
if (checked) { |
||||
|
if (start == null) |
||||
|
start = i; |
||||
|
else |
||||
|
end = i; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
this.$current.find('td.o_list_record_selector input').closest('tr').each(function (i, el) { |
||||
|
var record = records.get($(el).data('id')); |
||||
|
if (start != null && end != null && i >= start && i <= end) { |
||||
|
result.ids.push(record.get('id')); |
||||
|
result.records.push(record.attributes); |
||||
|
} else if(start != null && end == null && start == i) { |
||||
|
result.ids.push(record.get('id')); |
||||
|
result.records.push(record.attributes); |
||||
|
} |
||||
|
}); |
||||
|
return result; |
||||
|
}, |
||||
|
init: function() { |
||||
|
var self = this; |
||||
|
var res = this._super.apply(this, arguments); |
||||
|
this.$current.delegate('td.o_list_record_selector', 'click', function (e) { |
||||
|
if (e.shiftKey) { |
||||
|
var selection = self.get_range_selection(); |
||||
|
self.$current.find('td.o_list_record_selector input').closest('tr').each(function () { |
||||
|
var record = self.records.get($(this).data('id')); |
||||
|
if (selection.ids.indexOf(record.get('id')) != -1) |
||||
|
$(this).find('td.o_list_record_selector input').prop('checked', true); |
||||
|
}); |
||||
|
$(self).trigger( |
||||
|
'selected', [selection.ids, selection.records, true]); |
||||
|
} |
||||
|
}); |
||||
|
return res; |
||||
|
} |
||||
|
}); |
||||
|
}); |
@ -0,0 +1,61 @@ |
|||||
|
/* 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 core = require('web.core'), |
||||
|
_t = core._t, |
||||
|
listview = require('web.ListView'); |
||||
|
|
||||
|
listview.List.include({ |
||||
|
get_range_selection: function() { |
||||
|
var result = {ids: [], records: []}; |
||||
|
if (!this.options.selectable) { |
||||
|
return result; |
||||
|
} |
||||
|
var records = this.records; |
||||
|
var start = null, |
||||
|
end = null; |
||||
|
|
||||
|
//Get start and end;
|
||||
|
this.$current.find('td.o_list_record_selector input').each(function (i, el) { |
||||
|
var checked = $(el).prop('checked'); |
||||
|
if (checked) { |
||||
|
if (start == null) |
||||
|
start = i; |
||||
|
else |
||||
|
end = i; |
||||
|
} |
||||
|
}); |
||||
|
|
||||
|
this.$current.find('td.o_list_record_selector input').closest('tr').each(function (i, el) { |
||||
|
var record = records.get($(el).data('id')); |
||||
|
if (start != null && end != null && i >= start && i <= end) { |
||||
|
result.ids.push(record.get('id')); |
||||
|
result.records.push(record.attributes); |
||||
|
} else if(start != null && end == null && start == i) { |
||||
|
result.ids.push(record.get('id')); |
||||
|
result.records.push(record.attributes); |
||||
|
} |
||||
|
}); |
||||
|
return result; |
||||
|
}, |
||||
|
init: function() { |
||||
|
var self = this; |
||||
|
var res = this._super.apply(this, arguments); |
||||
|
this.$current.delegate('td.o_list_record_selector', 'click', function (e) { |
||||
|
if (e.shiftKey) { |
||||
|
var selection = self.get_range_selection(); |
||||
|
self.$current.find('td.o_list_record_selector input').closest('tr').each(function () { |
||||
|
var record = self.records.get($(this).data('id')); |
||||
|
if (selection.ids.indexOf(record.get('id')) != -1) |
||||
|
$(this).find('td.o_list_record_selector input').prop('checked', true); |
||||
|
}); |
||||
|
$(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> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue