Skip to content

Commit 21d6abf

Browse files
Convert loadmore.js to class structure
1 parent 629f9c4 commit 21d6abf

1 file changed

Lines changed: 58 additions & 67 deletions

File tree

public/js/loadmore.js

Lines changed: 58 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,75 @@
11
/* Icinga DB Web | (c) 2020 Icinga GmbH | GPLv2 */
22

3-
;(function(Icinga, $) {
3+
(function(Icinga, $) {
44

55
'use strict';
66

7-
Icinga.Behaviors = Icinga.Behaviors || {};
7+
class LoadMore extends Icinga.EventListener {
8+
constructor(icinga) {
9+
super(icinga);
810

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+
}
2414

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();
2919

30-
event.stopPropagation();
31-
event.preventDefault();
20+
event.stopPropagation();
21+
event.preventDefault();
3222

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();
3525

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) !== '.') {
4228
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+
}
4738
}
48-
}
4939

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+
}
8071
}
81-
};
72+
}
8273

8374
Icinga.Behaviors.LoadMore = LoadMore;
8475

0 commit comments

Comments
 (0)