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 b528b8dc17
commit 717c296e52
6 changed files with 154 additions and 90 deletions

View File

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

View File

@ -2,88 +2,104 @@
<main> <main>
<h2>Edit Anime List Item</h2> <h2>Edit Anime List Item</h2>
<form action="<?= $action ?>" method="post"> <form action="<?= $action ?>" method="post">
<table class="form"> <table class="form">
<thead> <thead>
<tr> <tr>
<th> <th>
<h3><?= $escape->html($item['anime']['title']) ?></h3> <h3><?= $escape->html($item['anime']['title']) ?></h3>
<?php if($item['anime']['alternate_title'] != ""): ?> <?php if($item['anime']['alternate_title'] != ""): ?>
<h4><?= $escape->html($item['anime']['alternate_title']) ?></h4> <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'] ?>
<?php endif ?> <?php endif ?>
</td> </th>
</tr> <th>
<tr> <article class="media">
<td><label for="rewatching_flag">Rewatching?</label></td> <?= $helper->img($item['anime']['image']); ?>
<td> </article>
<input type="checkbox" name="rewatching" id="rewatching_flag" </th>
<?php if($item['rewatching'] === TRUE): ?>checked="checked"<?php endif ?> </tr>
/> </thead>
</td> <tbody>
</tr> <tr>
<tr> <td><label for="private">Is Private?</label></td>
<td><label for="rewatched">Rewatch Count</label></td> <td>
<td> <input type="checkbox" name="private" id="private"
<input type="number" min="0" id="rewatched" name="rewatched" value="<?= $item['rewatched'] ?>" /> <?php if($item['private']): ?>checked="checked"<?php endif ?>
</td> />
</tr> </td>
<tr> </tr>
<td><label for="notes">Notes</label></td> <tr>
<td> <td><label for="watching_status">Watching Status</label></td>
<textarea name="notes" id="notes"><?= $escape->html($item['notes']) ?></textarea> <td>
</td> <select name="watching_status" id="watching_status">
</tr> <?php foreach($statuses as $status_key => $status_title): ?>
<tr> <option <?php if($item['watching_status'] === $status_key): ?>selected="selected"<?php endif ?>
<td>&nbsp;</td> value="<?= $status_key ?>"><?= $status_title ?></option>
<td> <?php endforeach ?>
<input type="hidden" value="<?= $item['anime']['slug'] ?>" name="id" /> </select>
<input type="hidden" value="true" name="edit" /> </td>
<button type="submit">Submit</button> </tr>
</td> <tr>
</tr> <td><label for="series_rating">Rating</label></td>
</tbody> <td>
</table> <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> </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> </main>
<script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script> <script src="<?= $urlGenerator->asset_url('js.php/g/edit') ?>"></script>
<?php endif ?> <?php endif ?>

View File

@ -152,6 +152,19 @@ h1 a {
margin: 0 auto; 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 CSS loading icon
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/

View File

@ -88,6 +88,18 @@ a:hover, a:active {
margin:0 auto; 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 CSS loading icon
------------------------------------------------------------------------------*/ ------------------------------------------------------------------------------*/

View File

@ -10,4 +10,14 @@
ac.hide(this); 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); })(AnimeClient);

View File

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