Commit 2445845d by David Baumgold

Make sure that we properly parse and save section release times

Firefox wasn't saving section release times, due to issues with JS Date() parsing.
I've modified the code to make it more explicit around what it should do and how
it should work, which also makes it work better with both Firefox and Chrome.
parent 55b68168
...@@ -253,6 +253,12 @@ function syncReleaseDate(e) { ...@@ -253,6 +253,12 @@ function syncReleaseDate(e) {
$("#start_time").val(""); $("#start_time").val("");
} }
function pad2(number) {
// pad a number to two places: useful for formatting months, days, hours, etc
// when displaying a date/time
return (number < 10 ? '0' : '') + number;
}
function getEdxTimeFromDateTimeVals(date_val, time_val) { function getEdxTimeFromDateTimeVals(date_val, time_val) {
if (date_val != '') { if (date_val != '') {
if (time_val == '') time_val = '00:00'; if (time_val == '') time_val = '00:00';
...@@ -772,21 +778,23 @@ function cancelSetSectionScheduleDate(e) { ...@@ -772,21 +778,23 @@ function cancelSetSectionScheduleDate(e) {
function saveSetSectionScheduleDate(e) { function saveSetSectionScheduleDate(e) {
e.preventDefault(); e.preventDefault();
var input_date = $('.edit-subsection-publish-settings .start-date').val(); var date = $('.edit-subsection-publish-settings .start-date').datepicker("getDate");
var input_time = $('.edit-subsection-publish-settings .start-time').val(); var time = $('.edit-subsection-publish-settings .start-time').timepicker("getTime");
var datetime = new Date(Date.UTC(
var start = getEdxTimeFromDateTimeVals(input_date, input_time); date.getFullYear(), date.getMonth(), date.getDate(),
time.getHours(), time.getMinutes()
));
var id = $modal.attr('data-id'); var id = $modal.attr('data-id');
analytics.track('Edited Section Release Date', { analytics.track('Edited Section Release Date', {
'course': course_location_analytics, 'course': course_location_analytics,
'id': id, 'id': id,
'start': start 'start': datetime
}); });
var saving = new CMS.Views.Notification.Mini({ var saving = new CMS.Views.Notification.Mini({
title: gettext("Saving") + "&hellip;", title: gettext("Saving") + "&hellip;"
}); });
saving.show(); saving.show();
// call into server to commit the new order // call into server to commit the new order
...@@ -798,7 +806,7 @@ function saveSetSectionScheduleDate(e) { ...@@ -798,7 +806,7 @@ function saveSetSectionScheduleDate(e) {
data: JSON.stringify({ data: JSON.stringify({
'id': id, 'id': id,
'metadata': { 'metadata': {
'start': start 'start': datetime
} }
}) })
}).success(function() { }).success(function() {
...@@ -806,12 +814,15 @@ function saveSetSectionScheduleDate(e) { ...@@ -806,12 +814,15 @@ function saveSetSectionScheduleDate(e) {
var html = _.template( var html = _.template(
'<span class="published-status">' + '<span class="published-status">' +
'<strong>' + gettext("Will Release:") + '&nbsp;</strong>' + '<strong>' + gettext("Will Release:") + '&nbsp;</strong>' +
gettext("<%= date %> at <%= time %> UTC") + gettext("{month}/{day}/{year} at {hour}:{minute} UTC") +
'</span>' + '</span>' +
'<a href="#" class="edit-button" data-date="<%= date %>" data-time="<%= time %>" data-id="<%= id %>">' + '<a href="#" class="edit-button" data-date="{month}/{day}/{year}" data-time="{hour}:{minute}" data-id="{id}">' +
gettext("Edit") + gettext("Edit") +
'</a>', '</a>',
{date: input_date, time: input_time, id: id}); {year: datetime.getUTCFullYear(), month: pad2(datetime.getUTCMonth() + 1), day: pad2(datetime.getUTCDate()),
hour: pad2(datetime.getUTCHours()), minute: pad2(datetime.getUTCMinutes()),
id: id},
{interpolate: /\{(.+?)\}/g});
$thisSection.find('.section-published-date').html(html); $thisSection.find('.section-published-date').html(html);
hideModal(); hideModal();
saving.hide(); saving.hide();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment