Commit aad5015a by Don Mitchell

Merge pull request #1398 from MITx/feature/christina/misc2

Fixes date bug (#149).
parents fbd9a126 b613bdc3
...@@ -211,15 +211,15 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -211,15 +211,15 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
'intro_video' : 'course-introduction-video', 'intro_video' : 'course-introduction-video',
'effort' : "course-effort" 'effort' : "course-effort"
}, },
setupDatePicker : function(fieldName) { setupDatePicker: function (fieldName) {
var cacheModel = this.model; var cacheModel = this.model;
var div = this.$el.find('#' + this.fieldToSelectorMap[fieldName]); var div = this.$el.find('#' + this.fieldToSelectorMap[fieldName]);
var datefield = $(div).find(".date"); var datefield = $(div).find(".date");
var timefield = $(div).find(".time"); var timefield = $(div).find(".time");
var cachethis = this; var cachethis = this;
var savefield = function() { var savefield = function () {
cachethis.clearValidationErrors(); cachethis.clearValidationErrors();
var date = datefield.datepicker('getDate'); var date = datefield.datepicker('getDate');
if (date) { if (date) {
var time = timefield.timepicker("getSecondsFromMidnight"); var time = timefield.timepicker("getSecondsFromMidnight");
...@@ -227,21 +227,24 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -227,21 +227,24 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
time = 0; time = 0;
} }
var newVal = new Date(date.getTime() + time * 1000); var newVal = new Date(date.getTime() + time * 1000);
if (cacheModel.get(fieldName) != newVal) cacheModel.save(fieldName, newVal, if (cacheModel.get(fieldName).getTime() !== newVal.getTime()) {
{ error : CMS.ServerError}); cacheModel.save(fieldName, newVal, { error: CMS.ServerError});
}
} }
}; };
// instrument as date and time pickers // instrument as date and time pickers
timefield.timepicker(); timefield.timepicker();
datefield.datepicker();
// FIXME being called 2x on each change. Was trapping datepicker onSelect b4 but change to datepair broke that
datefield.datepicker({ onSelect : savefield }); // Using the change event causes savefield to be triggered twice, but it is necessary
timefield.on('changeTime', savefield); // to pick up when the date is typed directly in the field.
datefield.change(savefield);
datefield.datepicker('setDate', this.model.get(fieldName)); timefield.on('changeTime', savefield);
if (this.model.has(fieldName)) timefield.timepicker('setTime', this.model.get(fieldName));
}, datefield.datepicker('setDate', this.model.get(fieldName));
if (this.model.has(fieldName)) timefield.timepicker('setTime', this.model.get(fieldName));
},
updateModel: function(event) { updateModel: function(event) {
switch (event.currentTarget.id) { switch (event.currentTarget.id) {
...@@ -294,29 +297,30 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -294,29 +297,30 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
} }
}, },
codeMirrors : {}, codeMirrors : {},
codeMirrorize : function(e, forcedTarget) { codeMirrorize: function (e, forcedTarget) {
if (forcedTarget) { var thisTarget;
thisTarget = forcedTarget; if (forcedTarget) {
thisTarget.id = $(thisTarget).attr('id'); thisTarget = forcedTarget;
} else { thisTarget.id = $(thisTarget).attr('id');
thisTarget = e.currentTarget; } else {
} thisTarget = e.currentTarget;
}
if (!this.codeMirrors[thisTarget.id]) { if (!this.codeMirrors[thisTarget.id]) {
var cachethis = this; var cachethis = this;
var field = this.selectorToField[thisTarget.id]; var field = this.selectorToField[thisTarget.id];
this.codeMirrors[thisTarget.id] = CodeMirror.fromTextArea(thisTarget, { this.codeMirrors[thisTarget.id] = CodeMirror.fromTextArea(thisTarget, {
mode: "text/html", lineNumbers: true, lineWrapping: true, mode: "text/html", lineNumbers: true, lineWrapping: true,
onBlur : function(mirror) { onBlur: function (mirror) {
mirror.save(); mirror.save();
cachethis.clearValidationErrors(); cachethis.clearValidationErrors();
var newVal = mirror.getValue(); var newVal = mirror.getValue();
if (cachethis.model.get(field) != newVal) cachethis.model.save(field, newVal, if (cachethis.model.get(field) != newVal) cachethis.model.save(field, newVal,
{ error : CMS.ServerError}); { error: CMS.ServerError});
} }
}); });
} }
} }
}); });
...@@ -668,7 +672,7 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({ ...@@ -668,7 +672,7 @@ CMS.Views.Settings.GraderView = CMS.Views.ValidatingView.extend({
$(event.currentTarget).parent().append( $(event.currentTarget).parent().append(
this.errorTemplate({message : 'For grading to work, you must change all "' + oldName + this.errorTemplate({message : 'For grading to work, you must change all "' + oldName +
'" subsections to "' + this.model.get('type') + '".'})); '" subsections to "' + this.model.get('type') + '".'}));
}; }
break; break;
default: default:
this.saveIfChanged(event); this.saveIfChanged(event);
......
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