The `_editable` class should only be set if the toolbar is really editable

pull/10556/head
Henriette Darge 3 years ago
parent 0f4d5b3159
commit f3b87c55dd
  1. 31
      frontend/src/app/shared/components/editable-toolbar-title/editable-toolbar-title.component.ts

@ -69,7 +69,10 @@ export class EditableToolbarTitleComponent implements OnInit, OnChanges {
@HostBinding('class.title-container') baseClass = true; @HostBinding('class.title-container') baseClass = true;
@HostBinding('class.title-container_editable') editableClass = true; @HostBinding('class.title-container_editable')
public get editableClass():boolean {
return this.editable;
}
@ViewChild('editableTitleInput') inputField?:ElementRef; @ViewChild('editableTitleInput') inputField?:ElementRef;
@ -95,7 +98,7 @@ export class EditableToolbarTitleComponent implements OnInit, OnChanges {
constructor(readonly injector:Injector) { constructor(readonly injector:Injector) {
} }
ngOnInit() { ngOnInit():void {
this.text.input_title = `${this.text.click_to_edit} ${this.text.press_enter_to_save}`; this.text.input_title = `${this.text.click_to_edit} ${this.text.press_enter_to_save}`;
jQuery(this.elementRef.nativeElement).on(triggerEditingEvent, (evt:Event, val = '') => { jQuery(this.elementRef.nativeElement).on(triggerEditingEvent, (evt:Event, val = '') => {
@ -125,36 +128,36 @@ export class EditableToolbarTitleComponent implements OnInit, OnChanges {
} }
} }
public onFocus(event:FocusEvent) { public onFocus(event:FocusEvent):void {
this.toggleToolbarButtonVisibility(true); this.toggleToolbarButtonVisibility(true);
this.selectInputOnInitalFocus(event.target as HTMLInputElement); this.selectInputOnInitalFocus(event.target as HTMLInputElement);
} }
public onBlur() { public onBlur():void {
this.toggleToolbarButtonVisibility(false); this.toggleToolbarButtonVisibility(false);
} }
public selectInputOnInitalFocus(input:HTMLInputElement) { public selectInputOnInitalFocus(input:HTMLInputElement):void {
if (this.initialFocus) { if (this.initialFocus) {
input.select(); input.select();
this.initialFocus = false; this.initialFocus = false;
} }
} }
public saveWhenFocusOutside($event:FocusEvent) { public saveWhenFocusOutside($event:FocusEvent):void {
whenOutside(this.elementRef.nativeElement, () => this.save($event)); whenOutside(this.elementRef.nativeElement, () => this.save($event));
} }
public reset() { public reset():void {
this.resetInputField(); this.resetInputField();
this.selectedTitle = this.inputTitle; this.selectedTitle = this.inputTitle;
} }
public get showSave() { public get showSave():boolean {
return this.editable && this.showSaveCondition; return this.editable && this.showSaveCondition;
} }
public save($event:Event, force = false) { public save($event:Event, force = false):void {
$event.preventDefault(); $event.preventDefault();
this.resetInputField(); this.resetInputField();
@ -195,20 +198,20 @@ export class EditableToolbarTitleComponent implements OnInit, OnChanges {
/** /**
* Called when saving the changed title * Called when saving the changed title
*/ */
private emitSave(title:string) { private emitSave(title:string):void {
this.onSave.emit(title); this.onSave.emit(title);
} }
/** /**
* Called when trying to save an empty text * Called when trying to save an empty text
*/ */
private onEmptyError() { private onEmptyError():void {
// this.updateItemInMenu(); // Throws an error message, when name is empty // this.updateItemInMenu(); // Throws an error message, when name is empty
this.onEmptySubmit.emit(); this.onEmptySubmit.emit();
this.focusInputOnError(); this.focusInputOnError();
} }
private focusInputOnError() { private focusInputOnError():void {
if (this.inputField) { if (this.inputField) {
const el = this.inputField.nativeElement; const el = this.inputField.nativeElement;
el.classList.add('-error'); el.classList.add('-error');
@ -216,14 +219,14 @@ export class EditableToolbarTitleComponent implements OnInit, OnChanges {
} }
} }
private resetInputField() { private resetInputField():void {
if (this.inputField) { if (this.inputField) {
const el = this.inputField.nativeElement; const el = this.inputField.nativeElement;
el.classList.remove('-error'); el.classList.remove('-error');
} }
} }
private toggleToolbarButtonVisibility(hidden:boolean) { private toggleToolbarButtonVisibility(hidden:boolean):void {
jQuery('.toolbar-items').toggleClass('hidden-for-mobile', hidden); jQuery('.toolbar-items').toggleClass('hidden-for-mobile', hidden);
} }
} }

Loading…
Cancel
Save