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
|
|
|
|
2017-02-16 11:47:54 -05:00
|
|
|
_.on('.manga.list', 'click', '.edit_buttons button', (e) => {
|
2017-02-15 16:58:08 -05:00
|
|
|
let thisSel = e.target;
|
|
|
|
let parentSel = _.closestParent(e.target, 'article');
|
2017-02-16 13:22:26 -05:00
|
|
|
let type = thisSel.classList.contains('plus_one_chapter') ? 'chapter' : 'volume';
|
2017-02-15 16:58:08 -05:00
|
|
|
let completed = parseInt(_.$(`.${type}s_read`, parentSel)[0].textContent, 10);
|
|
|
|
let total = parseInt(_.$(`.${type}_count`, parentSel)[0].textContent, 10);
|
|
|
|
let mangaName = _.$('.name', parentSel)[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;
|
|
|
|
}
|
|
|
|
|
2017-01-09 20:36:48 -05:00
|
|
|
// Setup the update data
|
2016-02-01 09:49:18 -05:00
|
|
|
let data = {
|
2017-03-29 14:00:57 -04:00
|
|
|
id: parentSel.dataset.kitsuId,
|
|
|
|
mal_id: parentSel.dataset.malId,
|
2017-01-09 20:36:48 -05:00
|
|
|
data: {
|
|
|
|
progress: completed
|
|
|
|
}
|
2015-06-24 16:01:35 -04:00
|
|
|
};
|
|
|
|
|
2017-01-09 21:38:42 -05:00
|
|
|
// If the episode count is 0, and incremented,
|
|
|
|
// change status to currently reading
|
|
|
|
if (isNaN(completed) || completed === 0) {
|
|
|
|
data.data.status = 'current';
|
|
|
|
}
|
|
|
|
|
|
|
|
// If you increment at the last chapter, mark as completed
|
2017-02-16 11:47:54 -05:00
|
|
|
if (( ! isNaN(completed)) && (completed + 1) === total) {
|
2017-01-09 21:38:42 -05:00
|
|
|
data.data.status = 'completed';
|
|
|
|
}
|
|
|
|
|
2015-06-24 16:01:35 -04:00
|
|
|
// Update the total count
|
2017-01-10 12:35:46 -05:00
|
|
|
data.data.progress = ++completed;
|
2015-06-24 16:01:35 -04:00
|
|
|
|
2016-02-08 20:21:41 -05:00
|
|
|
_.ajax(_.url('/manga/update'), {
|
2017-02-16 11:47:54 -05:00
|
|
|
data,
|
2015-11-13 16:31:01 -05:00
|
|
|
dataType: 'json',
|
2016-02-02 11:34:03 -05:00
|
|
|
type: 'POST',
|
2015-11-13 16:31:01 -05:00
|
|
|
mimeType: 'application/json',
|
2017-01-09 21:38:42 -05:00
|
|
|
success: () => {
|
2017-02-16 11:47:54 -05:00
|
|
|
if (data.data.status === 'completed') {
|
2017-02-15 16:58:08 -05:00
|
|
|
_.hide(parentSel);
|
2017-01-09 21:38:42 -05:00
|
|
|
}
|
|
|
|
|
2017-02-15 16:58:08 -05:00
|
|
|
_.$(`.${type}s_read`, parentSel)[0].textContent = completed;
|
|
|
|
_.showMessage('success', `Sucessfully updated ${mangaName}`);
|
2016-02-08 20:21:41 -05:00
|
|
|
_.scrollToTop();
|
2016-02-02 11:34:03 -05:00
|
|
|
},
|
2017-02-16 11:47:54 -05:00
|
|
|
error: () => {
|
2017-02-15 16:58:08 -05:00
|
|
|
_.showMessage('error', `Failed to updated ${mangaName}`);
|
2016-02-08 20:21:41 -05:00
|
|
|
_.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);
|