2015-06-24 16:01:35 -04:00
|
|
|
/**
|
|
|
|
* Javascript for editing anime, if logged in
|
|
|
|
*/
|
2015-11-13 11:33:27 -05:00
|
|
|
(function($){
|
|
|
|
|
|
|
|
"use strict";
|
2015-06-24 16:01:35 -04:00
|
|
|
|
|
|
|
if (CONTROLLER !== "anime") return;
|
|
|
|
|
|
|
|
// Action to increment episode count
|
2016-01-04 10:53:03 -05:00
|
|
|
$(".plus_one").on("click", function(e) {
|
2015-06-24 16:01:35 -04:00
|
|
|
e.stopPropagation();
|
|
|
|
|
2015-07-02 14:04:04 -04:00
|
|
|
var self = this;
|
2015-06-24 16:01:35 -04:00
|
|
|
var this_sel = $(this);
|
2016-01-04 10:53:03 -05:00
|
|
|
var parent_sel = $(this).closest("article, td");
|
2015-06-24 16:01:35 -04:00
|
|
|
|
|
|
|
var watched_count = parseInt(parent_sel.find('.completed_number').text(), 10);
|
|
|
|
var total_count = parseInt(parent_sel.find('.total_number').text(), 10);
|
|
|
|
var title = parent_sel.find('.name a').text();
|
|
|
|
|
|
|
|
// Setup the update data
|
|
|
|
var 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
|
|
|
|
if (isNaN(watched_count) || watched_count === 0)
|
|
|
|
{
|
|
|
|
data.status = "currently-watching";
|
|
|
|
}
|
|
|
|
|
|
|
|
// If you increment at the last episode, mark as completed
|
|
|
|
if (( ! isNaN(watched_count)) && (watched_count + 1) === total_count)
|
|
|
|
{
|
|
|
|
delete data.increment_episodes;
|
|
|
|
data.status = "completed";
|
|
|
|
}
|
|
|
|
|
|
|
|
// okay, lets actually make some changes!
|
2015-11-13 11:33:27 -05:00
|
|
|
$.ajax({
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
method: 'POST',
|
|
|
|
mimeType: 'application/json',
|
|
|
|
url: BASE_URL + CONTROLLER + '/update'
|
|
|
|
}).done(function(res) {
|
2015-06-24 16:01:35 -04:00
|
|
|
if (res.status === 'completed')
|
|
|
|
{
|
2016-01-04 10:53:03 -05:00
|
|
|
$(self).closest('article, tr').hide();
|
2015-06-24 16:01:35 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
add_message('success', "Sucessfully updated " + title);
|
|
|
|
parent_sel.find('.completed_number').text(++watched_count);
|
2015-11-13 11:33:27 -05:00
|
|
|
}).fail(function() {
|
|
|
|
add_message('error', "Failed to updated " + title);
|
2015-06-24 16:01:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}(jQuery));
|