Hey so I'm reasonably new to Node.js and Mongodb, I am making a roster creation system and I want to make it so that only two users/employees can work on a given shift. For simplicity the shifts are split into 'day' and 'night' which are in a table of radio buttons that the user can chosen. Onload of the shifts page however I want to disable those buttons which have already been chosen by two other users.
I think that the outer loop should iterate through the shifts array of the users (Monday --> Sunday), the inner loop should then iterate through each user in the mongodb database. Eventually I want to have the code working for each day of the week but for now just need Monday to function properly.
Thanks for any help and advise
function disableOnLoad() {
console.log("disableOnLoad reached");
var dayCount=0;
var nightCount=0;
$.getJSON( '/shiftsTable', function( data ) {
$.each(data, function(){
userListData = data;
for(i = 0; i < 7; i++) {
**//$.each(data, function(){**
if(this.shifts[i]=='day'){
if(i==0){
dayCount++;
console.log("dayCount: "+dayCount);
if(dayCount>2){document.getElementById("monDay").disabled=true;}
}
}
else if(this.shifts[0]=='night'){
nightCount++;
if (nightCount>2){document.getElementById("monNight").disabled=true;}
}
}
});
});
};