Always reload tray menu in loadNotesToCards(), loadCards() on delete, close #9

master
Skylar Ittner 5 years ago
parent 673b8fba4f
commit 265ae7d004

@ -52,6 +52,7 @@ $(".view-main").on("click", ".parsedown-task-list", function (e) {
}); });
function loadNotesToCards(notes, oldnotes, callback) { function loadNotesToCards(notes, oldnotes, callback) {
var reloadCards = true;
if (force_card_refresh != true && notes.length == oldnotes.length) { if (force_card_refresh != true && notes.length == oldnotes.length) {
var allSame = true; var allSame = true;
var allPresent = true; var allPresent = true;
@ -64,18 +65,16 @@ function loadNotesToCards(notes, oldnotes, callback) {
} }
} }
if (allSame && allPresent) { if (allSame && allPresent) {
window.shuffleInstance.layout(); reloadCards = false;
if (typeof callback == 'function') {
callback();
}
return;
} }
} }
force_card_refresh = false; force_card_refresh = false;
for (i in window.shuffleInstance.items) { if (reloadCards) {
window.shuffleInstance.remove(window.shuffleInstance.items[i]); for (i in window.shuffleInstance.items) {
window.shuffleInstance.remove(window.shuffleInstance.items[i]);
}
$(".notecard-col").remove();
} }
$(".notecard-col").remove();
var trayitems = []; var trayitems = [];
for (n in notes) { for (n in notes) {
var note = notes[n]; var note = notes[n];
@ -83,37 +82,41 @@ function loadNotesToCards(notes, oldnotes, callback) {
if (note.getSyncStatus() == "LOCAL_DELETED") { if (note.getSyncStatus() == "LOCAL_DELETED") {
continue; continue;
} }
$("#notecards-bin").append('<div class="col-100 tablet-50 desktop-33 notecard-col grid-item" id="notecard-col-' + note.noteid + '" data-favorite="' + (note.favorite ? "1" : "0") + '">' if (reloadCards) {
+ '<div class="card notecard" id="notecard-' + note.getID() + '" data-id="' + note.getID() + '" data-favorite="' + (note.getFavorite() ? "1" : "0") + '" data-bg="' + note.getColor() + '" data-fg="' + note.getTextColor() + '" style="background-color: #' + note.getColor() + '; color: #' + note.getTextColor() + ';">' $("#notecards-bin").append('<div class="col-100 tablet-50 desktop-33 notecard-col grid-item" id="notecard-col-' + note.noteid + '" data-favorite="' + (note.favorite ? "1" : "0") + '">'
+ '<div class="editbtn">' + '<div class="card notecard" id="notecard-' + note.getID() + '" data-id="' + note.getID() + '" data-favorite="' + (note.getFavorite() ? "1" : "0") + '" data-bg="' + note.getColor() + '" data-fg="' + note.getTextColor() + '" style="background-color: #' + note.getColor() + '; color: #' + note.getTextColor() + ';">'
+ '<i class="material-icons">edit</i>' + '<div class="editbtn">'
+ '</div>' + '<i class="material-icons">edit</i>'
+ '<div class="menubtn">' + '</div>'
+ '<i class="material-icons">more_vert</i>' + '<div class="menubtn">'
+ '</div>' + '<i class="material-icons">more_vert</i>'
+ '<div class="card-content card-content-padding"><div class="btnswrapthing"></div>' + note.getHTML() + '</div>' + '</div>'
+ '</div>' + '<div class="card-content card-content-padding"><div class="btnswrapthing"></div>' + note.getHTML() + '</div>'
+ '</div>'); + '</div>'
+ '</div>');
}
trayitems.push({ trayitems.push({
title: note.getTitle(), title: note.getTitle(),
id: note.getID() id: note.getID()
}); });
} }
$(".notecard .card-content ul li:has(input[type=checkbox])").addClass("parsedown-task-list"); if (reloadCards) {
$(".notecard .card-content ul li:has(input[type=checkbox]:checkbox:not(:checked))").addClass("parsedown-task-list-open"); $(".notecard .card-content ul li:has(input[type=checkbox])").addClass("parsedown-task-list");
$(".notecard .card-content ul li:has(input[type=checkbox]:checkbox:checked)").addClass("parsedown-task-list-close"); $(".notecard .card-content ul li:has(input[type=checkbox]:checkbox:not(:checked))").addClass("parsedown-task-list-open");
$(".parsedown-task-list input[type=checkbox]").removeAttr("disabled"); $(".notecard .card-content ul li:has(input[type=checkbox]:checkbox:checked)").addClass("parsedown-task-list-close");
var noteElements = document.getElementsByClassName("notecard-col"); $(".parsedown-task-list input[type=checkbox]").removeAttr("disabled");
window.shuffleInstance.add(noteElements); var noteElements = document.getElementsByClassName("notecard-col");
window.shuffleInstance.sort({ window.shuffleInstance.add(noteElements);
reverse: true, window.shuffleInstance.sort({
by: function (el) { reverse: true,
if (el.getAttribute("id") == "offline-indicator") { by: function (el) {
return "999999999"; if (el.getAttribute("id") == "offline-indicator") {
return "999999999";
}
return el.getAttribute("data-favorite");
} }
return el.getAttribute("data-favorite"); });
} }
});
setTrayMenu(trayitems); setTrayMenu(trayitems);
// Make sure gutters and stuff work // Make sure gutters and stuff work
setTimeout(function () { setTimeout(function () {
@ -180,7 +183,7 @@ function deleteNote(id) {
window.shuffleInstance.remove(document.getElementById("notecard-col-" + id)); window.shuffleInstance.remove(document.getElementById("notecard-col-" + id));
$("#notecard-col-" + id).remove(); $("#notecard-col-" + id).remove();
window.shuffleInstance.layout(); window.shuffleInstance.layout();
NOTES.syncAll(); loadCards();
}); });
} }

Loading…
Cancel
Save