From: Sven Schöling Date: Fri, 14 May 2021 14:24:48 +0000 (+0200) Subject: ImageUpload: Hochladen deaktivieren wenn Form nicht komplett gefüllt ist X-Git-Tag: kivitendo-mebil_0.1-0~9^2~73 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=555e9ec5607fe2107040f7122f55a76471fe1901;p=kivitendo-erp.git ImageUpload: Hochladen deaktivieren wenn Form nicht komplett gefüllt ist --- diff --git a/js/kivi.ImageUpload.js b/js/kivi.ImageUpload.js index 26529e24e..3ae00b20d 100644 --- a/js/kivi.ImageUpload.js +++ b/js/kivi.ImageUpload.js @@ -3,6 +3,8 @@ namespace("kivi.ImageUpload", function(ns) { const MAXSIZE = 15*1024*1024; // 5MB size limit + let num_images = 0; + ns.add_files = function(target) { let files = []; for (var i = 0; i < target.files.length; i++) { @@ -18,7 +20,10 @@ namespace("kivi.ImageUpload", function(ns) { ns.reload_images = function() { kivi.FileDB.retrieve_all((data) => { $('#stored-images').empty(); + num_images = data.length; + data.forEach(ns.create_thumb_row); + ns.set_image_button_enabled(); }); }; @@ -43,9 +48,16 @@ namespace("kivi.ImageUpload", function(ns) { let $row = $(event.target).closest(".image-upload-row"); kivi.FileDB.delete_key(key, () => { $row.remove(); + num_images--; + ns.set_image_button_enabled(); }); }; + ns.set_image_button_enabled = function() { + $('#upload_images_submit').attr("disabled", num_images == 0 || !$('#object_id').val()); + }; + + ns.upload_files = function() { let id = $('#object_id').val(); let type = $('#object_type').val(); @@ -128,10 +140,12 @@ namespace("kivi.ImageUpload", function(ns) { $("#object_description").html(json.description); $("#object_id").val(json.id); } + ns.set_image_button_enabled(); }, error: () => { $("#object_description").html(""); $("#object_id").val(""); + ns.set_image_button_enabled(); } }); }; @@ -139,8 +153,6 @@ namespace("kivi.ImageUpload", function(ns) { ns.init = function() { ns.reload_images(); }; - - }); $(kivi.ImageUpload.init);