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.

106 lines
3.9 KiB

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