From 555e9ec5607fe2107040f7122f55a76471fe1901 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 14 May 2021 16:24:48 +0200 Subject: [PATCH] =?utf8?q?ImageUpload:=20Hochladen=20deaktivieren=20wenn?= =?utf8?q?=20Form=20nicht=20komplett=20gef=C3=BCllt=20ist?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- js/kivi.ImageUpload.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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); -- 2.20.1