diff --git a/punch_list/public/js/myFirebase.js b/punch_list/public/js/myFirebase.js index 4dc91b4..66ea703 100644 --- a/punch_list/public/js/myFirebase.js +++ b/punch_list/public/js/myFirebase.js @@ -233,6 +233,7 @@ function setPriority(sortObject, newPosition) { firebase.database().ref().update(priority); + $( '#' + sortObject).attr("priority", newPosition); // loadPunches(window.uid); } @@ -601,6 +602,7 @@ function updatePunchElement(childKey, childData) { if (childData.progress.toLowerCase != "done") { updateElementData("priority" + childKey, childData.priority); + $( '#' + childKey).prop("priority", childData.priority); updateElementData("subject" + childKey, childData.subject); updateElementData("progress" + childKey, childData.progress); updateElementData("neededby-data" + childKey, childData.needByDate); @@ -616,7 +618,7 @@ function addPunchElement(childKey, childData) { else { style = "punch-default"; } if (childData.progress.toLowerCase() != "done") { - genPunchListItem('
', '#sortable'); + genPunchListItem('', '#sortable'); genPunchListItem('', '#' + childKey); genPunchListItem('', '#div-portlet' + childKey); genPunchListItem('', '#div-portlet' + childKey); @@ -717,13 +719,20 @@ function loadPunches(uid) { function sortList() { consoleLog('function: sortList()'); - var items = $('li'); - items.sort(function(a, b){ - consoleLog($(a).data('priority')); - return +$(a).data('priority') - +$(b).data('priority'); + + var list = $('#sortable'); + var li = list.children('li'); + + consoleLog(list); + consoleLog(li); + + li.detach().sort(function(a, b) { + console.log( $(a).attr('priority') ); + return $(a).attr('priority') - $(b).attr('priority'); }); - items.appendTo('#sortable'); + list.append(li); + positionLoop(); } var looper = setInterval(function() { @@ -774,6 +783,8 @@ function createNewEvent() { disableElement("newEvent"); enableElement("punchListAll"); + + sortList(); // loadPunches(window.uid); // document.getElementById("newEventList").innerHTML = jsonStr; }