All files / components/crud crud-cancel-button.ts

25% Statements 5/20
0% Branches 0/15
0% Functions 0/4
25% Lines 5/20

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 591x 1x   1x 1x         1x                                                                                                  
import { I18n } from '@zeedhi/core';
import { GridEditable } from '@zeedhi/common';
import { ICrudCancelButton } from './interfaces';
import { CrudButton } from './crud-button';
import { CrudForm } from './crud-form';
 
/**
 * Button to be used on Crud Forms
 */
export class CrudCancelButton extends CrudButton implements ICrudCancelButton {
  /**
   * Button label
   */
  private defaultLabel: string = 'CANCEL';
 
  /**
   * Button outline
   */
  private defaultOutline: boolean = true;
 
  /**
   * Create new Crud Cancel Button
   * @param props component properties
   */
  public constructor(props: ICrudCancelButton) {
    super({ ...props, clickShortcutKey: props.clickShortcutKey || 'esc' });
    this.label = props.label ? this.label : this.defaultLabel;
    this.outline = props.outline !== undefined ? this.outline : this.defaultOutline;
    this.tooltip.label = this.tooltip.label || `${I18n.translate(this.defaultLabel)} (${props.clickShortcutKey || 'esc'})`;
  }
 
  /**
   * Triggered when the component is clicked.
   * @param event DOM event
   * @param element Element clicked
   */
  public click(event: Event, element: HTMLElement) {
    if (this.parent instanceof CrudForm) {
      super.click(event, element);
      Iif (!event.defaultPrevented) {
        (this.parent as CrudForm).cancelEdit();
      }
    } else Iif (this.parent instanceof GridEditable) {
      super.click(event, element);
      Iif (!event.defaultPrevented) {
        (this.parent as GridEditable).cancelEditedRows();
      }
    }
  }
 
  get disabled() {
    return !this.parentIsEditing;
  }
 
  set disabled(_value: boolean) {
    // do nothing
  }
}