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

@ -84,6 +84,22 @@
</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
*
@ -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());
$response = $this->model->delete($this->request->getParsedBody());
if ($response['body'] == TRUE)
{
$this->set_flash_message("Successfully deleted anime", 'success');
$this->cache->purge();
$this->outputJSON($response['body'], $response['statusCode']);
}
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