From 9157f7c55d75c7e55aac425948abc132981ecfd7 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Wed, 22 Mar 2023 14:59:57 +0000 Subject: [PATCH] add appropriate title for course completion icon, fixes #2416 Closes #2416 Merge request studip/studip!1614 --- app/controllers/admin/courses.php | 5 ++++- app/views/admin/courses/_course.php | 5 +++-- lib/models/Course.class.php | 14 ++++++++++++++ .../assets/javascripts/bootstrap/application.js | 7 +++++-- 4 files changed, 26 insertions(+), 5 deletions(-) diff --git a/app/controllers/admin/courses.php b/app/controllers/admin/courses.php index 99b2943c6d8..7bdeaae2ee3 100644 --- a/app/controllers/admin/courses.php +++ b/app/controllers/admin/courses.php @@ -884,7 +884,10 @@ class Admin_CoursesController extends AuthenticatedController $course->store(); if (Request::isXhr()) { - $this->render_json((int)$course->completion); + $this->render_json([ + 'state' => (int)$course->completion, + 'label' => $course->getCompetionLabel(), + ]); } else { $this->redirect('admin/courses/index#course-' . $course_id); } diff --git a/app/views/admin/courses/_course.php b/app/views/admin/courses/_course.php index 87491fd152a..645b06e7443 100644 --- a/app/views/admin/courses/_course.php +++ b/app/views/admin/courses/_course.php @@ -25,10 +25,11 @@ if (!$values['parent_course'] || !in_array($values['parent_course'], array_keys( <td> <? if (Config::get()->ADMIN_COURSES_SHOW_COMPLETE): ?> <? if ($GLOBALS['perm']->have_studip_perm('tutor', $semid)) : ?> - <a href="<?= $controller->url_for('admin/courses/toggle_complete/' . $semid) ?>" + <a href="<?= $controller->toggle_complete($course) ?>" class="course-completion" data-course-completion="<?= $values['completion'] ?>" - title="<?= _('Bearbeitungsstatus ändern') ?>"> + title="<?= htmlReady($course->getCompetionLabel()) ?>" + aria-label="<?= _('Bearbeitungsstatus ändern') ?>"> <?= _('Bearbeitungsstatus ändern') ?> </a> <? else : ?> diff --git a/lib/models/Course.class.php b/lib/models/Course.class.php index 5df3e3e3e68..429bb1b8459 100644 --- a/lib/models/Course.class.php +++ b/lib/models/Course.class.php @@ -754,6 +754,20 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe return Icon::create('radiobutton-checked', $role); } + /** + * Returns the appropriate label for the completion status. + * + * @return string + */ + public function getCompetionLabel(): string + { + return [ + 0 => _('unvollständig'), + 1 => _('in Bearbeitung'), + 2 => _('fertig'), + ][$this->completion] ?? _('undefiniert'); + } + /** * Generates a general log entry if the course were changed. * Furthermore, this method emits notifications when the diff --git a/resources/assets/javascripts/bootstrap/application.js b/resources/assets/javascripts/bootstrap/application.js index 4802091dbf7..f97dd90e048 100644 --- a/resources/assets/javascripts/bootstrap/application.js +++ b/resources/assets/javascripts/bootstrap/application.js @@ -334,10 +334,13 @@ jQuery(document).on('click', '.course-admin td .course-completion', function () $(this).addClass('ajaxing'); }.bind(this), 300); - $.getJSON(href).done(function (completion) { + $.getJSON(href).done(function (response) { clearTimeout(timeout); - $(this).removeClass('ajaxing').attr('data-course-completion', completion); + $(this).removeClass('ajaxing').attr({ + 'data-course-completion': response.state, + title: response.label + }); }.bind(this)); return false; -- GitLab