From 8e99107681b3a48e082925b1b12247049805a884 Mon Sep 17 00:00:00 2001 From: Kameron Kenny Date: Wed, 17 Jul 2019 16:22:57 -0400 Subject: [PATCH] prioritization --- punch_list/public/js/myFirebase.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/punch_list/public/js/myFirebase.js b/punch_list/public/js/myFirebase.js index 833b71b..3a57f8d 100644 --- a/punch_list/public/js/myFirebase.js +++ b/punch_list/public/js/myFirebase.js @@ -340,6 +340,22 @@ function clearDefault(a){ } } +function positionLoop() { + $( "li" ).each(function( i, l ){ + var punchRef = firebase.database().ref('users/' + uid + '/punches/' + l.id + '/priority'); + punchRef.once('value').then(function(snapshot) { + var cPriority = snapshot.val(); + var nPriority = i; + + if ( parseInt(cPriority) < 100 ) { + console.log("Updating: " + l.id + " priority, from: " + cPriority + ", to: " + nPriority); + setPriority(l.id, nPriority); + } + }); + //console.log("i: " + i + " l: " + l.id); + }); +} + function mkSortable(){ console.log("function: mkSortable()"); $( function() { @@ -358,6 +374,7 @@ function mkSortable(){ console.log(event, ui); setPriority(ui.item.context.id, ui.item.index()); console.log(`New Position: ${ui.item.index()}`); + positionLoop(); } }); });