2015-06-24 16:01:35 -04:00
|
|
|
/**
|
|
|
|
* Javascript for editing manga, if logged in
|
|
|
|
*/
|
2015-11-13 16:31:01 -05:00
|
|
|
(function ($) {
|
|
|
|
|
|
|
|
"use strict";
|
2015-06-24 16:01:35 -04:00
|
|
|
|
|
|
|
if (CONTROLLER !== "manga") return;
|
|
|
|
|
|
|
|
$(".edit_buttons button").on("click", function(e) {
|
|
|
|
var this_sel = $(this);
|
|
|
|
var parent_sel = $(this).closest("article");
|
|
|
|
var manga_id = parent_sel.attr("id").replace("manga-", "");
|
|
|
|
var type = this_sel.is(".plus_one_chapter") ? 'chapter' : 'volume';
|
|
|
|
var completed = parseInt(parent_sel.find("." + type + "s_read").text(), 10);
|
|
|
|
var total = parseInt(parent_sel.find("."+type+"_count").text(), 10);
|
|
|
|
|
|
|
|
console.log(completed);
|
|
|
|
console.log(total);
|
|
|
|
|
|
|
|
if (isNaN(completed))
|
|
|
|
{
|
|
|
|
completed = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
var data = {
|
|
|
|
id: manga_id
|
|
|
|
};
|
|
|
|
|
|
|
|
// Update the total count
|
|
|
|
data[type + "s_read"] = ++completed;
|
|
|
|
|
2015-11-13 16:31:01 -05:00
|
|
|
$.ajax({
|
|
|
|
data: data,
|
|
|
|
dataType: 'json',
|
|
|
|
method: 'POST',
|
|
|
|
mimeType: 'application/json',
|
2015-11-16 15:57:37 -05:00
|
|
|
url: BASE_URL + CONTROLLER + '/update'
|
2015-11-13 16:31:01 -05:00
|
|
|
}).done(function(res) {
|
2015-06-24 16:01:35 -04:00
|
|
|
console.table(res);
|
|
|
|
parent_sel.find("."+type+"s_read").text(completed);
|
|
|
|
add_message('success', "Sucessfully updated " + res.manga[0].romaji_title);
|
2015-11-13 16:31:01 -05:00
|
|
|
}).fail(function() {
|
|
|
|
add_message('error', "Failed to updated " + res.manga[0].romaji_title);
|
2015-06-24 16:01:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}(jQuery));
|