<eg-staff-banner bannerText="Current Reservations" i18n-bannerText>
</eg-staff-banner>
-<eg-grid [dataSource]="gridSource"
+<eg-grid #grid [dataSource]="gridSource"
[sortable]="true" persistKey="booking.current_reservations" >
+ <eg-grid-toolbar-action label="Edit Selected" i18n-label [action]="editSelected"></eg-grid-toolbar-action>
<eg-grid-column name="id" [hidden]="true" [index]="true" i18n-label label="ID" path="id"></eg-grid-column>
<eg-grid-column i18n-label [hidden]="true" path="usr.first_given_name"></eg-grid-column>
<eg-grid-column i18n-label [hidden]="true" path="usr.second_given_name"></eg-grid-column>
</eg-grid>
+<eg-fm-record-editor #editDialog idlClass="bresv">
+</eg-fm-record-editor>
-import { Component, OnInit } from '@angular/core';
+import { Component, OnInit, ViewChild } from '@angular/core';
+import {GridComponent} from '@eg/share/grid/grid.component';
import { GridDataSource } from '@eg/share/grid/grid';
+import {IdlObject} from '@eg/core/idl.service';
import {PcrudService} from '@eg/core/pcrud.service';
import {Pager} from '@eg/share/util/pager';
+import {ToastService} from '@eg/share/toast/toast.service';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
+import {StringComponent} from '@eg/share/string/string.component';
+import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component';
@Component({
selector: 'eg-current-reservations',
gridSource: GridDataSource;
patronId: number;
+ @ViewChild('grid') grid: GridComponent;
+ @ViewChild('editDialog') editDialog: FmRecordEditorComponent;
+ @ViewChild('successString') successString: StringComponent;
+
+ editSelected: (rows: IdlObject[]) => void;
+
constructor(
private route: ActivatedRoute,
+ private toast: ToastService,
private pcrud: PcrudService
){
this.gridSource = new GridDataSource();
this.route.paramMap.subscribe((params: ParamMap) => {
this.patronId = +params.get('patron_id');
});
+
+ this.editSelected = (idlThings: IdlObject[]) => {
+ const editOneThing = (thing: IdlObject) => {
+ if (!thing) return;
+ this.showEditDialog(thing).then(
+ () => editOneThing(idlThings.shift()));
+ }
+ editOneThing(idlThings.shift()); };
+
}
+ showEditDialog(idlThing: IdlObject) {
+ this.editDialog.mode = 'update';
+ this.editDialog.recId = idlThing.id();
+ return this.editDialog.open({size: 'lg'}).then(
+ ok => {
+ this.successString.current()
+ .then(str => this.toast.success(str));
+ this.grid.reload();
+ },
+ err => {}
+ );
+ }
}