HummingBirdAnimeClient/public/js/manga_edit.js

45 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* Javascript for editing manga, if logged in
*/
2016-02-01 09:49:18 -05:00
(($, AnimeClient, w) => {
2015-11-13 16:31:01 -05:00
2016-02-01 09:49:18 -05:00
'use strict';
2016-02-01 09:49:18 -05:00
$('body.manga.list').on('click', '.edit_buttons button', function(e) {
let this_sel = $(this);
let parent_sel = $(this).closest("article");
let manga_id = parent_sel.attr("id").replace("manga-", "");
let type = this_sel.is(".plus_one_chapter") ? 'chapter' : 'volume';
let completed = parseInt(parent_sel.find(`.${type}s_read`).text(), 10);
let total = parseInt(parent_sel.find(`.${type}_count`).text(), 10);
if (isNaN(completed))
{
completed = 0;
}
2016-02-01 09:49:18 -05:00
let 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',
2016-02-01 09:49:18 -05:00
url: AnimeClient.url('/manga/update'),
}).done((res) => {
parent_sel.find(`.${type}s_read`).text(completed);
AnimeClient.showMessage('success', `Sucessfully updated ${res.body.manga[0].romaji_title}`);
// scroll to top
w.scroll(0,0);
}).fail(() => {
AnimeClient.showMessage('error', `Failed to updated ${res.body.manga[0].romaji_title}`);
});
});
2016-02-01 09:49:18 -05:00
})(jQuery, AnimeClient, window);