From cd120b2344d0c9d8f8bfa20466e3abb9fe0e4c8a Mon Sep 17 00:00:00 2001 From: tjhunt Date: Wed, 25 Feb 2009 07:14:03 +0000 Subject: [PATCH] quiz editing / question bank: MDL-18355 Convert the add question drop-down to be a button that pops up a YUI dialogue. That allows us to have a few sentences explanation of each question type, and is also easier to fit into a tight layout. This commit should also fix MDL-18214 Layout screwed in Safari with long category names. --- lang/en_utf8/qtype_calculated.php | 4 + lang/en_utf8/qtype_description.php | 6 ++ lang/en_utf8/qtype_essay.php | 6 ++ lang/en_utf8/qtype_match.php | 4 + lang/en_utf8/qtype_missingtype.php | 3 +- lang/en_utf8/qtype_multianswer.php | 5 +- lang/en_utf8/qtype_multichoice.php | 1 + lang/en_utf8/qtype_numerical.php | 4 + lang/en_utf8/qtype_random.php | 2 + lang/en_utf8/qtype_randomsamatch.php | 1 + lang/en_utf8/qtype_shortanswer.php | 1 + lang/en_utf8/qtype_truefalse.php | 1 + lang/en_utf8/question.php | 3 + lang/en_utf8/quiz.php | 3 + mod/quiz/editlib.php | 65 ++++-------- question/addquestion.php | 106 +++++++++++++++++++ question/edit.php | 14 ++- question/editlib.php | 117 +++++++++++++++++---- question/qbank.js | 100 +++++++++++++++++- question/question.php | 6 +- theme/standard/styles_color.css | 12 +++ theme/standard/styles_fonts.css | 11 ++ theme/standard/styles_layout.css | 152 +++++++++++++++++---------- 23 files changed, 489 insertions(+), 138 deletions(-) create mode 100644 lang/en_utf8/qtype_description.php create mode 100644 lang/en_utf8/qtype_essay.php create mode 100644 question/addquestion.php diff --git a/lang/en_utf8/qtype_calculated.php b/lang/en_utf8/qtype_calculated.php index 94e9448dd1..70e212ed72 100644 --- a/lang/en_utf8/qtype_calculated.php +++ b/lang/en_utf8/qtype_calculated.php @@ -1,10 +1,14 @@ \ No newline at end of file diff --git a/lang/en_utf8/qtype_essay.php b/lang/en_utf8/qtype_essay.php new file mode 100644 index 0000000000..5dd2ffff8b --- /dev/null +++ b/lang/en_utf8/qtype_essay.php @@ -0,0 +1,6 @@ + \ No newline at end of file diff --git a/lang/en_utf8/qtype_match.php b/lang/en_utf8/qtype_match.php index 293cf290b5..dec0566a84 100644 --- a/lang/en_utf8/qtype_match.php +++ b/lang/en_utf8/qtype_match.php @@ -1,6 +1,10 @@ q questions and $a->a answers.'; diff --git a/lang/en_utf8/qtype_missingtype.php b/lang/en_utf8/qtype_missingtype.php index 93e9c9b804..8235462718 100644 --- a/lang/en_utf8/qtype_missingtype.php +++ b/lang/en_utf8/qtype_missingtype.php @@ -1,5 +1,6 @@ -This question is of a type that has not been installed on your Moodle yet.
Please alert your Moodle administrator.'; ?> diff --git a/lang/en_utf8/qtype_multianswer.php b/lang/en_utf8/qtype_multianswer.php index 40f5e1d6e3..3b37fc1a30 100644 --- a/lang/en_utf8/qtype_multianswer.php +++ b/lang/en_utf8/qtype_multianswer.php @@ -1,15 +1,16 @@ sub (question->id={$a->id})'; $string['noquestions'] = 'The Cloze(multianswer) question \"$a\" does not contain any question '; $string['qtypenotrecognized'] = 'questiontype $a not recognized'; diff --git a/lang/en_utf8/qtype_multichoice.php b/lang/en_utf8/qtype_multichoice.php index 6f2d4659b0..cec4218bdd 100644 --- a/lang/en_utf8/qtype_multichoice.php +++ b/lang/en_utf8/qtype_multichoice.php @@ -24,6 +24,7 @@ $string['fractionsaddwrong'] = 'The positive grades you have chosen do not add u $string['fractionsnomax'] = 'One of the choices should be 100%%, so that it is
possible to get a full grade for this question.
Do you want to go back and fix this question?'; $string['incorrectfeedback'] = 'For any incorrect response'; $string['multichoice'] = 'Multiple choice'; +$string['multichoicesummary'] = 'Allows the selection of a single or multiple responses from a pre-defined list.'; $string['notenoughanswers'] = 'This type of question requires at least $a choices'; $string['overallfeedback'] = 'Overall Feedback'; $string['overallcorrectfeedback'] = 'Feedback for any correct response'; diff --git a/lang/en_utf8/qtype_numerical.php b/lang/en_utf8/qtype_numerical.php index 1aa6af279b..9ea2ec90bb 100644 --- a/lang/en_utf8/qtype_numerical.php +++ b/lang/en_utf8/qtype_numerical.php @@ -1,10 +1,14 @@ \ No newline at end of file diff --git a/lang/en_utf8/qtype_random.php b/lang/en_utf8/qtype_random.php index efa07f99ef..7453bc4d55 100644 --- a/lang/en_utf8/qtype_random.php +++ b/lang/en_utf8/qtype_random.php @@ -1,5 +1,7 @@ catname\'. Choose a different category, make some questions in this category.'; $string['notenoughsaincategory'] = 'There is/are only $a->nosaquestions short answer questions in the category that you chose \'$a->catname\'. Choose a different category, make some more questions in this category or reduce the amount of questions you\'ve selected.'; $string['randomsamatch'] = 'Random short-answer matching'; +$string['randomsamatchsummary'] = 'Like a Matching question, but created randomly from the shortanswer questions in a particular category.'; ?> \ No newline at end of file diff --git a/lang/en_utf8/qtype_shortanswer.php b/lang/en_utf8/qtype_shortanswer.php index 6da6bf7150..f5071234a3 100644 --- a/lang/en_utf8/qtype_shortanswer.php +++ b/lang/en_utf8/qtype_shortanswer.php @@ -6,4 +6,5 @@ $string['answerno'] = 'Answer $a'; $string['editingshortanswer'] = 'Editing a Short answer question'; $string['filloutoneanswer'] = 'You must provide at least one possible answer. Answers left blank will not be used. \'*\' can be used as a wildcard to match any characters. The first matching answer will be used to determine the score and feedback.'; $string['shortanswer'] = 'Short answer'; +$string['shortanswersummary'] = 'Allows a response of one or a few words that is graded by comparing against various model answers, which may contain wildcards.'; ?> \ No newline at end of file diff --git a/lang/en_utf8/qtype_truefalse.php b/lang/en_utf8/qtype_truefalse.php index f44cdabc03..4e10dc8ff8 100644 --- a/lang/en_utf8/qtype_truefalse.php +++ b/lang/en_utf8/qtype_truefalse.php @@ -9,5 +9,6 @@ $string['feedbackfalse'] = 'Feedback for the response \'False\'.'; $string['feedbacktrue'] = 'Feedback for the response \'True\'.'; $string['true'] = 'True'; $string['truefalse'] = 'True/False'; +$string['truefalsesummary'] = 'A simple form of multiple choice question with just the two choices \'True\' and \'False\'.'; ?> diff --git a/lang/en_utf8/question.php b/lang/en_utf8/question.php index 6a540c18af..463a30513a 100644 --- a/lang/en_utf8/question.php +++ b/lang/en_utf8/question.php @@ -49,6 +49,7 @@ $string['changepublishstatuscat'] = 'caturl\">Category \"$a->name\ $string['chooseqtypetoadd'] = 'Choose a question type to add'; $string['clicktoflag'] = 'Click to flag this question'; $string['clicktounflag'] = 'Click to un-flag this question'; +$string['createnewquestion'] = 'Create a new question ...'; $string['cwrqpfs'] = 'Random questions selecting questions from sub categories.'; $string['cwrqpfsinfo'] = '

During the upgrade to Moodle 1.9 we will separate question categories into different contexts. Some question categories and questions on your site will have to have their sharing @@ -161,6 +162,8 @@ $string['questionsrescuedfrominfo'] = 'These questions (some of which may be hid $string['questiontype'] = 'Question type'; $string['questionuse'] = 'Use question in this activity'; $string['saveflags'] = 'Save the state of the flags'; +$string['selectacategory'] = 'Select a category:'; +$string['selectaqtypefordescription'] = 'Select a question type to see its description.'; $string['selectquestionsforbulk'] = 'Select questions for bulk actions'; $string['shareincontext'] = 'Share in context for $a'; $string['tofilecategory'] = 'Write category to file'; diff --git a/lang/en_utf8/quiz.php b/lang/en_utf8/quiz.php index 045d229fa9..689805ccc4 100644 --- a/lang/en_utf8/quiz.php +++ b/lang/en_utf8/quiz.php @@ -9,6 +9,7 @@ $string['acceptederror'] = 'Accepted error'; $string['accessnoticesheader'] = 'You can preview this quiz, but if this were a real attempt, you would be blocked because:'; $string['action'] = 'Action'; $string['adaptive'] = 'Adaptive mode'; +$string['addaquestion'] = 'Add a question ...'; $string['addcategory'] = 'Add category'; $string['adddescriptionlabel'] = 'Add description/label'; $string['addingcalculated'] = 'Adding a Calculated question'; @@ -36,6 +37,7 @@ $string['addrandom1'] = '<< Add'; $string['addrandom2'] = 'random questions'; $string['addrandomfromcategory'] = 'Add random questions from category:'; $string['addrandomquestion'] = 'Add random question'; +$string['addarandomquestion'] = 'Add a random question ...'; $string['addrandomquestiontoquiz'] = 'Add random question to quiz $a'; $string['addselectedtoquiz'] = 'Add selected to quiz'; $string['addtoquiz'] = 'Add to quiz'; @@ -186,6 +188,7 @@ $string['createcategoryfornewrandomquestion'] = 'Create a question category for $string['createfirst'] = 'You must create some short-answer questions first.'; $string['createmultiple'] = 'Add several random questions to quiz'; $string['createnewquestion'] = 'Create new question'; +$string['createquestionandadd'] = 'Create a new question and add it to the quiz.'; $string['custom'] = 'Custom format'; $string['dataitemneed'] = 'You need to add at least one set of data items to get a valid question'; $string['datasetdefinitions'] = 'Reusable dataset definitions for category $a'; diff --git a/mod/quiz/editlib.php b/mod/quiz/editlib.php index 55fb73e0f6..e71ad1eef2 100644 --- a/mod/quiz/editlib.php +++ b/mod/quiz/editlib.php @@ -555,57 +555,30 @@ function quiz_print_question_list($quiz, $pageurl, $allowdelete=true, */ function quiz_print_pagecontrols($quiz,$pageurl,$page, $hasattempts){ global $CFG; - $strcreatenewquestion=get_string("createnewquestion",'quiz'); - $strselectquestiontype=get_string("selectquestiontype",'quiz'); echo '

'; - // get the current context + + // Get the current context $thiscontext = get_context_instance(CONTEXT_COURSE, $quiz->course); $contexts = new question_edit_contexts($thiscontext); - // get default category and turn its infor into a string that works in an url + + // Get the default category. $defaultcategory = question_make_default_categories($contexts->all()); - $categorystring = "$defaultcategory->id,$defaultcategory->contextid"; - //create the url the question page will return to - $returnurl_addtoquiz=new moodle_url($pageurl->out(true), - array("addonpage"=>$page)); - //create the url of the new question page to forward to. return url is given - //as a parameter and automatically urlencoded. + + // Create the url the question page will return to + $returnurl_addtoquiz = new moodle_url($pageurl->out(true), array("addonpage" => $page)); + + // Print a button linking to the choose question type page. $newquestionparams = array('returnurl' => $returnurl_addtoquiz->out(false), - 'cmid'=>$quiz->cmid, "appendqnumstring"=>"addquestion", "category"=>$categorystring); - $newquestionurl_object = new moodle_url("$CFG->wwwroot/question/question.php", - $newquestionparams); - $newquestionurl=$newquestionurl_object->out(false); - echo get_string("addquestion","quiz").": "; + 'cmid' => $quiz->cmid, 'appendqnumstring' => 'addquestion'); + create_new_question_button($defaultcategory->id, $newquestionparams, get_string('addaquestion', 'quiz'), + get_string('createquestionandadd', 'quiz'), $hasattempts); + if ($hasattempts) { $disabled = 'disabled="disabled"'; } else { $disabled = ''; } - popup_form ($newquestionurl.'&qtype=', - question_type_menu(), - "addquestion_$page", - "", - $strselectquestiontype, - "", - "", - false, - "self", - "", - null, - $strcreatenewquestion, $hasattempts); - helpbutton("questiontypes", $strcreatenewquestion, "quiz"); - echo '
'; - print_single_button($CFG->wwwroot."/question/question.php", - array("cmid"=>$quiz->cmid, - "courseid"=>$quiz->course, - "returnurl"=>$returnurl_addtoquiz->out(false), - "appendqnumstring"=>"addquestion", - "category"=>$categorystring, - "qtype"=>"description"), - get_string("adddescriptionlabel","quiz"),'get', '_self', false, '', - $hasattempts); - echo "\n
"; ?> -
@@ -613,14 +586,12 @@ function quiz_print_pagecontrols($quiz,$pageurl,$page, $hasattempts){ - " /> - - + /> +
-
+ "; } @@ -976,8 +947,8 @@ class question_bank_question_name_text_column extends question_bank_question_nam class quiz_question_bank_view extends question_bank_view { protected $quizhasattempts = false; - protected function know_field_types() { - $types = parent::know_field_types(); + protected function known_field_types() { + $types = parent::known_field_types(); $types[] = new question_bank_add_to_quiz_action_column($this); $types[] = new question_bank_question_name_text_column($this); return $types; diff --git a/question/addquestion.php b/question/addquestion.php new file mode 100644 index 0000000000..1e847f3e57 --- /dev/null +++ b/question/addquestion.php @@ -0,0 +1,106 @@ + $categoryid); + +// Validate params. +if (!$category = $DB->get_record('question_categories', array('id' => $categoryid))) { + print_error('categorydoesnotexist', 'question', $returnurl); +} + +if ($cmid){ + list($module, $cm) = get_module_from_cmid($cmid); + require_login($cm->course, false, $cm); + $thiscontext = get_context_instance(CONTEXT_MODULE, $cmid); + $hiddenparams['cmid'] = $cmid; +} else if ($courseid) { + require_login($courseid, false); + $thiscontext = get_context_instance(CONTEXT_COURSE, $courseid); + $module = null; + $cm = null; + $hiddenparams['courseid'] = $courseid; +} else { + print_error('missingcourseorcmid', 'question'); +} + +// Check permissions. +$categorycontext = get_context_instance_by_id($category->contextid); +require_capability('moodle/question:add', $categorycontext); + +// Ensure other optional params get passed on to question.php. +if (!empty($returnurl)) { + $hiddenparams['returnurl'] = $returnurl; +} +if (!empty($appendqnumstring)) { + $hiddenparams['appendqnumstring'] = $appendqnumstring; +} + +$chooseqtype = get_string('chooseqtypetoadd', 'question'); +if ($cm !== null) { + $navlinks = array(); + if (stripos($returnurl, "$CFG->wwwroot/mod/{$cm->modname}/view.php")!== 0){ + //don't need this link if returnurl returns to view.php + $navlinks[] = array('name' => get_string('editinga', 'moodle', get_string('modulename', $cm->modname)), 'link' => $returnurl, 'type' => 'title'); + } + $navlinks[] = array('name' => $chooseqtype, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($navlinks, $cm); + print_header_simple($chooseqtype, '', $navigation, '', '', true, update_module_button($cm->id, $cm->course, get_string('modulename', $cm->modname))); + +} else { + $navlinks = array(); + $navlinks[] = array('name' => get_string('editquestions', 'question'), 'link' => $returnurl, 'type' => 'title'); + $navlinks[] = array('name' => $chooseqtype, 'link' => '', 'type' => 'title'); + $navigation = build_navigation($navlinks); + print_header_simple($chooseqtype, '', $navigation); +} + +// Display a form to choose the question type. +print_box_start('generalbox boxwidthnormal boxaligncenter', 'chooseqtypebox'); +print_choose_qtype_to_add_form($hiddenparams); +print_box_end(); + +print_footer($COURSE); + + +?> \ No newline at end of file diff --git a/question/edit.php b/question/edit.php index 13c21e57a3..2579b71590 100644 --- a/question/edit.php +++ b/question/edit.php @@ -39,6 +39,8 @@ // TODO log this page view. + $localcss = ''; $context = $contexts->lowest(); $streditingquestions = get_string('editquestions', "quiz"); if ($cm!==null) { @@ -50,7 +52,7 @@ $navlinks[] = array('name' => format_string($module->name), 'link' => "$CFG->wwwroot/mod/{$cm->modname}/view.php?id={$cm->id}", 'type' => 'title'); $navlinks[] = array('name' => $streditingquestions, 'link' => '', 'type' => 'title'); $navigation = build_navigation($navlinks); - print_header_simple($streditingquestions, '', $navigation, "", "", true, $strupdatemodule); + print_header_simple($streditingquestions, '', $navigation, '', $localcss, true, $strupdatemodule); $currenttab = 'edit'; $mode = 'questions'; @@ -62,22 +64,18 @@ $navlinks[] = array('name' => $streditingquestions, 'link' => '', 'type' => 'title'); $navigation = build_navigation($navlinks); - print_header_simple($streditingquestions, '', $navigation); + print_header_simple($streditingquestions, '', $navigation, '', $localcss); // print tabs $currenttab = 'questions'; include('tabs.php'); } - echo ''; - echo ''; - echo '
'; - + echo '
'; $questionbank->display('questions', $pagevars['qpage'], $pagevars['qperpage'], $pagevars['qsortorder'], $pagevars['qsortorderdecoded'], $pagevars['cat'], $pagevars['recurse'], $pagevars['showhidden'], $pagevars['showquestiontext']); - - echo '
'; + echo "
\n"; print_footer($COURSE); ?> diff --git a/question/editlib.php b/question/editlib.php index dfda54a151..1982df8765 100644 --- a/question/editlib.php +++ b/question/editlib.php @@ -651,7 +651,7 @@ class question_bank_move_action_column extends question_bank_action_column_base protected function display_content($question, $rowclasses) { if (question_has_capability_on($question, 'move')) { - $this->print_icon('move', $this->strmove, $this->qbank->move_question_url($question->id)); + $this->print_icon('t/move.gif', $this->strmove, $this->qbank->move_question_url($question->id)); } } } @@ -676,9 +676,9 @@ class question_bank_delete_action_column extends question_bank_action_column_bas protected function display_content($question, $rowclasses) { if (question_has_capability_on($question, 'edit')) { if ($question->hidden) { - $this->print_icon('restore', $this->strrestore, $this->qbank->base_url()->out(false, array('unhide' => $question->id))); + $this->print_icon('t/restore.gif', $this->strrestore, $this->qbank->base_url()->out(false, array('unhide' => $question->id))); } else { - $this->print_icon('delete', $this->strdelete, + $this->print_icon('t/delete.gif', $this->strdelete, $this->qbank->base_url()->out(false, array('deleteselected' => $question->id, 'q' . $question->id => 1))); } } @@ -817,7 +817,7 @@ class question_bank_view { return $columns; } - protected function know_field_types() { + protected function known_field_types() { return array( new question_bank_checkbox_column($this), new question_bank_question_type_column($this), @@ -834,7 +834,7 @@ class question_bank_view { protected function init_column_types() { $this->knowncolumntypes = array(); - foreach ($this->know_field_types() as $col) { + foreach ($this->known_field_types() as $col) { $this->knowncolumntypes[$col->get_name()] = $col; } } @@ -1156,15 +1156,12 @@ class question_bank_view { global $CFG; /// Get all the existing categories now + echo '
'; $catmenu = question_category_options($contexts, false, 0, true); - - $strcategory = get_string('selectcategory', 'quiz'); - $strshow = get_string('show', 'quiz'); - $streditcats = get_string('editcategories', 'quiz'); - popup_form('edit.php?'.$pageurl->get_query_string().'&category=', $catmenu, 'catmenu', $current, '', '', '', false, 'self', - $strcategory); + get_string('selectacategory', 'question')); + echo "
\n"; } protected function display_options($recurse = 1, $showhidden = false, $showquestiontext = false) { @@ -1193,13 +1190,11 @@ class question_bank_view { } protected function create_new_question_form($category, $canadd) { - $qtypemenu = question_type_menu(); - $straddquestions = get_string('addquestions', 'quiz'); + global $CFG; echo '
'; if ($canadd) { - popup_form($this->editquestionurl->out(false, array('category' => $category->id)) . '&qtype=', - $qtypemenu, 'addquestion', '', 'choose', '', '', false, 'self', $straddquestions); - helpbutton('questiontypes', $straddquestions, 'quiz'); + create_new_question_button($category->id, $this->editquestionurl->params(), + get_string('createnewquestion', 'question')); } else { print_string('nopermissionadd', 'question'); } @@ -1259,8 +1254,8 @@ class question_bank_view { echo '
'; echo ''; echo $pageurl->hidden_params_out(); - echo '
'; + echo '
'; $this->start_table(); $rowcount = 0; foreach ($questions as $question) { @@ -1268,6 +1263,7 @@ class question_bank_view { $rowcount += 1; } $this->end_table(); + echo "
\n"; echo '
'; $paging = print_paging_bar($totalnumber, $page, $perpage, $pageurl, 'qpage', false, true); @@ -1400,7 +1396,7 @@ class question_bank_view { $checkforfiles = true; } } - $returnurl = $pageurl->out(false, array('category'=>"$tocategoryid,$contextid")); + $returnurl = $this->baseurl->out(false, array('category'=>"$tocategoryid,$contextid")); if (!$checkforfiles){ if (!question_move_questions_to_category(implode(',', $questionids), $tocategory->id)) { print_error('errormovingquestions', 'question', $returnurl, $questionids); @@ -1439,7 +1435,7 @@ class question_bank_view { } } } - redirect($pageurl->out()); + redirect($this->baseurl->out()); } else { print_error('invalidconfirm', 'question'); } @@ -1452,7 +1448,7 @@ class question_bank_view { if(!$DB->set_field('question', 'hidden', 0, array('id', $unhide))) { print_error('cannotunhidequestion', 'question'); } - redirect($pageurl->out()); + redirect($this->baseurl->out()); } } @@ -1821,4 +1817,85 @@ function require_login_in_context($contextorid = null){ require_login(); } } + +/** + * Print a form to let the user choose which question type to add. + * When the form is submitted, it goes to the question.php script. + * @param $hiddenparams hidden parameters to add to the form, in addition to + * the qtype radio buttons. + */ +function print_choose_qtype_to_add_form($hiddenparams) { + global $CFG, $QTYPES; + require_js(array('yui_yahoo','yui_dom','yui_event')); + require_js('question/qbank.js'); + echo '
' . "\n"; + print_heading(get_string('chooseqtypetoadd', 'question'), '', 3); + echo "
\n"; + echo '
' . "\n"; + echo '
' . "\n"; + foreach ($hiddenparams as $name => $value) { + echo '' . "\n"; + } + echo "
\n"; + $types = question_type_menu(); + echo '
' . "\n"; + echo '
' . get_string('selectaqtypefordescription', 'question') . "
\n"; + foreach ($types as $qtype => $localizedname) { + print_qtype_to_add_option($qtype, $localizedname); + } + echo "
\n"; + echo '
' . "\n"; + echo '' . "\n"; + echo '' . "\n"; + echo "
\n"; + echo "
\n"; + print_js_call('qtype_chooser.init', array('chooseqtype')); +} + +/** + * Private function used by the preceding one. + * @param $qtype the question type. + * @param $localizedname the localized name of this question type. + */ +function print_qtype_to_add_option($qtype, $localizedname) { + global $QTYPES; + echo '
' . "\n"; + echo ''; + echo '\n"; + echo "
\n"; +} + +/** + * Print a button for creating a new question. This will open question/addquestion.php, + * which in turn goes to question/question.php before getting back to $params['returnurl'] + * (by default the question bank screen). + * + * @param integer $categoryid The id of the category that the new question should be added to. + * @param array $params Other paramters to add to the URL. You need either $params['cmid'] or + * $params['courseid'], and you should probably set $params['returnurl'] + * @param string $caption the text to display on the button. + * @param string $tooltip a tooltip to add to the button (optional). + * @param boolean $disabled if true, the button will be disabled. + */ +function create_new_question_button($categoryid, $params, $caption, $tooltip = '', $disabled = false) { + global $CFG; + static $choiceformprinted = false; + $params['category'] = $categoryid; + print_single_button($CFG->wwwroot . '/question/addquestion.php', $params, + $caption,'get', '', false, $tooltip, $disabled); + helpbutton('questiontypes', get_string('createnewquestion', 'question'), 'question'); + require_js(array('yui_yahoo','yui_dom','yui_event', 'yui_dragdrop', 'yui_container')); + if (!$choiceformprinted) { + echo '
'; + print_choose_qtype_to_add_form(array()); + echo "
\n"; + $choiceformprinted = true; + } +} + ?> diff --git a/question/qbank.js b/question/qbank.js index 7c756f834a..0e1d46e424 100644 --- a/question/qbank.js +++ b/question/qbank.js @@ -1,5 +1,6 @@ -// This script is included by question_bank_view in question/editlib.php. +// This script is included by question_bank_view and other parts of question/editlib.php. +// JavaScript belonging to question_bank_view. question_bank = { strselectall: '', strdeselectall: '', @@ -33,3 +34,100 @@ question_bank = { question_bank.headercheckbox.checked = false; } }; + +// JavaScript to make the list of question types pop-up when you click an add +// add question button. +qtype_chooser = { + radiobuttons: [], + labels: [], + container: null, + submitbutton: null, + + init: function(boxid) { + // Find the radio buttons. + qtype_chooser.radiobuttons = YAHOO.util.Dom.getElementsBy( + function(el) { return el.type == 'radio'; }, 'input' , boxid); + qtype_chooser.labels = YAHOO.util.Dom.getElementsByClassName('qtypeoption', 'div', boxid); + + // Find the submit button. + qtype_chooser.submitbutton = document.getElementById(boxid + '_submit'); + qtype_chooser.enable_disable_submit(); + + // Add the event handlers. + YAHOO.util.Event.addListener(boxid, 'click', qtype_chooser.enable_disable_submit); + YAHOO.util.Event.addListener(boxid, 'key_down', qtype_chooser.enable_disable_submit); + YAHOO.util.Event.addListener(boxid, 'key_up', qtype_chooser.enable_disable_submit); + YAHOO.util.Event.addListener(boxid, 'dblclick', qtype_chooser.double_click); + + YAHOO.util.Event.onDOMReady(qtype_chooser.init_container); + }, + + enable_disable_submit: function() { + var ok = false; + for (var i = 0; i < qtype_chooser.radiobuttons.length; i++) { + if (qtype_chooser.radiobuttons[i].checked) { + ok = true; + YAHOO.util.Dom.addClass(qtype_chooser.labels[i], 'selected'); + } else { + YAHOO.util.Dom.removeClass(qtype_chooser.labels[i], 'selected'); + } + } + qtype_chooser.submitbutton.disabled = !ok; + }, + + double_click: function() { + if (!qtype_chooser.submitbutton.disabled) { + qtype_chooser.submitbutton.form.submit(); + } + }, + + init_container: function() { + if (!document.getElementById('qtypechoicecontainer')) { + return; + } + qtype_chooser.container = new YAHOO.widget.Dialog('qtypechoicecontainer', { + constraintoviewport: true, + visible: false, + modal: true, + fixedcenter: true, + close: true, + draggable: true, + dragOnly: true, + postmethod: 'form', + zIndex: 1000 + }); + qtype_chooser.container.render(); + + YAHOO.util.Event.addListener('chooseqtypecancel', 'click', qtype_chooser.cancel_popup); + + var addforms = YAHOO.util.Dom.getElementsBy(function(el) { + return /question\/addquestion\.php/.test(el.action); }, 'form', document.body); + for (var i = 0; i < addforms.length; i++) { + YAHOO.util.Event.addListener(addforms[i], 'submit', qtype_chooser.add_button_click); + } + }, + + add_button_click: function(e) { + var form = document.getElementById('qtypeformdiv'); + + var oldhidden = YAHOO.util.Dom.getElementsBy( + function(el) { return el.type == 'hidden'; }, 'input', form); + for (var i = 0; i < oldhidden.length; i++) { + oldhidden[i].parentNode.removeChild(oldhidden[i]); + } + + var wantedhidden = YAHOO.util.Dom.getElementsBy( + function(el) { return el.type == 'hidden'; }, 'input', this); + for (i = 0; i < wantedhidden.length; i++) { + form.appendChild(wantedhidden[i].cloneNode(true)); + } + + qtype_chooser.container.show(); + YAHOO.util.Event.preventDefault(e); + }, + + cancel_popup: function(e) { + qtype_chooser.container.hide(); + YAHOO.util.Event.preventDefault(e); + } +}; \ No newline at end of file diff --git a/question/question.php b/question/question.php index aea20da477..5f0ee6d809 100644 --- a/question/question.php +++ b/question/question.php @@ -48,6 +48,10 @@ if (!$returnurl) { $returnurl = "{$CFG->wwwroot}/question/edit.php?courseid={$COURSE->id}"; } +if (optional_param('addcancel', false, PARAM_BOOL)) { + redirect($returnurl); +} + if ($id) { if (!$question = $DB->get_record('question', array('id' => $id))) { print_error('questiondoesnotexist', 'question', $returnurl); @@ -228,7 +232,7 @@ if ($mform->is_cancelled()){ } } else { - list($streditingquestion,) = $QTYPES[$question->qtype]->get_heading(); + $streditingquestion = $QTYPES[$question->qtype]->get_heading(); if ($cm !== null) { $strmodule = get_string('modulename', $cm->modname); $strupdatemodule = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $COURSE->id)) diff --git a/theme/standard/styles_color.css b/theme/standard/styles_color.css index b1e45606b2..97f315de67 100644 --- a/theme/standard/styles_color.css +++ b/theme/standard/styles_color.css @@ -809,6 +809,18 @@ table.message_search_results td { *** Question ***/ +#qtypechoicecontainer #chooseqtype .qtypes { + border-bottom-color: grey; +} +#qtypechoicecontainer #chooseqtype .selected { + background: #dddddd; +} +#qtypechoicecontainer #chooseqtype .instruction, +#qtypechoicecontainer #chooseqtype .qtypesummary { + border-left-color: grey; + background-color: white; +} + .que { border-color: #DDD; } diff --git a/theme/standard/styles_fonts.css b/theme/standard/styles_fonts.css index c9403cda94..afbf97f894 100644 --- a/theme/standard/styles_fonts.css +++ b/theme/standard/styles_fonts.css @@ -725,6 +725,17 @@ body#grade-index .grades .header { *** Question ***/ +#chooseqtype .instruction, +#chooseqtype .qtypesummary { + font-size: 0.8em; +} +#chooseqtype .qtypename { + font-weight: bold; +} +#qtypechoicecontainer #chooseqtype .qtypename { + font-weight: normal; +} + .que .info h2 { font-size: 1.25em; font-weight: bold; diff --git a/theme/standard/styles_layout.css b/theme/standard/styles_layout.css index 45276ea907..c76abf1cb8 100644 --- a/theme/standard/styles_layout.css +++ b/theme/standard/styles_layout.css @@ -2897,6 +2897,67 @@ body.notes .notesgroup { margin-top: 0; } +#chooseqtypebox { + margin-top: 1em; +} +#chooseqtype h3 { + margin: 0 0 0.3em; +} +#chooseqtype .instruction { + display: none; +} +#chooseqtype .qtypeoption { + margin-bottom: 0.5em; +} +#chooseqtype .qtypename img { + padding: 0 0.3em; +} +#chooseqtype .qtypesummary { + display: block; + margin: 0 2em; +} +#chooseqtype .submitbuttons { + margin: 0.7em 0; + text-align: center; +} + +#qtypechoicecontainer { + display: none; +} +body.jsenabled #qtypechoicecontainer { + display: block; +} +#qtypechoicecontainer #chooseqtype { + width: 30em; +} +#qtypechoicecontainer #chooseqtypehead h3 { + margin: 0; +} +#qtypechoicecontainer #chooseqtype .qtypes { + position: relative; + border-bottom: 1px solid grey; + padding: 0.24em 0; +} +#qtypechoicecontainer #chooseqtype .qtypeoption { + margin-bottom: 0; +} +#qtypechoicecontainer #chooseqtype .instruction, +#qtypechoicecontainer #chooseqtype .qtypesummary { + display: none; + position: absolute; + top: 0px; + right: 0px; + bottom: 0px; + left: 60%; + margin: 0; + border-left: 1px solid grey; + padding: 0.3em 0.5em; +} +#qtypechoicecontainer #chooseqtype .instruction, +#qtypechoicecontainer #chooseqtype .selected .qtypesummary { + display: block; +} + .que { text-align: left; margin: 0 auto 1.8em auto; @@ -4831,50 +4892,34 @@ table.quizreviewsummary td.cell { z-index:999; } -#mod-quiz-edit .quizpagedelete img{ +#mod-quiz-edit .quizpagedelete img { background-color:#d6d6d6; padding:0.5em; } -#mod-quiz-edit .pagecontrols{ +#mod-quiz-edit .pagecontrols { clear:both; margin-left:0.5em; padding-top:0.5em; } -#mod-quiz-edit .pagecontrols .singlebutton{ - float:left; -} - -#mod-quiz-edit div.quizpage .pagecontent form#addquestion{ - margin-right:1em; - -webkit-border-radius:0.2em; - border-radius:0.2em; - padding:0.3em; +#mod-quiz-edit .pagecontrols .singlebutton { + float:left; + margin-left: 1em; } - -#mod-quiz-edit div.quizpage .pagecontent form.randomquestionform{ - padding-left:1em; +#mod-quiz-edit .pagecontrols .helplink { + float:left; } #mod-quiz-edit div.quizpage .pagecontent form.randomquestionform div{ /* it is a mystery why this has to be inline-table but otherwise the layout gets screwed, even if it is "inline" */ - display:inline-table; + display: inline-table; } #mod-quiz-edit div.quizpage .pagecontent form.randomquestionform div input{ - display:inline; -} - -#mod-quiz-edit div.quizpage .pagecontent .adddescription{ - clear:left; - margin-top:0.3em; -} - -#mod-quiz-edit div.quizpage .pagecontent .addrandomquestion{ - margin-top:0.3em; + display: inline; } /* a CSS class YUI container creates on the fly: */ @@ -5013,24 +5058,28 @@ table.quizreviewsummary td.cell { } /*start question bank*/ - -/*TODO: below applies to also question bank, so when -question bank is adapted to the new UI, add the appropriate -css id's of question bank*/ -#mod-quiz-edit .questionbankwindow .createnewquestion select, -#mod-quiz-edit .questionbankwindow #catmenu select{ - width:80%; +.questionbankwindow .choosecategory, +.questionbankwindow .createnewquestion { + padding: 0.3em; } -#mod-quiz-addrandom select { - width:100%; +.questionbankwindow .createnewquestion .singlebutton { + display: inline; } -#mod-quiz-edit table#categoryquestions{ +.questionbankwindow #catmenu_jump { + display: block; +} +#mod-quiz-edit .questionbankwindow .createnewquestion select, +#mod-quiz-edit .questionbankwindow #catmenu select, +#mod-quiz-edit .questionbankwindow #menucategory { + width: 100%; +} +table#categoryquestions { width: 100%; overflow: hidden; table-layout: fixed; } -#mod-quiz-edit table#categoryquestions td,#mod-quiz-edit table#categoryquestions th{ +table#categoryquestions td,#mod-quiz-edit table#categoryquestions th{ overflow:hidden; white-space:nowrap; } @@ -5051,7 +5100,7 @@ css id's of question bank*/ text-align: center; } -#mod-quiz-edit #categoryquestions .qtype { +#categoryquestions .qtype { width: 24px; padding: 0; } @@ -5059,8 +5108,8 @@ css id's of question bank*/ #categoryquestions .questiontext p { margin: 0; } -#mod-quiz-edit .categoryinfo{ - padding:0.3em; +.categoryinfo { + padding: 0.3em; } #mod-quiz-edit .paging{ @@ -5069,10 +5118,6 @@ css id's of question bank*/ display:block; } -#mod-quiz-edit .questionsortoptions{ - margin-top:0.3em; -} - #mod-quiz-edit .pagingbottom{ padding-bottom:0.3em; } @@ -5081,11 +5126,6 @@ css id's of question bank*/ clear:both; } -#mod-quiz-edit div.createnewquestion{ - padding-top:0.3em; - clear:left; -} - #mod-quiz-edit .sideblock .content{ padding:0; } @@ -5095,25 +5135,21 @@ css id's of question bank*/ margin-top:0.3em; } -#mod-quiz-edit .questionbank .categoryselectallcontainer{ - padding-bottom:0.5em; -} - -#mod-quiz-edit .questionbank div.categoryquestionscontainer, -#mod-quiz-edit .questionbank .categorysortopotionscontainer, -#mod-quiz-edit .questionbank .categorypagingbarcontainer, -#mod-quiz-edit .questionbank .categoryselectallcontainer{ +.questionbank div.categoryquestionscontainer, +.questionbank .categorysortopotionscontainer, +.questionbank .categorypagingbarcontainer, +.questionbank .categoryselectallcontainer{ padding-left:0.3em; padding-right:0.3em; } -#mod-quiz-edit .noquestionsincategory{ +.noquestionsincategory{ clear:both; padding-top:1em; padding-bottom:1em; } -#mod-quiz-edit .modulespecificbuttonscontainer{ +.modulespecificbuttonscontainer{ padding-left:0.3em; padding-right:0.3em; } -- 2.39.5