function regvalidate() { var limit = document.getElementById('id_limit'); var terms = document.getElementById('id_terms'); if( limit.value < 4 || limit.value > 25) { alert("Team size must be between 4 and 25."); return false; } if(!terms.checked) { alert("You must agree to the terms and conditions in order to continue."); return false; } return confirm('You are about to create an invoice for ' + limit.value + ' places!\nCost per person: £25\nTotal cost: £' + parseInt(limit.value) * 25 + '\n\nAre you sure?'); } function validateAddRunnerForm() { var name = document.getElementById('id_name'); var time_mm = document.getElementById('id_time_mm'); var time_ss = document.getElementById('id_time_ss'); var surname = document.getElementById('id_surname'); var gender = document.getElementById('id_gender'); var email1 = document.getElementById('id_email'); var email2 = document.getElementById('id_email2'); if( time_mm.value == '' || time_mm.value == 0 || name.value.length == 0 || surname.value.length == 0 || email1.value.length ==0 || email2.value.length == 0 || gender.options[gender.selectedIndex].value == '') { alert('Please fill in all fields.'); return false; } if(email1.value != email2.value) { alert('Email addresses do not match.'); return false; } return confirm('You are about to add the following athlete to the team:\n\nName: ' + name.value + '\nSurname: ' + surname.value + '\nGender: ' + gender.options[gender.selectedIndex].value + '\nEmail: ' + email1.value + '\n\nAre you sure?'); } var currpage = 1; function initiateSearch() { currpage = 1; companySearch(); } function companySearch() { var text = document.getElementById('company').value.toLowerCase(); //console.log('Currpage: ', currpage); if( text.length == 0) { $("#company-div").empty(); $("#list-action").empty(); return; } //GET type var radios = document.getElementsByName("limit"); type = -1; $(radios).each( function(i) { if(this.checked) { type = this.value; } }); if(type == -1) { alert("Please choose a search category."); return false; } var req = "/admin/ajax/company/" + type + "/" + currpage + "/" + text + "/"; //$("#company-div").empty().append("
\"progress
"); $("#company-div").fadeTo("fast", 0.3); $.getJSON(req , function(data) { if( data.items.length == 0 ) { //$("#company-div").empty().append("
No results returned.. please broaden your search.
"); $("#company-div").empty().append("No results returned.. please broaden your search."); $("#list-action").empty(); $("#company-div").fadeTo("fast",1); return; } $("#company-div").empty(); $.each(data.items, function(i,item){ var text = ''; text += '' + item.invoice_id + ''; text += ''; if (item.invoice_count > 0) { if( item.outstanding == 1) { text += 'outstanding invoices'; } else if( item.outstanding == 0) { text += 'outstanding invoices'; } else if( item.outstanding == 2) { text += 'outstanding invoices'; } } text += ''; text += '' + item.name + ''; text += ''; if (item.invoice_count > 0) { if( item.active == 1 ) { text += 'active'; } else { text += 'deactivated'; } } else { text += 'inactive'; } text += ''; text += '' + item.joined + ''; text += '' + item.limit + ''; text += ' '; text += ''; text += 'edit'; text += ''; $(text).appendTo("#company-div"); }); /* $.each(data.items, function(i,item){ var text = '
' + item.id + '
'; //console.log('item.coutstanding ', item.outstanding); if(item.outstanding == 0) { text += 'Company has unpaid invoices!'; } else { text += 'Company has no unpaid invoices!'; } text += '
' + item.name + '
' + item.joined + '
' + item.limit + '
Delete
'; $(text).appendTo("#company-div"); }); */ $("#info").empty().append(data.data[0].start + ' to ' + data.data[0].last + ' of ' + data.data[0].size); $("#info2").empty().append(data.data[0].start + ' to ' + data.data[0].last + ' of ' + data.data[0].size); $("#company-div").fadeTo("fast",1); //ratio = data.items.length / 20; ratio = data.data[0].results / 20; pages = Math.floor(ratio); //console.log('Results: ', data.data[0].results); //if(data.items.length % 20) pages++; //This is wrong as data.items.length will always be <=20 if(data.data[0].results % 20) pages++; if(pages == 0) pages=1; $("#list-action").empty().append("Page " + currpage + " of " + pages); if(currpage != 1) { $("#list-action").append("\"previous "); } if(currpage != pages) { $("#list-action").append(" \"next"); } }); } function prevPage() { currpage--; companySearch(); } function nextPage() { currpage++; companySearch(); } function deleteNote(note) { if(!confirm("Do you really want to delete this note?")) { return; } $.post('/admin/ajax/note/delete/', { note: note }, function() { $("#company-note-" + note).hide("slow", function() { $(this).remove(); }); }); } document.createParagraph = function(text) { var p = document.createElement("p"); var t = text.split('\n'); for (var i=0; iClick here for more information.'); }); } function getStatus() { $("#status_percentage").empty(); $("#status_fill").css("width","0"); $.post('/admin/ajax/getStatus/', {}, function(data) { data = eval('(' + data + ')'); //console.log('getStatus() returned: ', data); total = parseInt(data.allocated, 10) + parseInt(data.media, 10) + parseInt(data.scb, 10) + parseInt(data.vip, 10) + parseInt(data.charity, 10) $("#__places__").empty().append( data.total ); $("#__allocated__").empty().append( data.allocated ); $("#__available__").empty().append( data.available ); $("#__media__").empty().append( data.media ); $("#__scb__").empty().append( data.scb ); $("#__vip__").empty().append( data.vip ); $("#__charity__").empty().append( data.charity ); $("#__normal_places__").empty().append( data.normal_places ); $("#__total__").empty().append( data.total ); $("#__normal_available__").empty().append( data.normal_available ); $("#status_percentage").empty().append( data.percentage + '%' ); $("#status_fill").animate({width: + data.percentage + '%' }, 'slow'); if(data.flagup == 1) { $("#flagup").fadeIn("slow"); } else { $("#flagup").fadeOut("slow"); } }); } function validateChangeAccountPassword() { var oldpass = document.getElementById('oldpasswd').value; var newpass1 = document.getElementById('newpasswd1').value; var newpass2 = document.getElementById('newpasswd2').value; if( oldpass.length != 0 && newpass1 == newpass2 && newpass1.length >=6 ) { return true; } alert('Please make sure that your passwords match, and that your new password is >= 6 charcters.'); return false; } function chLimit(company_id) { var nl = prompt("Enter a new limit for this company:"); if(!nl) { return false; } if(isNaN(nl)) { alert("You have entered an invalid number."); return false; } if(nl<0) { alert("You have entered a negative number."); return false; } $.post('/admin/ajax/chlimit/', { company_id: company_id, limit: nl }, function(data) { alert("Company limit has been updated."); window.location.href = unescape( window.location.pathname ); }); } function chTeamLimit(invoice_id) { var nl = prompt("Enter a new limit for this team:"); if(!nl) { return false; } if(isNaN(nl)) { alert("You have entered an invalid number."); return false; } if(nl<0) { alert("You have entered a negative number."); return false; } $.post('/admin/ajax/chTeamLimit/', { invoice_id: invoice_id, limit: nl }, function(data) { alert("Team limit has been updated."); window.location.href = unescape( window.location.pathname ); }); } function deleteCompanies() { var arr = [] $(':checkbox').each( function(i) { if(this.checked) { arr.push(this.value); } }); if(arr.length==0) { return false; } console.log(arr); $.post('/admin/ajax/cdelete/', { list: arr }, function(data) { console.log(data); }); }