|
1 | 1 | /* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */ |
2 | 2 |
|
3 | | -;(function(Icinga, $) { |
| 3 | +(function(Icinga, $) { |
4 | 4 |
|
5 | 5 | 'use strict'; |
6 | 6 |
|
7 | | - Icinga.Behaviors = Icinga.Behaviors || {}; |
| 7 | + class LoadMore extends Icinga.EventListener { |
| 8 | + constructor(icinga) { |
| 9 | + super(icinga); |
8 | 10 |
|
9 | | - /** |
10 | | - * Icinga DB Load More behavior. |
11 | | - * |
12 | | - * @param icinga {Icinga} The current Icinga Object |
13 | | - */ |
14 | | - var LoadMore = function(icinga) { |
15 | | - Icinga.EventListener.call(this, icinga); |
16 | | - |
17 | | - this.icinga = icinga; |
18 | | - |
19 | | - this.on('click', '.show-more[data-no-icinga-ajax] a', this.onClick, this); |
20 | | - this.on('keypress', '.show-more[data-no-icinga-ajax] a', this.onKeyPress, this); |
21 | | - }; |
22 | | - |
23 | | - LoadMore.prototype = new Icinga.EventListener(); |
| 11 | + this.on('click', '.show-more[data-no-icinga-ajax] a', this.onClick, this); |
| 12 | + this.on('keypress', '.show-more[data-no-icinga-ajax] a', this.onKeyPress, this); |
| 13 | + } |
24 | 14 |
|
25 | | - LoadMore.prototype.onClick = function(event) { |
26 | | - var _this = event.data.self; |
27 | | - var $anchor = $(event.target); |
28 | | - var $showMore = $anchor.parent(); |
| 15 | + onClick(event) { |
| 16 | + var _this = event.data.self; |
| 17 | + var $anchor = $(event.target); |
| 18 | + var $showMore = $anchor.parent(); |
29 | 19 |
|
30 | | - event.stopPropagation(); |
31 | | - event.preventDefault(); |
| 20 | + event.stopPropagation(); |
| 21 | + event.preventDefault(); |
32 | 22 |
|
33 | | - var progressTimer = _this.icinga.timer.register(function () { |
34 | | - var label = $anchor.html(); |
| 23 | + var progressTimer = _this.icinga.timer.register(function () { |
| 24 | + var label = $anchor.html(); |
35 | 25 |
|
36 | | - var dots = label.substr(-3); |
37 | | - if (dots.slice(0, 1) !== '.') { |
38 | | - dots = '. '; |
39 | | - } else { |
40 | | - label = label.slice(0, -3); |
41 | | - if (dots === '...') { |
| 26 | + var dots = label.substr(-3); |
| 27 | + if (dots.slice(0, 1) !== '.') { |
42 | 28 | dots = '. '; |
43 | | - } else if (dots === '.. ') { |
44 | | - dots = '...'; |
45 | | - } else if (dots === '. ') { |
46 | | - dots = '.. '; |
| 29 | + } else { |
| 30 | + label = label.slice(0, -3); |
| 31 | + if (dots === '...') { |
| 32 | + dots = '. '; |
| 33 | + } else if (dots === '.. ') { |
| 34 | + dots = '...'; |
| 35 | + } else if (dots === '. ') { |
| 36 | + dots = '.. '; |
| 37 | + } |
47 | 38 | } |
48 | | - } |
49 | 39 |
|
50 | | - $anchor.html(label + dots); |
51 | | - }, null, 250); |
52 | | - |
53 | | - var url = $anchor.attr('href'); |
54 | | - var req = _this.icinga.loader.loadUrl( |
55 | | - // Add showCompact, we don't want controls in paged results |
56 | | - _this.icinga.utils.addUrlFlag(url, 'showCompact'), |
57 | | - $showMore.parent(), |
58 | | - undefined, |
59 | | - undefined, |
60 | | - 'append', |
61 | | - false, |
62 | | - progressTimer |
63 | | - ); |
64 | | - req.addToHistory = false; |
65 | | - req.done(function () { |
66 | | - $showMore.remove(); |
67 | | - |
68 | | - // Set data-icinga-url to make it available for Icinga.History.getCurrentState() |
69 | | - req.$target.closest('.container').data('icingaUrl', url); |
70 | | - |
71 | | - _this.icinga.history.replaceCurrentState(); |
72 | | - }); |
73 | | - |
74 | | - return false; |
75 | | - }; |
76 | | - |
77 | | - LoadMore.prototype.onKeyPress = function(event) { |
78 | | - if (event.which === 32) { |
79 | | - event.data.self.onClick(event); |
| 40 | + $anchor.html(label + dots); |
| 41 | + }, null, 250); |
| 42 | + |
| 43 | + var url = $anchor.attr('href'); |
| 44 | + var req = _this.icinga.loader.loadUrl( |
| 45 | + // Add showCompact, we don't want controls in paged results |
| 46 | + _this.icinga.utils.addUrlFlag(url, 'showCompact'), |
| 47 | + $showMore.parent(), |
| 48 | + undefined, |
| 49 | + undefined, |
| 50 | + 'append', |
| 51 | + false, |
| 52 | + progressTimer |
| 53 | + ); |
| 54 | + req.addToHistory = false; |
| 55 | + req.done(function () { |
| 56 | + $showMore.remove(); |
| 57 | + |
| 58 | + // Set data-icinga-url to make it available for Icinga.History.getCurrentState() |
| 59 | + req.$target.closest('.container').data('icingaUrl', url); |
| 60 | + |
| 61 | + _this.icinga.history.replaceCurrentState(); |
| 62 | + }); |
| 63 | + |
| 64 | + return false; |
| 65 | + } |
| 66 | + |
| 67 | + onKeyPress(event) { |
| 68 | + if (event.which === 32) { |
| 69 | + event.data.self.onClick(event); |
| 70 | + } |
80 | 71 | } |
81 | | - }; |
| 72 | + } |
82 | 73 |
|
83 | 74 | Icinga.Behaviors.LoadMore = LoadMore; |
84 | 75 |
|
|
0 commit comments