|
42 | 42 | } |
43 | 43 |
|
44 | 44 | onClick(event) { |
45 | | - var _this = event.data.self; |
46 | | - var $activeItems; |
47 | | - var $target = $(event.currentTarget); |
48 | | - var $item = $target.closest('[data-action-item]'); |
49 | | - var $list = $item.closest('.action-list'); |
| 45 | + let _this = event.data.self; |
| 46 | + let activeItems; |
| 47 | + let target = event.currentTarget; |
| 48 | + let item = target.closest('[data-action-item]'); |
| 49 | + let list = target.closest('.action-list'); |
50 | 50 |
|
51 | | - if ($target.is('a') && !$target.is('.subject')) { |
| 51 | + if (target.matches('a') && ! target.matches('.subject')) { |
52 | 52 | return true; |
53 | 53 | } |
54 | 54 |
|
55 | 55 | event.preventDefault(); |
56 | 56 | event.stopImmediatePropagation(); |
57 | 57 | event.stopPropagation(); |
58 | 58 |
|
59 | | - if ($list.is('[data-icinga-multiselect-url]')) { |
| 59 | + if (list.matches('[data-icinga-multiselect-url]')) { |
60 | 60 | if (event.ctrlKey || event.metaKey) { |
61 | | - $item.toggleClass('active'); |
| 61 | + item.classList.toggle('active'); |
62 | 62 | } else if (event.shiftKey) { |
63 | 63 | document.getSelection().removeAllRanges(); |
| 64 | + let allItems = Array.from(list.children); |
| 65 | + activeItems = list.querySelectorAll('[data-action-item].active'); |
64 | 66 |
|
65 | | - $activeItems = $list.find('[data-action-item].active'); |
66 | | - |
67 | | - var $firstActiveItem = $activeItems.first(); |
68 | | - |
69 | | - $activeItems.removeClass('active'); |
| 67 | + _this.clearSelection(activeItems); |
70 | 68 |
|
71 | | - $firstActiveItem.addClass('active'); |
72 | | - $item.addClass('active'); |
| 69 | + let startIndex = allItems.indexOf(item); |
| 70 | + let endIndex = allItems.indexOf(activeItems[0]); |
73 | 71 |
|
74 | | - if ($item.index() > $firstActiveItem.index()) { |
75 | | - $item.prevUntil($firstActiveItem).addClass('active'); |
| 72 | + if (startIndex > endIndex) { |
| 73 | + for (let i = startIndex; i >= endIndex; i--) { |
| 74 | + _this.setActive(allItems[i]); |
| 75 | + } |
76 | 76 | } else { |
77 | | - var $lastActiveItem = $activeItems.last(); |
78 | | - |
79 | | - $lastActiveItem.addClass('active'); |
80 | | - $item.nextUntil($lastActiveItem).addClass('active'); |
| 77 | + endIndex = allItems.indexOf(activeItems[activeItems.length - 1]); |
| 78 | + for (let i = startIndex; i <= endIndex; i++) { |
| 79 | + _this.setActive(allItems[i]); |
| 80 | + } |
81 | 81 | } |
82 | 82 | } else { |
83 | | - $list.find('[data-action-item].active').removeClass('active'); |
84 | | - $item.addClass('active'); |
| 83 | + _this.clearSelection(list.querySelectorAll('[data-action-item].active')); |
| 84 | + _this.setActive(item); |
85 | 85 | } |
86 | 86 | } else { |
87 | | - $list.find('[data-action-item].active').removeClass('active'); |
88 | | - $item.addClass('active'); |
| 87 | + _this.clearSelection(list.querySelectorAll('[data-action-item].active')); |
| 88 | + _this.setActive(item); |
89 | 89 | } |
90 | 90 |
|
91 | | - $activeItems = $list.find('[data-action-item].active'); |
92 | | - if ($item.hasClass('active')) { |
93 | | - _this.setLastActivatedItemUrl($item.data('icingaDetailFilter')); |
| 91 | + activeItems = list.querySelectorAll('[data-action-item].active'); |
| 92 | + if (item.classList.contains('active')) { |
| 93 | + _this.setLastActivatedItemUrl(item.dataset.icingaDetailFilter); |
94 | 94 | } else { |
95 | 95 | _this.setLastActivatedItemUrl( |
96 | | - $activeItems.length |
97 | | - ? $activeItems.last().data('icingaDetailFilter') |
| 96 | + activeItems.length |
| 97 | + ? activeItems[activeItems.length - 1].dataset.icingaDetailFilter |
98 | 98 | : null |
99 | 99 | ); |
100 | 100 | } |
101 | 101 |
|
102 | | - _this.addSelectionCountToFooter($list[0]); |
| 102 | + _this.addSelectionCountToFooter(list); |
103 | 103 |
|
104 | | - if ($activeItems.length === 0) { |
105 | | - if (_this.icinga.loader.getLinkTargetFor($target).attr('id') === 'col2') { |
| 104 | + if (activeItems.length === 0) { |
| 105 | + if (_this.icinga.loader.getLinkTargetFor($(target)).attr('id') === 'col2') { |
106 | 106 | _this.icinga.ui.layout1col(); |
107 | 107 | } |
108 | 108 | } else { |
109 | | - _this.loadDetailUrl( |
110 | | - $list[0], |
111 | | - $target.is('a') ? $target.attr('href') : null |
112 | | - ); |
| 109 | + _this.loadDetailUrl(list, target.matches('a') ? target.href : null); |
113 | 110 | } |
114 | 111 | } |
115 | 112 |
|
|
468 | 465 | event.stopPropagation(); |
469 | 466 | event.preventDefault(); |
470 | 467 |
|
471 | | - event.data.self.loadMore($(event.target)); |
| 468 | + event.data.self.loadMore(event.target); |
472 | 469 |
|
473 | 470 | return false; |
474 | 471 | } |
|
482 | 479 | /** |
483 | 480 | * Load more list items based on the given anchor |
484 | 481 | * |
485 | | - * @param $anchor |
| 482 | + * @param anchor |
486 | 483 | * |
487 | 484 | * @returns {*|{getAllResponseHeaders: function(): *|null, abort: function(*): this, setRequestHeader: function(*, *): this, readyState: number, getResponseHeader: function(*): null|*, overrideMimeType: function(*): this, statusCode: function(*): this}|jQuery|boolean} |
488 | 485 | */ |
489 | | - loadMore($anchor) { |
490 | | - var $showMore = $anchor.parent(); |
| 486 | + loadMore(anchor) { |
| 487 | + let showMore = anchor.parentElement; |
491 | 488 | var progressTimer = this.icinga.timer.register(function () { |
492 | | - var label = $anchor.html(); |
| 489 | + var label = anchor.innerText; |
493 | 490 |
|
494 | 491 | var dots = label.substr(-3); |
495 | 492 | if (dots.slice(0, 1) !== '.') { |
|
505 | 502 | } |
506 | 503 | } |
507 | 504 |
|
508 | | - $anchor.html(label + dots); |
| 505 | + anchor.innerText = label + dots; |
509 | 506 | }, null, 250); |
510 | 507 |
|
511 | | - var url = $anchor.attr('href'); |
512 | | - var req = this.icinga.loader.loadUrl( |
| 508 | + let url = anchor.href; |
| 509 | + let req = this.icinga.loader.loadUrl( |
513 | 510 | // Add showCompact, we don't want controls in paged results |
514 | 511 | this.icinga.utils.addUrlFlag(url, 'showCompact'), |
515 | | - $showMore.parent(), |
| 512 | + $(showMore.parentElement), |
516 | 513 | undefined, |
517 | 514 | undefined, |
518 | 515 | 'append', |
|
521 | 518 | ); |
522 | 519 | req.addToHistory = false; |
523 | 520 | req.done(function () { |
524 | | - $showMore.remove(); |
| 521 | + showMore.remove(); |
525 | 522 |
|
526 | 523 | // Set data-icinga-url to make it available for Icinga.History.getCurrentState() |
527 | 524 | req.$target.closest('.container').data('icingaUrl', url); |
|
0 commit comments