2015-06-24 16:01:35 -04:00
|
|
|
/**
|
|
|
|
* 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';
|
2015-06-24 16:01:35 -04:00
|
|
|
|
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);
|
2016-02-02 14:13:49 -05:00
|
|
|
let manga_name = parent_sel.find('.name').text();
|
2015-06-24 16:01:35 -04:00
|
|
|
|
2016-02-02 11:34:03 -05:00
|
|
|
if (isNaN(completed)) {
|
2015-06-24 16:01:35 -04:00
|
|
|
completed = 0;
|
|
|
|
}
|
|
|
|
|
2016-02-01 09:49:18 -05:00
|
|
|
let data = {
|
2015-06-24 16:01:35 -04:00
|
|
|
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();
|
|
|
|
}
|
2015-06-24 16:01:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-02 11:34:03 -05:00
|
|
|
})(Zepto, AnimeClient);
|