Browse Source

Ace based editors disabled state handling

pull/2592/head
Igor Kulikov 7 years ago
parent
commit
73da299aaf
  1. 3
      ui-ngx/src/app/shared/components/js-func.component.ts
  2. 4
      ui-ngx/src/app/shared/components/json-content.component.html
  3. 7
      ui-ngx/src/app/shared/components/json-content.component.ts
  4. 4
      ui-ngx/src/app/shared/components/json-object-edit.component.html
  5. 7
      ui-ngx/src/app/shared/components/json-object-edit.component.ts

3
ui-ngx/src/app/shared/components/js-func.component.ts

@ -185,6 +185,9 @@ export class JsFuncComponent implements OnInit, OnDestroy, ControlValueAccessor,
setDisabledState(isDisabled: boolean): void { setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled; this.disabled = isDisabled;
if (this.jsEditor) {
this.jsEditor.setReadOnly(this.disabled);
}
} }
public validate(c: FormControl) { public validate(c: FormControl) {

4
ui-ngx/src/app/shared/components/json-content.component.html

@ -22,11 +22,11 @@
<label class="tb-title no-padding">{{ label }}</label> <label class="tb-title no-padding">{{ label }}</label>
<span fxFlex></span> <span fxFlex></span>
<button type="button" <button type="button"
mat-button *ngIf="!readonly" class="tidy" (click)="beautifyJSON()"> mat-button *ngIf="!readonly && !disabled" class="tidy" (click)="beautifyJSON()">
{{'js-func.tidy' | translate }} {{'js-func.tidy' | translate }}
</button> </button>
<button type="button" <button type="button"
mat-button *ngIf="!readonly" class="tidy" (click)="minifyJSON()"> mat-button *ngIf="!readonly && !disabled" class="tidy" (click)="minifyJSON()">
{{'js-func.mini' | translate }} {{'js-func.mini' | translate }}
</button> </button>
<button type='button' mat-button mat-icon-button (click)="fullscreen = !fullscreen" <button type='button' mat-button mat-icon-button (click)="fullscreen = !fullscreen"

7
ui-ngx/src/app/shared/components/json-content.component.ts

@ -118,7 +118,7 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid
mode: `ace/mode/${mode}`, mode: `ace/mode/${mode}`,
showGutter: true, showGutter: true,
showPrintMargin: false, showPrintMargin: false,
readOnly: this.readonly readOnly: this.disabled || this.readonly
}; };
const advancedOptions = { const advancedOptions = {
@ -185,6 +185,9 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid
setDisabledState(isDisabled: boolean): void { setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled; this.disabled = isDisabled;
if (this.jsonEditor) {
this.jsonEditor.setReadOnly(this.disabled || this.readonly);
}
} }
public validate(c: FormControl) { public validate(c: FormControl) {
@ -196,7 +199,7 @@ export class JsonContentComponent implements OnInit, ControlValueAccessor, Valid
} }
validateOnSubmit(): void { validateOnSubmit(): void {
if (!this.readonly) { if (!this.disabled && !this.readonly) {
this.cleanupJsonErrors(); this.cleanupJsonErrors();
this.contentValid = true; this.contentValid = true;
this.propagateChange(this.contentBody); this.propagateChange(this.contentBody);

4
ui-ngx/src/app/shared/components/json-object-edit.component.html

@ -25,11 +25,11 @@
'tb-error': !objectValid}">{{ label }}</label> 'tb-error': !objectValid}">{{ label }}</label>
<span fxFlex></span> <span fxFlex></span>
<button type="button" <button type="button"
mat-button *ngIf="!readonly" class="tidy" (click)="beautifyJSON()"> mat-button *ngIf="!readonly && !disabled" class="tidy" (click)="beautifyJSON()">
{{'js-func.tidy' | translate }} {{'js-func.tidy' | translate }}
</button> </button>
<button type="button" <button type="button"
mat-button *ngIf="!readonly" class="tidy" (click)="minifyJSON()"> mat-button *ngIf="!readonly && !disabled" class="tidy" (click)="minifyJSON()">
{{'js-func.mini' | translate }} {{'js-func.mini' | translate }}
</button> </button>
<button mat-button mat-icon-button (click)="fullscreen = !fullscreen" <button mat-button mat-icon-button (click)="fullscreen = !fullscreen"

7
ui-ngx/src/app/shared/components/json-object-edit.component.ts

@ -111,7 +111,7 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va
mode: 'ace/mode/json', mode: 'ace/mode/json',
showGutter: true, showGutter: true,
showPrintMargin: false, showPrintMargin: false,
readOnly: this.readonly readOnly: this.disabled || this.readonly
}; };
const advancedOptions = { const advancedOptions = {
@ -161,6 +161,9 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va
setDisabledState(isDisabled: boolean): void { setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled; this.disabled = isDisabled;
if (this.jsonEditor) {
this.jsonEditor.setReadOnly(this.disabled || this.readonly);
}
} }
public validate(c: FormControl) { public validate(c: FormControl) {
@ -172,7 +175,7 @@ export class JsonObjectEditComponent implements OnInit, ControlValueAccessor, Va
} }
validateOnSubmit(): void { validateOnSubmit(): void {
if (!this.readonly) { if (!this.disabled && !this.readonly) {
this.cleanupJsonErrors(); this.cleanupJsonErrors();
if (!this.objectValid) { if (!this.objectValid) {
this.store.dispatch(new ActionNotificationShow( this.store.dispatch(new ActionNotificationShow(

Loading…
Cancel
Save