Created
October 24, 2015 12:50
-
-
Save aviogreen/df37d695386d4519a288 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$('[data-ajax=modal]').each(function(index, el) { | |
var this_el = $(this); | |
var form_el = $('form', this_el); | |
this_el.on('hide.bs.modal', function(){ | |
var next_el = $('.modal-header', this_el).next(); | |
if( next_el.hasClass('alert') ) | |
next_el.remove(); | |
}); | |
form_el.ajaxForm({ | |
beforeSubmit: function(res){ | |
$('[type=submit]', form_el).prop('disabled', true); | |
}, | |
success: function(res){ | |
form_el.ajaxSubmit(function(){ | |
var next_el = $('.modal-header', this_el).next(); | |
if( next_el.hasClass('alert') ) | |
next_el.remove(); | |
$('[type=submit]', form_el).prop('disabled', false); | |
var alert = $('<div/>').addClass('alert').html(res.message); | |
if( res.success ) | |
alert.addClass('alert-success'); | |
else | |
alert.addClass('alert-danger'); | |
if( res.updated ){ | |
$.each(res.updated, function(index, value) { | |
$('[data-live-update=' + index + ']').html(value); | |
}); | |
} | |
alert.insertAfter( $('.modal-header', this_el) ); | |
}); | |
}, | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment