required min-date="minDate">
</eg-date-input>
</div>
- <div class="col-md-1">
+ <div class="col-md-2">
<label for="appointment-time">[% l('Time') %]</label>
<select class="form-control" id="appointment-time" ng-model="appt.slot_time"
- name="slot_time"
+ name="slot_time" style="display: block;"
required ng-focus="refreshAvailableTimes(appt)">
- <option ng-repeat="t in appt.available_times" value="{{t}}">{{t}}</option>
+ <option ng-repeat="t in appt.available_times track by t.time" value="{{t.time}}">[% l('[_1] (Available: [_2])', '{{t.time_fmt}}', '{{t.available}}') %]</option>
</select>
</div>
<div class="col-md-2">
});
}
+ function mungeAvailableTimes(hash, times) {
+ var existing_present = false;
+ hash.available_times = times.map(function(t) {
+ if (hash.slot_time !== null && hash.slot_time === t[0]) existing_present = true;
+ return {
+ time: t[0],
+ available: t[1],
+ time_fmt: moment(t[0], [moment.ISO_8601, 'HH:mm:ss']).format('LT')
+ };
+ });
+ if (hash.slot_time !== null && !existing_present) {
+ hash.available_times.unshift({
+ time: hash.slot_time,
+ available: 0,
+ time_fmt: moment(hash.slot_time, [moment.ISO_8601, 'HH:mm:ss']).format('LT')
+ });
+ }
+ }
+
function mungeOneAppointment(c, isNew) {
var hash = egCore.idl.toHash(c);
if (hash.slot === null) {
egCore.auth.token(),
hash.slot.substring(0, 10),
).then(function(times) {
- hash.available_times = times.map(function(t) { return t[0]; });
- if (hash.slot_time !== null && hash.available_times.indexOf(hash.slot_time) === -1) {
- hash.available_times.unshift(hash.slot_time);
- }
+ mungeAvailableTimes(hash, times);
});
return hash;
}
egCore.auth.token(),
dateStr,
).then(function(times) {
- hash.available_times = times.map(function(t) { return t[0]; });
- if (hash.slot_time !== null && hash.available_times.indexOf(hash.slot_time) === -1) {
- hash.available_times.unshift(hash.slot_time);
- }
+ mungeAvailableTimes(hash, times);
});
}