diff --git a/app/controllers/course/feedback.php b/app/controllers/course/feedback.php index c6eb9771be60c71dee66a7d196905d06b75f90d0..df600c7a1f502ad6409f55d7819ef75906ae9eda 100644 --- a/app/controllers/course/feedback.php +++ b/app/controllers/course/feedback.php @@ -85,26 +85,24 @@ class Course_FeedbackController extends AuthenticatedController if (!Feedback::hasRangeAccess($range_id, $range_type)) { throw new AccessDeniedException(); } elseif ($this->create_perm) { - if (Request::bool('comment_only')) { - $mode = FeedbackElement::MODE_NO_RATING; - $commentable = 1; - } else { - $mode = Request::int('mode', FeedbackElement::MODE_NO_RATING); - $commentable = Request::bool('commentable'); + $mode = FeedbackElement::MODE_NO_RATING; + $commentable = true; + if (!Request::bool('comment_only')) { + $mode = Request::int('mode', $mode); + $commentable = Request::bool('commentable', false); } - $feedback = FeedbackElement::build([ + $feedback = FeedbackElement::create([ 'range_id' => $range_id, 'range_type' => $range_type, 'user_id' => $GLOBALS['user']->id, 'course_id' => $this->course_id, 'question' => trim(Request::get('question')), 'description' => Studip\Markup::purifyHtml(Request::get('description')), - 'results_visible' => intval(Request::get('results_visible')), + 'results_visible' => Request::bool('results_visible', false), 'commentable' => $commentable, - 'anonymous_entries' => intval(Request::get('anonymous_entries')), + 'anonymous_entries' => Request::bool('anonymous_entries', false), 'mode' => $mode ]); - $feedback->store(); PageLayout::postSuccess(_('Feedback-Element erfolgreich angelegt')); } else { PageLayout::postError(_('Sie haben keine Berechtigung, an dieser Stelle ein Feedback-Element anzulegen.')); diff --git a/app/views/course/feedback/_add_edit_entry_form.php b/app/views/course/feedback/_add_edit_entry_form.php index 1481f57fb747054ca10ce20acead54ed5f777fe3..f55390f80751b2525013312e8d2d6eef4831f66f 100644 --- a/app/views/course/feedback/_add_edit_entry_form.php +++ b/app/views/course/feedback/_add_edit_entry_form.php @@ -17,7 +17,7 @@ <label class="star-rating undecorated <?= (isset($entry) && $i <= $entry->rating) || $i === 1 ? ' checked' : '' ?>"> <input class="star-rating-input" name="rating" value="<?= $i ?>" type="radio" required - <? if (isset($entry) && $i == $entry->rating) echo 'selected'; ?>> + <? if (isset($entry) && $i == $entry->rating || $i === 1) echo 'checked'; ?>> <?= Icon::create('star') ?> </label> <? endfor; ?> @@ -26,16 +26,23 @@ <? if ($feedback->commentable) : ?> <label> <?= _('Kommentar') ?> - <textarea name="comment"><?= htmlReady(isset($entry) ? $entry->comment : '') ?></textarea> + <textarea name="comment"><?= htmlReady($entry->comment ?? '') ?></textarea> </label> <? endif; ?> <? if ($feedback->anonymous_entries) : ?> <label> - <input type="checkbox" name="anonymous" value="1" <?= $entry->anonymous ? 'checked' : '' ?> > + <input type="checkbox" name="anonymous" value="1" <?= !empty($entry->anonymous) ? 'checked' : '' ?> > <?= _('Kommentar anonym abgeben') ?> </label> <? endif; ?> + +<? if (Request::isDialog()): ?> +<div data-dialog-button> + <?= Studip\Button::createAccept(_('Absenden'), 'add', ['class' => 'feedback-entry-submit']) ?> +</div> +<? else: ?> <div> <?= Studip\Button::createAccept(_('Absenden'), 'add', ['class' => 'feedback-entry-submit']) ?> <?= Studip\Button::createCancel(_('Abbrechen'), 'cancel', ['class' => 'feedback-entry-cancel']) ?> </div> +<? endif; ?> diff --git a/resources/assets/javascripts/feedback.js b/resources/assets/javascripts/feedback.js index 5555bb7ea2abcb001f634a4739eedb9a94fd04c5..316bc42bc9b8ed2336c711685d847db8f1f9f933 100644 --- a/resources/assets/javascripts/feedback.js +++ b/resources/assets/javascripts/feedback.js @@ -125,12 +125,14 @@ STUDIP.Feedback = { } ); } - if ($('.feedback-entry-cancel').length) { + if ($('.feedback-entry-cancel').length > 0) { $('.feedback-entry-cancel').prop("onclick", null).off("click"); $('.feedback-entry-cancel').click(function (event) { event.preventDefault(); - $(this).closest('form')[0].reset(); - $(this).closest('form').find('.star-rating').removeClass('checked'); + $(this).closest('form').each(function () { + this.reset(); + $(this).find('.star-rating').removeClass('checked'); + }); }); } }