Commit b81f802b by Chris Dodge

get CodeMirror to work - set the right background in the .scss, make sure the…

get CodeMirror to work - set the right background in the .scss, make sure the textarea is visible before binding it to CodeMirror
parent 130de49b
...@@ -41,7 +41,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -41,7 +41,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
"/static/coffee/src/client_templates/course_info_update.html", "/static/coffee/src/client_templates/course_info_update.html",
function (raw_template) { function (raw_template) {
self.template = _.template(raw_template); self.template = _.template(raw_template);
self.render(); self.render();
} }
); );
}, },
...@@ -68,6 +68,14 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -68,6 +68,14 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
this.collection.add(newModel, {at : 0}); this.collection.add(newModel, {at : 0});
var $newForm = $(this.template({ updateModel : newModel })); var $newForm = $(this.template({ updateModel : newModel }));
var $textArea = $newForm.find(".new-update-content").first();
this.$codeMirror = CodeMirror.fromTextArea($textArea.get(0), {
mode: "text/html",
lineNumbers: true,
lineWrapping: true,
});
var updateEle = this.$el.find("#course-update-list"); var updateEle = this.$el.find("#course-update-list");
$(updateEle).prepend($newForm); $(updateEle).prepend($newForm);
$newForm.addClass('editing'); $newForm.addClass('editing');
...@@ -85,7 +93,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -85,7 +93,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
onSave: function(event) { onSave: function(event) {
var targetModel = this.eventModel(event); var targetModel = this.eventModel(event);
console.log(this.contentEntry(event).val()); console.log(this.contentEntry(event).val());
targetModel.set({ date : this.dateEntry(event).val(), content : this.contentEntry(event).val() }); targetModel.set({ date : this.dateEntry(event).val(), content : this.$codeMirror.getValue() });
// push change to display, hide the editor, submit the change // push change to display, hide the editor, submit the change
this.closeEditor(this); this.closeEditor(this);
targetModel.save(); targetModel.save();
...@@ -102,7 +110,17 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -102,7 +110,17 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
var self = this; var self = this;
this.$currentPost = $(event.target).closest('li'); this.$currentPost = $(event.target).closest('li');
this.$currentPost.addClass('editing'); this.$currentPost.addClass('editing');
$(this.editor(event)).slideDown(150);
$(this.editor(event)).show();
var $textArea = this.$currentPost.find(".new-update-content").first();
if (this.$codeMirror == null ) {
this.$codeMirror = CodeMirror.fromTextArea($textArea.get(0), {
mode: "text/html",
lineNumbers: true,
lineWrapping: true,
});
}
$modalCover.show(); $modalCover.show();
var targetModel = this.eventModel(event); var targetModel = this.eventModel(event);
$modalCover.bind('click', function() { $modalCover.bind('click', function() {
...@@ -218,8 +236,16 @@ CMS.Views.ClassInfoHandoutsView = Backbone.View.extend({ ...@@ -218,8 +236,16 @@ CMS.Views.ClassInfoHandoutsView = Backbone.View.extend({
}, },
onEdit: function(event) { onEdit: function(event) {
var self = this;
this.$editor.val(this.$preview.html()); this.$editor.val(this.$preview.html());
this.$form.show(); this.$form.show();
if (this.$codeMirror == null) {
this.$codeMirror = CodeMirror.fromTextArea(this.$editor.get(0), {
mode: "text/html",
lineNumbers: true,
lineWrapping: true,
});
}
$modalCover.show(); $modalCover.show();
$modalCover.bind('click', function() { $modalCover.bind('click', function() {
self.closeEditor(self); self.closeEditor(self);
...@@ -227,7 +253,7 @@ CMS.Views.ClassInfoHandoutsView = Backbone.View.extend({ ...@@ -227,7 +253,7 @@ CMS.Views.ClassInfoHandoutsView = Backbone.View.extend({
}, },
onSave: function(event) { onSave: function(event) {
this.model.set('data', this.$editor.val()); this.model.set('data', this.$codeMirror.getValue());
this.render(); this.render();
this.model.save(); this.model.save();
this.$form.hide(); this.$form.hide();
......
...@@ -21,6 +21,12 @@ ...@@ -21,6 +21,12 @@
border-radius: 3px 0 0 3px; border-radius: 3px 0 0 3px;
border-right-color: $mediumGrey; border-right-color: $mediumGrey;
} }
.CodeMirror {
border: 1px solid #3c3c3c;
background: #fff;
color: #3c3c3c;
}
} }
.course-updates { .course-updates {
......
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