diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index 91eace9fe3..cbd27135f3 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -863,3 +863,39 @@ class EditAMoleculeInput(InputTypeBase): return context registry.register(EditAMoleculeInput) + +#----------------------------------------------------------------------------- + +class DesignProtein2dInput(InputTypeBase): + """ + An input type for design of a protein in 2D. Integrates with the Protex java applet. + + Example: + + + """ + + template = "designprotein2dinput.html" + tags = ['designprotein2dinput'] + + @classmethod + def get_attributes(cls): + """ + Note: width, hight, and target_shape are required. + """ + return [Attribute('width'), + Attribute('height'), + Attribute('target_shape') + ] + + def _extra_context(self): + """ + """ + context = { + 'applet_loader': '/static/js/capa/design-protein-2d.js', + } + + return context + +registry.register(DesignProtein2dInput) + diff --git a/common/lib/capa/capa/responsetypes.py b/common/lib/capa/capa/responsetypes.py index b25f429ffa..4aae384f72 100644 --- a/common/lib/capa/capa/responsetypes.py +++ b/common/lib/capa/capa/responsetypes.py @@ -188,7 +188,7 @@ class LoncapaResponse(object): # problem author can make this span display:inline if self.xml.get('inline',''): tree.set('class','inline') - + for item in self.xml: # call provided procedure to do the rendering item_xhtml = renderer(item) @@ -875,7 +875,8 @@ def sympy_check2(): allowed_inputfields = ['textline', 'textbox', 'crystallography', 'chemicalequationinput', 'vsepr_input', - 'drag_and_drop_input', 'editamoleculeinput'] + 'drag_and_drop_input', 'editamoleculeinput', + 'designprotein2dinput'] def setup_response(self): xml = self.xml diff --git a/common/lib/capa/capa/templates/designprotein2dinput.html b/common/lib/capa/capa/templates/designprotein2dinput.html new file mode 100644 index 0000000000..7b1c6b6f41 --- /dev/null +++ b/common/lib/capa/capa/templates/designprotein2dinput.html @@ -0,0 +1,39 @@ +
+
+ + % if status == 'unsubmitted': +
+ % elif status == 'correct': +
+ % elif status == 'incorrect': +
+ % elif status == 'incomplete': +
+ % endif + + + + + + Applet failed to run. No Java plug-in was found. + + + + +

+ % if status == 'unsubmitted': + unanswered + % elif status == 'correct': + correct + % elif status == 'incorrect': + incorrect + % elif status == 'incomplete': + incomplete + % endif +

+ +

+ % if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']: +
+% endif +
diff --git a/common/static/applets/capa/Protex.jar b/common/static/applets/capa/Protex.jar new file mode 100644 index 0000000000..2c6a819ec5 Binary files /dev/null and b/common/static/applets/capa/Protex.jar differ diff --git a/common/static/js/capa/design-protein-2d.js b/common/static/js/capa/design-protein-2d.js new file mode 100644 index 0000000000..e4e37995d3 --- /dev/null +++ b/common/static/js/capa/design-protein-2d.js @@ -0,0 +1,27 @@ +(function () { + var timeout = 1000; + + function initializeApplet(applet) { + console.log("Initializing " + applet); + waitForApplet(applet); + } + + function waitForApplet(applet) { + if (applet.isActive && applet.isActive()) { + console.log("Applet is ready."); + var answerStr = applet.checkAnswer(); + console.log(answerStr); + var input = $('.designprotein2dinput input'); + console.log(input); + input.val(answerStr); + } else if (timeout > 30 * 1000) { + console.error("Applet did not load on time."); + } else { + console.log("Waiting for applet..."); + setTimeout(function() { waitForApplet(applet); }, timeout); + } + } + + var applets = $('.designprotein2dinput object'); + applets.each(function(i, el) { initializeApplet(el); }); +}).call(this);