2015-06-24 16:01:35 -04:00
|
|
|
/**
|
|
|
|
* Javascript for editing manga, if logged in
|
|
|
|
*/
|
2016-02-08 20:21:41 -05:00
|
|
|
((_) => {
|
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-08 20:21:41 -05:00
|
|
|
_.on('.manga.list', 'click', '.edit_buttons button', function(e) {
|
|
|
|
let this_sel = this;
|
|
|
|
let parent_sel = this.parentElement.parentElement;
|
|
|
|
let manga_id = parent_sel.id.replace("manga-", "");
|
|
|
|
let type = this_sel.classList.contains("plus_one_chapter") ? 'chapter' : 'volume';
|
|
|
|
let completed = parseInt(_.$(`.${type}s_read`, parent_sel)[0].textContent, 10);
|
|
|
|
let total = parseInt(_.$(`.${type}_count`, parent_sel)[0].textContent, 10);
|
|
|
|
let manga_name = _.$('.name', parent_sel)[0].textContent;
|
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;
|
|
|
|
|
2016-02-08 20:21:41 -05:00
|
|
|
_.ajax(_.url('/manga/update'), {
|
2015-11-13 16:31:01 -05:00
|
|
|
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-08 10:57:44 -05:00
|
|
|
success: (res) => {
|
2016-02-08 20:21:41 -05:00
|
|
|
_.$(`.${type}s_read`, parent_sel)[0].textContent = completed;
|
|
|
|
_.showMessage('success', `Sucessfully updated ${manga_name}`);
|
|
|
|
_.scrollToTop();
|
2016-02-02 11:34:03 -05:00
|
|
|
},
|
|
|
|
error: (xhr, errorType, error) => {
|
|
|
|
console.error(error);
|
2016-02-08 20:21:41 -05:00
|
|
|
_.showMessage('error', `Failed to updated ${manga_name}`);
|
|
|
|
_.scrollToTop();
|
2016-02-02 11:34:03 -05:00
|
|
|
}
|
2015-06-24 16:01:35 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-02-08 20:21:41 -05:00
|
|
|
})(AnimeClient);
|