You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

129 lines
4.4 KiB

//replace
$(document).ready(function(){
$('.delete_file').click(function(){
var url = '/admin/ajax_delete_file/';
$this = $(this);
$.get(
url, {'id': $(this).attr("value")}, function(j){
if (j = 'success'){
$this.parent().parent().remove();
}
else{
console.log('error');
}
});//end get
return false;
});//end delete
$('#file_form').submit(function(){
var fileData = new FormData($(this)[0]);//file (request.FILES)
var formData = $(this).serialize();// another data (request.POST)
//check if object is new
if ($('#obj_id').val() != '') {
var url = '/admin/ajax_post_file/'+$('#obj_id').val()+'/';
}
else {
var url = '/admin/ajax_post_file/'
}
$.ajax({
url: url, //server script to process data
type: 'POST',
xhr: function() { // custom xhr
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){ // check if upload property exists
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload
}
return myXhr;
},
//Ajax events
success: postSuccess,
error: function(){ alert('error'); },
// Form data
data: (formData, fileData),
//Options to tell JQuery not to process data or worry about content-type
cache: false,
contentType: false,
processData: false
});//end ajax
return false;
});//end submit
/*
$('#photo_form').submit(function(event){
event.preventDefault()
var fileData = new FormData($(this)[0]);//file (request.FILES)
var formData = $(this).serialize();// another data (request.POST)
if ($('#obj_id').val() != '') {
var url = '/admin/ajax_post_photo/'+$('#obj_id').val()+'/';
}
else {
var url = '/admin/ajax_post_photo/'
}
$.ajax({
url: url, //server script to process data
type: 'POST',
xhr: function() { // custom xhr
var myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){ // check if upload property exists
myXhr.upload.addEventListener('progress',progressHandlingFunction, false); // for handling the progress of the upload
}
return myXhr;
},
//Ajax events
success: postPhoto,
error: function(){ alert('error'); },
// Form data
data: (formData, fileData),
//Options to tell JQuery not to process data or worry about content-type
cache: false,
contentType: false,
processData: false
});//end ajax
});
*/
});//end ready
function postSuccess(data, textStatus, jqXHR){
//console.log(data);
//$('#close').click();
if (data.indexOf("<form")+1){
$('#form_body').html(data);
}
else
{
$('#file_list table tbody').html(data);
$('#close').click();
}
}
//function for progress bar
function progressHandlingFunction(e){
if(e.lengthComputable){
$('progress').attr({value:e.loaded,max:e.total});
}
}
function postPhoto(data, textStatuse, jqXHR){
console.log(data);
if (data.indexOf("<form")+1){
$('#form_body').html(data);
}
else{
$('#photo_list table tbody').html(data);
$('#close').click();
}
}