|
|
|
|
|
|
|
|
width: 4, |
|
|
width: 4, |
|
|
curpage: 0, |
|
|
curpage: 0, |
|
|
end: 0 |
|
|
end: 0 |
|
|
|
|
|
}, |
|
|
|
|
|
run: { |
|
|
|
|
|
"upload_handler": 0 |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
upload_handler(); |
|
|
|
|
|
|
|
|
if (conf.run.upload_handler == 0) { |
|
|
|
|
|
upload_handler(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function upload_handler() { |
|
|
function upload_handler() { |
|
|
|
|
|
|
|
|
|
|
|
conf.run.upload_handler = 1; |
|
|
|
|
|
console.log("upload_handler"); |
|
|
if (temp.documentid == null) { |
|
|
if (temp.documentid == null) { |
|
|
|
|
|
console.log("creating documentId"); |
|
|
$.post(conf.openapi + "/documents", {}, function (data) { |
|
|
$.post(conf.openapi + "/documents", {}, function (data) { |
|
|
temp.documentid = data.id; |
|
|
temp.documentid = data.id; |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
for(var id=0; id<temp.upload.length; id++) { |
|
|
|
|
|
var file = temp.upload[id]; |
|
|
|
|
|
|
|
|
|
|
|
if ( file.progress != 100 ) { |
|
|
|
|
|
if ( file.progress == 0 ) { |
|
|
|
|
|
|
|
|
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') { |
|
|
if (file.obj.type != 'application/pdf' && file.obj.type != 'image/png' && file.obj.type != 'image/jpeg') { |
|
|
file['progress'] = 100; |
|
|
file['progress'] = 100; |
|
|
file['error'] = 'invalid file type'; |
|
|
file['error'] = 'invalid file type'; |
|
|
|
|
|
|
|
|
var reader = new FileReader(); |
|
|
var reader = new FileReader(); |
|
|
file['progress'] = 1; |
|
|
file['progress'] = 1; |
|
|
|
|
|
|
|
|
$(reader).on('load', id, upload_read_event); |
|
|
|
|
|
|
|
|
$(reader).on('load', id, upload_read_event); |
|
|
$(reader).on('loadstart', id, upload_read_event); |
|
|
$(reader).on('loadstart', id, upload_read_event); |
|
|
$(reader).on('loadend', id, upload_read_event); |
|
|
|
|
|
$(reader).on('progress', id, upload_read_event); |
|
|
|
|
|
$(reader).on('error', id, upload_read_event); |
|
|
|
|
|
$(reader).on('abort', id, upload_read_event); |
|
|
|
|
|
|
|
|
$(reader).on('loadend', id, upload_read_event); |
|
|
|
|
|
$(reader).on('progress', id, upload_read_event); |
|
|
|
|
|
$(reader).on('error', id, upload_read_event); |
|
|
|
|
|
$(reader).on('abort', id, upload_read_event); |
|
|
|
|
|
|
|
|
reader.readAsArrayBuffer(file.obj); |
|
|
reader.readAsArrayBuffer(file.obj); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
setTimeout(function() { upload_handler(); }, 1000); |
|
|
|
|
|
|
|
|
setTimeout(function () { upload_handler(); }, 1000); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function upload_read_event(e) { |
|
|
function upload_read_event(e) { |
|
|
if ( e.type == 'progress' ) { |
|
|
|
|
|
if ( e.lengthComputable ) { |
|
|
|
|
|
var progress = Math.floor(e.originalEvent.loaded / e.originalEvent.total * 50); |
|
|
|
|
|
if ( progress < 1 ) { progress = 1; } |
|
|
|
|
|
if ( progress > 49 ) { progress = 49; } |
|
|
|
|
|
temp.upload[e.data]['progress'] = progress; |
|
|
|
|
|
|
|
|
if (e.type == 'progress') { |
|
|
|
|
|
if (e.lengthComputable) { |
|
|
|
|
|
var progress = Math.floor(e.originalEvent.loaded / e.originalEvent.total * 50); |
|
|
|
|
|
if (progress < 1) { progress = 1; } |
|
|
|
|
|
if (progress > 49) { progress = 49; } |
|
|
|
|
|
temp.upload[e.data]['progress'] = progress; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
else if ( e.type == 'load' ) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else if (e.type == 'load') { |
|
|
|
|
|
|
|
|
temp.upload[e.data]['progress'] = 50; |
|
|
temp.upload[e.data]['progress'] = 50; |
|
|
console.log(e.target.result); |
|
|
console.log(e.target.result); |
|
|
console.log("upload_id", e.data); |
|
|
console.log("upload_id", e.data); |
|
|
|
|
|
|
|
|
contentType: temp.upload[e.data].obj.type, |
|
|
contentType: temp.upload[e.data].obj.type, |
|
|
context: e.data, |
|
|
context: e.data, |
|
|
processData: false, |
|
|
processData: false, |
|
|
xhr: function() |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
xhr: function () { |
|
|
var xhr = $.ajaxSettings.xhr(); |
|
|
var xhr = $.ajaxSettings.xhr(); |
|
|
xhr.upload.addEventListener("progress", (function(){ |
|
|
|
|
|
|
|
|
xhr.upload.addEventListener("progress", (function () { |
|
|
var id = e.data; |
|
|
var id = e.data; |
|
|
return function(evt) { |
|
|
|
|
|
if (evt.lengthComputable) { |
|
|
|
|
|
|
|
|
return function (evt) { |
|
|
|
|
|
if (evt.lengthComputable) { |
|
|
var progress = Math.floor(evt.loaded / evt.total * 50); |
|
|
var progress = Math.floor(evt.loaded / evt.total * 50); |
|
|
if ( progress < 1 ) { progress = 1; } |
|
|
|
|
|
if ( progress > 49 ) { progress = 49; } |
|
|
|
|
|
|
|
|
if (progress < 1) { progress = 1; } |
|
|
|
|
|
if (progress > 49) { progress = 49; } |
|
|
temp.upload[id].progress = 50 + progress; |
|
|
temp.upload[id].progress = 50 + progress; |
|
|
// console.log("upload_progress_event", evt); |
|
|
// console.log("upload_progress_event", evt); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
})(), false); |
|
|
})(), false); |
|
|
return xhr; |
|
|
return xhr; |
|
|
}, |
|
|
}, |
|
|
success: function(data, status, xhr){ |
|
|
|
|
|
|
|
|
success: function (data, status, xhr) { |
|
|
console.log("upload_success_this", this); |
|
|
console.log("upload_success_this", this); |
|
|
//var ctx = this.context; |
|
|
//var ctx = this.context; |
|
|
//temp.upload[this.context].progress = 100; |
|
|
|
|
|
|
|
|
temp.upload[this.context].progress = 100; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
console.log(e); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function upload_status() { |
|
|
function upload_status() { |
|
|
$.each(temp.upload, function (id, file) { |
|
|
$.each(temp.upload, function (id, file) { |
|
|
if (!$('.autodoc_upload_status_' + id).length) { |
|
|
if (!$('.autodoc_upload_status_' + id).length) { |
|
|
var obj = $(".autodoc_template_progress").children().clone(); |
|
|
var obj = $(".autodoc_template_progress").children().clone(); |
|
|
$(obj).addClass('autodoc_upload_status_'+id); |
|
|
|
|
|
|
|
|
$(obj).addClass('autodoc_upload_status_' + id); |
|
|
$('.autodoc_upload_status').append(obj); |
|
|
$('.autodoc_upload_status').append(obj); |
|
|
} |
|
|
} |
|
|
var obj = $('.autodoc_upload_status_' + id).children(); |
|
|
var obj = $('.autodoc_upload_status_' + id).children(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
setTimeout(function() { upload_status(); }, 100); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setTimeout(function () { upload_status(); }, 100); |
|
|
} |
|
|
} |