Skip to content

Commit 327b545

Browse files
committed
modal.js: Use arrow functions to avoid _this
1 parent 6e73566 commit 327b545

1 file changed

Lines changed: 19 additions & 23 deletions

File tree

public/js/icinga/behavior/modal.js

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,16 @@
8282
const req = this.icinga.loader.loadUrl(url, $(modal.querySelector('#modal-content')));
8383
req.addToHistory = false;
8484

85-
const _this = this;
86-
req.done(function () {
87-
_this.setTitle(req.$target.data('icingaTitle').replace(/\s::\s.*/, ''));
88-
_this.show();
89-
_this.focus();
85+
req.done(() => {
86+
this.setTitle(req.$target.data('icingaTitle').replace(/\s::\s.*/, ''));
87+
this.show();
88+
this.focus();
9089
});
91-
req.fail(function (req, _, errorThrown) {
90+
req.fail((req, _, errorThrown) => {
9291
if (req.status >= 500) {
9392
// Yes, that's done twice (by us and by the base fail handler),
9493
// but `renderContentToContainer` does too many useful things..
95-
_this.icinga.loader.renderContentToContainer(req.responseText, $(redirectTarget), req.action);
94+
this.icinga.loader.renderContentToContainer(req.responseText, $(redirectTarget), req.action);
9695
} else if (req.status > 0) {
9796
const msg = "".concat(...iterator.map(
9897
not$.render("<div>" + req.responseText + "</div>").querySelectorAll('.error-message'),
@@ -102,10 +101,10 @@
102101
errorThrown += ': ' + msg;
103102
}
104103

105-
_this.icinga.loader.createNotice('error', errorThrown);
104+
this.icinga.loader.createNotice('error', errorThrown);
106105
}
107106

108-
_this.hide();
107+
this.hide();
109108
});
110109

111110
return false;
@@ -148,18 +147,17 @@
148147
const req = this.icinga.loader.submitForm($(form), $autoSubmittedBy, $button);
149148
req.addToHistory = false;
150149

151-
const _this = this;
152-
req.done(function (data, textStatus, req) {
150+
req.done((data, textStatus, req) => {
153151
const title = req.getResponseHeader('X-Icinga-Title');
154152
if (!! title) {
155-
_this.setTitle(decodeURIComponent(title).replace(/\s::\s.*/, ''));
153+
this.setTitle(decodeURIComponent(title).replace(/\s::\s.*/, ''));
156154
}
157155

158156
if (req.getResponseHeader('X-Icinga-Redirect')) {
159-
_this.hide();
157+
this.hide();
160158
}
161-
}).always(function () {
162-
delete _this.modal?.dataset.noIcingaAjax;
159+
}).always(() => {
160+
delete this.modal?.dataset.noIcingaAjax;
163161
});
164162

165163
if (! ('baseTarget' in form.dataset)) {
@@ -319,10 +317,9 @@
319317
this.modal.classList.add("wobble");
320318
}
321319

322-
const _this = this;
323-
this._wobbleTimeout = setTimeout(function () {
324-
_this.modal?.classList.remove("wobble");
325-
_this._wobbleTimeout = null;
320+
this._wobbleTimeout = setTimeout(() => {
321+
this.modal?.classList.remove("wobble");
322+
this._wobbleTimeout = null;
326323
}, 1000 - timingOffset);
327324
}
328325

@@ -342,11 +339,10 @@
342339
this.modal.classList.remove("active");
343340

344341
// Using `setTimeout` here to let the transition finish
345-
const _this = this;
346-
setTimeout(function () {
347-
not$(_this.modal.querySelector('#modal-content'))
342+
setTimeout(() => {
343+
not$(this.modal.querySelector('#modal-content'))
348344
.trigger('close-modal')
349-
.then(() => _this.modal = null);
345+
.then(() => this.modal = null);
350346
}, 200);
351347
}
352348
}

0 commit comments

Comments
 (0)