|
|
@@ -14,7 +14,7 @@ var conf = { |
|
|
|
}; |
|
|
|
|
|
|
|
var temp = { |
|
|
|
upload: [ ], |
|
|
|
upload: [], |
|
|
|
documentid: null |
|
|
|
}; |
|
|
|
|
|
|
@@ -161,7 +161,7 @@ function page_home_scroll() { |
|
|
|
} |
|
|
|
|
|
|
|
function upload_zone_init() { |
|
|
|
$(window).on("dragover dragleave drop", function(e) { e.preventDefault() }); |
|
|
|
$(window).on("dragover dragleave drop", function (e) { e.preventDefault() }); |
|
|
|
|
|
|
|
$('.autodoc_upload_zone').on({ |
|
|
|
dragenter: upload_zone_highlight, |
|
|
@@ -186,7 +186,7 @@ function upload_zone_normal(e) { |
|
|
|
function upload_zone_drop(e) { |
|
|
|
var ev = e.originalEvent; |
|
|
|
|
|
|
|
$.each(ev.dataTransfer.files, function(id,file) { |
|
|
|
$.each(ev.dataTransfer.files, function (id, file) { |
|
|
|
console.log(file); |
|
|
|
var fileid = temp.upload.length; |
|
|
|
temp.upload.push({ |
|
|
@@ -194,74 +194,87 @@ function upload_zone_drop(e) { |
|
|
|
error: null, |
|
|
|
obj: file |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
if ( temp.documentid == null ) { |
|
|
|
$.post(conf.openapi + "/documents", {}, function(data) { |
|
|
|
upload_handler(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
function upload_handler() { |
|
|
|
|
|
|
|
if (temp.documentid == null) { |
|
|
|
$.post(conf.openapi + "/documents", {}, function (data) { |
|
|
|
temp.documentid = data.id; |
|
|
|
upload_status(); |
|
|
|
upload_handler(); |
|
|
|
}); |
|
|
|
} |
|
|
|
else { |
|
|
|
upload_handler(); |
|
|
|
for(var id=0; id<temp.upload.length; id++) { |
|
|
|
var file = temp.upload[id]; |
|
|
|
|
|
|
|
if ( file.progress != 100 ) { |
|
|
|
if ( file.progress == 0 ) { |
|
|
|
if (file.obj.type != 'application/pdf' && file.obj.type != 'image/png' && file.obj.type != 'image/jpeg') { |
|
|
|
file['progress'] = 100; |
|
|
|
file['error'] = 'invalid file type'; |
|
|
|
} |
|
|
|
else { |
|
|
|
var reader = new FileReader(); |
|
|
|
file['progress'] = 1; |
|
|
|
|
|
|
|
$(reader).on({ |
|
|
|
loadstart: upload_read_event, |
|
|
|
load: upload_read_event, |
|
|
|
loadend: upload_read_event, |
|
|
|
progress: upload_read_event, |
|
|
|
error: upload_read_event, |
|
|
|
abort: upload_read_event |
|
|
|
}); |
|
|
|
reader.readAsArrayBuffer(file.obj); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
setTimeout(upload_handler, 1000); |
|
|
|
} |
|
|
|
|
|
|
|
function upload_handler() { |
|
|
|
function upload_read_event(e) { |
|
|
|
console.log(e); |
|
|
|
} |
|
|
|
|
|
|
|
function upload_status() { |
|
|
|
|
|
|
|
console.log(temp.upload); |
|
|
|
$.each(temp.upload, function (id, file) { |
|
|
|
if (!$('.autodoc_upload_status_' + id)) { |
|
|
|
var obj = $(".autodoc_template_progress").children().clone(); |
|
|
|
$('.autodoc_upload_status').append(obj); |
|
|
|
} |
|
|
|
|
|
|
|
$.each(temp.upload, function(id,file) { |
|
|
|
console.log(upload_handler, file); |
|
|
|
var obj = $('.autodoc_upload_status_' + id).children(); |
|
|
|
|
|
|
|
if ( file.obj.type != 'application/pdf' && file.obj.type != 'image/png' && file.obj.type != 'image/jpeg' ) { |
|
|
|
temp.upload[id]['progress']=1; |
|
|
|
temp.upload[id]['error']='invalid file type'; |
|
|
|
if (file.error != null) { |
|
|
|
$(obj).html(file.obj.name + ': ' + file.error); |
|
|
|
$(obj).css('width', '100%'); |
|
|
|
$(obj).addClass('bg-danger'); |
|
|
|
$(obj).removeClass("progress-bar-animated"); |
|
|
|
} |
|
|
|
else { |
|
|
|
var reader = new FileReader(); |
|
|
|
var data; |
|
|
|
reader.onload = function(e) { |
|
|
|
$.post(conf.openapi + "/documents/" + temp.documentid + "/data", e.result, function(data) { |
|
|
|
console.log(data); |
|
|
|
}, file.obj.type) |
|
|
|
}; |
|
|
|
reader.readAsArrayBuffer(data); |
|
|
|
else if (file.progress == 100) { |
|
|
|
$(obj).html(file.obj.name); |
|
|
|
$(obj).addClass('bg-success'); |
|
|
|
$(obj).removeClass('progress-bar-animated'); |
|
|
|
$(obj).css('width', '100%'); |
|
|
|
} |
|
|
|
}); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
function upload_status() { |
|
|
|
var finished = 1; |
|
|
|
$('.autodoc_upload_status').children().remove(); |
|
|
|
$.each(temp.upload, function(id, file) { |
|
|
|
console.log(id,file); |
|
|
|
var obj = $(".autodoc_template_progress").children().clone(); |
|
|
|
$(obj).children().html(file.obj.name); |
|
|
|
$(obj).children().css('width', "50%"); |
|
|
|
if ( file.progress==1) { |
|
|
|
if ( file.error != null ) { |
|
|
|
$(obj).children().html(file.obj.name + ': ' + file.error); |
|
|
|
$(obj).children().addClass('bg-danger'); |
|
|
|
$(obj).children().removeClass("progress-bar-animated"); |
|
|
|
$(obj).children().css('width', "100%"); |
|
|
|
} |
|
|
|
else { |
|
|
|
finished=0; |
|
|
|
$(obj).children().addClass('bg-success'); |
|
|
|
$(obj).children().css('width', "100%"); |
|
|
|
$(obj).children().removeClass("progress-bar-animated"); |
|
|
|
else if (file.progress < 50) { |
|
|
|
$(obj).html(file.obj.name + ': ' + 'reading file'); |
|
|
|
$(obj).css('width', file.progress + '%'); |
|
|
|
} |
|
|
|
else { |
|
|
|
$(obj).html(file.obj.name + ': ' + 'sending file'); |
|
|
|
$(obj).css('width', file.progress + '%'); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
console.log(obj); |
|
|
|
$('.autodoc_upload_status').append(obj); |
|
|
|
}); |
|
|
|
if ( !finished || temp.upload.length == 0 ) { |
|
|
|
console.log("status again"); |
|
|
|
setTimeout(upload_status, 1000); |
|
|
|
} |
|
|
|
setTimeout(upload_status, 1000); |
|
|
|
} |