mirror of https://github.com/OCA/web.git
[MIG] web_listview_range_select: Migration to 11.0
parent
864472ba38
commit
3484ed65de
|
@ -1,5 +1,5 @@
|
||||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
|
||||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
:target: https://www.gnu.org/licenses/agpl
|
||||||
:alt: License: AGPL-3
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
====================
|
====================
|
||||||
|
@ -24,7 +24,7 @@ To use this module, you need to:
|
||||||
|
|
||||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||||
:alt: Try me on Runbot
|
:alt: Try me on Runbot
|
||||||
:target: https://runbot.odoo-community.org/runbot/162/10.0
|
:target: https://runbot.odoo-community.org/runbot/162/11.0
|
||||||
|
|
||||||
Bug Tracker
|
Bug Tracker
|
||||||
===========
|
===========
|
||||||
|
@ -41,6 +41,7 @@ Contributors
|
||||||
------------
|
------------
|
||||||
|
|
||||||
* Dennis Sluijk <d.sluijk@onestein.nl>
|
* Dennis Sluijk <d.sluijk@onestein.nl>
|
||||||
|
* Aldo Soares <soares_aldo@hotmail.com>
|
||||||
|
|
||||||
Maintainer
|
Maintainer
|
||||||
----------
|
----------
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2017 Onestein (<http://www.onestein.eu>)
|
# © 2017 Onestein (<http://www.onestein.eu>)
|
||||||
# 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).
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# © 2017 Onestein (<http://www.onestein.eu>)
|
# © 2017 Onestein (<http://www.onestein.eu>)
|
||||||
# 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).
|
||||||
|
|
||||||
|
@ -7,10 +6,10 @@
|
||||||
'summary': """
|
'summary': """
|
||||||
Enables selecting a range of records using the shift key
|
Enables selecting a range of records using the shift key
|
||||||
""",
|
""",
|
||||||
'version': '10.0.1.0.0',
|
'version': '11.0.1.0.0',
|
||||||
'category': 'Web',
|
'category': 'Web',
|
||||||
'author': 'Onestein,Odoo Community Association (OCA)',
|
'author': 'Onestein,Odoo Community Association (OCA)',
|
||||||
'website': 'http://www.onestein.eu',
|
'website': 'https://github.com/oca/web',
|
||||||
'license': 'AGPL-3',
|
'license': 'AGPL-3',
|
||||||
'depends': [
|
'depends': [
|
||||||
'web',
|
'web',
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
# Translation of Odoo Server.
|
||||||
|
# This file contains the translation of the following modules:
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: Odoo Server 11.0\n"
|
||||||
|
"Report-Msgid-Bugs-To: \n"
|
||||||
|
"Last-Translator: <>\n"
|
||||||
|
"Language-Team: \n"
|
||||||
|
"MIME-Version: 1.0\n"
|
||||||
|
"Content-Type: text/plain; charset=UTF-8\n"
|
||||||
|
"Content-Transfer-Encoding: \n"
|
||||||
|
"Plural-Forms: \n"
|
||||||
|
|
|
@ -3,25 +3,21 @@
|
||||||
|
|
||||||
odoo.define('web_listview_range_select', function (require) {
|
odoo.define('web_listview_range_select', function (require) {
|
||||||
"use strict";
|
"use strict";
|
||||||
var core = require('web.core'),
|
|
||||||
_t = core._t,
|
|
||||||
listview = require('web.ListView');
|
|
||||||
|
|
||||||
listview.List.include({
|
var ListRenderer = require('web.ListRenderer');
|
||||||
|
|
||||||
|
ListRenderer.include({
|
||||||
_range_history: [],
|
_range_history: [],
|
||||||
|
|
||||||
_get_range_selection: function() {
|
_get_range_selection: function() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var result = {ids: [], records: []};
|
var result = {ids: [], records: []};
|
||||||
if (!this.options.selectable) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
var records = this.records;
|
|
||||||
|
|
||||||
//Get start and end
|
//Get start and end
|
||||||
var start = null,
|
var start = null,
|
||||||
end = null;
|
end = null;
|
||||||
|
|
||||||
this.$current.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).prop('checked')) {
|
if (checked && $(el).prop('checked')) {
|
||||||
|
@ -33,11 +29,11 @@ odoo.define('web_listview_range_select', function (require) {
|
||||||
});
|
});
|
||||||
|
|
||||||
//Preserve already checked
|
//Preserve already checked
|
||||||
this.$current.find('td.o_list_record_selector input:checked').closest('tr').each(function (i, el) {
|
this.$el.find('td.o_list_record_selector input:checked').closest('tr').each(function (i, el) {
|
||||||
if (i == start || i == end) return;
|
if (i == start || i == end) return;
|
||||||
var record = records.get($(el).data('id'));
|
var record_id = $(el).data('id')
|
||||||
result.ids.push(record.get('id'));
|
result.ids.push(record_id);
|
||||||
result.records.push(record.attributes);
|
result.records.push(el.attributes);
|
||||||
});
|
});
|
||||||
|
|
||||||
var new_range = this.get_range_selection(start, end);
|
var new_range = this.get_range_selection(start, end);
|
||||||
|
@ -46,48 +42,48 @@ odoo.define('web_listview_range_select', function (require) {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
get_range_selection: function(start, end) {
|
get_range_selection: function(start, end) {
|
||||||
var records = this.records;
|
|
||||||
var result = {ids: [], records: []};
|
var result = {ids: [], records: []};
|
||||||
this.$current.find('td.o_list_record_selector input').closest('tr').each(function (i, el) {
|
this.$el.find('td.o_list_record_selector input').closest('tr').each(function (i, el) {
|
||||||
var record = records.get($(el).data('id'));
|
var record_id = $(el).data('id');
|
||||||
if (start != null && end != null && i >= start && i <= end) {
|
if (start != null && end != null && i >= start && i <= end) {
|
||||||
result.ids.push(record.get('id'));
|
result.ids.push(record_id);
|
||||||
result.records.push(record.attributes);
|
result.records.push(el.attributes);
|
||||||
} else if(start != null && end == null && start == i) {
|
} else if(start != null && end == null && start == i) {
|
||||||
result.ids.push(record.get('id'));
|
result.ids.push(record_id);
|
||||||
result.records.push(record.attributes);
|
result.records.push(el.attributes);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
push_range_history: function(id) {
|
push_range_history: function(id) {
|
||||||
this._range_history.push(id);
|
this._range_history.push(id);
|
||||||
if (this._range_history.length == 3)
|
if (this._range_history.length == 3)
|
||||||
this._range_history.shift();
|
this._range_history.shift();
|
||||||
},
|
},
|
||||||
init: function() {
|
|
||||||
var self = this;
|
|
||||||
var res = this._super.apply(this, arguments);
|
|
||||||
this.$current.delegate('td.o_list_record_selector', 'click', function (e) {
|
|
||||||
//Update history
|
|
||||||
if ($(this).find('input').prop('checked'))
|
|
||||||
self.push_range_history($(this).closest('tr').data('id'));
|
|
||||||
|
|
||||||
if (e.shiftKey) {
|
_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
|
//Get selection
|
||||||
var selection = self._get_range_selection();
|
var selection = self._get_range_selection();
|
||||||
self.$current.find('td.o_list_record_selector input').closest('tr').each(function () {
|
this.$el.find('td.o_list_record_selector input').closest('tr').each(function () {
|
||||||
//Check input visual
|
//Check input visual
|
||||||
var record = self.records.get($(this).data('id'));
|
var record_id = $(this).data('id');
|
||||||
if (selection.ids.indexOf(record.get('id')) != -1)
|
if (selection.ids.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);
|
||||||
});
|
});
|
||||||
//Check input internal
|
//Check input internal
|
||||||
$(self).trigger(
|
$(self).trigger(
|
||||||
'selected', [selection.ids, selection.records, true]);
|
'selected', [selection.ids, selection.records, true]);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue