瀏覽代碼

sdf

master
Pascal Gloor 5 年之前
父節點
當前提交
dbd83c0f67
共有 1 個檔案被更改,包括 38 行新增36 行删除
  1. 38
    36
      www/js/autodoc.js

+ 38
- 36
www/js/autodoc.js 查看文件

@@ -11,6 +11,9 @@ var conf = {
width: 4,
curpage: 0,
end: 0
},
run: {
"upload_handler": 0
}
};

@@ -201,23 +204,27 @@ function upload_zone_drop(e) {
});
});

upload_handler();
if (conf.run.upload_handler == 0) {
upload_handler();
}

}

function upload_handler() {

conf.run.upload_handler = 1;
console.log("upload_handler");
if (temp.documentid == null) {
console.log("creating documentId");
$.post(conf.openapi + "/documents", {}, function (data) {
temp.documentid = data.id;
});
}
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') {
file['progress'] = 100;
file['error'] = 'invalid file type';
@@ -226,12 +233,12 @@ function upload_handler() {
var reader = new FileReader();
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('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);
}
@@ -240,20 +247,20 @@ function upload_handler() {
}
}
}
setTimeout(function() { upload_handler(); }, 1000);
setTimeout(function () { upload_handler(); }, 1000);
}

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;
console.log(e.target.result);
console.log("upload_id", e.data);
@@ -264,16 +271,15 @@ function upload_read_event(e) {
contentType: temp.upload[e.data].obj.type,
context: e.data,
processData: false,
xhr: function()
{
xhr: function () {
var xhr = $.ajaxSettings.xhr();
xhr.upload.addEventListener("progress", (function(){
xhr.upload.addEventListener("progress", (function () {
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);
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;
// console.log("upload_progress_event", evt);
}
@@ -281,25 +287,21 @@ function upload_read_event(e) {
})(), false);
return xhr;
},
success: function(data, status, xhr){
success: function (data, status, xhr) {
console.log("upload_success_this", this);
//var ctx = this.context;
//temp.upload[this.context].progress = 100;
temp.upload[this.context].progress = 100;

}
});

}

console.log(e);
}

function upload_status() {
$.each(temp.upload, function (id, file) {
if (!$('.autodoc_upload_status_' + id).length) {
var obj = $(".autodoc_template_progress").children().clone();
$(obj).addClass('autodoc_upload_status_'+id);
$(obj).addClass('autodoc_upload_status_' + id);
$('.autodoc_upload_status').append(obj);
}
var obj = $('.autodoc_upload_status_' + id).children();
@@ -325,6 +327,6 @@ function upload_status() {

}
});
setTimeout(function() { upload_status(); }, 100);
setTimeout(function () { upload_status(); }, 100);
}

Loading…
取消
儲存