Index: edit_multianswer_form.php
===================================================================
--- edit_multianswer_form.php (revision 3)
+++ edit_multianswer_form.php (working copy)
@@ -17,7 +17,117 @@
// $questiondisplay will contain the qtype_multianswer_extract_question from the questiontext
var $questiondisplay ;
+ function add_subquestion_builder(&$mform) {
+ global $CFG;
+ require_js(array('yui_yahoo',
+ 'yui_dom',
+ 'yui_event',
+ 'yui_selector',
+ 'yui_element',
+ $CFG->wwwroot . '/question/type/multianswer/subquestionbuilder.js'));
+
+ $creategrades = get_grade_options();
+
+ $subquestionbuilder = '' . get_string('showbuilder','qtype_multianswer') . '';
+ $subquestionbuilder .= '
+
+
' . get_string('subquestionbuilder','qtype_multianswer') . ' [' . get_string('close' , 'qtype_multianswer') .']
+
+
+
+
+
+
+
+
+
+ ';
+
+ $builderlink = $mform->createElement('static', 'subquestionbuilder', '', $subquestionbuilder);
+ $mform->insertElementBefore($builderlink, 'questiontextformat');
+ }
+
function definition_inner(&$mform) {
+ $this->add_subquestion_builder($mform);
$question_type_names = question_type_menu();
$mform->addRule('questiontext', null, 'required', null, 'client');
Index: styles.css
===================================================================
--- styles.css (revision 0)
+++ styles.css (revision 0)
@@ -0,0 +1,125 @@
+#subquestionbuilder {
+ display: none;
+ position: absolute;
+ width: 780px;
+ z-index: 1000;
+ background: none repeat scroll 0 0 #FEFEFE;
+ border: 2px solid #DDDDCC;
+ padding: 5px;
+ left: 50%;
+ margin-left: -400px;
+}
+#subquestionbuilderbg {
+ position: absolute;
+ display: none;
+ z-index: 999;
+ background: none repeat scroll 0 0 #000;
+ left:0px;
+ top:0px;
+ width:100%;
+ filter:alpha(opacity=50);
+ -moz-opacity:0.5;
+ -khtml-opacity: 0.5;
+ opacity: 0.5;
+}
+
+#subquestionbuilder h3 {
+ margin: 5px 0px;
+ border-bottom: 1px solid #999;
+}
+
+#subquestionbuilder h4 {
+ margin: 0px 0px 5px 05px;
+ border-bottom: 1px solid #ddd;
+}
+
+#subquestionbuilder .close {
+ float: right;
+ font-size: 11px;
+}
+
+#sqbuilder_content {
+ width: 99%;
+}
+
+#sqbuilder_content .right {
+ clear: right;
+ float: right;
+ margin-top: 0;
+}
+
+#sqbuilder_content fieldset {
+ width: 49%;
+ padding:5px 0;
+}
+
+#subquestion_preview {
+ margin: 0px 5px;
+}
+
+#sqbuilder_content .fitemtitle {
+ width: 25%;
+}
+
+#sqbuilder_content .right .fitemtitle {
+ clear: both;
+ display: block;
+ text-align: left;
+ width: 90%;
+}
+
+#subquestion_addanswer {
+ float: right;
+ margin-right: 7px;
+}
+
+#subquestion_btn {
+ margin-left: 10px;
+}
+
+#sqbuilder_content .right .felement {
+ clear: both;
+}
+
+
+#subquestion_answers {
+
+}
+
+#subquestion_answers .a_answer {
+ border-bottom: 1px solid #DDDDDD;
+}
+
+#subquestion_answers strong {
+ clear: both;
+ float: left;
+ width: 70px;
+}
+
+#subquestion_answers span {
+ clear: right;
+ display: inline;
+ float: left;
+}
+
+#subquestion_answers .remove {
+ cursor: pointer;
+ float: right;
+}
+
+#link_subquestion_builder,#subquestionbuilder .close {
+ cursor: pointer;
+}
+
+#subquestion_element {
+ border: 0px none;
+ overflow-x: auto;
+ width: 369px;
+}
+#sqbuilder_content textarea {
+
+}
+#sqbuilder_content .fbutton {
+ width: 100% !important;
+ clear: both;
+}
\ No newline at end of file
Index: subquestionbuilder.js
===================================================================
--- subquestionbuilder.js (revision 0)
+++ subquestionbuilder.js (revision 0)
@@ -0,0 +1,203 @@
+/**
+ *
+ *
+ * @copyright © 2010 Mohamed Alsharaf
+ * @author Mohamed Alsharaf mohamed.alsharaf@gmail.com
+ * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
+ */
+var quiz_subquestion_builder = {
+ SQTYPE_SA: 'SHORTANSWER',
+ SQTYPE_SAC: 'SHORTANSWER_C',
+ SQTYPE_NM: 'NUMERICAL',
+ SQTYPE_MC: 'MULTICHOICE',
+ SQTYPE_MCV: 'MULTICHOICE_V',
+ SQTYPE_MCH: 'MULTICHOICE_H',
+ sqwin: null,
+ sqid: 'subquestionbuilder',
+ sqparts: null,
+ init: function() {
+ this.sqwin = document.getElementById(this.sqid);
+ this.sqparts = {type:'', weight:'', answers:new Array()};
+
+ var close = YAHOO.util.Selector.query('#' + this.sqid + ' .close');
+ YAHOO.util.Event.on(close, 'click', this.close_win, this);
+ YAHOO.util.Event.addListener("link_subquestion_builder", "click", this.show_win, this);
+
+ YAHOO.util.Event.addListener("subquestion-type", "change", this.add_type, this);
+ YAHOO.util.Event.addListener("subquestion-weight", "change", this.add_weight, this);
+ YAHOO.util.Event.addListener("subquestion_addanswer", "click", this.addanswer, this);
+
+ YAHOO.util.Event.addListener("subquestion_btn", "click", this.insert, this);
+ },
+ insert: function(e, obj) {
+ var code = document.getElementById('subquestion-code').value;
+ var questiontextelement = document.getElementById('id_questiontext');
+ var questiontext = questiontextelement.value+code;
+
+ // update textarea
+ // @todo insert into html editor FCKeditor, ...
+ questiontextelement.value = questiontext;
+
+ // if we have TinyMCE then insert the code into the question text editor
+ if(tinyMCE) {
+ questiontextelement = tinyMCE.getInstanceById('id_questiontext');
+ if(questiontextelement != null) {
+ questiontextelement.execCommand('mceInsertContent', false, questiontext);
+ }
+ }
+
+ obj.close_win(e, obj);
+ },
+ add_type: function(e, obj) {
+ var inputvalue = YAHOO.util.Event.getTarget(e, 1).value;
+ if(inputvalue == '') {
+ return false;
+ }
+ obj.sqparts.type = inputvalue;
+ obj.render();
+ },
+ add_weight: function(e, obj) {
+ var inputvalue = parseInt(YAHOO.util.Event.getTarget(e, 1).value);
+ if(isNaN(inputvalue)) {
+ inputvalue = '';
+ }
+ obj.sqparts.weight = inputvalue;
+ obj.render();
+ },
+ addanswer: function(e, obj) {
+ var answertxt = document.getElementById('subquestion-answer');
+ var answergrade = document.getElementById('subquestion-grade');
+ var answerfeedback = document.getElementById('subquestion-feedback');
+
+ if(answertxt.value == '') {
+ alert('Answer text must not be empty.');
+ return false;
+ }
+ var c = obj.sqparts.answers.length;
+ obj.sqparts['answers'][c] = new Array();
+ obj.sqparts['answers'][c]['text'] = answertxt.value;
+ obj.sqparts['answers'][c]['grade'] = answergrade.value;
+ obj.sqparts['answers'][c]['feedback'] = answerfeedback.value;
+ obj.render();
+
+ answertxt.value = '';
+ answergrade.value = '1';
+ answerfeedback.value = '';
+ },
+ remove_answer: function(e, obj) {
+ var answerel = YAHOO.util.Event.getTarget(e, 1);
+ var segments = answerel.id.split('_');
+ obj.sqparts['answers'].splice(segments[1], 1);
+ obj.render();
+ },
+ render: function() {
+ var xhtmlans = '', obj = this, xhtmlelement = '', preview = document.getElementById('subquestion_preview'), previewelement = document.getElementById('subquestion_element'), previewanswers = document.getElementById('subquestion_answers');
+ switch(obj.sqparts['type']) {
+ case obj.SQTYPE_SA:
+ case obj.SQTYPE_SAC:
+ xhtmlelement += '';
+ break;
+ case obj.SQTYPE_NM:
+ xhtmlelement += '';
+ break;
+ case obj.SQTYPE_MC:
+ xhtmlelement += '';
+ break;
+ case obj.SQTYPE_MCV:
+ case obj.SQTYPE_MCH:
+ xhtmlelement += '';
+ break;
+ }
+ previewelement.innerHTML = xhtmlelement;
+
+ xhtmlelement = '';
+ for(var i = 0; i < obj.sqparts['answers'].length; i++) {
+ xhtmlans += '[remove]';
+ xhtmlans += 'Answer:' + obj.sqparts['answers'][i]['text'] + '
';
+ xhtmlans += 'Grade:' + (obj.sqparts['answers'][i]['grade']*100) + '%
';
+ xhtmlans += 'Feedback:' + obj.sqparts['answers'][i]['feedback'] + '
';
+ xhtmlans += '
';
+ switch(obj.sqparts['type']) {
+ case obj.SQTYPE_MC:
+ xhtmlelement += '';
+ break;
+ case obj.SQTYPE_MCV:
+ xhtmlelement += '';
+ xhtmlelement += ' | ';
+ xhtmlelement += '' + obj.sqparts['answers'][i]['text'] + ' | ';
+ xhtmlelement += '
';
+ break;
+ case obj.SQTYPE_MCH:
+ xhtmlelement += ' | ';
+ xhtmlelement += '' + obj.sqparts['answers'][i]['text'] + ' | ';
+ break;
+ }
+ }
+ previewanswers.innerHTML = xhtmlans;
+ if(xhtmlans != '') {
+ var remove = YAHOO.util.Selector.query('#subquestion_answers .remove');
+ YAHOO.util.Event.on(remove, 'click', obj.remove_answer, obj);
+ }
+
+ if(obj.sqparts['type'] == obj.SQTYPE_MC) {
+ var sel = previewelement.getElementsByTagName('select')[0];
+ sel.innerHTML = xhtmlelement;
+ } else if(obj.sqparts['type'] == obj.SQTYPE_MCV) {
+ previewelement.innerHTML = '';
+ } else if(obj.sqparts['type'] == obj.SQTYPE_MCH) {
+ previewelement.innerHTML = '';
+ }
+ this.render_code();
+ },
+ render_code: function() {
+ if(this.sqparts.type == '') {
+ return false;
+ }
+ var code = '';
+ code += '{';
+ if(this.sqparts.weight != '') {
+ code += this.sqparts.weight;
+ }
+ code += ':' + this.sqparts.type + ':';
+ var ans = this.sqparts['answers'].length;
+ for(var i = 0; i < ans; i++) {
+ code += '%' + (100 * this.sqparts['answers'][i]['grade']) + '%';
+ code += this.sqparts['answers'][i]['text'];
+ if(this.sqparts['answers'][i]['feedback'] != '') {
+ code += '#' + this.sqparts['answers'][i]['text'];
+ }
+ if((i+1) < ans) {
+ code += '~';
+ }
+ }
+ code += '}';
+ document.getElementById('subquestion-code').value = code;
+ },
+ close_win: function(e, obj) {
+ document.getElementById('subquestion-code').value = '';
+ obj.sqparts = {type:'', weight:'', answers:new Array()};
+ obj.render();
+ obj.sqwin.style.display = 'none';
+ document.getElementById('subquestionbuilderbg').style.display = 'none';
+ return false;
+ },
+ show_win: function(e, obj) {
+ //var x = YAHOO.util.Event.getPageX(e);
+
+ var docheight = YAHOO.util.Dom.getDocumentHeight();
+ document.getElementById('subquestionbuilderbg').style.display = 'block';
+ document.getElementById('subquestionbuilderbg').style.height = docheight + 'px';
+
+ var scrolltop = YAHOO.util.Dom.getDocumentScrollTop();
+ obj.sqwin.style.display = 'block';
+ obj.sqwin.style.top = (scrolltop+100) + 'px';
+
+ return false;
+ }
+};
+
+(function() {
+ YAHOO.util.Event.onDOMReady(function() {
+ quiz_subquestion_builder.init();
+ });
+})();
\ No newline at end of file
Index: lang/en_utf8/qtype_multianswer.php
===================================================================
--- lang/en_utf8/qtype_multianswer.php (revision 0)
+++ lang/en_utf8/qtype_multianswer.php (revision 0)
@@ -0,0 +1,19 @@
+