Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion common/lib/capa/capa/inputtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def _extra_context(self):
'queue_len': str(self.queue_len),
'queue_msg': self.queue_msg,
'button_enabled': self.button_enabled(),
'matlab_editor_js': '{static_url}js/vendor/CodeMirror/addons/octave.js'.format(
'matlab_editor_js': '{static_url}js/vendor/CodeMirror/octave.js'.format(
static_url=self.capa_system.STATIC_URL),
}
return extra_context
Expand Down Expand Up @@ -961,6 +961,15 @@ def get_attributes(cls):
Attribute('label', ''),
]

def _extra_context(self):
"""
"""
context = {
'setup_script': '{static_url}js/capa/schematicinput.js'.format(
static_url=self.capa_system.STATIC_URL),
}

return context

#-----------------------------------------------------------------------------

Expand Down
27 changes: 16 additions & 11 deletions common/lib/capa/capa/templates/schematicinput.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
<span>
<input type="hidden" class="schematic" height="${height}" width="${width}" parts="${parts}" analyses="${analyses}" name="input_${id}" id="input_${id}" aria-label="${label}" aria-describedby="answer_${id}" value="" initial_value=""/>

<div id="value_${id}" style="display:none">${value}</div>
<div id="initial_value_${id}" style="display:none">${initial_value}</div>
<div id="submit_value_${id}" style="display:none">${submit_analyses}</div>

<script>
$("#input_${id}").attr("value",$("#value_${id}").text());
$("#input_${id}").attr("initial_value",$("#initial_value_${id}").text());
$("#input_${id}").attr("submit_analyses",$("#submit_value_${id}").text());
</script>
<div class="script_placeholder" data-src="${setup_script}"/>
<input type="hidden"
class="schematic"
height="${height}"
width="${width}"
parts="${parts}"
analyses="${analyses}"
name="input_${id}"
id="input_${id}"
aria-label="${label}"
aria-describedby="answer_${id}"
value="${value|h}"
initial_value="${initial_value|h}"
submit_analyses="${submit_analyses|h}"
/>

<span id="answer_${id}"></span>
% if status == 'unsubmitted':
Expand All @@ -29,5 +33,6 @@
<span class="sr">Status: incomplete</span>
</span>
% endif

</span>

11 changes: 6 additions & 5 deletions common/lib/capa/capa/tests/test_inputtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ def test_rendering(self):
'tabsize': int(self.tabsize),
'button_enabled': True,
'queue_len': '3',
'matlab_editor_js': '/dummy-static/js/vendor/CodeMirror/addons/octave.js',
'matlab_editor_js': '/dummy-static/js/vendor/CodeMirror/octave.js',
}

self.assertEqual(context, expected)
Expand Down Expand Up @@ -486,7 +486,7 @@ def test_rendering_with_state(self):
'tabsize': int(self.tabsize),
'button_enabled': True,
'queue_len': '3',
'matlab_editor_js': '/dummy-static/js/vendor/CodeMirror/addons/octave.js',
'matlab_editor_js': '/dummy-static/js/vendor/CodeMirror/octave.js',
}

self.assertEqual(context, expected)
Expand Down Expand Up @@ -519,7 +519,7 @@ def test_rendering_when_completed(self):
'tabsize': int(self.tabsize),
'button_enabled': False,
'queue_len': '0',
'matlab_editor_js': '/dummy-static/js/vendor/CodeMirror/addons/octave.js',
'matlab_editor_js': '/dummy-static/js/vendor/CodeMirror/octave.js',
}

self.assertEqual(context, expected)
Expand Down Expand Up @@ -551,7 +551,7 @@ def test_rendering_while_queued(self):
'tabsize': int(self.tabsize),
'button_enabled': True,
'queue_len': '1',
'matlab_editor_js': '/dummy-static/js/vendor/CodeMirror/addons/octave.js',
'matlab_editor_js': '/dummy-static/js/vendor/CodeMirror/octave.js',
}

self.assertEqual(context, expected)
Expand Down Expand Up @@ -617,7 +617,7 @@ def test_get_html(self):
output = self.the_input.get_html()
self.assertEqual(
etree.tostring(output),
"""<div>{\'status\': \'queued\', \'button_enabled\': True, \'linenumbers\': \'true\', \'rows\': \'10\', \'queue_len\': \'3\', \'mode\': \'\', \'cols\': \'80\', \'value\': \'print "good evening"\', \'status_class\': \'processing\', \'queue_msg\': \'\', \'STATIC_URL\': \'/dummy-static/\', \'msg\': u\'Submitted. As soon as a response is returned, this message will be replaced by that feedback.\', \'matlab_editor_js\': \'/dummy-static/js/vendor/CodeMirror/addons/octave.js\', \'hidden\': \'\', \'status_display\': u\'queued\', \'id\': \'prob_1_2\', \'tabsize\': 4}</div>"""
"""<div>{\'status\': \'queued\', \'button_enabled\': True, \'linenumbers\': \'true\', \'rows\': \'10\', \'queue_len\': \'3\', \'mode\': \'\', \'cols\': \'80\', \'value\': \'print "good evening"\', \'status_class\': \'processing\', \'queue_msg\': \'\', \'STATIC_URL\': \'/dummy-static/\', \'msg\': u\'Submitted. As soon as a response is returned, this message will be replaced by that feedback.\', \'matlab_editor_js\': \'/dummy-static/js/vendor/CodeMirror/octave.js\', \'hidden\': \'\', \'status_display\': u\'queued\', \'id\': \'prob_1_2\', \'tabsize\': 4}</div>"""
)

# test html, that is correct HTML5 html, but is not parsable by XML parser.
Expand Down Expand Up @@ -693,6 +693,7 @@ def test_rendering(self):
'width': width,
'height': height,
'parts': parts,
'setup_script': '/dummy-static/js/capa/schematicinput.js',
'analyses': analyses,
'submit_analyses': submit_analyses,
}
Expand Down
58 changes: 58 additions & 0 deletions common/static/js/capa/schematicinput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var schematic_height = 220;
var schematic_width = 400;
var styling_height_delta = 2; //How many pixels are added to the height of the box because of styling (like a shadow)
var styling_width_delta = 2;

$(function() {
// TODO: someone should fix all of this...
//$("a[rel*=leanModal]").leanModal(); //TODO: Make this work with the new modal library. Try and integrate this with the "slices"

$("body").append('\
<div id="circuit_editor_modal" class="modal hide fade"> \
<div class="modal-body"> \
<input class="schematic" height="300" width="500" id="schematic_editor" name="schematic" type="hidden" value=""/> \
</div> \
<div class="modal-footer"> \
<button type="button" id="circuit_save_btn" class="btn btn-primary" data-dismiss="modal"> \
Save circuit \
</button> \
</div> \
</div>');

//This is the editor that pops up as a modal
var editorCircuit = $("#schematic_editor").get(0);
//This is the circuit that they last clicked. The one being edited.
var editingCircuit = null;
//Notice we use live, because new circuits can be inserted
$(".schematic_open").live("click", function() {
//Find the new editingCircuit. Transfer its contents to the editorCircuit
editingCircuit = $(this).children("input.schematic").get(0);

editingCircuit.schematic.update_value();
var circuit_so_far = $(editingCircuit).val();

var n = editorCircuit.schematic.components.length;
for (var i = 0; i < n; i++)
editorCircuit.schematic.components[n - 1 - i].remove();

editorCircuit.schematic.load_schematic(circuit_so_far, "");
editorCircuit.schematic.zoomall();
});

$("#circuit_save_btn").click(function () {
//Take the circuit from the editor and put it back into editingCircuit
editorCircuit.schematic.update_value();
var saving_circuit = $(editorCircuit).val();

var n = editingCircuit.schematic.components.length;
for (var i = 0; i < n; i++)
editingCircuit.schematic.components[n - 1 - i].remove();

editingCircuit.schematic.load_schematic(saving_circuit, "");
editingCircuit.schematic.zoomall();

if (editingCircuit.codeMirrorLine) {
editingCircuit.codeMirrorLine.replace(0, null, "circuit-schematic:" + saving_circuit);
}
});
});
64 changes: 0 additions & 64 deletions common/static/js/vendor/CodeMirror/addons/edx_markdown.js
Original file line number Diff line number Diff line change
@@ -1,67 +1,3 @@
var schematic_height = 220;
var schematic_width = 400;
var styling_height_delta = 2; //How many pixels are added to the height of the box because of styling (like a shadow)
var styling_width_delta = 2;

var schematic_editor_height = 300;
var schematic_editor_width = 500;

$(function(){
$(document).ready(function() {
//$("a[rel*=leanModal]").leanModal(); //TODO: Make this work with the new modal library. Try and integrate this with the "slices"

$("body").append('\
<div id="circuit_editor_modal" class="modal hide fade"> \
<div class="modal-body"> \
<input class="schematic" height="' + schematic_editor_height + '" width="' + schematic_editor_width + '" id="schematic_editor" name="schematic" type="hidden" value=""/> \
</div> \
<div class="modal-footer"> \
<button type="button" id="circuit_save_btn" class="btn btn-primary" data-dismiss="modal"> \
Save circuit \
</button> \
</div> \
</div>');

//This is the editor that pops up as a modal
var editorCircuit = $("#schematic_editor").get(0);
//This is the circuit that they last clicked. The one being edited.
var editingCircuit = null;
//Notice we use live, because new circuits can be inserted
$(".schematic_open").live("click", function() {
//Find the new editingCircuit. Transfer its contents to the editorCircuit
editingCircuit = $(this).children("input.schematic").get(0);

editingCircuit.schematic.update_value();
var circuit_so_far = $(editingCircuit).val();

var n = editorCircuit.schematic.components.length;
for (var i = 0; i < n; i++)
editorCircuit.schematic.components[n - 1 - i].remove();

editorCircuit.schematic.load_schematic(circuit_so_far, "");
editorCircuit.schematic.zoomall();
});

$("#circuit_save_btn").click(function () {
//Take the circuit from the editor and put it back into editingCircuit
editorCircuit.schematic.update_value();
var saving_circuit = $(editorCircuit).val();

var n = editingCircuit.schematic.components.length;
for (var i = 0; i < n; i++)
editingCircuit.schematic.components[n - 1 - i].remove();

editingCircuit.schematic.load_schematic(saving_circuit, "");
editingCircuit.schematic.zoomall();

if (editingCircuit.codeMirrorLine) {
editingCircuit.codeMirrorLine.replace(0, null, "circuit-schematic:" + saving_circuit);
}
});
});
});


CodeMirror.defineMode("edx_markdown", function(cmCfg, modeCfg) {

var htmlFound = CodeMirror.mimeModes.hasOwnProperty("text/html");
Expand Down
4 changes: 2 additions & 2 deletions common/static/js/vendor/codemirror-compressed.js

Large diffs are not rendered by default.