Log Message:
-----------
Additional support for debugging -- including the ability to reset the applet to
it's virgin state.
Modified Files:
--------------
webwork2/htdocs/js:
ww_applet_support.js
Revision Data
-------------
Index: ww_applet_support.js
===================================================================
RCS file: /webwork/cvs/system/webwork2/htdocs/js/ww_applet_support.js,v
retrieving revision 1.4
retrieving revision 1.5
diff -Lhtdocs/js/ww_applet_support.js -Lhtdocs/js/ww_applet_support.js -u -r1.4 -r1.5
--- htdocs/js/ww_applet_support.js
+++ htdocs/js/ww_applet_support.js
@@ -174,14 +174,15 @@
function base64Q(str) { /// determine whether an XML string has been base64 encoded.
return ( !str.match(/<XML/i) && !str.match(/<?xml/i));
}
-function setEmptyState(appletName){
- var newState = "<xml></xml>";
- ww_applet_list[appletName].setState(newState);
+function setAppletStateToRestart(appletName){
+ var newState = "<xml>restart_applet</xml>";
+ //ww_applet_list[appletName].setState(newState);
getQE(appletName+"_state").value = newState;
getQE("previous_" + appletName + "_state").value = newState
}
function getQE(name1) { // get Question Element in problemMainForm by name
+ //alert("getting " + name1);
var isIE = navigator.appName.indexOf("Microsoft") != -1;
var obj = (isIE) ? document.getElementById(name1)
:document.problemMainForm[name1];
@@ -195,6 +196,7 @@
};
} else {
+ //alert("found " +obj);
return( obj );
}
@@ -278,6 +280,13 @@
if ( base64Q(state) ) {
state=Base64.decode(state);
}
+ // if we are restarting the applet bail -- we don't want to set the state.
+
+ if (state.match(/^<xml>restart_applet<\/xml>/) ) {
+ alert("The applet " +appletName + "has been reset to its virgin state.");
+ ww_preserve_applet_state.value =""; //Fixme? should we set the last answer to blank as well?
+ return('');
+ }
if (state.match(/<xml/i) || state.match(/<?xml/i) ) { // if state starts with <?xml
debug_add(" Set (decoded) state for " + appletName + " to \n\n" +
@@ -296,7 +305,7 @@
alert(msg);
}
} else if (debug) {
- debug_add(" new state was empty string or did not begin with <xml-- \n Applet state was not reset");
+ debug_add(" new state was empty string or did not begin with <xml> -- Applet state was not reset");
}
return('');
};
@@ -372,15 +381,28 @@
ww_applet.prototype.submitAction = function () {
var appletName = this.appletName;
// var getAnswer = this.getAnswerAlias;
+ var ww_preserve_applet_state = getQE(appletName + "_state"); // hidden answer box preserving applet state
+ var saved_state = ww_preserve_applet_state.value;
+
if (debug) {debug_add("Begin submit action for applet " + appletName);}
var applet = getApplet(appletName);
if (! this.isReady ) {
alert(appletName + " is not ready");
initializeAction();
}
- this.getState(); // have ww_applet retrieve state from applet and store in answerbox
- eval(this.submitActionScript);
- //getQE(this.answerBox).value = applet.[getAnswer](); //FIXME -- not needed in general?
+ // Check to see if we want to restart the applet
+
+ if (saved_state.match(/^<xml>restart_applet<\/xml>/) ) {
+ if (debug) { debug_add("Restarting the applet "+appletName);}
+ setAppletStateToRestart(appletName); // erases all of the saved state
+ return('');
+ }
+ // if we are not restarting the applet save the state and submit
+
+ this.getState(); // have ww_applet retrieve state from applet and store in answerbox
+ if (debug) {debug_add("Submit Action Script " + this.submitActionScript + "\n");}
+ eval(this.submitActionScript);
+ //getQE(this.answerBox).value = applet.[getAnswer](); //FIXME -- not needed in general?
if (debug) {debug_add("Completed submitAction() for applet " + appletName+ "\n");}
};
|