Adding an editor
authorJane Sandberg <sandbej@linnbenton.edu>
Wed, 12 Dec 2018 23:38:15 +0000 (15:38 -0800)
committerJane Sandberg <sandbej@linnbenton.edu>
Wed, 23 Jan 2019 23:08:13 +0000 (15:08 -0800)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/booking/current-reservations.component.html
Open-ILS/src/eg2/src/app/staff/booking/current-reservations.component.ts

index 2c4c527..b4c8f7e 100644 (file)
@@ -2,8 +2,9 @@
 <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>
@@ -30,3 +31,5 @@
 
 </eg-grid>
 
+<eg-fm-record-editor #editDialog idlClass="bresv">
+</eg-fm-record-editor>
index b2095d8..554c8d5 100644 (file)
@@ -1,8 +1,13 @@
-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',
@@ -13,8 +18,15 @@ export class CurrentReservationsComponent implements OnInit {
   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();
@@ -37,8 +49,29 @@ export class CurrentReservationsComponent implements OnInit {
     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 => {}
+    );
+  }
 
 }