Revision 714f86ed
Von Sven Schöling vor mehr als 3 Jahren hinzugefügt
js/kivi.ImageUpload.js | ||
---|---|---|
1 | 1 |
namespace("kivi.ImageUpload", function(ns) { |
2 | 2 |
"use strict"; |
3 | 3 |
|
4 |
const MAXSIZE = 5*1024*1024; // 5MB size limit |
|
5 |
|
|
4 | 6 |
ns.add_files = function(target) { |
5 | 7 |
let files = []; |
6 | 8 |
for (var i = 0; i < target.files.length; i++) { |
... | ... | |
44 | 46 |
}); |
45 | 47 |
}; |
46 | 48 |
|
47 |
ns.upload_selected_files = function(id,type,filetype,maxsize) { |
|
49 |
ns.upload_files = function() { |
|
50 |
let id = $('#object_id').val(); |
|
51 |
let type = $('#object_type').val(); |
|
52 |
|
|
53 |
ns.upload_selected_files(id, type, MAXSIZE); |
|
54 |
}; |
|
55 |
|
|
56 |
ns.upload_selected_files = function(id, type, maxsize) { |
|
48 | 57 |
kivi.FileDB.retrieve_all((myfiles) => { |
49 | 58 |
let filesize = 0; |
50 | 59 |
myfiles.forEach(file => { |
... | ... | |
55 | 64 |
} |
56 | 65 |
|
57 | 66 |
let data = new FormData(); |
58 |
data.append(file); |
|
67 |
data.append("file", file);
|
|
59 | 68 |
data.append("action", "File/ajax_files_uploaded"); |
60 | 69 |
data.append("json", "1"); |
61 | 70 |
data.append("object_type", type); |
62 | 71 |
data.append("object_id", id); |
63 |
data.append("file_type", filetype);
|
|
72 |
data.append("file_type", "attachment");
|
|
64 | 73 |
|
65 | 74 |
$("#upload_result").html(kivi.t8("start upload")); |
66 | 75 |
|
67 |
$.ajax({ |
|
68 |
url: "controller.pl", |
|
69 |
data: data, |
|
70 |
success: ns.attSuccess, |
|
71 |
progress: ns.attProgress, |
|
72 |
error: ns.attFailes, |
|
73 |
abort: ns.attCanceled |
|
74 |
}); |
|
76 |
let xhr = new XMLHttpRequest; |
|
77 |
xhr.open('POST', 'controller.pl', true); |
|
78 |
xhr.success = ns.attSuccess; |
|
79 |
xhr.progress = ns.attProgress; |
|
80 |
xhr.error = ns.attFailed; |
|
81 |
xhr.abort = ns.attCanceled; |
|
82 |
xhr.send(data); |
|
75 | 83 |
}); |
76 | 84 |
}); |
77 | 85 |
}; |
... | ... | |
98 | 106 |
$("#upload_result").html(kivi.t8("Files have been uploaded successfully.")); |
99 | 107 |
}; |
100 | 108 |
|
109 |
ns.resolve_object = function(event) { |
|
110 |
let obj_type = $('#object_type').val(); |
|
111 |
let number = event.target.value; |
|
112 |
|
|
113 |
$.ajax({ |
|
114 |
url: "controller.pl", |
|
115 |
data: { |
|
116 |
action: "ImageUpload/resolve_object_by_number", |
|
117 |
object_type: obj_type, |
|
118 |
object_number: number |
|
119 |
}, |
|
120 |
type: "json", |
|
121 |
success: (json) => { |
|
122 |
if (json.error) { |
|
123 |
$("#object_description").html(""); |
|
124 |
$("#object_id").val(""); |
|
125 |
} else { |
|
126 |
$("#object_description").html(json.description); |
|
127 |
$("#object_id").val(json.id); |
|
128 |
} |
|
129 |
}, |
|
130 |
error: () => { |
|
131 |
$("#object_description").html(""); |
|
132 |
$("#object_id").val(""); |
|
133 |
} |
|
134 |
}); |
|
135 |
}; |
|
136 |
|
|
101 | 137 |
ns.init = function() { |
102 | 138 |
ns.reload_images(); |
103 | 139 |
}; |
Auch abrufbar als: Unified diff
ImageUpload: client side Scripte