@progress/kendo-angular-grid
Version:
Kendo UI Grid for Angular - high performance data grid with paging, filtering, virtualization, CRUD, and more.
100 lines (99 loc) • 4.89 kB
JavaScript
/**-----------------------------------------------------------------------------------------
* Copyright © 2025 Progress Software Corporation. All rights reserved.
* Licensed under commercial license. See LICENSE.md in the project root for more information
*-------------------------------------------------------------------------------------------*/
import { ChangeDetectorRef, Directive, Inject, NgZone } from '@angular/core';
import { take } from 'rxjs/operators';
import { ToolBarButtonComponent } from '@progress/kendo-angular-toolbar';
import { isPresent } from '@progress/kendo-angular-common';
import { SelectionService } from '../selection/selection.service';
import { EditService } from '../editing/edit.service';
import { ContextService } from '../common/provider.service';
import { ToolbarToolBase } from '../common/toolbar-tool-base.directive';
import { ToolbarToolName } from '../navigation/toolbar-tool-name';
import * as i0 from "@angular/core";
import * as i1 from "@progress/kendo-angular-toolbar";
import * as i2 from "../common/provider.service";
import * as i3 from "../editing/edit.service";
import * as i4 from "../selection/selection.service";
/**
* @hidden
*/
export class ToolbarEditingToolBase extends ToolbarToolBase {
host;
commandName;
ctx;
editService;
selection;
isEdited = false;
lastToolState = null;
constructor(host, commandName, ctx, zone, cdr, editService, selection) {
super(host, commandName, ctx, zone, cdr);
this.host = host;
this.commandName = commandName;
this.ctx = ctx;
this.editService = editService;
this.selection = selection;
}
ngAfterViewInit() {
super.ngAfterViewInit();
const commandText = this.ctx.localization.get(`${this.commandName}ToolbarToolText`);
this.buttonElement?.setAttribute('title', commandText);
}
ngDoCheck() {
if (!isPresent(this.editService)) {
return;
}
this.isEdited = this.editService.isEditing();
const isAddNewItem = this.editService.hasNewItem;
let isToolInactive = false;
let formGroup;
const selectionPresent = isPresent(this.lastSelectionIndex);
if (this.isEdited || isAddNewItem) {
formGroup = isAddNewItem ? this.editService.context()?.group : this.editService.editedIndices[0].group;
}
switch (this.commandName) {
case ToolbarToolName.edit:
isToolInactive = this.isEdited || !selectionPresent;
break;
case ToolbarToolName.save:
isToolInactive = !(this.isEdited || isAddNewItem) || !formGroup?.valid;
break;
case ToolbarToolName.remove:
isToolInactive = this.isEdited || !selectionPresent;
break;
case ToolbarToolName.cancel:
isToolInactive = !(this.isEdited || isAddNewItem);
break;
}
if (this.lastToolState !== isToolInactive) {
this.lastToolState = isToolInactive;
if (this.ctx.grid.showInactiveTools) {
this.host.disabled = isToolInactive;
}
else if (this.host.isHidden !== isToolInactive) {
this.host.isHidden = isToolInactive;
const toolbar = this.host.host;
toolbar.refreshService.refresh(this.host);
this.zone.onStable.pipe(take(1)).subscribe(() => {
toolbar.onResize();
});
}
}
}
get lastSelectionIndex() {
return this.selection?.selected[this.selection?.selected.length - 1];
}
get isSelectionPresent() {
return isPresent(this.lastSelectionIndex) && this.lastSelectionIndex > -1;
}
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToolbarEditingToolBase, deps: [{ token: i1.ToolBarButtonComponent }, { token: 'command' }, { token: i2.ContextService }, { token: i0.NgZone }, { token: i0.ChangeDetectorRef }, { token: i3.EditService }, { token: i4.SelectionService }], target: i0.ɵɵFactoryTarget.Directive });
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.14", type: ToolbarEditingToolBase, usesInheritance: true, ngImport: i0 });
}
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: ToolbarEditingToolBase, decorators: [{
type: Directive,
args: [{}]
}], ctorParameters: () => [{ type: i1.ToolBarButtonComponent }, { type: undefined, decorators: [{
type: Inject,
args: ['command']
}] }, { type: i2.ContextService }, { type: i0.NgZone }, { type: i0.ChangeDetectorRef }, { type: i3.EditService }, { type: i4.SelectionService }] });