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.
 
 
 
 
 
 

131 lines
4.9 KiB

$(document.forms['load_file']).on('change', "input[name=file_load]" , function(){ upload_file(this);});
function check_file_load(clip_id, type_in){
var response = '';
$.ajax({
type: 'GET',
url: '/storage/check_file_load/',
data: ({key:clip_id, 'type_in': type_in}),
async: false,
success: function(data) {
if (data.code == '1'){
response = true;
} else {
response = false;
}
}
});
return response;
}
function get_file_sketch(clip_id){
var response = '';
$.ajax({
type: 'GET',
url: '/storage/get_file_sketch/',
data: ({key:clip_id}),
async: false,
success: function(data) {
if (data.code == '1'){
response = data['data'];
}
}
});
return response;
}
function check_file_error(clip_id){
var response = '';
$.ajax({
type: 'GET',
url: '/storage/check_file_error/',
data: ({key:clip_id}),
async: false,
success: function(data) {
if (data.code == '1'){
response = true;
} else {
response = false;
}
}
});
return response;
}
function remove_file_sketch(clip_id){
$('[sketch_file_clip_key='+clip_id+']').fadeOut('slow', function(){
$('[sketch_file_clip_key='+clip_id+']').html('')
})
}
function write_sketch(id){
var clip_file = $('[id='+id+'_form]').find($( "[name='clip_file_id']" )).val();
var data = get_file_sketch(clip_file);
$('[name='+$('[id='+id+']').attr('sketch_place')+']').append(
'<div style="float: left;background-color: #fff;padding: 5px 10px;margin-right: 10px; margin-top: 10px; border-radius: 3px;padding: 10px 15px;padding-left: 5px;" sketch_file_clip_key="'+clip_file+'">' +
'<i class="'+ data['icon'] +' text-lg inline text-primary" style="margin-right: 5px;"></i>' +
'<span class="clear inline">' +
'<span>'+ data['name'] +'</span>' +
'<small class="text-muted clear text-ellipsis">'+ data['file_name'] +'</small>' +
'<input name="file_'+clip_file+'" readonly style="display: none;" value='+clip_file+'>' +
'</span>' +
'<a type="button" class="glyphicon glyphicon-remove" style="margin-top: 15px;margin-left: -3px;" onclick="remove_file_sketch(\''+clip_file+'\')"></a>' +
'</div>'
)
}
function load_file_process(id){
if (!window.load_process_interval){
start_load(id);
}
function start_load(id){
window.load_process_interval = setInterval( function(){check_error(id); check_load(id);}, 1000);
}
function stop_load_process(){
clearInterval(window.load_process_interval);
delete window.load_process_interval;
}
function check_load(id){
if (check_file_load($('[id='+id+'_form]').find($( "[name='clip_file_id']" )).val(), 'loaded')){
stop_load_process();
$("[name="+id+"_progress]").fadeOut();
$("[name="+id+"_button]").fadeIn();
$("[id="+id+"]").replaceWith($("[id="+id+"]").clone());
write_sketch(id);
clear_load_img_data(id)
}
}
function check_error(id){
if (check_file_error($('[id='+id+'_form]').find($( "[name='clip_file_id']" )).val())){
stop_load_process();
$("[name="+id+"_progress]").fadeOut();
$("[name="+id+"_button]").fadeIn();
$("[id="+id+"]").replaceWith($("[id="+id+"]").clone());
show_system_message('При загрузке файла произошла ошибка.<br>Попробуйте загрузить файл другого формата или размера.');
clear_load_img_data(id)
}
}
}
function upload_file(block){
var id= $(block).attr('id');
$("[name="+id+"_progress]").fadeIn();
$("[name="+id+"_button]").fadeOut();
var code = gen_unique_key();
$('[id='+id+'_form]').find($( "[name='clip_file_id']" )).val(code);
document.forms['load_file'].submit();
load_file_process(id);
}
function clear_load_img_data(id){
$('[name="load_image_x1"]').val('');
$('[name="load_image_x2"]').val('');
$('[name="load_image_y1"]').val('');
$('[name="load_image_y2"]').val('');
$('[name="load_image_width"]').val('');
$('[name="load_image_height"]').val('');
$('[id='+id+'_form]').find($( "[name='clip_file_id']" )).val('');
$('[name="load_image_place_name"]').val('');
$('[name="load_image_placed_size"]').val('');
}