Created
September 21, 2012 10:05
-
-
Save mikecmpbll/3760732 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready( function() { | |
school_id = $('h1 a:first').attr('data-id'); | |
source_code = $('h1 a:first').attr('data-sc'); | |
$.ajax({ | |
url: 'https://api.mywebsite.net/schools/' + school_id + '/imports?source_code=' + source_code, | |
dataType: 'json', | |
success: function(data) { | |
$('tr#results_placeholder').remove(); | |
$.each( data, function() { | |
if( this.error_count > 0 ) { | |
status = 'Error'; | |
background = '#B34143'; | |
} else if( this.warning_count > 0 ) { | |
status = 'Warning'; | |
background = '#D09055'; | |
} else if( this.success_count > 0 ) { | |
status = 'Success'; | |
background = '#00AB39'; | |
} | |
matches = this.created_at.match(/([0-9]{4})-([0-9]{2})-([0-9]{2})/); | |
str = '<tr>'; | |
str += '<td>' + matches[3] + '/' + matches[2] + '/' + matches[1] + '</td><td>' + this.success_count + ' (<a href="/administration/logs/' + this.id + '/success#import_logs">view messages</a>)</td><td>' + this.warning_count + ' (<a href="/administration/logs/' + this.id + '/warnings#import_logs">view messages</a>)</td><td>' + this.error_count + ' (<a href="/administration/logs/' + this.id + '/errors#import_logs">view messages</a>)</td>'; | |
str += '<td style="background: ' + background + '; color: white; text-shadow: none;">' + status + '</td>'; | |
str += '</tr>'; | |
$('table#imports_table').append( str ); | |
}); | |
}, | |
error: function ErrorMsg(result) { | |
alert(result.status); | |
$('tr#results_placeholder td').html('The import logs cannot be loaded at this time.'); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment