85 lines
2.2 KiB
JavaScript
85 lines
2.2 KiB
JavaScript
$(document).ready(function()
|
|
{
|
|
$("#mask").hide();
|
|
$("#uploadprogress").hide();
|
|
$('#updoc').change(function() {
|
|
$("#filename").val($(this).val().split(/(\\|\/)/g).pop());
|
|
startUpload(document.getElementById("updoc"));
|
|
});
|
|
});
|
|
|
|
function getFile()
|
|
{
|
|
$('#updoc').trigger('click');
|
|
}
|
|
|
|
function uploadFile(fileElm,formElm,validExt)
|
|
{
|
|
if(checkExtension(fileElm,validExt))
|
|
{
|
|
var options = {
|
|
beforeSend: function()
|
|
{
|
|
$("#mask").show();
|
|
$("#uploadprogress").show();
|
|
$("#bar").width('0%');
|
|
$("#percent").html("0%");
|
|
},
|
|
uploadProgress: function(event, position, total, percentComplete)
|
|
{
|
|
$("#bar").width(percentComplete+'%');
|
|
$("#percent").html(percentComplete+'%');
|
|
},
|
|
success: function(data)
|
|
{
|
|
$("#bar").width('100%');
|
|
$("#percent").html('100%');
|
|
$("#uploadprogress").hide();
|
|
$("#mask").hide();
|
|
$("#bar").width('0%');
|
|
$("#percent").html("0%");
|
|
},
|
|
complete: function(response)
|
|
{
|
|
curindx=0;
|
|
var dataArray = jQuery.parseJSON(response.responseText);
|
|
if(dataArray.msg!='error')
|
|
{
|
|
if($('#'+$("#doctype").val()).length > 0)
|
|
{
|
|
if(dataArray.msg == "success")
|
|
{
|
|
$(".container",$("#"+$("#doctype").val())).append(dataArray.data);
|
|
if(dataArray.hasOwnProperty('path')){
|
|
activaTab($("#doctype").val(),dataArray.path);
|
|
}
|
|
else
|
|
{
|
|
activaTab($("#doctype").val());
|
|
}
|
|
|
|
}
|
|
else
|
|
{
|
|
alert(dataArray.data);
|
|
}
|
|
}
|
|
}
|
|
document.getElementById(formElm).reset();
|
|
},
|
|
error: function(data)
|
|
{
|
|
var errors = data.responseJSON;
|
|
alert(errors);
|
|
alert("Error");
|
|
curindx=0;
|
|
document.getElementById(formElm).reset();
|
|
}
|
|
};
|
|
$("#"+formElm).ajaxForm(options).submit();
|
|
}
|
|
else
|
|
{
|
|
alert("Invalid file format. Only "+validExt+" files are allowed");
|
|
}
|
|
} |