Skip to content

Commit

Permalink
Pickadate format now based on js format.
Browse files Browse the repository at this point in the history
Closes #237
  • Loading branch information
r-xyz committed Jun 18, 2024
1 parent 0e4813a commit e229656
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 11 deletions.
10 changes: 5 additions & 5 deletions NEMO/apps/kiosk/templates/kiosk/tool_reservation.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ <h4>When would you like to reserve the {{ tool }}?</h4>
{% for item in tool_reservation_times %}
unavailable_times.push([{{ item.start|date:"U" }},{{ item.end|date:"U" }}]);
{% endfor %}
let date_picker = $('#date').pickadate({format: "dddd, mmmm d", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times});
let start_time_picker = $('#start').pickatime({interval: 15, formatSubmit: "H:i", hiddenName: true, formatLabel: format_label});
let end_time_picker = $('#end').pickatime({interval: 15, formatSubmit: "H:i", hiddenName: true, formatLabel: format_label});
let date_picker = $('#date').pickadate({format: "{{ pick_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times});
let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "HH:mm", hiddenName: true, formatLabel: format_label});
let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label});
// set initial date
if ('{{ date|default_if_none:'' }}') {
date_picker.pickadate('picker').set('select', '{{ date }}', {format: 'yyyy-mm-dd'})
Expand All @@ -77,11 +77,11 @@ <h4>When would you like to reserve the {{ tool }}?</h4>
let start = times[0];
let end = times[1];
if (date_time_selected >= start && date_time_selected < end) {
return '<sp !an>h:i A</sp !an> <sm !all> !alre!ad!y re!serve!d</sm !all>';
return '<sp !an>{{ pick_time_format }}</sp !an> <sm !all> !alre!ad!y re!serve!d</sm !all>';
}
}
}
return "h:i A";
return '{{ pick_time_format }}';
}
revert(120)
</script>
8 changes: 7 additions & 1 deletion NEMO/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from NEMO.models import Area, Notification, PhysicalAccessLevel, Tool, User
from NEMO.utilities import date_input_js_format, datetime_input_js_format, time_input_js_format
from NEMO.utilities import (
date_input_js_format,
datetime_input_js_format,
time_input_js_format,
convert_js_time_format_to_pick_time,
convert_js_date_format_to_pick_date,
)
from NEMO.views.customization import CustomizationBase
from NEMO.views.notifications import get_notification_counts

Expand Down
10 changes: 5 additions & 5 deletions NEMO/templates/mobile/new_reservation.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ <h4>When would you like to reserve the {{ item }}?</h4>
{% for times in item_reservation_times %}
unavailable_times.push([{{ times.start|date:"U" }},{{ times.end|date:"U" }}]);
{% endfor %}
let date_picker = $('#date').pickadate({format: "dddd, mmmm d", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times});
let start_time_picker = $('#start').pickatime({interval: 15, formatSubmit: "H:i", hiddenName: true, formatLabel: format_label});
let end_time_picker = $('#end').pickatime({interval: 15, formatSubmit: "H:i", hiddenName: true, formatLabel: format_label});
let date_picker = $('#date').pickadate({format: "{{ pick_date_format }}", formatSubmit: "yyyy-mm-dd", firstDay: 1, hiddenName: true, onSet: refresh_times});
let start_time_picker = $('#start').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label });
let end_time_picker = $('#end').pickatime({interval: 15, format: "{{ pick_time_format }}", formatSubmit: "H:i", hiddenName: true, formatLabel: format_label});
// set initial date
if ('{{ date|default_if_none:'' }}')
{
Expand All @@ -93,11 +93,11 @@ <h4>When would you like to reserve the {{ item }}?</h4>
let start = times[0];
let end = times[1];
if (date_time_selected >= start && date_time_selected < end) {
return '<sp !an>h:i A</sp !an> <sm !all> !alre!ad!y re!serve!d</sm !all>';
return '<sp !an>{{ pick_time_format }}</sp !an> <sm !all> !alre!ad!y re!serve!d</sm !all>';
}
}
}
return "h:i A";
return "{{ pick_time_format }}";
}

</script>
Expand Down
15 changes: 15 additions & 0 deletions NEMO/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,21 @@ def convert_py_format_to_js(string_format: str) -> str:
return string_format


def convert_js_time_format_to_pick_time(string_format: str) -> str:
return (
string_format.replace("mm", "i")
.replace("m", "i")
.replace("tt", "a")
.replace("t", "a")
.replace("TT", "A")
.replace("T", "A")
)


def convert_js_date_format_to_pick_date(string_format: str) -> str:
return string_format.replace("M", "m").replace("S", "").replace("W", "")


time_input_format = get_format("TIME_INPUT_FORMATS")[0]
date_input_format = get_format("DATE_INPUT_FORMATS")[0]
datetime_input_format = get_format("DATETIME_INPUT_FORMATS")[0]
Expand Down

0 comments on commit e229656

Please sign in to comment.