From e791027fc53afbc29d4377f877219824778f1e51 Mon Sep 17 00:00:00 2001
From: Thomas Fradet <t.fradet8@gmail.com>
Date: Thu, 24 Oct 2019 15:11:45 +0200
Subject: [PATCH] dropdowns, coursidbug and assignment direct link
---
competency_iena_competencies_mgmt.php | 57 +++---------
course_competency.php | 51 +++++------
js/cpt-x-studs.js | 44 ----------
js/dropdown.js | 119 ++++++++++++++++++++++++++
js/stud-x-cpts.js | 42 ---------
styles.css | 22 ++++-
6 files changed, 180 insertions(+), 155 deletions(-)
delete mode 100644 js/cpt-x-studs.js
create mode 100644 js/dropdown.js
delete mode 100644 js/stud-x-cpts.js
diff --git a/competency_iena_competencies_mgmt.php b/competency_iena_competencies_mgmt.php
index f89ec08..ee25f27 100644
--- a/competency_iena_competencies_mgmt.php
+++ b/competency_iena_competencies_mgmt.php
@@ -14,20 +14,12 @@
global $COURSE, $DB, $CFG;
- try {
- $courseid = required_param('courseid', PARAM_INT);
- } catch (coding_exception $e) {
- }
- try {
- $url = new moodle_url('/blocks/competency_iena/competency_iena_competencies_mgmt.php', array('courseid' => $courseid));
- } catch (moodle_exception $e) {
- }
+ $courseid = required_param('courseid', PARAM_INT);
+
+ $url = new moodle_url('/blocks/competency_iena/competency_iena_competencies_mgmt.php', array('courseid' => $courseid));
//$requete = $DB->get_record_sql('SELECT course FROM {block_competency_iena} WHERE id = ?', array($courseid));
- try {
- $PAGE->set_url($url);
- } catch (coding_exception $e) {
- }
+ $PAGE->set_url($url);
if ($_POST) {
@@ -129,40 +121,17 @@
exit;
}
- try {
- $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
- } catch (dml_exception $e) {
- }
- try {
- require_login($course, false, NULL);
- } catch (coding_exception $e) {
- } catch (require_login_exception $e) {
- } catch (moodle_exception $e) {
- }
-
- try {
- $PAGE->set_title(get_string('title_plugin', 'block_competency_iena'));
- } catch (coding_exception $e) {
- }
- try {
- $PAGE->set_heading($OUTPUT->heading($COURSE->fullname, 2, 'headingblock header outline'));
- } catch (coding_exception $e) {
- }
-
-
- try {
- echo $OUTPUT->header();
- } catch (coding_exception $e) {
- }
-//$PAGE->requires->js("/blocks/competency_iena/js/jquery.min.js");
+ $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
+ require_login($course, false, NULL);
+
+ $PAGE->set_title(get_string('title_plugin', 'block_competency_iena'));
+ $PAGE->set_heading($OUTPUT->heading($COURSE->fullname, 2, 'headingblock header outline'));
+ echo $OUTPUT->header();
+
$PAGE->requires->js("/blocks/competency_iena/js/file.js");
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"styles.css\">";
$view = new view_competency_iena_competencies_mgmt();
echo $view->get_content(htmlspecialchars($courseid));
-
-
- try {
- echo $OUTPUT->footer();
- } catch (coding_exception $e) {
- }
+
+ echo $OUTPUT->footer();
diff --git a/course_competency.php b/course_competency.php
index 16054c0..5d286ae 100644
--- a/course_competency.php
+++ b/course_competency.php
@@ -16,9 +16,7 @@ require_login($courseid, false, NULL);
$PAGE->set_pagelayout('course');
$PAGE->set_title(get_string('title_plugin', 'block_competency_iena'));
$PAGE->set_heading($OUTPUT->heading($COURSE->fullname, 2, 'headingblock header outline'));
-$PAGE->requires->js("/blocks/competency_iena/js/datalist-polyfill.min.js");
-$PAGE->requires->js("/blocks/competency_iena/js/stud-x-cpts.js");
-$PAGE->requires->js("/blocks/competency_iena/js/cpt-x-studs.js");
+$PAGE->requires->js("/blocks/competency_iena/js/dropdown.js");
$PAGE->requires->js("/blocks/competency_iena/js/cpt-stud-course.js");
/* <<< GESTION DROITS D'ACCÈS >>> */
@@ -133,10 +131,6 @@ $course_cpts = \core_competency\course_competency::list_competencies($COURSE->id
/* <<< PAGE >>> */
-// echo "<pre>";
-// var_dump($cpt_scale);
-// echo "</pre>";
-
/* STUDENT NAME */
_html("h2", $student->firstname . " " . $student->lastname, "h3' style='margin-bottom: 0.3rem;'");
@@ -144,19 +138,21 @@ _html("h2", $student->firstname . " " . $student->lastname, "h3' style='margin-b
/* SWITCH STUDENT FORM */
if ( $is_teacher && $students != NULL && count($students) != 0 ) {
- echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/course_competency.php' id='change_stud_form' class='form-inline m-b-1'>";
+ echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/course_competency.php' id='change_student' class='form-inline m-b-1' autocomplete='off' style='display: block;height: 1.5rem;'>";
echo "<input type='text' hidden name='courseid' value='{$courseid}'>";
echo "<input type='text' hidden name='competencyid' value='{$competencyid}'>";
echo "<span hidden id='studentid'>{$studentid}</span>";
- /*echo "<label class='m-y-1 m-r-1' for='studentid_sel' style='color: black;'>Etudiant</label>";*/
- echo "<input type='text' name='studentid' id='studentid_sel' value='' list='student_list' class='form-control' style='font-size: .7rem; line-height: 1;'>";
- echo "<datalist id='student_list' title='Select student'>";
+
+ echo "<div id='student_dropdown' class='iena-dropdown' style='z-index: 10;'>";
+ echo "<input type='text' hidden name='studentid' id='studentid_sel' class='iena-drop-input-value' value=''>";
+ echo "<input type='text' value='' class='form-control iena-drop-input' style='font-size: .7rem; line-height: 1; width: 300px;' placeholder='{$student->firstname} {$student->lastname}'><button class='btn btn-secondary' id='prevStud' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Précédent</button><button class='btn btn-secondary' id='nextStud' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Suivant</button>";
+ echo "<div class='iena-droplist' id='student_list'>";
foreach ($students as $stud) {
- echo "<option value='{$stud->firstname} {$stud->lastname} ({$stud->id})' data-value='{$stud->id}'>{$stud->firstname} {$stud->lastname} ({$stud->id})</option>";
+ echo "<a href='#' data-value='{$stud->id}' class='iena-drop-item' style='display: none;'>{$stud->firstname} {$stud->lastname}</a>";
}
- echo "</datalist>";
- echo "<div><button class='btn btn-secondary' id='prevStud' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Précédent</button>";
- echo "<button class='btn btn-secondary' id='nextStud' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Suivant</button></div>";
+ echo "</div>";
+ echo "</div>";
+
echo "</form>";
}
@@ -184,19 +180,21 @@ echo "<div style='margin-bottom: 0.7rem;'>" . $cpt_path_link . "</div>";
/* SWITCH COMPETENCY FORM */
-echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/course_competency.php' id='change_cpt_form' class='form-inline m-b-1'>";
+echo "<form action='{$CFG->wwwroot}/blocks/competency_iena/course_competency.php' id='change_cpt_form' class='form-inline m-b-1' autocomplete='off' style='display: block;height: 1.5rem;'>";
echo "<input type='text' hidden name='courseid' value='{$courseid}'>";
echo "<input type='text' hidden name='studentid' value='{$studentid}'>";
echo "<span hidden id='competencyid'>{$competencyid}</span>";
-/*echo "<label class='m-r-1' for='competencyid_sel' style=''>Changer de compétence</label>";*/
-echo "<input type='text' name='competencyid' id='competencyid_sel' value='' list='competency_list' class='form-control' style='font-size: .7rem; line-height: 1;'>";
-echo "<datalist id='competency_list' title='Select competency'>";
+
+echo "<div id='student_dropdown' class='iena-dropdown' style='z-index: 1;'>";
+echo "<input type='text' hidden name='competencyid' id='competencyid_sel' class='iena-drop-input-value' value=''>";
+echo "<input type='text' value='' class='form-control iena-drop-input' style='font-size: .7rem; line-height: 1; width: 300px;' placeholder='{$cpt->get('shortname')}' autocomplete='nope'><button class='btn btn-secondary' id='prevCpt' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Précédent</button><button class='btn btn-secondary' id='nextCpt' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Suivant</button>";
+echo "<div class='iena-droplist' id='competency_list'>";
foreach ($course_cpts as $course_cpt) {
- echo "<option value='{$course_cpt->get('shortname')} ({$course_cpt->get('id')})' data-value='{$course_cpt->get('id')}'>{$course_cpt->get('shortname')} ({$course_cpt->get('id')})</option>";
+ echo "<a href='#' data-value='{$course_cpt->get('id')}' class='iena-drop-item' style='display: none;'>{$course_cpt->get('shortname')}</a>";
}
-echo "</datalist>";
-echo "<button class='btn btn-secondary' id='prevCpt' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Précédent</button>";
-echo "<button class='btn btn-secondary' id='nextCpt' style='font-size: .8rem;line-height: 1.09; margin-left: 0.5rem;'>Suivant</button>";
+echo "</div>";
+echo "</div>";
+
echo "</form>";
/* END switch competency form */
@@ -398,7 +396,12 @@ if ( count($cm_ids) !== 0 ) {
$modinfo = get_fast_modinfo($courseid);
echo "<div class='list-group'>";
foreach ($cm_ids as $cm_id) {
- echo "<a href='{$modinfo->cms[$cm_id]->url->out()}' target='_blank' class='list-group-item list-group-item-action'><img src='$CFG->wwwroot/theme/image.php/boost/{$modinfo->cms[$cm_id]->modname}/1/icon>' style='height: 1.3rem;'><span class='align-middle'> {$modinfo->cms[$cm_id]->name}</span></a>";
+ $url = $modinfo->cms[$cm_id]->url->out();
+ $is_assign = strpos($url, '/mod/assign') !== false;
+ if ($is_teacher && $is_assign) {
+ $url = $url . "&rownum=0&action=grader&userid=" . $studentid;
+ }
+ echo "<a href='{$url}' target='_blank' class='list-group-item list-group-item-action'><img src='$CFG->wwwroot/theme/image.php/boost/{$modinfo->cms[$cm_id]->modname}/1/icon>' style='height: 1.3rem;'><span class='align-middle'> {$modinfo->cms[$cm_id]->name}</span></a>";
}
echo "</div>";
} else {
diff --git a/js/cpt-x-studs.js b/js/cpt-x-studs.js
deleted file mode 100644
index 57c32c9..0000000
--- a/js/cpt-x-studs.js
+++ /dev/null
@@ -1,44 +0,0 @@
-(function() {
-
- /* Submit datalist selector to change current competency
- on the dashboard listing avery student status regarding a particular competency. */
- window.addEventListener('load', function () {
- var opts = document.getElementById('competency_list').childNodes;
- var competencyid = document.getElementById('competencyid').innerHTML;
- for (var i = 0; i < opts.length; i++) {
- if (opts[i].dataset.value === competencyid) {
- var prev = opts[i - 1] === undefined ? false : opts[i - 1].dataset.value;
- var next = opts[i + 1] === undefined ? false : opts[i + 1].dataset.value;
- if (prev === false) {
- document.getElementById('prevCpt').setAttribute('disabled', 'disabled');
- } else {
- // document.getElementById('prevCpt').href += prev;
- document.getElementById('prevCpt').dataset.prev = prev;
- document.getElementById('prevCpt').onclick = function () {
- document.getElementById('competencyid_sel').value = document.getElementById('prevCpt').dataset.prev;
- }
- }
- if (next === false) {
- document.getElementById('nextCpt').setAttribute('disabled', 'disabled');
- } else {
- // document.getElementById('nextCpt').href += next;
- document.getElementById('nextCpt').dataset.next = next;
- document.getElementById('nextCpt').onclick = function () {
- document.getElementById('competencyid_sel').value = document.getElementById('nextCpt').dataset.next;
- }
- }
- }
- }
- /* remplace le nom de l'étu par son id dans la valeur de l'input puis soumet le formulaire */
- document.getElementById('competencyid_sel').oninput = function (e) {
- var val = document.getElementById('competencyid_sel').value;
- var opts = document.getElementById('competency_list').childNodes;
- for (var i = 0; i < opts.length; i++) {
- if (opts[i].value === val) {
- document.getElementById('competencyid_sel').value = opts[i].dataset.value;
- document.getElementById('change_cpt_form').submit();
- }
- }
- };
- });
-})()
\ No newline at end of file
diff --git a/js/dropdown.js b/js/dropdown.js
new file mode 100644
index 0000000..0dfa1b1
--- /dev/null
+++ b/js/dropdown.js
@@ -0,0 +1,119 @@
+(function() {
+ function filter (e) {
+ let filter = e.target.value.toUpperCase();
+ let a = e.target.parentNode.querySelectorAll('a');
+ for (let k = 0; k < a.length; k++) {
+ let txtValue = a[k].textContent || a[k].innerText;
+ if (txtValue.toUpperCase().indexOf(filter) > -1) {
+ a[k].style.display = "block";
+ } else {
+ a[k].style.display = "none";
+ }
+ }
+ }
+ window.addEventListener('load', function () {
+
+ /* Activation of dropdowns in the page */
+
+ let drops = document.querySelectorAll('.iena-dropdown');
+
+ for (var i = 0; i < drops.length; i++) {
+
+ drops[i].querySelector('.iena-drop-input').addEventListener('focus', function(e) {
+ let a = e.target.parentNode.querySelectorAll('a');
+ for (var i = 0; i < a.length; i++) {
+ a[i].style.display = "block";
+ }
+ filter(e);
+ });
+
+ let a = drops[i].querySelectorAll('a');
+
+ for (var j = 0; j < a.length; j++) {
+ a[j].onmousedown = function(e) {
+ e.preventDefault();
+ let true_input = e.target.parentNode.parentNode.querySelector('.iena-drop-input-value');
+ let value = e.target.dataset.value;
+ true_input.value = value;
+ let input = e.target.parentNode.parentNode.querySelector('.iena-drop-input')
+ input.value = e.target.innerText;
+ let a = e.target.parentNode.querySelectorAll('a');
+ for (var i = 0; i < a.length; i++) {
+ a[i].style.display = "none";
+ }
+ e.target.parentNode.parentNode.parentNode.submit();
+ };
+ }
+
+ drops[i].querySelector('.iena-drop-input').addEventListener('blur', function(e) {
+ let a = e.target.parentNode.querySelectorAll('a');
+ for (var i = 0; i < a.length; i++) {
+ a[i].style.display = "none";
+ }
+ });
+
+ drops[i].querySelector('.iena-drop-input').addEventListener('keyup', function(e) {
+ filter(e);
+ });
+
+ }
+
+ /* Activation of previous and next buttons for dropdowns */
+
+ var opts = document.getElementById('student_list').childNodes;
+ var studentid = document.getElementById('studentid').innerHTML;
+ for (var i = 0; i < opts.length; i++) {
+ if (opts[i].dataset.value === studentid) {
+ var prev = opts[i - 1] === undefined ? false : opts[i - 1].dataset.value;
+ var next = opts[i + 1] === undefined ? false : opts[i + 1].dataset.value;
+ if (prev === false) {
+ document.getElementById('prevStud').setAttribute('disabled', 'disabled');
+ } else {
+ // document.getElementById('prevStud').href += prev;
+ document.getElementById('prevStud').dataset.prev = prev;
+ document.getElementById('prevStud').onclick = function () {
+ document.getElementById('studentid_sel').value = document.getElementById('prevStud').dataset.prev;
+ }
+ }
+ if (next === false) {
+ document.getElementById('nextStud').setAttribute('disabled', 'disabled');
+ } else {
+ // document.getElementById('nextStud').href += next;
+ document.getElementById('nextStud').dataset.next = next;
+ document.getElementById('nextStud').onclick = function () {
+ document.getElementById('studentid_sel').value = document.getElementById('nextStud').dataset.next;
+ }
+ }
+ }
+ }
+
+ var opts = document.getElementById('competency_list').childNodes;
+ var competencyid = document.getElementById('competencyid').innerHTML;
+ for (var i = 0; i < opts.length; i++) {
+ if (opts[i].dataset.value === competencyid) {
+ var prev = opts[i - 1] === undefined ? false : opts[i - 1].dataset.value;
+ var next = opts[i + 1] === undefined ? false : opts[i + 1].dataset.value;
+ if (prev === false) {
+ document.getElementById('prevCpt').setAttribute('disabled', 'disabled');
+ } else {
+ // document.getElementById('prevCpt').href += prev;
+ document.getElementById('prevCpt').dataset.prev = prev;
+ document.getElementById('prevCpt').onclick = function () {
+ document.getElementById('competencyid_sel').value = document.getElementById('prevCpt').dataset.prev;
+ }
+ }
+ if (next === false) {
+ document.getElementById('nextCpt').setAttribute('disabled', 'disabled');
+ } else {
+ // document.getElementById('nextCpt').href += next;
+ document.getElementById('nextCpt').dataset.next = next;
+ document.getElementById('nextCpt').onclick = function () {
+ document.getElementById('competencyid_sel').value = document.getElementById('nextCpt').dataset.next;
+ }
+ }
+ }
+ }
+
+ });
+
+})()
\ No newline at end of file
diff --git a/js/stud-x-cpts.js b/js/stud-x-cpts.js
deleted file mode 100644
index 6c3ad42..0000000
--- a/js/stud-x-cpts.js
+++ /dev/null
@@ -1,42 +0,0 @@
-(function() {
- window.addEventListener('load', function () {
- var opts = document.getElementById('student_list').childNodes;
- var studentid = document.getElementById('studentid').innerHTML;
- for (var i = 0; i < opts.length; i++) {
- if (opts[i].dataset.value === studentid) {
- var prev = opts[i - 1] === undefined ? false : opts[i - 1].dataset.value;
- var next = opts[i + 1] === undefined ? false : opts[i + 1].dataset.value;
- if (prev === false) {
- document.getElementById('prevStud').setAttribute('disabled', 'disabled');
- } else {
- // document.getElementById('prevStud').href += prev;
- document.getElementById('prevStud').dataset.prev = prev;
- document.getElementById('prevStud').onclick = function () {
- document.getElementById('studentid_sel').value = document.getElementById('prevStud').dataset.prev;
- }
- }
- if (next === false) {
- document.getElementById('nextStud').setAttribute('disabled', 'disabled');
- } else {
- // document.getElementById('nextStud').href += next;
- document.getElementById('nextStud').dataset.next = next;
- document.getElementById('nextStud').onclick = function () {
- document.getElementById('studentid_sel').value = document.getElementById('nextStud').dataset.next;
- }
- }
- }
- }
- /* remplace le nom de l'étu par son id dans la valeur de l'input puis soumet le formulaire */
- document.getElementById('studentid_sel').oninput = function (e) {
- var val = document.getElementById('studentid_sel').value;
- var opts = document.getElementById('student_list').childNodes;
- for (var i = 0; i < opts.length; i++) {
- if (opts[i].value === val) {
- document.getElementById('studentid_sel').value = opts[i].dataset.value;
- document.getElementById('change_stud_form').submit();
- }
- }
- };
- });
-
-})()
\ No newline at end of file
diff --git a/styles.css b/styles.css
index 8abf7d7..0ef22f3 100644
--- a/styles.css
+++ b/styles.css
@@ -77,4 +77,24 @@
padding: 0.12rem 0.35rem;
background-color: #008090;
color: white;
-}
\ No newline at end of file
+}
+
+/* Dropdown selectors */
+
+.iena-dropdown {
+ position: absolute;
+}
+
+.iena-dropdown a:hover { background-color: #ddd; }
+
+.iena-droplist {
+ max-height: 250px;
+ overflow:scroll;
+ width: 300px;
+ background-color: #f6f6f6;
+}
+
+.iena-drop-item {
+ text-decoration: none !important;
+ padding: 0.25rem 0.5rem;
+}
--
GitLab