-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.js
40 lines (30 loc) · 963 Bytes
/
config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
$(function() {
$('#submit-button').click(function() {
var $message = $('#ajax-response').empty().removeClass().html('Saving Settings <img src="'+base_url+'assets/i/ajax-loader.gif" alt="">').show();
$('input.invalid').removeClass('invalid');
var data = $(this).closest('form').serialize();
$.post('', data, function(data) {
if (typeof data === 'string')
data = $.parseJSON(data);
$message.empty();
if (data.message)
$message.html(data.message);
if (data.errors) {
$message.addClass('error');
for (var i = 0; i < data.errors.length; i++) {
var error = data.errors[i];
$message.append('<div class="'+(i == 0 ? ' first' : '')+'">'+error.message+'</div>');
$(':input[name='+error.field+']').addClass('invalid');
}
$(':input.invalid').first().focus();
}
else {
setTimeout(function() {
$message.slideUp();
}, 5000);
}
$message.show();
}, 'text');
return false;
});
});