Commit aad5015a by Don Mitchell

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

Fixes date bug (#149).
parents fbd9a126 b613bdc3
...@@ -212,13 +212,13 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -212,13 +212,13 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
'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) {
...@@ -227,16 +227,19 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -227,16 +227,19 @@ 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 // Using the change event causes savefield to be triggered twice, but it is necessary
datefield.datepicker({ onSelect : savefield }); // to pick up when the date is typed directly in the field.
datefield.change(savefield);
timefield.on('changeTime', savefield); timefield.on('changeTime', savefield);
datefield.datepicker('setDate', this.model.get(fieldName)); datefield.datepicker('setDate', this.model.get(fieldName));
...@@ -294,7 +297,8 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -294,7 +297,8 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
} }
}, },
codeMirrors : {}, codeMirrors : {},
codeMirrorize : function(e, forcedTarget) { codeMirrorize: function (e, forcedTarget) {
var thisTarget;
if (forcedTarget) { if (forcedTarget) {
thisTarget = forcedTarget; thisTarget = forcedTarget;
thisTarget.id = $(thisTarget).attr('id'); thisTarget.id = $(thisTarget).attr('id');
...@@ -307,12 +311,12 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({ ...@@ -307,12 +311,12 @@ CMS.Views.Settings.Details = CMS.Views.ValidatingView.extend({
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