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) {
$("#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) {
if (date_val != '') {
if (time_val == '') time_val = '00:00';
......@@ -772,21 +778,23 @@ function cancelSetSectionScheduleDate(e) {
function saveSetSectionScheduleDate(e) {
e.preventDefault();
var input_date = $('.edit-subsection-publish-settings .start-date').val();
var input_time = $('.edit-subsection-publish-settings .start-time').val();
var start = getEdxTimeFromDateTimeVals(input_date, input_time);
var date = $('.edit-subsection-publish-settings .start-date').datepicker("getDate");
var time = $('.edit-subsection-publish-settings .start-time').timepicker("getTime");
var datetime = new Date(Date.UTC(
date.getFullYear(), date.getMonth(), date.getDate(),
time.getHours(), time.getMinutes()
));
var id = $modal.attr('data-id');
analytics.track('Edited Section Release Date', {
'course': course_location_analytics,
'id': id,
'start': start
'start': datetime
});
var saving = new CMS.Views.Notification.Mini({
title: gettext("Saving") + "&hellip;",
title: gettext("Saving") + "&hellip;"
});
saving.show();
// call into server to commit the new order
......@@ -798,7 +806,7 @@ function saveSetSectionScheduleDate(e) {
data: JSON.stringify({
'id': id,
'metadata': {
'start': start
'start': datetime
}
})
}).success(function() {
......@@ -806,12 +814,15 @@ function saveSetSectionScheduleDate(e) {
var html = _.template(
'<span class="published-status">' +
'<strong>' + gettext("Will Release:") + '&nbsp;</strong>' +
gettext("<%= date %> at <%= time %> UTC") +
gettext("{month}/{day}/{year} at {hour}:{minute} UTC") +
'</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") +
'</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);
hideModal();
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