/*
* Codificación UTF-8
* Eventos asociados al componente upload
*/
//$('input[type=file][data-gvhWindow='+ambito+']').on({
$('#gvhPage').offon( 'change', 'input[type=file]', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
console.log(' ** UPDATE FILE '+$(this).attr('id'));
var panel = $(this).attr('data-gvhPanelOn');
var claseM = $(this).attr('data-gvhClaseManejadora');
var statePanel = gvh.getStatePanel(panel);
gvh.blockExit( false, statePanel, panel, claseM );
var fileCollection = new Object();
/*fileCollection['name'] = new Array();
fileCollection['type'] = new Array();
fileCollection['tmp_name'] = new Array();
fileCollection['error'] = new Array();
fileCollection['size'] = new Array();*/
var panelJSON = $(this).attr('data-gvhPanelJSON');
var iter = $(this).attr('data-gvhIterActual');
var actualizaA = $(this).attr('data-gvhActualizaA');
var id = $(this).attr('id');
var campoJSON = id;
if (panel != 'fil')
campoJSON = id.split('___')[1];
idToUpload = "toUpload_"+id;
var files = e.target.files;
var count = files.length;
var tmp_files = '';
toUpload = $('span[id='+idToUpload+']');
toUpload.map( function() {
$(this).empty();
} );
id_ulFile = 'ulFile_'+id;
$('#'+id_ulFile).empty();
toUpload.append("
");
padre = $('#progress_bar').parent().attr('id');
$("#percent").css("width", "5%");
$("#percent").text("0%");
formData = new FormData();
$.each(files, function(i, file) {
console.log(file);
console.log(file.tmp_name);
/*fileCollection['name'][i] = file.name;
fileCollection['type'][i] = file.type;
fileCollection['error'][i] = file.error;
fileCollection['size'][i] = file.size;*/
fileCollection[i] = file;
formData.append('file[]', file );
var reader = new FileReader();
reader.readAsDataURL(file);
// Barra progreso
reader.onprogress = function(data) {
if (data.lengthComputable) {
var percentLoaded = Math.round((data.loaded / data.total) * 100);
if (percentLoaded < 100) {
$('.listFiles').show();
$("#percent").css("width", percentLoaded+"%");
$("#percent").text(file.name+' '+percentLoaded+"%");
$('#progress_bar').show();
}
}
}
reader.onload = function(e) {
//console.log(e);
$('#'+id_ulFile).append('- '+file.name+'
');
if (!--count)
{
$('#'+idToUpload).append("
");
$('#'+idToUpload).css('visibility', 'visible');
}
$("#percent").css("width", "100%");
$("#percent").text(file.name+" 100%");
//formData.append('image',fileCollection);
$('.listFiles').show();
$('.listFiles .paper').show();
}
//console.log( file );
} );
numReg = id.split('___')[2].split('_')[1];
// Mostramos el progreso
Pace.restart();
document.body.className = document.body.className; // Forzamos a actualizar la interfaz
$.ajax( {
type:'POST',
url: 'phrame.php?action=ManageUpload__upFile',
data:formData,
processData: false,
contentType: false,
enctype: 'multipart/form-data',
cache: false,
success:function(data) {
console.log(data);
//datosJSON[claseM][panelJSON]['data'][numReg]['gvhJS_fields'][campoJSON]['files'] = data;
//datosJSON[claseM][panelJSON]['dataPerform']['data'][numReg]['gvhJS_fields'][campoJSON]['files'] = data;
var raizJSON = gvh.getRoot(claseM,panelJSON);
gvh.setFilesUp(raizJSON,campoJSON,numReg,data);
$("#percent").css("width", "100%");
$("#percent").text("...100%");
$('#progress_bar').hide();
if (statePanel == 'I')
operacion = 'inserted';
else if (statePanel == 'W')
operacion = 'updated';
gvh.setStateReg(raizJSON, operacion, numReg );
gvh.setSelectedReg(raizJSON,numReg,'add');
} ,
error: function(data) {
console.hide(data);
}
} );
} );