function initUpload(){ vvDebugg('++--> initUpload v3'); // Dropzone var $upload_zone = $('.upload-zone:not(.upload-zone-enabled),.upload-zone-multi:not(.upload-zone-enabled)'); if ($upload_zone.length > 0 ) { $upload_zone.each(function(){ var $self = $(this); $self.addClass('upload-zone-enabled'); console.log($("#"+$self.data('guid_key'))); if($("#"+$self.data('guid_key')).attr('option-transparent') == 1){ $("#"+$self.data('guid_key')+"_obj").addClass('enable-option-transparent'); } if($self.hasClass('upload-zone-multi')){ $self.multi = true; }else{ $self.multi = false; } var parms = []; $.each($self.get(0).attributes, function(i, attrib){ var name = attrib.name; var value = attrib.value; if(name.match(/data/)){ parms[name.substring(5)] = value; } }); var queryString = Object.keys(parms).map((key) => { return encodeURIComponent(key) + '=' + encodeURIComponent(parms[key]) }).join('&'); if($(this).hasClass('local')){ var queryString = Object.keys(parms).map((key) => { return encodeURIComponent(key) + '=' + encodeURIComponent(parms[key]) }).join('&'); var url = "/?init=vvUpload&multi=true&replace=false&"+queryString+"&r="+Math.random(); }else{ var url = settings.cdn['h']+"actions.php?init=_upload&utoken="+settings.utoken+"&multi="+$self.multi+"&replace=true&"+queryString+"&r="+Math.random(); } $self.addClass('dropzone').dropzone({ uploadMultiple:false, maxFiles:50, url: url, headers: { }, init: function() { this.on("uploadprogress", function(file, progress, bytesSent) { vvDebugg(progress); if(progress > 90){ $(file.previewElement).parent().find(".dz-filename").html('Scanning file for malware, Please Wait'); }else{ $(file.previewElement).parent().find(".dz-filename").html('Sending file.'); } }); this.on("sending", function(file) { vvDebugg('Upload sending'); clearTimeout(multi_timeout); $(file.previewElement).parent().find(".dz-message").hide(); file.timeout = setTimeout(()=>{ window.location.reload(); },50000); }); this.on("canceled", function(file, data) { vvDebugg('Upload canceled'); vvDebugg(data); clearTimeout(file.timeout); }); this.on("error", function(file, data) { vvDebugg('**** upload error'); clearTimeout(file.timeout); vvDebugg(data); $(file.previewElement).parent().find(".dz-message").show(); vvMsgBox(data.msg,'error',10000,'danger',settings['upload_failed_msg']); this.removeAllFiles(true); }); this.on("success", function(file, data) { vvDebugg('Upload success #1-1'); vvDebugg(data); vvReturnDataAction(data); clearTimeout(file.timeout); if(!data.success){ vvDebugg('**** upload failed'); vvMsgBox(data.msg,'error',10000,'danger'); $(file.previewElement).parent().find(".dz-message").show(); this.removeAllFiles(true); }else if(data.file != undefined){ vvDebugg('Data file success #1-1'); if(data.multi == "false"){ $(file.previewElement).parents(".upload-box").hide(); } $(file.previewElement).parent().find(".dz-message").show(); var _template = '
'; if(data.file.guid_key != undefined){ vvDebugg('Data guid_key success #1-2'); if(data.multi == "false"){ vvDebugg('Multi = false #1-3'); $(file.previewElement).parents('.upload-box').parent().append(_template); }else{ vvDebugg('Multi = true #1-4'); $(file.previewElement).parents('.upload-box').parent().find('.files-holder').append(_template); } } else{ vvDebugg('Data guid_key missing #1-2'); } $(file.previewElement).remove(); if(data.file.filename != undefined && lang.upload != undefined){ vvMsgBox(lang.upload.success,data.file.id,10000,'info',lang.upload.success_subject,data); } clearTimeout(multi_timeout); multi_timeout = setTimeout("vvInit()",3000); $(document).trigger('vvUploadComplete',data); }else{ vvDebugg('**** Upload error #1-2'); } }); } }); }); } // Dropzone multi var $upload_zone = $('.upload-zone-multi-test:not(.upload-zone-enabled)'); var multi_timeout = null; if ($upload_zone.length > 0 ) { $upload_zone.each(function(){ $(this).addClass('upload-zone-enabled'); var $self = $(this); var parms = []; $.each($self.get(0).attributes, function(i, attrib){ var name = attrib.name; var value = attrib.value; if(name.match(/data/)){ parms[name.substring(5)] = value; } }); var queryString = Object.keys(parms).map((key) => { return encodeURIComponent(key) + '=' + encodeURIComponent(parms[key]) }).join('&'); var url = settings.cdn['h']+"actions.php?init=_upload&utoken="+settings.utoken+"&multi=true&replace=false&"+queryString+"&r="+Math.random(); $self.addClass('dropzone').dropzone({ uploadMultiple:false, maxFiles:50, url: url, headers: { }, init: function() { this.on("uploadprogress", function(file, progress, bytesSent) { vvDebugg(progress); if(progress > 90){ $(file.previewElement).parent().find(".dz-filename").html('Scanning file for malware, Please Wait'); }else{ $(file.previewElement).parent().find(".dz-filename").html('Sending file.'); } }); this.on("sending", function(file) { vvDebugg('Upload sending'); vvDebugg('+++init multi upload file'); clearTimeout(multi_timeout); $(file.previewElement).parent().find(".dz-message").hide(); }); this.on("canceled", function(file, data) { vvDebugg('Upload canceled'); vvDebugg(data); clearTimeout(file.timeout); }); this.on("error", function(file, data) { vvDebugg('Upload error'); clearTimeout(file.timeout); vvDebugg(data); $(file.previewElement).parent().find(".dz-message").show(); $(file.previewElement).remove(); vvMsgBox(data.msg,'error',10000,'danger',settings['upload_failed_msg']); this.removeAllFiles(true); }); this.on("success", function(file, data) { vvDebugg('Upload success #2'); vvDebugg(data); vvReturnDataAction(data); if(!data.success){ vvDebugg('**** upload failed'); vvMsgBox(data.msg,'error',10000,'danger'); $(file.previewElement).parent().find(".dz-message").show(); $(file.previewElement).remove(); }else{ vvDebugg('Upload success #3'); if(data.file != undefined && data.file.filename != undefined){ vvDebugg('Upload success #4'); if(lang.upload != undefined){ vvMsgBox(lang.upload.success,data.file.id,10000,'info',lang.upload.success_subject,data); } clearTimeout(multi_timeout); multi_timeout = setTimeout("vvInit()",3000); $(document).trigger('vvUploadComplete',data); } } }); } }); }); } // Dropzone local multi var $upload_zone = $('.upload-zone-local-multi:not(.upload-zone-enabled)'); var multi_timeout = null; if ($upload_zone.length > 0 ) { $upload_zone.each(function(){ $(this).addClass('upload-zone-enabled'); var $self = $(this); var parms = []; $.each($self.get(0).attributes, function(i, attrib){ var name = attrib.name; var value = attrib.value; if(name.match(/data/)){ parms[name.substring(5)] = value; } }); var queryString = Object.keys(parms).map((key) => { return encodeURIComponent(key) + '=' + encodeURIComponent(parms[key]) }).join('&'); var url = "/?init=vvUpload&multi=true&replace=false&"+queryString+"&r="+Math.random(); var __options = { uploadMultiple:false, maxFiles:50, url: url, headers: { 'Access-Control-Allow-Headers': '*', 'Cache-Control': null, 'X-Requested-With': null }, init: function() { this.on("uploadprogress", function(file, progress, bytesSent) { vvDebugg(progress); if(progress > 90){ $(file.previewElement).parent().find(".dz-filename").html('Scanning file for malware, Please Wait'); }else{ $(file.previewElement).parent().find(".dz-filename").html('Sending file.'); } }); this.on("sending", function(file) { vvDebugg('+++init multi upload file'); clearTimeout(multi_timeout); $(file.previewElement).parent().find(".dz-message").hide(); }); this.on("canceled", function(file, data) { vvDebugg(data); clearTimeout(file.timeout); }); this.on("error", function(file, data) { clearTimeout(file.timeout); vvDebugg(data); $(file.previewElement).parent().find(".dz-message").show(); $(file.previewElement).remove(); vvMsgBox(data.msg,'error',10000,'danger',settings['upload_failed_msg']); this.removeAllFiles(true); }); this.on("success", function(file, data) { vvDebugg(data); vvReturnDataAction(data); if(!data.success){ vvDebugg('**** upload failed'); vvMsgBox(data.msg,'error',10000,'danger'); $(file.previewElement).parent().find(".dz-message").show(); $(file.previewElement).remove(); }else{ if(data.file != undefined && data.file.filename != undefined){ if(lang.upload != undefined){ vvMsgBox(lang.upload.success,data.file.id,10000,'info',lang.upload.success_subject,data); } clearTimeout(multi_timeout); multi_timeout = setTimeout("vvInit()",3000); } } $(document).trigger('vvUploadComplete',data); }); } }; console.log(__options); $self.addClass('dropzone').dropzone(__options); }); } }