Skip to content

Commit

Permalink
Refactor choosing error message templates
Browse files Browse the repository at this point in the history
We moved the template logic in show_error.

Props @dzver.
  • Loading branch information
nb committed Apr 17, 2013
1 parent 881ccd9 commit e836c9b
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions js/liveblog-admin.js
Expand Up @@ -2,23 +2,23 @@
jQuery( function( $ ) {
var $meta_box = $( '#liveblog' ),
post_id = $( '#post_ID' ).val(),
show_error = function( message ) {
show_error = function( status, code ) {
var template = code? liveblog_admin_settings.error_message_template : liveblog_admin_settings.short_error_message_template,
message = template.replace( '{error-message}', status ).replace( '{error-code}', code );
$( 'p.error', $meta_box ).show().html( message );
};
$meta_box.on( 'click', 'button', function( e ) {
e.preventDefault();
var url = ajaxurl + '?action=set_liveblog_state_for_post&post_id=' + encodeURIComponent( post_id ) + '&state=' + encodeURIComponent( $( this ).val() ) + '&' + liveblog_admin_settings.nonce_key + '=' + liveblog_admin_settings.nonce;
$( '.inside', $meta_box ).load( url, function( response, status, xhr ) {
var message;
if ( status === 'success') {
return;
}
if (xhr.status && xhr.status > 200) {
message = liveblog_admin_settings.error_message_template.replace( '{error-code}', xhr.status ).replace( '{error-message}', xhr.statusText );
show_error( xhr.statusText, xhr.status );
} else {
message = liveblog_admin_settings.short_error_message_template.replace( '{error-message}', status );
show_error( status );
}
show_error(message);
} );
} );
} );
} );

0 comments on commit e836c9b

Please sign in to comment.