You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.9 KiB

  1. /**********************************************************************************
  2. *
  3. * Copyright (C) 2017 MuK IT GmbH
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. **********************************************************************************/
  19. odoo.define('muk_web_theme.ListRenderer', function (require) {
  20. "use strict";
  21. var dom = require('web.dom');
  22. var core = require('web.core');
  23. var config = require("web.config");
  24. var ListRenderer = require('web.ListRenderer');
  25. var _t = core._t;
  26. var QWeb = core.qweb;
  27. ListRenderer.include({
  28. _range_history: [],
  29. _render: function() {
  30. var res = this._super.apply(this, arguments);
  31. this.$table = this.$el.find('.o_list_view');
  32. return res;
  33. },
  34. _getRangeSelection: function() {
  35. var self = this;
  36. var start = null, end = null;
  37. this.$el.find('td.o_list_record_selector input').each(function (i, el) {
  38. var id = $(el).closest('tr').data('id');
  39. var checked = self._range_history.indexOf(id) !== -1;
  40. if (checked && $(el).is(':checked')) {
  41. if (start == null) {
  42. start = i;
  43. } else {
  44. end = i;
  45. }
  46. }
  47. });
  48. var new_range = this._getSelectionByRange(start, end);
  49. var current_selection = this.selection;
  50. current_selection = _.uniq(current_selection.concat(new_range));
  51. return current_selection;
  52. },
  53. _getSelectionByRange: function(start, end) {
  54. var result = [];
  55. this.$el.find('td.o_list_record_selector input').closest('tr').each(function (i, el) {
  56. var record_id = $(el).data('id');
  57. if (start != null && end != null && i >= start && i <= end) {
  58. result.push(record_id);
  59. } else if(start != null && end == null && start == i) {
  60. result.push(record_id);
  61. }
  62. });
  63. return result;
  64. },
  65. _pushRangeHistory: function(id) {
  66. if (this._range_history.length === 2) {
  67. this._range_history = [];
  68. }
  69. this._range_history.push(id);
  70. },
  71. _deselectTable: function() {
  72. window.getSelection().removeAllRanges();
  73. },
  74. _onSelectRecord: function(event) {
  75. var res = this._super.apply(this, arguments);
  76. var element = $(event.currentTarget);
  77. if (/firefox/i.test(navigator.userAgent) && event.shiftKey) {
  78. element.find('input').prop('checked', !element.find('input').prop('checked'));
  79. }
  80. if (element.find('input').prop('checked')) {
  81. this._pushRangeHistory(element.closest('tr').data('id'));
  82. }
  83. if (event.shiftKey) {
  84. var selection = this._getRangeSelection();
  85. var $rows = this.$el.find('td.o_list_record_selector input').closest('tr');
  86. $rows.each(function () {
  87. var record_id = $(this).data('id');
  88. if (selection.indexOf(record_id) !== -1) {
  89. $(this).find('td.o_list_record_selector input').prop('checked', true);
  90. }
  91. });
  92. this._updateSelection();
  93. this._deselectTable();
  94. }
  95. return res;
  96. }
  97. });
  98. });