<eg-staff-banner bannerText="Circulation Limit Set Administration" i18n-bannerText>
</eg-staff-banner>
-<eg-admin-page idlClass="ccls" [templateFields]="[{name: 'Linked Entities', template: cclsLinkedEntitiesTmpl}]"></eg-admin-page>
+<eg-string #createFailedString i18n-text text="Created Circulation Limit
+ Set"></eg-string>
+<eg-string #createSuccessString i18n-text text="Failed to Create Circulation
+ Limit Set"></eg-string>
+<eg-string #deleteFailedString i18n-text text="Delete of Circulation Limit Set
+ failed or was not allowed"></eg-string>
+<eg-string #deleteSuccessString i18n-text text="Delete of Circulation Limit Set
+ succeeded"></eg-string>
+<eg-string #updateSuccessString i18n-text text="Circulation Limit Set Update
+ Succeeded"></eg-string>
+<eg-string #updateFailedString i18n-text text="Circulation Limit Set
+ Update Failed"></eg-string>
-<ng-template #cclsLinkedEntitiesTmpl let-row="row">
- <div>
- <a routerLink="/staff/admin/local/config/circ_limit_set/{{row.id()}}">
- Manage
- </a>
- </div>
-</ng-template>
+<eg-grid #grid idlClass="ccls" [dataSource]="gridDataSource" hideFields="id">
+ <eg-grid-toolbar-button label="New Circulation Limit Set" i18n-label
+ (onClick)="createNew()"></eg-grid-toolbar-button>
+ <eg-grid-toolbar-action label="Edit Selected" i18n-label
+ (onClick)="editSelected($event)"></eg-grid-toolbar-action>
+ <eg-grid-toolbar-action label="Delete Selected" i18n-label
+ (onClick)="deleteSelected($event)"></eg-grid-toolbar-action>
+</eg-grid>
<eg-fm-record-editor #editDialog hiddenFields="id" idlClass="ccls"></eg-fm-record-editor>
-import {Component} from '@angular/core';
+import {Pager} from '@eg/share/util/pager';
+import {Component, OnInit, Input, ViewChild} from '@angular/core';
+import {GridComponent} from '@eg/share/grid/grid.component';
+import {GridDataSource} from '@eg/share/grid/grid';
+import {Router} from '@angular/router';
+import {IdlObject} from '@eg/core/idl.service';
+import {PcrudService} from '@eg/core/pcrud.service';
+import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
+import {StringComponent} from '@eg/share/string/string.component';
+import {ToastService} from '@eg/share/toast/toast.service';
@Component({
templateUrl: './circ_limit_set.component.html'
})
-export class CircLimitSetComponent { }
+export class CircLimitSetComponent implements OnInit {
+
+ recId: number;
+ gridDataSource: GridDataSource;
+ initDone = false;
+ cspSource: GridDataSource = new GridDataSource();
+
+ @ViewChild('editDialog', {static: true}) editDialog: FmRecordEditorComponent;
+ @ViewChild('grid', {static: true}) grid: GridComponent;
+ @ViewChild('updateSuccessString', {static: true}) updateSuccessString: StringComponent;
+ @ViewChild('updateFailedString', {static: true}) updateFailedString: StringComponent;
+ @ViewChild('deleteFailedString', {static: true}) deleteFailedString: StringComponent;
+ @ViewChild('deleteSuccessString', {static: true}) deleteSuccessString: StringComponent;
+ @ViewChild('createSuccessString', {static: true}) createSuccessString: StringComponent;
+ @ViewChild('createErrString', {static: true}) createErrString: StringComponent;
+
+ @Input() dialogSize: 'sm' | 'lg' = 'lg';
+
+ constructor(
+ private pcrud: PcrudService,
+ private toast: ToastService,
+ private router: Router
+ ) {
+ this.gridDataSource = new GridDataSource();
+ }
+
+ ngOnInit() {
+ this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
+ const orderBy: any = {};
+ const searchOps = {
+ offset: pager.offset,
+ limit: pager.limit,
+ order_by: orderBy
+ };
+ return this.pcrud.retrieveAll('ccls', searchOps, {fleshSelectors: true});
+ };
+
+ this.grid.onRowActivate.subscribe(
+ (set: IdlObject) => {
+ const idToEdit = set.id();
+ this.navigateToEditPage(idToEdit);
+ }
+ );
+ }
+
+ deleteSelected = (idlThings: IdlObject[]) => {
+ idlThings.forEach(idlThing => idlThing.isdeleted(true));
+ this.pcrud.autoApply(idlThings).subscribe(
+ val => {
+ this.deleteSuccessString.current()
+ .then(str => this.toast.success(str));
+ },
+ err => {
+ this.deleteFailedString.current()
+ .then(str => this.toast.danger(str));
+ },
+ () => this.grid.reload()
+ );
+ }
+
+ editSelected(sets: IdlObject[]) {
+ const idToEdit = sets[0].id();
+ this.navigateToEditPage(idToEdit);
+ }
+
+ navigateToEditPage(id: any) {
+ this.router.navigate(['/staff/admin/local/config/circ_limit_set/' + id]);
+ }
+
+ createNew() {
+ this.editDialog.mode = 'create';
+ this.editDialog.recordId = null;
+ this.editDialog.record = null;
+ this.editDialog.open({size: this.dialogSize}).subscribe(
+ ok => {
+ this.createSuccessString.current()
+ .then(str => this.toast.success(str));
+ this.grid.reload();
+ },
+ rejection => {
+ if (!rejection.dismissed) {
+ this.createErrString.current()
+ .then(str => this.toast.danger(str));
+ }
+ }
+ );
+ }
+
+ showEditDialog(standingPenalty: IdlObject): Promise<any> {
+ this.editDialog.mode = 'update';
+ this.editDialog.recordId = standingPenalty['id']();
+ return new Promise((resolve, reject) => {
+ this.editDialog.open({size: this.dialogSize}).subscribe(
+ result => {
+ this.updateSuccessString.current()
+ .then(str => this.toast.success(str));
+ this.grid.reload();
+ resolve(result);
+ },
+ error => {
+ this.updateFailedString.current()
+ .then(str => this.toast.danger(str));
+ reject(error);
+ }
+ );
+ });
+ }
+}