2018-07-06 07:18:51 +02:00
|
|
|
class EntryHandler {
|
|
|
|
static updateEntriesStatus(entryIDs, status, callback) {
|
|
|
|
let url = document.body.dataset.entriesStatusUrl;
|
|
|
|
let request = new RequestBuilder(url);
|
|
|
|
request.withBody({entry_ids: entryIDs, status: status});
|
|
|
|
request.withCallback(callback);
|
|
|
|
request.execute();
|
|
|
|
|
|
|
|
if (status === "read") {
|
|
|
|
UnreadCounterHandler.decrement(1);
|
|
|
|
} else {
|
|
|
|
UnreadCounterHandler.increment(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static toggleEntryStatus(element) {
|
|
|
|
let entryID = parseInt(element.dataset.id, 10);
|
2018-08-29 05:44:34 +02:00
|
|
|
let link = element.querySelector("a[data-toggle-status]");
|
2018-07-06 07:18:51 +02:00
|
|
|
|
2018-08-29 05:44:34 +02:00
|
|
|
let currentStatus = link.dataset.value;
|
|
|
|
let newStatus = currentStatus === "read" ? "unread" : "read";
|
2018-07-06 07:18:51 +02:00
|
|
|
|
2018-08-29 05:44:34 +02:00
|
|
|
this.updateEntriesStatus([entryID], newStatus);
|
2018-07-06 07:18:51 +02:00
|
|
|
|
2018-08-29 05:44:34 +02:00
|
|
|
if (currentStatus === "read") {
|
2018-07-06 07:18:51 +02:00
|
|
|
link.innerHTML = link.dataset.labelRead;
|
|
|
|
link.dataset.value = "unread";
|
|
|
|
} else {
|
|
|
|
link.innerHTML = link.dataset.labelUnread;
|
|
|
|
link.dataset.value = "read";
|
|
|
|
}
|
2018-08-29 05:44:34 +02:00
|
|
|
|
|
|
|
if (element.classList.contains("item-status-" + currentStatus)) {
|
|
|
|
element.classList.remove("item-status-" + currentStatus);
|
|
|
|
element.classList.add("item-status-" + newStatus);
|
|
|
|
}
|
2018-07-06 07:18:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static toggleBookmark(element) {
|
|
|
|
element.innerHTML = element.dataset.labelLoading;
|
|
|
|
|
|
|
|
let request = new RequestBuilder(element.dataset.bookmarkUrl);
|
|
|
|
request.withCallback(() => {
|
|
|
|
if (element.dataset.value === "star") {
|
|
|
|
element.innerHTML = element.dataset.labelStar;
|
|
|
|
element.dataset.value = "unstar";
|
|
|
|
} else {
|
|
|
|
element.innerHTML = element.dataset.labelUnstar;
|
|
|
|
element.dataset.value = "star";
|
|
|
|
}
|
|
|
|
});
|
|
|
|
request.execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
static markEntryAsRead(element) {
|
|
|
|
if (element.classList.contains("item-status-unread")) {
|
|
|
|
element.classList.remove("item-status-unread");
|
|
|
|
element.classList.add("item-status-read");
|
|
|
|
|
|
|
|
let entryID = parseInt(element.dataset.id, 10);
|
|
|
|
this.updateEntriesStatus([entryID], "read");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static saveEntry(element) {
|
|
|
|
if (element.dataset.completed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
element.innerHTML = element.dataset.labelLoading;
|
|
|
|
|
|
|
|
let request = new RequestBuilder(element.dataset.saveUrl);
|
|
|
|
request.withCallback(() => {
|
|
|
|
element.innerHTML = element.dataset.labelDone;
|
|
|
|
element.dataset.completed = true;
|
|
|
|
});
|
|
|
|
request.execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
static fetchOriginalContent(element) {
|
|
|
|
if (element.dataset.completed) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
element.innerHTML = element.dataset.labelLoading;
|
|
|
|
|
|
|
|
let request = new RequestBuilder(element.dataset.fetchContentUrl);
|
|
|
|
request.withCallback((response) => {
|
|
|
|
element.innerHTML = element.dataset.labelDone;
|
|
|
|
element.dataset.completed = true;
|
|
|
|
|
|
|
|
response.json().then((data) => {
|
|
|
|
if (data.hasOwnProperty("content")) {
|
|
|
|
document.querySelector(".entry-content").innerHTML = data.content;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
request.execute();
|
|
|
|
}
|
|
|
|
}
|