Use buttons instead of anchors in exercise submit - refs BT#12444

remotes/angel/1.11.x
Angel Fernando Quiroz Campos 8 years ago
parent 0f9d2111a1
commit 82ff09884a
  1. 45
      main/exercise/exercise.class.php
  2. 46
      main/exercise/exercise_submit.php

@ -2889,7 +2889,8 @@ class Exercise
$nbrQuestions = $this->get_count_question_list();
$all_button = $html = $label = '';
$all_button = [];
$html = $label = '';
$hotspot_get = isset($_POST['hotspot']) ? Security::remove_XSS($_POST['hotspot']):null;
if ($this->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT && $this->type == ONE_PER_PAGE) {
@ -2938,19 +2939,39 @@ class Exercise
if ($this->type == ONE_PER_PAGE) {
if ($questionNum != 1) {
$prev_question = $questionNum - 2;
$all_button .= '<a href="javascript://" class="btn btn-default" onclick="previous_question_and_save('.$prev_question.', '.$question_id.' ); ">'.get_lang('PreviousQuestion').'</a>';
$all_button[] = Display::button(
'previous_question_and_save',
get_lang('PreviousQuestion'),
[
'type' => 'button',
'class' => 'btn btn-default',
'data-prev' => $prev_question,
'data-question' => $question_id
]
);
}
//Next question
if (!empty($questions_in_media)) {
$questions_in_media = "['".implode("','",$questions_in_media)."']";
$all_button .= '&nbsp;<a href="javascript://" class="'.$class.'" onclick="save_question_list('.$questions_in_media.'); ">'.$label.'</a>';
$all_button[] = Display::button(
'save_question_list',
$label,
[
'type' => 'button',
'class' => $class,
'data-list' => implode(",", $questions_in_media)
]
);
} else {
$all_button .= '&nbsp;<a href="javascript://" class="'.$class.'" onclick="save_now('.$question_id.', \'\', \''.$currentAnswer.'\'); ">'.$label.'</a>';
$all_button[] = Display::button(
'save_now',
$label,
['type' => 'button', 'class' => $class, 'data-question' => $question_id]
);
}
$all_button .= '<span id="save_for_now_'.$question_id.'" class="exercise_save_mini_message"></span>&nbsp;';
$all_button[] = '<span id="save_for_now_'.$question_id.'" class="exercise_save_mini_message"></span>&nbsp;';
$html .= $all_button;
$html .= implode(PHP_EOL, $all_button);
} else {
if ($this->review_answers) {
$all_label = get_lang('ReviewQuestions');
@ -2960,9 +2981,13 @@ class Exercise
$class = 'btn btn-warning';
}
$class .= ' question-validate-btn'; // used to select it with jquery
$all_button = '&nbsp;<a href="javascript://" class="'.$class.'" onclick="validate_all(); ">'.$all_label.'</a>';
$all_button .= '&nbsp;' . Display::span(null, ['id' => 'save_all_reponse']);
$html .= $all_button;
$all_button[] = Display::button(
'validate_all',
$all_label,
['type' => 'button', 'class' => $class]
);
$all_button[] = '&nbsp;' . Display::span(null, ['id' => 'save_all_reponse']);
$html .= implode(PHP_EOL, $all_button);
}
}
}

@ -974,6 +974,50 @@ if (!empty($error)) {
$(\'form#exercise_form\').prepend($(\'#exercise-description\'));
});
$(document).on(\'ready\', function () {
$(\'button[name="previous_question_and_save"]\').on(\'click\', function (e) {
e.preventDefault();
e.stopPropagation();
var
$this = $(this),
previousId = parseInt($this.data(\'prev\')) || 0,
questionId = parseInt($this.data(\'question\')) || 0;
previous_question_and_save(previousId, questionId);
});
$(\'button[name="save_question_list"\').on(\'click\', function (e) {
e.preventDefault();
e.stopPropagation();
var
$this = $(this),
questionList = $this.data(\'list\').split(",");
save_question_list(questionList);
});
$(\'button[name="save_now"]\').on(\'click\', function (e) {
e.preventDefault();
e.stopPropagation();
var
$this = $(this),
questionId = parseInt($this.data(\'question\')) || 0,
urlExtra = $this.data(\'url\') || null;
save_now(questionId, urlExtra);
});
$(\'button[name="validate_all"]\').on(\'click\', function (e) {
e.preventDefault();
e.stopPropagation();
validate_all();
});
});
function previous_question(question_num) {
url = "exercise_submit.php?'.$params.'&num="+question_num;
window.location = url;
@ -1064,7 +1108,6 @@ if (!empty($error)) {
$("#save_for_now_"+question_id).html(\'' . Display::return_icon('error.png', get_lang('Error'), array(), ICON_SIZE_SMALL) . '\');
}
});
return false;
}
function save_now_all(validate) {
@ -1119,7 +1162,6 @@ if (!empty($error)) {
function validate_all() {
save_now_all("validate");
return false;
}
</script>';

Loading…
Cancel
Save