import-buttons.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. VamTam Import Buttons
  3. */
  4. /*global jQuery*/
  5. (function( $ ) {
  6. 'use strict';
  7. $( function() {
  8. $( 'body' ).on( 'click', '.vamtam-import-button', function( e ) {
  9. e.preventDefault();
  10. var button = $( this );
  11. if ( ! button.hasClass( 'disabled' ) ) {
  12. button.addClass( 'disabled' );
  13. var spinner = $( '<span></span>' ).addClass( 'spinner' ).css( {
  14. visibility: 'visible',
  15. float: 'none',
  16. 'vertical-align': 'top'
  17. } );
  18. button.after( spinner );
  19. $.get( button.attr( 'href' ), function( result ) {
  20. spinner.remove();
  21. var result_wrap = $( '<span />' );
  22. if ( result.match( /all done\./i ) ) {
  23. result_wrap.html( button.data( 'success-msg' ) ).addClass( 'import-success' );
  24. if ( button.attr( 'id' ) === 'content-import-button' ) {
  25. button.closest( '.form-table' ).find( '.disabled.content-disabled' ).removeClass( 'disabled content-disabled' );
  26. }
  27. } else {
  28. result_wrap.html( button.data( 'error-msg' ).replace( '{fullimport}', button.attr( 'href' ) ) ).addClass( 'import-fail' );
  29. }
  30. button.after( result_wrap );
  31. } );
  32. }
  33. } );
  34. } );
  35. })( jQuery );