JSFiddle - React, Tailwind, and code Playground
by Newman4088
JavaScript
// global variable setup
isLoggedIn = false;
isAdmin = false;
var voter;
// user db setup
var site_users = [
{voterId: '0001', voterPass: '1111', voterName: 'Aidan Newman', hasVoted: false, postcode:2950, isAdmin:true},
{voterId: '0002', voterPass: '2222', voterName: 'Jayden Canete', hasVoted: false, postcode:2345},
{voterId: '0003', voterPass: '3333', voterName: 'Evan Cornwell', hasVoted: false, postcode:2683},
{voterId: '0004', voterPass: '4444', voterName: 'Cameron Stoltenberg', hasVoted: false, postcode:2098},
];
var community_issues = [];
//Load community issues into the UI
function loadCommunityIssues() {
if(community_issues.length == 0){
$('select[name=community_issues]').append('<option class="list-group-item">No issues loaded. Please see an Admin</option>');
$('button[name=cast_vote]').attr('disabled', true);
}else{
//Clear the element just to make sure we get the right number of elements in it.
$('select[name=community_issues]').html('');
//Reset the disabled button
$('button[name=cast_vote]').attr('disabled', false);
console.log(community_issues);
for(i = 0; i < community_issues.length; i++) {
$('select[name=community_issues]').append('<option value="'+community_issues[i].id+'" class="list-group-item">'+community_issues[i].title+'</option>');
}
}
}
//Display votes in the Admin UI
function displayVotes() {
$('.final_votes').html('');
for (i = 0; i < community_issues.length; i++){
$('.final_votes').append('<li class="list-group-item"><span class="label label-default label-pill pull-right"> '+community_issues[i].votes+'</span>'+community_issues[i].title+'</li>');
}
}
//Admin create issues form
$('button[name=add_issue]').click(function() {
var issue = $('input[name=new_community_issue]');
if(issue.val() == ''){
messageUsers("Please enter an issue to store first.");
}else{
community_issues.push({id:(community_issues.length + 1), title:issue.val(), votes:0});
...