@Input() validatorError = '';
@Input() initialIso: string;
+ @Input() initialMoment: Moment;
@Output() onChangeAsIso = new EventEmitter<string>();
@Output() onChangeAsMoment = new EventEmitter<Moment>();
}
ngOnInit() {
- const start = this.initialIso ? Moment.tz(this.initialIso, Moment.ISO_8601, this.timezone) : Moment.tz([], this.timezone);
+ let start = this.initialIso ? Moment.tz(this.initialIso, Moment.ISO_8601, this.timezone) : Moment.tz([], this.timezone);
+ if (this.initialMoment) { start = this.initialMoment; }
this.stringVersion = this.format.transform({value: start, datatype: 'timestamp', datePlusTime: true});
this.setDatePicker(start);
this.setTimePicker(start);
<eg-grid *ngIf="resources.length" #scheduleGrid
[sortable]="false"
- (onRowActivate)="showNewDialog($event)"
+ (onRowActivate)="openCreateDialog([$event])"
[dataSource]="scheduleSource"
[rowFlairIsEnabled]="true"
[rowFlairCallback]="resourceAvailabilityIcon"
[disablePager]="true"
[disableSaveSettings]="true"
[cellClassCallback]="isBooked">
+ <eg-grid-toolbar-action label="Create Reservation" i18n-label [action]="openCreateDialog"></eg-grid-toolbar-action>
<eg-grid-column path="time" [index]="true" ></eg-grid-column>
<eg-grid-column *ngFor="let resource of resources" path="{{resource.barcode()}}" [cellTemplate]="reservationsTemplate"></eg-grid-column>
</eg-grid>
<eg-fm-record-editor #newDialog
idlClass="bresv"
datetimeFields="start_time,end_time"
- [fieldOptions]="{usr:{customTemplate:{template:patronTemplate,context:{'patronId':this.patronId}}}}"
+ [fieldOptions]="{usr:{customTemplate:{template:patronTemplate}},start_time:{customTemplate:{template:datetimeWithDefaults}},end_time:{customTemplate:{template:datetimeWithDefaults}}}"
hiddenFields="id,xact_start,request_time,capture_time,pickup_time,return_time,capture_staff,xact_finish,cancel_time,booking_interval,target_resource,unrecovered,request_lib,fine_interval,fine_amount,max_fine">
</eg-fm-record-editor>
</ul>
</ng-container>
</ng-template>
-<ng-template #patronTemplate let-record="record" let-patronId="patronId">
+<ng-template #patronTemplate let-record="record">
<input type="hidden" value="{{record.request_lib(auth.user().ws_ou())}}">
<ng-container *ngIf="patronId">
<input *ngIf="patronId" type="text" disabled value="{{record.usr(patronId)}}" class="form-control" name="usr">
</div>
</div>
</ng-template>
+<ng-template #datetimeWithDefaults let-record="record" let-field="field">
+ <input type="hidden" value="{{record[field.name](defaultTimes[field.name].toIsoString()}}">
+ <eg-datetime-select
+ [showTZ]="true"
+ [minuteStep]="minuteStep()"
+ timezone="{{format.wsOrgTimezone}}"
+ (onChangeAsIso)="record[field.name]($event)"
+ [initialMoment]="defaultTimes[field.name]">
+ </eg-datetime-select>
+</ng-template>
endOfDay: NgbTimeStruct = {hour: 17, minute: 0, second: 0};
granularity: 15 | 30 | 60 | 1440 = 30; // 1440 minutes = 24 hours
+ defaultTimes: {start_time: Moment, end_time: Moment};
+
scheduleSource: GridDataSource = new GridDataSource();
+ minuteStep: () => number;
+
resources: IdlObject[] = [];
limitByAttr: (attributeId: number, $event: ComboboxEntry) => void;
useCurrentResourceBarcode: () => void;
ngOnInit() {
+ this.defaultTimes = {
+ 'start_time': Moment.tz([], this.format.wsOrgTimezone),
+ 'end_time': Moment.tz([], this.format.wsOrgTimezone).add(this.granularity, 'minutes')
+ };
this.route.paramMap.subscribe((params: ParamMap) => {
this.patronId = +params.get('patron_id');
this.resourceBarcode = params.get('resource_barcode');
.pipe(single())
.subscribe((item) => {
this.net.request( 'open-ils.booking',
- 'open-ils.booking.resources.create_from_copies',
+ 'open-ils.booking.resources.create_from_copies',
this.auth.token(), [item.id()])
- .subscribe((response) => {
+ .subscribe((response) => {
this.toast.info('Made this barcode bookable');
this.resourceId = response['brsrc'][0][0];
}, (error) => {
this.toast.danger('Cannot make this barcode bookable');
- })
+ });
}, (acperror) => {
this.toast.danger('No resource found with this barcode');
this.resourceId = -1;
this.granularity = 1440;
} else {
this.store.getItem('eg.booking.create.granularity').then(granularity => {
- if (granularity) {
+ if (granularity) {
this.granularity = granularity;
} else {
this.granularity = 30;
);
}
};
-
+ this.minuteStep = () => {
+ return (this.granularity < 60) ? this.granularity : 15;
+ }
}
this.fetchData();
}
- showNewDialog(idlThing: IdlObject) {
+ 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');
+ }
return this.newDialog.open({size: 'lg'}).then(
response => {
console.log(response);
ngOnInit() {
- this.disableOrgs = () => {return this.org.filterList({canHaveVolumes : false}, true);}
+ this.disableOrgs = () => { return this.org.filterList( { canHaveVolumes : false }, true); };
this.fill_grid = (orgId = this.auth.user().ws_ou()) => {
this.net.request(
});
this.dataSource.data = data;
});
- }
+ };
this.dataSource = new GridDataSource();
this.fill_grid(this.auth.user().ws_ou());
}