Add ability to delete items from anime list. References #10

This commit is contained in:
Timothy Warren 2016-04-14 15:16:13 -04:00
parent 79f71eee09
commit d17549c0fb
6 changed files with 154 additions and 90 deletions

View File

@ -60,6 +60,11 @@ return [
'id' => '[a-z0-9\-]+'
]
],
'anime.delete' => [
'path' => '/anime/delete',
'action' => 'delete',
'verb' => 'post'
],
// ---------------------------------------------------------------------
// Manga Routes
// ---------------------------------------------------------------------

View File

@ -2,88 +2,104 @@
<main>
<h2>Edit Anime List Item</h2>
<form action="<?= $action ?>" method="post">
<table class="form">
<thead>
<tr>
<th>
<h3><?= $escape->html($item['anime']['title']) ?></h3>
<?php if($item['anime']['alternate_title'] != ""): ?>
<h4><?= $escape->html($item['anime']['alternate_title']) ?></h4>
<?php endif ?>
</th>
<th>
<article class="media">
<?= $helper->img($item['anime']['image']); ?>
</article>
</th>
</tr>
</thead>
<tbody>
<tr>
<td><label for="private">Is Private?</label></td>
<td>
<input type="checkbox" name="private" id="private"
<?php if($item['private']): ?>checked="checked"<?php endif ?>
/>
</td>
</tr>
<tr>
<td><label for="watching_status">Watching Status</label></td>
<td>
<select name="watching_status" id="watching_status">
<?php foreach($statuses as $status_key => $status_title): ?>
<option <?php if($item['watching_status'] === $status_key): ?>selected="selected"<?php endif ?>
value="<?= $status_key ?>"><?= $status_title ?></option>
<?php endforeach ?>
</select>
</td>
</tr>
<tr>
<td><label for="series_rating">Rating</label></td>
<td>
<input type="number" min="0" max="10" maxlength="2" name="user_rating" id="series_rating" value="<?= $item['user_rating'] ?>" id="series_rating" size="2" /> / 10
</td>
</tr>
<tr>
<td><label for="episodes_watched">Episodes Watched</label></td>
<td>
<input type="number" min="0" size="4" maxlength="4" value="<?= $item['episodes']['watched'] ?>" name="episodes_watched" id="episodes_watched" />
<?php if($item['episodes']['total'] > 0): ?>
/ <?= $item['episodes']['total'] ?>
<table class="form">
<thead>
<tr>
<th>
<h3><?= $escape->html($item['anime']['title']) ?></h3>
<?php if($item['anime']['alternate_title'] != ""): ?>
<h4><?= $escape->html($item['anime']['alternate_title']) ?></h4>
<?php endif ?>
</td>
</tr>
<tr>
<td><label for="rewatching_flag">Rewatching?</label></td>
<td>
<input type="checkbox" name="rewatching" id="rewatching_flag"
<?php if($item['rewatching'] === TRUE): ?>checked="checked"<?php endif ?>
/>
</td>
</tr>
<tr>
<td><label for="rewatched">Rewatch Count</label></td>
<td>
<input type="number" min="0" id="rewatched" name="rewatched" value="<?= $item['rewatched'] ?>" />
</td>
</tr>
<tr>
<td><label for="notes">Notes</label></td>
<td>
<textarea name="notes" id="notes"><?= $escape->html($item['notes']) ?></textarea>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="hidden" value="<?= $item['anime']['slug'] ?>" name="id" />
<input type="hidden" value="true" name="edit" />
<button type="submit">Submit</button>
</td>
</tr>
</tbody>
</table>
</th>
<th>
<article class="media">
<?= $helper->img($item['anime']['image']); ?>
</article>
</th>
</tr>
</thead>
<tbody>
<tr>
<td><label for="private">Is Private?</label></td>
<td>
<input type="checkbox" name="private" id="private"
<?php if($item['private']): ?>checked="checked"<?php endif ?>
/>
</td>
</tr>
<tr>
<td><label for="watching_status">Watching Status</label></td>
<td>
<select name="watching_status" id="watching_status">
<?php foreach($statuses as $status_key => $status_title): ?>
<option <?php if($item['watching_status'] === $status_key): ?>selected="selected"<?php endif ?>
value="<?= $status_key ?>"><?= $status_title ?></option>
<?php endforeach ?>
</select>
</td>
</tr>
<tr>
<td><label for="series_rating">Rating</label></td>
<td>
<input type="number" min="0" max="10" maxlength="2" name="user_rating" id="series_rating" value="<?= $item['user_rating'] ?>" id="series_rating" size="2" /> / 10
</td>
</tr>
<tr>
<td><label for="episodes_watched">Episodes Watched</label></td>
<td>
<input type="number" min="0" size="4" maxlength="4" value="<?= $item['episodes']['watched'] ?>" name="episodes_watched" id="episodes_watched" />
<?php if($item['episodes']['total'] > 0): ?>
/ <?= $item['episodes']['total'] ?>
<?php endif ?>
</td>
</tr>
<tr>
<td><label for="rewatching_flag">Rewatching?</label></td>
<td>
<input type="checkbox" name="rewatching" id="rewatching_flag"
<?php if($item['rewatching'] === TRUE): ?>checked="checked"<?php endif ?>
/>
</td>
</tr>
<tr>
<td><label for="rewatched">Rewatch Count</label></td>
<td>
<input type="number" min="0" id="rewatched" name="rewatched" value="<?= $item['rewatched'] ?>" />
</td>
</tr>
<tr>
<td><label for="notes">Notes</label></td>
<td>
<textarea name="notes" id="notes"><?= $escape->html($item['notes']) ?></textarea>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input type="hidden" value="<?= $item['anime']['slug'] ?>" name="id" />
<input type="hidden" value="true" name="edit" />
<button type="submit">Submit</button>
</td>
</tr>
</tbody>
</table>
</form>
<fieldset>
<legend>Danger Zone</legend>
<form class="js-danger" action="<?= $url->generate('anime.delete') ?>" method="post">
<table class="form invisible">
<tbody>
<tr>
<td>&nbsp;</td>
<td>
<input type="hidden" value="<?= $item['anime']['slug'] ?>" name="id" />
<button type="submit" class="danger">Delete Entry</button>
</td>
</tr>
</tbody>
</table>
</form>
</fieldset>
</main>
<script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script>
<?php endif ?>

View File

@ -152,6 +152,19 @@ h1 a {
margin: 0 auto;
}
.danger {
background-color: #ff4136;
border-color: #924949;
color: #fff;
}
.danger:hover,
.danger:active {
background-color: #924949;
border-color: #ff4136;
color: #fff;
}
/* -----------------------------------------------------------------------------
CSS loading icon
------------------------------------------------------------------------------*/

View File

@ -88,6 +88,18 @@ a:hover, a:active {
margin:0 auto;
}
.danger {
background-color: #ff4136;
border-color: #924949;
color:#fff;
}
.danger:hover, .danger:active {
background-color: #924949;
border-color: #ff4136;
color:#fff;
}
/* -----------------------------------------------------------------------------
CSS loading icon
------------------------------------------------------------------------------*/

View File

@ -10,4 +10,14 @@
ac.hide(this);
});
// Confirm deleting of list or library items
ac.on('form.js-danger', 'submit', function (event) {
let proceed = confirm("Are you ABSOLUTELY SURE you want to delete this item?");
if (proceed === false) {
event.preventDefault();
event.stopPropagation();
}
});
})(AnimeClient);

View File

@ -1,5 +1,4 @@
<?php
/**
* Hummingbird Anime Client
*
@ -37,7 +36,7 @@ class Anime extends BaseController {
* @var array $base_data
*/
protected $base_data;
/**
* Data cache
*/
@ -60,7 +59,7 @@ class Anime extends BaseController {
'other_type' => 'manga',
'config' => $this->config,
]);
$this->cache = $container->get('cache');
}
@ -100,7 +99,7 @@ class Anime extends BaseController {
'' => 'cover',
'list' => 'list'
];
$data = ($type != 'all')
? $this->cache->get($this->model, 'get_list', ['status' => $model_map[$type]])
: $this->cache->get($this->model, 'get_all_lists', []);
@ -154,7 +153,7 @@ class Anime extends BaseController {
$result = $this->model->update($data);
if ($result['statusCode'] == 201)
if (intval($result['statusCode']) === 201)
{
$this->set_flash_message('Added new anime to list', 'success');
$this->cache->purge();
@ -262,15 +261,25 @@ class Anime extends BaseController {
*/
public function delete()
{
$response = $this->model->update($this->request->getParsedBody());
$this->cache->purge();
$this->outputJSON($response['body'], $response['statusCode']);
$response = $this->model->delete($this->request->getParsedBody());
if ($response['body'] == TRUE)
{
$this->set_flash_message("Successfully deleted anime", 'success');
$this->cache->purge();
}
else
{
$this->set_flash_message('Failed to delete anime.', 'error');
}
$this->session_redirect();
}
/**
* View details of an anime
*
* @param string anime_id
* @param string $anime_id
* @return void
*/
public function details($anime_id)
@ -284,5 +293,4 @@ class Anime extends BaseController {
}
}
// End of AnimeController.php