LP1816475: fixing lifecycle issue
authorJane Sandberg <sandbej@linnbenton.edu>
Sun, 7 Apr 2019 20:46:46 +0000 (13:46 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Wed, 17 Apr 2019 20:41:53 +0000 (13:41 -0700)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/staff/booking/create-reservation.component.ts

index 75a66a6..dc3d7d5 100644 (file)
@@ -53,6 +53,8 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
 
     minuteStep: () => number;
 
+    openCreateDialog: (rows: IdlObject[]) => void;
+
     resources: IdlObject[] = [];
     limitByAttr: (attributeId: number, $event: ComboboxEntry) => void;
     useCurrentResourceBarcode: () => void;
@@ -232,26 +234,30 @@ export class CreateReservationComponent implements OnInit, AfterViewInit {
         this.dateLimiters.forEach((dl) => dl.initialDate = new Date());
         this.setGranularity();
         this.fetchData();
-    }
 
-    openCreateDialog(rows: IdlObject[]) {
-        if (this.multiday) {
-            this.defaultTimes['start_time'] = this.format.momentizeDateString(rows[0]['time'], this.format.wsOrgTimezone);
-            this.defaultTimes['end_time'] = this.format.momentizeDateString(
-                rows[rows.length - 1]['time'], this.format.wsOrgTimezone).clone()
-                .add(this.granularity, 'minutes');
-        } else {
-            this.defaultTimes['start_time'] = Moment.tz(rows[0]['time'], 'LT', this.format.wsOrgTimezone);
-            this.defaultTimes['end_time'] = Moment.tz(rows[rows.length - 1]['time'], 'LT', this.format.wsOrgTimezone).add(this.granularity, 'minutes');
+       this.openCreateDialog = (rows: IdlObject[]) => {
+            if (rows.length) {
+                if (this.multiday) {
+                    this.defaultTimes['start_time'] = this.format.momentizeDateString(rows[0]['time'], this.format.wsOrgTimezone);
+                    this.defaultTimes['end_time'] = this.format.momentizeDateString(
+                        rows[rows.length - 1]['time'], this.format.wsOrgTimezone).clone()
+                        .add(this.granularity, 'minutes');
+                } else {
+                    this.defaultTimes['start_time'] = Moment.tz(rows[0]['time'], 'LT', this.format.wsOrgTimezone);
+                    this.defaultTimes['end_time'] = Moment.tz(rows[rows.length - 1]['time'], 'LT', this.format.wsOrgTimezone).add(this.granularity, 'minutes');
+                }
+            } else {
+                if (this.multiday) { this.defaultTimes['end_time'] = this.defaultTimes['start_time'].clone().add(1, 'days'); }
+            }
+            return this.newDialog.open({size: 'lg'}).then(
+                response => {
+                   console.log(response);
+                    this.toast.success('Reservation successfully created'); // TODO: needs i18n, pluralization
+                    this.fetchData();
+                },
+                err => {}
+            );
         }
-        return this.newDialog.open({size: 'lg'}).then(
-            response => {
-               console.log(response);
-                this.toast.success('Reservation successfully created'); // TODO: needs i18n, pluralization
-                this.fetchData();
-            },
-            err => {}
-        );
     }
     handleResourceTypeChange($event: ComboboxEntry) {
         this.resourceBarcode = null;