Skip to content

Commit

Permalink
Adjustments for saving favorite status
Browse files Browse the repository at this point in the history
Concerns #253
  • Loading branch information
mikron-ia committed Oct 6, 2023
1 parent f24e1ae commit e9de95b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
11 changes: 8 additions & 3 deletions common/messages/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,19 @@
'SCENARIO_TECHNICAL_DETAILS' => 'Technical details',
'SCENARIO_TITLE_CREATE' => 'Create scenario',
'SCENARIO_TITLE_UPDATE' => 'Modify scenario',
'SCRIBBLES_TITLE_NO' => 'Click to mark as favorite',
'SCRIBBLES_TITLE_YES' => 'Marked as favorite; click to unmark',
'SCRIBBLES_BUTTON_NO' => 'Click to mark as favorite',
'SCRIBBLES_BUTTON_WORKING' => 'Status change in progress...',
'SCRIBBLES_BUTTON_YES' => 'Marked as favorite; click to unmark',
'SCRIBBLES_FAVORITE_ERROR_GENERIC' => 'Status change error',
'SCRIBBLES_TITLE_NO' => 'Click for player\'s scribbles',
'SCRIBBLES_TITLE_YES' => 'Click for player\'s scribbles',
'SCRIBBLE_DENIED_ACCESS' => 'You have no rights to access this',
'SCRIBBLE_ID' => 'ID',
'SCRIBBLE_IS_FAVORITE' => 'Favorited?',
'SCRIBBLE_PACK' => 'Pack of scribbles',
'SCRIBBLE_PACK_CLASS' => 'Class',
'SCRIBBLE_PACK_ID' => 'ID',
'SCRIBBLE_TITLE' => 'Scribbles',
'SCRIBBLE_TITLE' => 'Player\'s scribbles',
'SEEN_ALERT' => 'Alert threshold',
'SEEN_BEFORE_UPDATE' => 'Modified for:',
'SEEN_ID' => 'ID',
Expand Down
11 changes: 8 additions & 3 deletions common/messages/pl/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,19 @@
'SCENARIO_TECHNICAL_DETAILS' => 'Szczegóły techniczne',
'SCENARIO_TITLE_CREATE' => 'Dodaj scenariusz',
'SCENARIO_TITLE_UPDATE' => 'Zmień scenariusz',
'SCRIBBLES_TITLE_NO' => 'Klinij, by dodać do ulubionych',
'SCRIBBLES_TITLE_YES' => 'W ulubionych; kliknij, by usunąć z ulubionych',
'SCRIBBLES_BUTTON_NO' => 'Klinij, by dodać do ulubionych',
'SCRIBBLES_BUTTON_WORKING' => 'Zmiana statusu w toku...',
'SCRIBBLES_BUTTON_YES' => 'W ulubionych; kliknij, by usunąć z ulubionych',
'SCRIBBLES_FAVORITE_ERROR_GENERIC' => 'Błąd zapisu statusu',
'SCRIBBLES_TITLE_NO' => 'Zapiski',
'SCRIBBLES_TITLE_YES' => 'Zapiski',
'SCRIBBLE_DENIED_ACCESS' => 'Brak dostępu',
'SCRIBBLE_ID' => 'ID',
'SCRIBBLE_IS_FAVORITE' => 'Ulubione?',
'SCRIBBLE_PACK' => 'Paczka zapisków',
'SCRIBBLE_PACK_CLASS' => 'Klasa',
'SCRIBBLE_PACK_ID' => 'ID',
'SCRIBBLE_TITLE' => 'Notatki',
'SCRIBBLE_TITLE' => 'Zapiski',
'SEEN_ALERT' => 'Próg sygnalizacji',
'SEEN_BEFORE_UPDATE' => 'Zmienione dla:',
'SEEN_ID' => 'ID',
Expand Down
2 changes: 1 addition & 1 deletion frontend/controllers/ScribbleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function getModelWithValidation(int $scribbleId): Scribble

$scribble = $this->findModel($scribbleId);

if (!$scribble->scribblePack->canUserControlYou()) {
if (!$scribble->scribblePack->canUserReadYou()) {
throw new ForbiddenHttpException(Yii::t('app', 'SCRIBBLE_DENIED_ACCESS'));
}

Expand Down
32 changes: 21 additions & 11 deletions frontend/views/scribble/_modal_box.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,48 @@
/** @var common\models\Scribble $model */

$favoriteButtonTexts = [
false => Yii::t('app', 'SCRIBBLES_TITLE_NO'),
true => Yii::t('app', 'SCRIBBLES_TITLE_YES'),
false => Yii::t('app', 'SCRIBBLES_BUTTON_NO'),
true => Yii::t('app', 'SCRIBBLES_BUTTON_YES'),
];

?>
<div class="scribble-view">

<p id="scribble-modal-error-box" class="error-summary"></p>
<?= Html::button($favoriteButtonTexts[$model->favorite], [
'id' => 'favorite-button',
'class' => 'btn btn-primary btn-block',
'data-scribble-id' => $model->scribble_id,
]) ?>

</div>

<script>
let favorite = <?= (int)$model->favorite ?>;
const isFavoriteText = "<?= $favoriteButtonTexts[true] ?>";
const isNotFavoriteText = "<?= $favoriteButtonTexts[false] ?>";
var favorite = <?= (int)$model->favorite ?>;

$('#scribble-modal-error-box').hide();

$('#favorite-button').on('click', function () {
const button = $('#favorite-button');
button.text('<?= Yii::t('app', 'SCRIBBLES_BUTTON_WORKING') ?>');
button.prop('disabled', true);

$.ajax(
'../scribble/reverse-favorite',
{
method: "GET",
method: 'GET',
data: {
id: <?= $model->scribble_id ?>
id: $(this).data('scribble-id')
}
}
).done(function () {
favorite = !favorite;
$(this).val(favorite ? isFavoriteText : isNotFavoriteText);
$('#scribble-modal-error-box').hide();
}).fail(function () {
const errorBox = $('#scribble-modal-error-box');
errorBox.text('<?= Yii::t('app', 'SCRIBBLES_FAVORITE_ERROR_GENERIC') ?>');
errorBox.show();
}).always(function () {
button.prop('disabled', false);
$('#favorite-button').text(favorite ? "<?= $favoriteButtonTexts[true] ?>" : "<?= $favoriteButtonTexts[false] ?>");
});
});
</script>
</script>

0 comments on commit e9de95b

Please sign in to comment.