HummingBirdAnimeClient/public/js/manga_edit.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

/**
* Javascript for editing manga, if logged in
*/
2016-02-02 11:34:03 -05:00
(($, AnimeClient) => {
2015-11-13 16:31:01 -05:00
2016-02-01 09:49:18 -05:00
'use strict';
2016-02-02 11:34:03 -05:00
$('.manga.list').on('click', '.edit_buttons button', function(e) {
2016-02-01 09:49:18 -05:00
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);
let manga_name = parent_sel.find('.name').text();
2016-02-02 11:34:03 -05:00
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',
2016-02-02 11:34:03 -05:00
type: 'POST',
2015-11-13 16:31:01 -05:00
mimeType: 'application/json',
2016-02-01 09:49:18 -05:00
url: AnimeClient.url('/manga/update'),
2016-02-02 11:34:03 -05:00
success: (res, status) => {
parent_sel.find(`.${type}s_read`).text(completed);
AnimeClient.showMessage('success', `Sucessfully updated ${manga_name}`);
AnimeClient.scrollToTop();
},
error: (xhr, errorType, error) => {
console.error(error);
AnimeClient.showMessage('error', `Failed to updated ${manga_name}`);
AnimeClient.scrollToTop();
}
});
});
2016-02-02 11:34:03 -05:00
})(Zepto, AnimeClient);