Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions xadmin/static/xadmin/js/xadmin.plugin.quick-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
}, this))
.fail($.proxy(function(xhr) {
this.$mask.hide();
alert(typeof xhr === 'string' ? xhr : xhr.responseText || xhr.statusText || 'Unknown error!');
alert(typeof xhr === 'string' ? xhr : xhr.responseText || xhr.statusText || 'Unknown error!');
}, this));
}
, save: function(newValue) {
Expand All @@ -108,16 +108,31 @@
// }
// })

var $nonfile_input = this.$form.serializeArray();

var formData = new FormData();

$nonfile_input.forEach(function(field) {
formData.append(field.name, field.value)
});

var $file_input = this.$form.find("input[type=file]");
$file_input.each(function (idx, file) {
formData.append($(file).attr('name'), file.files[0]);
});

return $.ajax({
data: [this.$form.serialize(), $.param(off_check_box)].join('&'),
data: formData,
url: this.$form.attr('action'),
type: "POST",
dataType: 'json',
contentType: false,
processData: false,
beforeSend: function(xhr, settings) {
xhr.setRequestHeader("X-CSRFToken", $.getCookie('csrftoken'));
}
})
},
},
}

$.fn.ajaxform = function ( option ) {
Expand Down Expand Up @@ -167,7 +182,7 @@

if(!this.modal){
var modal = $('<div class="modal fade quick-form" role="dialog"><div class="modal-dialog"><div class="modal-content">'+
'<div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h3>'+
'<div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h3>'+
this.$btn.attr('title') +'</h3></div><div class="modal-body"></div>'+
'<div class="modal-footer" style="display: none;"><button class="btn btn-default" data-dismiss="modal" aria-hidden="true">'+gettext('Close')+'</button>'+
'<a class="btn btn-primary btn-submit">'+gettext('Add')+'</a></div></div></div></div>')
Expand All @@ -180,7 +195,7 @@
form.addClass('quick-form')
form.on('post-success', $.proxy(self.post, self))
form.exform()

modal.find('.modal-footer').show()
modal.find('.btn-submit').click(function(){form.submit()})

Expand Down