Commit 039160f5 by cahrens

Beginning of CodeMirror.

parent ac732f6b
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<div class="value"> <div class="value">
<label for="course-advanced-policy-value">Policy Value:</label> <label for="course-advanced-policy-value">Policy Value:</label>
<div class="field"> <div class="field">
<div class="ace text" id="course-advanced-policy-value"><%= value %></div> <textarea class="json text" id="course-advanced-policy-value"><%= value %></textarea>
</div> </div>
</div> </div>
</div> <a href="#" class="delete-button standard remove-item advanced-policy-data"> </div> <a href="#" class="delete-button standard remove-item advanced-policy-data">
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
if (typeof window.templateLoader == 'function') return; if (typeof window.templateLoader == 'function') return;
var templateLoader = { var templateLoader = {
templateVersion: "0.0.14", templateVersion: "0.0.15",
templates: {}, templates: {},
loadRemoteTemplate: function(templateName, filename, callback) { loadRemoteTemplate: function(templateName, filename, callback) {
if (!this.templates[templateName]) { if (!this.templates[templateName]) {
......
...@@ -47,29 +47,28 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ ...@@ -47,29 +47,28 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
listEle$.append(self.template({ key : key, value : JSON.stringify(self.model.get(key))})); listEle$.append(self.template({ key : key, value : JSON.stringify(self.model.get(key))}));
self.fieldToSelectorMap[key] = key; self.fieldToSelectorMap[key] = key;
}); });
var policyValueDivs = listEle$.find('.ace'); var policyValues = listEle$.find('.json');
_.each(policyValueDivs, this.attachAce, this); _.each(policyValues, this.attachJSONEditor, this);
this.showMessage(); this.showMessage();
return this; return this;
}, },
attachAce : function (div) { attachJSONEditor : function (textarea) {
var self = this; var self = this;
var editor = ace.edit(div); CodeMirror.fromTextArea(textarea, {
editor.setTheme("ace/theme/chrome"); mode: "text/html", lineNumbers: true, lineWrapping: true,
editor.setHighlightActiveLine(false); onBlur: function (mirror) {
editor.on("blur", var key = $(mirror.getWrapperElement()).closest('.row').children('.key').attr('id');
function (e) { mirror.save();
var key = $(editor.container).closest('.row').children('.key').attr('id'); var quotedValue = mirror.getValue();
// TODO: error checking in case it does not parse!
var quotedValue = editor.getValue();
var JSONValue = JSON.parse(quotedValue); var JSONValue = JSON.parse(quotedValue);
self.model.set(key, JSONValue, {validate: true}); self.model.set(key, JSONValue, {validate: true});
self.showMessage(self.unsaved_changes); self.showMessage(self.unsaved_changes);
// cachethis.clearValidationErrors();
}); // var newVal = mirror.getValue();
// Calling getSession() directly in render causes a crash on Chrome. // if (cachethis.model.get(field) != newVal) cachethis.model.save(field, newVal,
// Seems to be OK in afterRender method. // { error: CMS.ServerError});
editor.getSession().setMode("ace/mode/json"); }
});
}, },
showMessage: function (type) { showMessage: function (type) {
...@@ -140,7 +139,7 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ ...@@ -140,7 +139,7 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
// need to refind b/c replaceWith seems to copy rather than use the specific ele instance // need to refind b/c replaceWith seems to copy rather than use the specific ele instance
var policyValueDivs = this.$el.find('#' + this.new_key).closest('li').find('.ace'); var policyValueDivs = this.$el.find('#' + this.new_key).closest('li').find('.ace');
// only 1 but hey, let's take advantage of the context mechanism // only 1 but hey, let's take advantage of the context mechanism
_.each(policyValueDivs, this.attachAce, this); _.each(policyValueDivs, this.attachJSONEditor, this);
this.showMessage(this.unsaved_changes); this.showMessage(this.unsaved_changes);
}, },
updateKey : function(event) { updateKey : function(event) {
...@@ -205,7 +204,7 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({ ...@@ -205,7 +204,7 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
// need to refind b/c replaceWith seems to copy rather than use the specific ele instance // need to refind b/c replaceWith seems to copy rather than use the specific ele instance
var policyValueDivs = this.$el.find('#' + newKey).closest('li').find('.ace'); var policyValueDivs = this.$el.find('#' + newKey).closest('li').find('.ace');
// only 1 but hey, let's take advantage of the context mechanism // only 1 but hey, let's take advantage of the context mechanism
_.each(policyValueDivs, this.attachAce, this); _.each(policyValueDivs, this.attachJSONEditor, this);
this.fieldToSelectorMap[newKey] = newKey; this.fieldToSelectorMap[newKey] = newKey;
this.showMessage(this.unsaved_changes); this.showMessage(this.unsaved_changes);
......
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