<div class="col-lg-3 offset-lg-2" i18n>Open Time</div>
<div class="col-lg-3" i18n>Close Time</div>
</div>
- <div class="row">
- <div class="col-lg-2" i18n>Monday</div>
+ <div class="row mb-2" *ngFor="let dow of [0,1,2,3,4,5,6]">
+ <div class="col-lg-2" [ngSwitch]="dow">
+ <span *ngSwitchCase="0" i18n>Monday</span>
+ <span *ngSwitchCase="1" i18n>Tuesday</span>
+ <span *ngSwitchCase="2" i18n>Wednesday</span>
+ <span *ngSwitchCase="3" i18n>Thursday</span>
+ <span *ngSwitchCase="4" i18n>Friday</span>
+ <span *ngSwitchCase="5" i18n>Saturday</span>
+ <span *ngSwitchCase="6" i18n>Sunday</span>
+ </div>
<div class="col-lg-3">
<input class="form-control" type='time' step="60"
- [ngModel]="hours().dow_0_open()" min="00:00:00" max="23:59:59"
- (ngModelChange)="hours().dow_0_open($event)"/>
+ [ngModel]="hours(dow, 'open')" min="00:00:00" max="23:59:59"
+ (ngModelChange)="hours(dow, 'open', $event)"/>
</div>
<div class="col-lg-3">
<input class="form-control" type='time' step="60"
- [ngModel]="hours().dow_0_close()" min="00:00:00" max="23:59:59"
- (ngModelChange)="hours().dow_0_close($event)"/>
+ [ngModel]="hours(dow, 'close')" min="00:00:00" max="23:59:59"
+ (ngModelChange)="hours(dow, 'close', $event)"/>
</div>
<div class="col-lg-2">
- <button class="btn btn-outline-dark" (click)="closedOn(0)" i18n>
+ <button class="btn btn-outline-dark" (click)="closedOn(dow)" i18n>
Closed
</button>
</div>
if (!orgNode) { return; }
if (!orgNode.hours_of_operation()) {
- const hours = this.idl.create('aouhoo');
- hours.org_unit(orgNode.id());
- hours.isnew(true);
- [0, 1, 2, 3, 4, 5, 6].forEach(dow => {
- hours[`dow_${dow}_open`]('09:00:00');
- hours[`dow_${dow}_close`]('17:00:00');
- });
- orgNode.hours_of_operation(hours);
+ this.generateHours(orgNode);
}
// TODO addresses
this.selected = $event;
}
- hours(): IdlObject {
- if (this.selected) {
- console.log('we have org ', this.selected.callerData.orgUnit);
- console.log('we have hours ', this.selected.callerData.orgUnit.hours_of_operation());
- return this.selected.callerData.orgUnit.hours_of_operation();
+ generateHours(org: IdlObject) {
+ const hours = this.idl.create('aouhoo');
+ hours.org_unit(org.id());
+ hours.isnew(true);
+
+ [0, 1, 2, 3, 4, 5, 6].forEach(dow => {
+ this.hours(dow, 'open', '09:00:00', hours);
+ this.hours(dow, 'close', '17:00:00', hours);
+ });
+
+ org.hours_of_operation(hours);
+ }
+
+ // if a 'value' is passed, it will be applied to the optional
+ // hours-of-operation object, otherwise the hours on the currently
+ // selected org unit.
+ hours(dow: number, which: 'open' | 'close', value?: string, hoo?: IdlObject): IdlObject {
+ if (!hoo && !this.selected) { return null; }
+
+ const hours = hoo || this.selected.callerData.orgUnit.hours_of_operation();
+
+ if (value) {
+ hours[`dow_${dow}_${which}`](value);
+ hours.ischanged(true);
}
- return this.selected ?
- this.selected.callerData.orgUnit.hours_of_operation() : null;
+
+ return hours[`dow_${dow}_${which}`]();
+ }
+
+ closedOn(dow: number) {
+ this.hours(dow, 'open', '00:00:00');
+ this.hours(dow, 'close', '00:00:00');
}
postUpdate(message: StringComponent) {