2015-06-24 16:01:35 -04:00
|
|
|
/**
|
|
|
|
* Javascript for editing anime, if logged in
|
|
|
|
*/
|
2016-02-02 11:34:03 -05:00
|
|
|
(($, AnimeClient) => {
|
2015-11-13 11:33:27 -05:00
|
|
|
|
2016-02-01 09:49:18 -05:00
|
|
|
'use strict';
|
2015-06-24 16:01:35 -04:00
|
|
|
|
|
|
|
// Action to increment episode count
|
2016-02-01 09:49:18 -05:00
|
|
|
$('body.anime.list').on('click', '.plus_one', function(e) {
|
|
|
|
let self = this;
|
|
|
|
let this_sel = $(this);
|
|
|
|
let parent_sel = $(this).closest('article, td');
|
2015-06-24 16:01:35 -04:00
|
|
|
|
2016-02-01 09:49:18 -05:00
|
|
|
let watched_count = parseInt(parent_sel.find('.completed_number').text(), 10);
|
|
|
|
let total_count = parseInt(parent_sel.find('.total_number').text(), 10);
|
|
|
|
let title = parent_sel.find('.name a').text();
|
2015-06-24 16:01:35 -04:00
|
|
|
|
|
|
|
// Setup the update data
|
2016-02-01 09:49:18 -05:00
|
|
|
let data = {
|
2016-01-04 10:53:03 -05:00
|
|
|
id: this_sel.parent('article, td').attr('id'),
|
2015-06-24 16:01:35 -04:00
|
|
|
increment_episodes: true
|
|
|
|
};
|
|
|
|
|
|
|
|
// If the episode count is 0, and incremented,
|
|
|
|
// change status to currently watching
|
2016-02-01 09:49:18 -05:00
|
|
|
if (isNaN(watched_count) || watched_count === 0) {
|
|
|
|
data.status = 'currently-watching';
|
2015-06-24 16:01:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If you increment at the last episode, mark as completed
|
2016-02-01 09:49:18 -05:00
|
|
|
if (( ! isNaN(watched_count)) && (watched_count + 1) === total_count) {
|
2015-06-24 16:01:35 -04:00
|
|
|
delete data.increment_episodes;
|
2016-02-01 09:49:18 -05:00
|
|
|
data.status = 'completed';
|
2015-06-24 16:01:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// okay, lets actually make some changes!
|
2015-11-13 11:33:27 -05:00
|
|
|
$.ajax({
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
2016-02-02 11:34:03 -05:00
|
|
|
type: 'POST',
|
2015-11-13 11:33:27 -05:00
|
|
|
mimeType: 'application/json',
|
2016-02-01 09:49:18 -05:00
|
|
|
url: AnimeClient.url('/anime/update'),
|
2016-02-02 11:34:03 -05:00
|
|
|
success: (res) => {
|
|
|
|
if (res.status === 'completed') {
|
|
|
|
$(this).closest('article, tr').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
AnimeClient.showMessage('success', `Sucessfully updated ${title}`);
|
|
|
|
parent_sel.find('.completed_number').text(++watched_count);
|
|
|
|
AnimeClient.scrollToTop();
|
|
|
|
},
|
|
|
|
error: (xhr, errorType, error) => {
|
|
|
|
console.error(error);
|
|
|
|
AnimeClient.showMessage('error', `Failed to updated ${title}. `);
|
|
|
|
AnimeClient.scrollToTop();
|
2015-06-24 16:01:35 -04:00
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-02 11:34:03 -05:00
|
|
|
})(Zepto, AnimeClient);
|