Index: lams_tool_assessment/web/includes/javascript/assessmentoption.js
===================================================================
RCS file: /usr/local/cvsroot/lams_tool_assessment/web/includes/javascript/assessmentoption.js,v
diff -u -r1.8 -r1.9
--- lams_tool_assessment/web/includes/javascript/assessmentoption.js 13 Dec 2010 23:43:36 -0000 1.8
+++ lams_tool_assessment/web/includes/javascript/assessmentoption.js 17 Jun 2011 20:08:09 -0000 1.9
@@ -6,6 +6,8 @@
// var removeOptionUrl = "";
// var addOptionUrl = "";
function addOption(){
+ var oldCkeditorInstances = storeOldCkeditorInstances();
+
var url= addOptionUrl;
var contentFolderID= $("#contentFolderID").val();
prepareOptionEditorsForAjaxSubmit();
@@ -16,10 +18,15 @@
contentFolderID: contentFolderID,
questionType: questionType,
optionList: optionList
+ },
+ function(){
+ reinitializeGeneralCKEditorInstances(oldCkeditorInstances);
}
);
}
function removeOption(idx){
+ var oldCkeditorInstances = storeOldCkeditorInstances();
+
var url= removeOptionUrl;
var contentFolderID= $("#contentFolderID").val();
prepareOptionEditorsForAjaxSubmit();
@@ -31,10 +38,15 @@
questionType: questionType,
optionIndex: idx,
optionList: optionList
+ },
+ function(){
+ reinitializeGeneralCKEditorInstances(oldCkeditorInstances);
}
);
}
function upOption(idx){
+ var oldCkeditorInstances = storeOldCkeditorInstances();
+
var url= upOptionUrl;
var contentFolderID= $("#contentFolderID").val();
prepareOptionEditorsForAjaxSubmit();
@@ -46,31 +58,60 @@
questionType: questionType,
optionIndex: idx,
optionList: optionList
+ },
+ function(){
+ reinitializeGeneralCKEditorInstances(oldCkeditorInstances);
}
);
}
function downOption(idx){
+ var oldCkeditorInstances = storeOldCkeditorInstances();
+
var url= downOptionUrl;
var contentFolderID= $("#contentFolderID").val();
prepareOptionEditorsForAjaxSubmit();
var optionList = $("#optionForm").serialize(true);
- $(optionTargetDiv).load(
+ $(optionTargetDiv).load(
url,
{
- contentFolderID: contentFolderID,
+ contentFolderID: contentFolderID,
questionType: questionType,
optionIndex: idx,
optionList: optionList
},
function(){
- //alert("The last 25 entries in the feed have been loaded");
- //reinitializeCKEditorInstances();
- //alert("haha");
+ reinitializeGeneralCKEditorInstances(oldCkeditorInstances);
}
);
}
- //in order to be able to use option's value, copy it from ckeditor to textarea
+ //store references to general CKEditors before doing Ajax call
+ function storeOldCkeditorInstances(oldCkeditorInstances){
+ var oldCkeditorInstances = new Array();
+ oldCkeditorInstances.question = CKEDITOR.instances["question"];
+ oldCkeditorInstances.generalFeedback = CKEDITOR.instances["generalFeedback"];
+ oldCkeditorInstances.feedbackOnCorrect = CKEDITOR.instances["feedbackOnCorrect"];
+ oldCkeditorInstances.feedbackOnIncorrect = CKEDITOR.instances["feedbackOnIncorrect"];
+ oldCkeditorInstances.feedbackOnCorrectOutsideForm = CKEDITOR.instances["feedbackOnCorrectOutsideForm"];
+ oldCkeditorInstances.feedbackOnPartiallyCorrectOutsideForm = CKEDITOR.instances["feedbackOnPartiallyCorrectOutsideForm"];
+ oldCkeditorInstances.feedbackOnIncorrectOutsideForm = CKEDITOR.instances["feedbackOnIncorrectOutsideForm"];
+ return oldCkeditorInstances;
+ }
+
+ //reinitialize all general CKEditor after Ajax call has done
+ function reinitializeGeneralCKEditorInstances(oldCkeditorInstances){
+ for (var instanceId in oldCkeditorInstances){
+ if (instanceId == null) continue;
+ var instance = oldCkeditorInstances[instanceId];
+ if (instance == null) continue;
+ var initializeFunction = instance.initializeFunction;
+ instance.destroy();
+ instance = initializeFunction();
+ instance.initializeFunction = initializeFunction;
+ }
+ }
+
+ //in order to be able to use option's value, copy it from CKEditor to textarea
function prepareOptionEditorsForAjaxSubmit(){
if ((questionType == 1) || (questionType == 7)) {
$("textarea[name^=optionString]").each(function() {