Revision b16bfc90
Von Sven Schöling vor mehr als 3 Jahren hinzugefügt
js/kivi.ImageUpload.js | ||
---|---|---|
3 | 3 |
|
4 | 4 |
const MAXSIZE = 15*1024*1024; // 5MB size limit |
5 | 5 |
|
6 |
let num_images = 0; |
|
7 |
|
|
6 | 8 |
ns.add_files = function(target) { |
7 | 9 |
let files = []; |
8 | 10 |
for (var i = 0; i < target.files.length; i++) { |
... | ... | |
18 | 20 |
ns.reload_images = function() { |
19 | 21 |
kivi.FileDB.retrieve_all((data) => { |
20 | 22 |
$('#stored-images').empty(); |
23 |
num_images = data.length; |
|
24 |
|
|
21 | 25 |
data.forEach(ns.create_thumb_row); |
26 |
ns.set_image_button_enabled(); |
|
22 | 27 |
}); |
23 | 28 |
}; |
24 | 29 |
|
... | ... | |
43 | 48 |
let $row = $(event.target).closest(".image-upload-row"); |
44 | 49 |
kivi.FileDB.delete_key(key, () => { |
45 | 50 |
$row.remove(); |
51 |
num_images--; |
|
52 |
ns.set_image_button_enabled(); |
|
46 | 53 |
}); |
47 | 54 |
}; |
48 | 55 |
|
56 |
ns.set_image_button_enabled = function() { |
|
57 |
$('#upload_images_submit').attr("disabled", num_images == 0 || !$('#object_id').val()); |
|
58 |
}; |
|
59 |
|
|
60 |
|
|
49 | 61 |
ns.upload_files = function() { |
50 | 62 |
let id = $('#object_id').val(); |
51 | 63 |
let type = $('#object_type').val(); |
... | ... | |
128 | 140 |
$("#object_description").html(json.description); |
129 | 141 |
$("#object_id").val(json.id); |
130 | 142 |
} |
143 |
ns.set_image_button_enabled(); |
|
131 | 144 |
}, |
132 | 145 |
error: () => { |
133 | 146 |
$("#object_description").html(""); |
134 | 147 |
$("#object_id").val(""); |
148 |
ns.set_image_button_enabled(); |
|
135 | 149 |
} |
136 | 150 |
}); |
137 | 151 |
}; |
... | ... | |
139 | 153 |
ns.init = function() { |
140 | 154 |
ns.reload_images(); |
141 | 155 |
}; |
142 |
|
|
143 |
|
|
144 | 156 |
}); |
145 | 157 |
|
146 | 158 |
$(kivi.ImageUpload.init); |
Auch abrufbar als: Unified diff
ImageUpload: Hochladen deaktivieren wenn Form nicht komplett gefüllt ist