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 | 1x 1x 1x 1x 1x | import { I18n } from '@zeedhi/core';
import { GridEditable } from '@zeedhi/common';
import { ICrudSaveButton } from './interfaces';
import { CrudButton } from './crud-button';
import { CrudForm } from './crud-form';
/**
* Button to be used on Crud Forms
*/
export class CrudSaveButton extends CrudButton implements ICrudSaveButton {
/**
* Button label
*/
private defaultLabel: string = 'SAVE';
/**
* Create new Crud Save Button
* @param props component properties
*/
public constructor(props: ICrudSaveButton) {
super({ ...props, clickShortcutKey: props.clickShortcutKey || 'ctrl+enter' });
this.label = this.label || this.defaultLabel;
const label = `${I18n.translate(this.defaultLabel)} (${props.clickShortcutKey || 'ctrl+enter'})`;
this.tooltip.label = this.tooltip.label || label;
}
/**
* 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) {
const form = this.parent as CrudForm;
Iif (form.validate()) {
super.click(event, element);
Iif (!event.defaultPrevented) {
form.saveEdit();
}
}
} else Iif (this.parent instanceof GridEditable) {
super.click(event, element);
Iif (!event.defaultPrevented) {
(this.parent as GridEditable).saveEditedRows();
}
}
}
get disabled() {
return !this.parentIsEditing;
}
set disabled(_value: boolean) {
// do nothing
}
}
|