$(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( '
' ) } 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('При загрузке файла произошла ошибка.