Skip to content

Commit

Permalink
Merge pull request #445 from ox-it/new-datetime-picker
Browse files Browse the repository at this point in the history
New datetime picker
  • Loading branch information
ahaith committed May 3, 2016
2 parents 794f39f + 0eb7d3c commit 539e14d
Show file tree
Hide file tree
Showing 11 changed files with 3,058 additions and 2,224 deletions.
781 changes: 370 additions & 411 deletions static/css/bootstrap-datetimepicker.css
100644 → 100755

Large diffs are not rendered by default.

4,305 changes: 2,551 additions & 1,754 deletions static/js/bootstrap-datetimepicker.js
100644 → 100755

Large diffs are not rendered by default.

39 changes: 22 additions & 17 deletions static/js/event-form.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
var animationTime = 200; // ms

$(function() {

var today_eleven_am = new Date();
today_eleven_am.setHours(11);

// Register event to show event group forms
$('#id_event-group-enabled').on('change', function(ev) {
if (ev.target.checked) {
Expand All @@ -12,27 +16,28 @@ $(function() {
}
});

var today_eleven_am = new Date();
today_eleven_am.setHours(11);
// Initialise datetimepicker's

$('.js-datetimepicker').datetimepicker({
format: 'dd/mm/yyyy hh:ii',
autoclose: true,
initialDate: today_eleven_am
format: 'DD/MM/YYYY HH:mm',
sideBySide : true,
allowInputToggle : true,
stepping : 5
}).each(function(i,v){
$(v).data("DateTimePicker").ignoreReadonly(true);
if (typeof $('input', v).attr('value') !== 'undefined') {
$(v).data("DateTimePicker").defaultDate(moment($('input', v).attr('value')));
}
else {

}
});

$('#event-start.js-datetimepicker').on('changeDate', function(ev) {
//correct for daylight savings - the widget assumes we're picking in GMT
var date = new Date(ev.date);
var gmt_offset = date.getTimezoneOffset();
date.setMinutes( date.getMinutes() + gmt_offset );
var picker = $(ev.target).data('datetimepicker');
picker.setDate(date);

//set the end time to 1 hour later
var end_date = new Date(date);
date.setHours(date.getHours()+1, date.getMinutes());
$('#event-end.js-datetimepicker').data('datetimepicker').setDate(date);
$('#event-start.js-datetimepicker').on("dp.change", function(e) {
var date = new Date(e.date);
var endDate = date.setHours(date.getHours()+1, date.getMinutes());

$('#event-end.js-datetimepicker').data('DateTimePicker').minDate(e.date).date(moment(endDate));
});

//prepend a message div to the given element, containing the given text.
Expand Down
76 changes: 76 additions & 0 deletions static/js/moment-with-locales.min.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions talks/contributors/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ def valid_value(self, value):
class BootstrappedDateTimeWidget(forms.DateTimeInput):
def render(self, name, value, attrs=None):
html = super(BootstrappedDateTimeWidget, self).render(name, value, attrs)
html = """<div class="input-group date js-datetimepicker" id='""" + name + """'>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
html = """<div class='input-group date js-datetimepicker' id='""" + name + """'>
<span class="input-group-addon">
<span class="glyphicon glyphicon-calendar"></span>
</span>
""" + html + "</div>"

return mark_safe(html)
Expand Down
2 changes: 1 addition & 1 deletion talks/templates/contributors/event_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<!-- Date picker -->
<link href="{% static "css/bootstrap-datetimepicker.css"%}" rel="stylesheet">

<script src="{% static "js/moment-with-locales.min.js"%}"></script>
<script src="{% static "js/bootstrap-datetimepicker.js"%}"></script>

<!-- Typeahead.js -->
Expand Down
2 changes: 1 addition & 1 deletion talks/templates/contributors/event_group_form.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<!-- Date picker -->
<link href="{% static "css/bootstrap-datetimepicker.css"%}" rel="stylesheet">

<script src="{% static "js/moment-with-locales.min.js"%}"></script>
<script src="{% static "js/bootstrap-datetimepicker.js"%}"></script>

<!-- Typeahead.js -->
Expand Down
26 changes: 20 additions & 6 deletions talks/templates/events/browse.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<!-- Date picker -->
<link href="{% static "css/bootstrap-datetimepicker.css"%}" rel="stylesheet">

<script src="{% static "js/moment-with-locales.min.js"%}"></script>
<script src="{% static "js/bootstrap-datetimepicker.js"%}"></script>

<!-- Typeahead.js -->
Expand Down Expand Up @@ -40,7 +40,7 @@ <h3>Filters</h3>
<ul class="nav nav-list well">
<form action="{% url 'browse_events' %}" method="get">
{{ browse_events_form.start_date | bootstrap }}
<a class="clear-datepicker pull-right" href="#">clear</a>
<a id="clear-datepicker" class="pull-right" href="#">clear</a>
{{ browse_events_form.to | bootstrap }}
{{ browse_events_form.organising_department | bootstrap }}
{{ browse_events_form.include_subdepartments | bootstrap }}
Expand All @@ -52,12 +52,26 @@ <h3>Filters</h3>
</form>

<script type="text/javascript">
$(function() {



$(document).ready(function(){

$('#clear-datepicker').click(function(e){
$('#to').data("DateTimePicker").clear();
});

$('.js-datetimepicker').datetimepicker({
format: 'yyyy-mm-dd',
minView: 2,
autoclose: true
format : 'YYYY-MM-DD',
allowInputToggle : true
}).each(function(i,v){
$(v).data("DateTimePicker").ignoreReadonly(true);
});

$('#start_date').on('dp.change', function(e){
$('#to').data('DateTimePicker').minDate(e.date);
});

});
</script>

Expand Down
30 changes: 8 additions & 22 deletions tests/add_talk.robot
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,9 @@ Scenario: Add the simplest talk
type "something" into ${title field}
type "something else" into ${abstract field}
click on ${start field}
${datetimepicker[0]} should appear
Select current date and time for ${datetimepicker[0]}
${datetimepicker[0]} should disappear
Select current date and time for ${datetimepicker}
click on ${end field}
${datetimepicker[1]} should appear
Select current date and time for ${datetimepicker[1]}
${datetimepicker[1]} should disappear
Select current date and time for ${datetimepicker}
click on ${button done}
current page should be ${talk page}
${success message} should be displayed
Expand All @@ -41,13 +37,9 @@ Scenario: Add talk to existing group of talks
Select from list ${group field.locator} foo
page should appear text "Chemical Biology"
click on ${start field}
${datetimepicker[0]} should appear
Select current date and time for ${datetimepicker[0]}
${datetimepicker[0]} should disappear
Select current date and time for ${datetimepicker}
click on ${end field}
${datetimepicker[1]} should appear
Select current date and time for ${datetimepicker[1]}
${datetimepicker[1]} should disappear
Select current date and time for ${datetimepicker}
click on ${button done}
${success message} should appear
${success message} should contain text "New talk has been created"
Expand Down Expand Up @@ -197,13 +189,9 @@ Scenario: Save and add another
go to ${add talk page}
type "something" into ${title field}
click on ${start field}
${datetimepicker[0]} should appear
Select current date and time for ${datetimepicker[0]}
${datetimepicker[0]} should disappear
Select current date and time for ${datetimepicker}
click on ${end field}
${datetimepicker[1]} should appear
Select current date and time for ${datetimepicker[1]}
${datetimepicker[1]} should disappear
Select current date and time for ${datetimepicker}
click on ${button save add another}
current page should be ${add talk page}
${success message} should be displayed
Expand Down Expand Up @@ -267,8 +255,6 @@ Scenario: Preserve form data after validation
Fill in required fields
type "${TEST_NAME}" into ${field('Title')}
click on ${start field}
${datetimepicker[0]} should appear
Select current date and time for ${datetimepicker[0]}
Select current date and time for ${datetimepicker}
click on ${end field}
${datetimepicker[1]} should appear
Select current date and time for ${datetimepicker[1]}
Select current date and time for ${datetimepicker}
4 changes: 1 addition & 3 deletions tests/keywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,8 @@ ${element} selected item should be "${label}"
should be equal ${v} ${label}

Select current date and time for ${widget}
${widget} should appear
click on ${datetimepicker current day.in_('widget')}
click on ${datetimepicker current hour.in_('widget')}
click on ${datetimepicker current minute.in_('widget')}
click on ${body}

Login as ${username} ${password}
go to ${login_page}
Expand Down
9 changes: 4 additions & 5 deletions tests/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def in_(self, other):
show_talk_page = lambda slug: Page('/talks/id/%s/' % slug)

# elements

body = Element('//body')
abstract_field = Element('css=#id_event-description')
title_field = Element('css=#id_event-title')
start_field = Element('css=#id_event-start')
Expand All @@ -84,10 +84,9 @@ def in_(self, other):
modal_dialog = Element('//*[@id="form-modal"]')
modal_dialog_title = Element('//*[@id="form-modal-label"]')
modal_dialog_submit_button = Element('//*[@id="form-modal"]//input[@type="submit"]')
datetimepicker = Element('//div[contains(@class,"datetimepicker ")]')
datetimepicker_current_day = Element('//*[@class="datetimepicker-days"]//*[contains(@class, "active")]')
datetimepicker_current_hour = Element('//*[@class="datetimepicker-hours"]//*[contains(@class, "active")]')
datetimepicker_current_minute = Element('//*[@class="datetimepicker-minutes"]//*[contains(@class, "active")]')
datetimepicker = Element('css=.bootstrap-datetimepicker-widget')
datetimepicker_current_day = Element('css=.datepicker-days')
datetimepicker_time = Element('css=.timepicker-picker')
button_login = Element('//input[@type="submit"]')
username_field = Element('css=#id_username')
password_field = Element('css=#id_password')
Expand Down

0 comments on commit 539e14d

Please sign in to comment.