Commit 9bc25ff3 by Carlos Andrés Rocha Committed by Victor Shnayder

Replace editamolecule input type applet with GWT version

parent ab9bd4b8
<section id="editamoleculeinput_${id}" class="editamoleculeinput"> <section id="editamoleculeinput_${id}" class="editamoleculeinput">
<div class="script_placeholder" data-src="/static/js/capa/jsmolcalc/jsmolcalc.nocache.js"/> <div class="script_placeholder" data-src="/static/js/capa/jsmolcalc/jsmolcalc.nocache.js"/>
<div class="script_placeholder" data-src="${applet_loader}"/> <div class="script_placeholder" data-src="/static/js/capa/jsme/jsme_export.nocache.js"/>
<div class="script_placeholder" data-src="${applet_loader}"/>
% if status == 'unsubmitted': % if status == 'unsubmitted':
<div class="unanswered" id="status_${id}"> <div class="unanswered" id="status_${id}">
% elif status == 'correct': % elif status == 'correct':
<div class="correct" id="status_${id}"> <div class="correct" id="status_${id}">
% elif status == 'incorrect': % elif status == 'incorrect':
<div class="incorrect" id="status_${id}"> <div class="incorrect" id="status_${id}">
% elif status == 'incomplete': % elif status == 'incomplete':
<div class="incorrect" id="status_${id}"> <div class="incorrect" id="status_${id}">
% endif % endif
<object type="application/x-java-applet" id="applet_${id}" class="applet" height="400" width="500"> <div id="applet_${id}" class="applet" data-molfile-src="${file}" style="display:block;width:500px;height:400px">
<param name="archive" value="/static/applets/capa/editamolecule/JME.jar" /> </div>
<param name="code" value="JME.class" />
<param name="molfile" value="${file}" />
Applet failed to run. No Java plug-in was found.
</object>
<br/>
<input type="hidden" name="input_${id}" id="input_${id}" value="${value|h}"/> <input type="hidden" name="input_${id}" id="input_${id}" value="${value|h}"/>
<button id="reset_${id}" class="reset">Reset</button>
<p id="answer_${id}" class="answer"></p>
<p class="status"> <p class="status">
% if status == 'unsubmitted': % if status == 'unsubmitted':
unanswered unanswered
...@@ -33,11 +35,6 @@ ...@@ -33,11 +35,6 @@
incomplete incomplete
% endif % endif
</p> </p>
<br/>
<button id="reset_${id}" class="reset">Reset</button>
<p id="answer_${id}" class="answer"></p>
% if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']: % if status in ['unsubmitted', 'correct', 'incorrect', 'incomplete']:
</div> </div>
% endif % endif
......
(function () { (function () {
var timeout = 100; var timeout = 100;
waitForJSMolCalc(); // Simple "lock" to prevent applets from being initialized more than once
if (typeof(_editamolecule_lock) == 'undefined' || _editamolecule_lock == false) {
_editamolecule_lock = true;
waitForGWT();
} else {
return;
}
// FIXME: [rocha] jsmolcalc and jsmol.API should be initialized // FIXME: [rocha] jsme and jsmolcalc are not initialized automatically by
// automatically by the GWT script loader. However, it is not // the GWT script loader. To fix this, wait for the scripts to load, initialize
// working correcly when including them inside the // them manually and wait until they are ready
// courseware. function waitForGWT() {
function waitForJSMolCalc() {
if (typeof(jsmolcalc) != "undefined" && jsmolcalc) if (typeof(jsmolcalc) != "undefined" && jsmolcalc)
{ {
// FIXME: [rocha] this should be called automatically by
// GWT at the end of the loader. However it is not.
jsmolcalc.onInjectionDone('jsmolcalc'); jsmolcalc.onInjectionDone('jsmolcalc');
} }
if (typeof(jsmol) != "undefined") { if (typeof(jsme_export) != "undefined" && jsme_export)
{
// dummy function called by jsme_export
window.jsmeOnLoad = function() {};
jsme_export.onInjectionDone('jsme_export');
}
// jsmol is defined my jsmolcalc and JavaScriptApplet is defined by jsme
if (typeof(jsmol) != 'undefined' && typeof(JavaScriptApplet) != 'undefined') {
// ready, initialize applets // ready, initialize applets
initializeApplets(); initializeApplets();
_editamolecule_lock = false; // release lock, for reloading
} else { } else {
setTimeout(function() { waitForJSMolCalc(); }, timeout); setTimeout(waitForGWT, timeout);
} }
} }
function initializeApplets() { function initializeApplets() {
var applets = $('.editamoleculeinput object'); var applets = $('.editamoleculeinput div.applet');
applets.each(function(i, element) { applets.each(function(i, element) {
var applet = $(element); if (!$(element).hasClass('loaded')) {
if (!applet.hasClass('initialized')) { var applet = new JavaScriptApplet.JSME(
applet.addClass("initialized"); element.id,
waitForApplet(applet, configureApplet); $(element).width(),
$(element).height(),
{
"options" : "query, hydrogens"
});
$(element).addClass('loaded');
configureApplet(element, applet);
} }
}); });
} }
function waitForApplet(applet, callback) { function configureApplet(element, applet) {
if (applet[0].isActive && applet[0].isActive()) {
callback(applet);
} else {
setTimeout(function() {
waitForApplet(applet, callback); }, timeout);
}
}
function configureApplet(applet) {
// Traverse up the DOM tree and get the other relevant elements // Traverse up the DOM tree and get the other relevant elements
var parent = applet.parent(); var parent = $(element).parent();
var input_field = parent.find('input[type=hidden]'); var input_field = parent.find('input[type=hidden]');
var reset_button = parent.find('button.reset'); var reset_button = parent.find('button.reset');
console.log(input_field.toArray()); // Applet options
console.log(input_field.toArray().length); applet.setAntialias(true);
// Load initial data // Load initial data
var value = input_field.val(); var value = input_field.val();
value = false;
if (value) { if (value) {
console.log('loading old');
var data = JSON.parse(value)["mol"]; var data = JSON.parse(value)["mol"];
console.log(data);
loadAppletData(applet, data, input_field); loadAppletData(applet, data, input_field);
} else { } else {
console.log('loading preset'); requestAppletData(element, applet, input_field);
requestAppletData(applet, input_field);
} }
reset_button.on('click', function() { reset_button.on('click', function() {
console.log('reseting'); requestAppletData(element, applet, input_field);
requestAppletData(applet, input_field);
}); });
// FIXME: [rocha] This is a hack to capture the click on the check // Update the input element everytime the is an interaction
// button and update the hidden field with the applet values // with the applet (click, drag, etc)
var problem = applet.parents('.problem'); $(element).on('mouseup', function() {
var check_button = problem.find('input.check');
check_button.on('click', function() {
console.log('check');
updateInput(applet, input_field); updateInput(applet, input_field);
}); });
} }
function requestAppletData(applet, input_field) { function requestAppletData(element, applet, input_field) {
var molFile = applet.find('param[name=molfile]').attr('value'); var molFile = $(element).data('molfile-src');
jQuery.ajax({ jQuery.ajax({
url: molFile, url: molFile,
...@@ -98,14 +98,14 @@ ...@@ -98,14 +98,14 @@
} }
function loadAppletData(applet, data, input_field) { function loadAppletData(applet, data, input_field) {
applet[0].readMolFile(data); applet.readMolFile(data);
updateInput(applet, input_field); updateInput(applet, input_field);
} }
function updateInput(applet, input_field) { function updateInput(applet, input_field) {
var mol = applet[0].molFile(); var mol = applet.molFile();
var smiles = applet[0].smiles(); var smiles = applet.smiles();
var jme = applet[0].jmeFile(); var jme = applet.jmeFile();
var info = jsmol.API.getInfo(mol, smiles, jme).toString(); var info = jsmol.API.getInfo(mol, smiles, jme).toString();
var err = jsmol.API.getErrors(mol, smiles, jme).toString(); var err = jsmol.API.getErrors(mol, smiles, jme).toString();
......
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
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