export {ImageManager} from './image-manager';
export {ImagePicker} from './image-picker';
export {ListSortControl} from './list-sort-control';
+export {LoadingButton} from './loading-button';
export {MarkdownEditor} from './markdown-editor';
export {NewUserPassword} from './new-user-password';
export {Notification} from './notification';
--- /dev/null
+import {Component} from "./component.js";
+import {showLoading} from "../services/dom";
+import {el} from "../wysiwyg/utils/dom";
+
+/**
+ * Loading button.
+ * Shows a loading indicator and disables the button when the button is clicked,
+ * or when the form attached to the button is submitted.
+ */
+export class LoadingButton extends Component {
+
+ protected button!: HTMLButtonElement;
+ protected loadingEl: HTMLDivElement|null = null;
+
+ setup() {
+ this.button = this.$el as HTMLButtonElement;
+ const form = this.button.form;
+
+ const action = () => {
+ setTimeout(() => this.showLoadingState(), 10)
+ };
+
+ this.button.addEventListener('click', action);
+ if (form) {
+ form.addEventListener('submit', action);
+ }
+ }
+
+ showLoadingState() {
+ this.button.disabled = true;
+
+ if (!this.loadingEl) {
+ this.loadingEl = el('div', {class: 'inline block'}) as HTMLDivElement;
+ showLoading(this.loadingEl);
+ this.button.after(this.loadingEl);
+ }
+ }
+}
\ No newline at end of file
])
@endif
- <div class="text-right">
+ <div class="flex-container-row items-center justify-flex-end">
<a href="{{ url('/import') }}" class="button outline">{{ trans('common.cancel') }}</a>
<div component="dropdown" class="inline block mx-s">
<button refs="dropdown@toggle"
<button type="submit" form="import-delete-form" class="text-link small text-item">{{ trans('common.confirm') }}</button>
</div>
</div>
- <button type="submit" class="button">{{ trans('entities.import_run') }}</button>
+ <button component="loading-button" type="submit" class="button">{{ trans('entities.import_run') }}</button>
</div>
</form>
</main>