checked and refined remaining ported js utils

This commit is contained in:
Felix Hamann 2019-05-28 23:18:47 +02:00
parent fa9c67a918
commit c72335c13f
9 changed files with 33 additions and 35 deletions

View File

@ -41,7 +41,7 @@ export class AutoSubmitInput {
this._element.removeEventListener('input', this._debouncedHandler); this._element.removeEventListener('input', this._debouncedHandler);
} }
autoSubmit() { autoSubmit = () => {
this._form.submit(); this._form.submit();
} }
} }

View File

@ -23,7 +23,7 @@ export class FormErrorRemover {
// find form groups // find form groups
const formGroups = Array.from(element.querySelectorAll(FORM_GROUP_SELECTOR)); const formGroups = Array.from(element.querySelectorAll(FORM_GROUP_SELECTOR));
formGroups.forEach(function(formGroup) { formGroups.forEach((formGroup) => {
if (!formGroup.classList.contains(FORM_GROUP_WITH_ERRORS_CLASS)) { if (!formGroup.classList.contains(FORM_GROUP_WITH_ERRORS_CLASS)) {
return; return;
} }
@ -33,8 +33,8 @@ export class FormErrorRemover {
return false; return false;
} }
inputElements.forEach(function(inputElement) { inputElements.forEach((inputElement) => {
inputElement.addEventListener('input', function() { inputElement.addEventListener('input', () => {
formGroup.classList.remove(FORM_GROUP_WITH_ERRORS_CLASS); formGroup.classList.remove(FORM_GROUP_WITH_ERRORS_CLASS);
}); });
}); });

View File

@ -73,7 +73,7 @@ export class InteractiveFieldset {
this.target.classList.toggle('hidden', !active); this.target.classList.toggle('hidden', !active);
this.childInputs.forEach(function(el) { this.childInputs.forEach((el) => {
el.disabled = !active; el.disabled = !active;
// disable input for flatpickrs added input as well if exists // disable input for flatpickrs added input as well if exists

View File

@ -32,12 +32,12 @@ export class NavigateAwayPrompt {
window.addEventListener('beforeunload', this._beforeUnloadHandler); window.addEventListener('beforeunload', this._beforeUnloadHandler);
this._element.addEventListener('submit', function() { this._element.addEventListener('submit', () => {
this.unloadDueToSubmit = true; this._unloadDueToSubmit = true;
}); });
this._element.addEventListener('change', function() { this._element.addEventListener('change', () => {
this.touched = true; this._touched = true;
this.unloadDueToSubmit = false; this._unloadDueToSubmit = false;
}); });
// mark initialized // mark initialized
@ -49,7 +49,7 @@ export class NavigateAwayPrompt {
window.removeEventListener('beforeunload', this._beforeUnloadHandler); window.removeEventListener('beforeunload', this._beforeUnloadHandler);
} }
_beforeUnloadHandler(event) { _beforeUnloadHandler = (event) => {
// allow the event to happen if the form was not touched by the // allow the event to happen if the form was not touched by the
// user or the unload event was initiated by a form submit // user or the unload event was initiated by a form submit
if (!this._touched || this._unloadDueToSubmit) { if (!this._touched || this._unloadDueToSubmit) {
@ -58,6 +58,8 @@ export class NavigateAwayPrompt {
// cancel the unload event. This is the standard to force the prompt to appear. // cancel the unload event. This is the standard to force the prompt to appear.
event.preventDefault(); event.preventDefault();
// chrome
event.returnValue = true;
// for all non standard compliant browsers we return a truthy value to activate the prompt. // for all non standard compliant browsers we return a truthy value to activate the prompt.
return true; return true;
} }

View File

@ -55,10 +55,10 @@ export class ReactiveSubmitButton {
} }
setupInputs() { setupInputs() {
this._requiredInputs.forEach(function(el) { this._requiredInputs.forEach((el) => {
var checkbox = el.getAttribute('type') === 'checkbox'; var checkbox = el.getAttribute('type') === 'checkbox';
var eventType = checkbox ? 'change' : 'input'; var eventType = checkbox ? 'change' : 'input';
el.addEventListener(eventType, function() { el.addEventListener(eventType, () => {
this.updateButtonState(); this.updateButtonState();
}); });
}); });
@ -74,7 +74,7 @@ export class ReactiveSubmitButton {
inputsValid() { inputsValid() {
var done = true; var done = true;
this._requiredInputs.forEach(function(inp) { this._requiredInputs.forEach((inp) => {
var len = inp.value.trim().length; var len = inp.value.trim().length;
if (done && len === 0) { if (done && len === 0) {
done = false; done = false;

View File

@ -40,7 +40,7 @@ export class FileInput {
this._updateLabel(); this._updateLabel();
// add change listener // add change listener
this._element.addEventListener('change', function() { this._element.addEventListener('change', () => {
this.updateLabel(); this.updateLabel();
this.renderFileList(); this.renderFileList();
}); });
@ -61,7 +61,7 @@ export class FileInput {
const files = this._element.files; const files = this._element.files;
this._fileList.innerHTML = ''; this._fileList.innerHTML = '';
Array.from(files).forEach(function(file) { Array.from(files).forEach((file) => {
const fileDisplayEl = document.createElement('li'); const fileDisplayEl = document.createElement('li');
fileDisplayEl.innerHTML = file.name; fileDisplayEl.innerHTML = file.name;
this.fileList.appendChild(fileDisplayEl); this.fileList.appendChild(fileDisplayEl);

View File

@ -41,8 +41,8 @@ export class MassInput {
// setup submit buttons inside this massinput so browser // setup submit buttons inside this massinput so browser
// uses correct submit button for form submission. // uses correct submit button for form submission.
const buttons = this._getMassInputSubmitButtons(); const buttons = this._getMassInputSubmitButtons();
buttons.forEach(function(button) { buttons.forEach((button) => {
this.setupSubmitButton(button); this._setupSubmitButton(button);
}); });
this._massInputForm.addEventListener('submit', this._massInputFormSubmitHandler); this._massInputForm.addEventListener('submit', this._massInputFormSubmitHandler);
@ -66,7 +66,7 @@ export class MassInput {
requestFn = this._app.httpClient[method.toLowerCase()].bind(this._app.httpClient); requestFn = this._app.httpClient[method.toLowerCase()].bind(this._app.httpClient);
} }
return function(event) { return (event) => {
let activeElement; let activeElement;
// check if event occured from either a mass input add/delete button or // check if event occured from either a mass input add/delete button or
@ -96,10 +96,10 @@ export class MassInput {
} }
event.preventDefault(); event.preventDefault();
const requestBody = this.serializeForm(submitButton, enctype); const requestBody = this._serializeForm(submitButton, enctype);
if (requestFn && requestBody) { if (requestFn && requestBody) {
const headers = {'Mass-Input-Shortcircuit': this.massInputId}; const headers = {'Mass-Input-Shortcircuit': this._massInputId};
if (enctype !== 'multipart/form-data') { if (enctype !== 'multipart/form-data') {
headers['Content-Type'] = enctype; headers['Content-Type'] = enctype;
@ -109,19 +109,19 @@ export class MassInput {
url: url, url: url,
headers: headers, headers: headers,
body: requestBody, body: requestBody,
}).then(function(response) { }).then((response) => {
return this._app.htmlHelpers.parseResponse(response); return this._app.htmlHelpers.parseResponse(response);
}).then(function(response) { }).then((response) => {
this.processResponse(response.element); this._processResponse(response.element);
if (isAddCell) { if (isAddCell) {
this.reFocusAddCell(); this._reFocusAddCell();
} }
}); });
} }
}; };
} }
_keypressHandler(event) { _keypressHandler = (event) => {
if (event.keyCode !== 13) { if (event.keyCode !== 13) {
return false; return false;
} }
@ -190,8 +190,8 @@ export class MassInput {
this._massInputForm.removeEventListener('keypress', this._keypressHandler); this._massInputForm.removeEventListener('keypress', this._keypressHandler);
const buttons = this._getMassInputSubmitButtons(); const buttons = this._getMassInputSubmitButtons();
buttons.forEach(function(button) { buttons.forEach((button) => {
this.resetSubmitButton(button); this._resetSubmitButton(button);
}); });
} }
} }

View File

@ -59,10 +59,6 @@ export class ShowHide {
} }
destroy() { destroy() {
this._removeClickListener();
}
_removeClickListener() {
this._element.removeEventListener('click', this._clickHandler); this._element.removeEventListener('click', this._clickHandler);
} }
@ -73,8 +69,8 @@ export class ShowHide {
_clickHandler = () => { _clickHandler = () => {
const newState = this._element.parentElement.classList.toggle(SHOW_HIDE_COLLAPSED_CLASS); const newState = this._element.parentElement.classList.toggle(SHOW_HIDE_COLLAPSED_CLASS);
if (this.__showHideId) { if (this._showHideId) {
this._setLocalStorage(this.__showHideId, newState); this._setLocalStorage(this._showHideId, newState);
} }
} }

View File

@ -1,7 +1,7 @@
import { Utility } from '../../core/utility'; import { Utility } from '../../core/utility';
import './tooltips.scss'; import './tooltips.scss';
// empty shell to be able to load styles // empty "shell" to be able to load styles
@Utility({ @Utility({
selector: '[not-something-that-would-be-found]', selector: '[not-something-that-would-be-found]',
}) })