mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	Various fixes to the "Download image from URL" functionality (#4101)
* Various fixes to the "Download image from URL" functionality This commit adds an user-agent string to the download request wich prevents some sites from returning a 403 (forbidden) status. Clicking the download button on the thumbnail, also showed the thumbnail because the event wasn't stopped. The parts thumbnail didn't update after a succesfull download of the image, reloadImage was never called. * Fixed copy and paste errors in previous commit * Reverted back the user-agent immitation from the previous commit * Add a user-agent overide setting Add a setting to allow overiding the default user-agent that is used for downloading images and files from a URL * Fixed a typo in the description * Another typo fixed * Removed cast to string to prevent using 'None' as the user-agent * Thumbnail delete button not visible after upload The delete button on the image thumbnails of both parts and companies isn't showing when we upload a new image. This is fixed by always including the element on the page, and use javascript to show and hide the element.
This commit is contained in:
		@@ -391,6 +391,8 @@
 | 
			
		||||
    $('#part-thumb').click(function() {
 | 
			
		||||
        showModalImage('{{ part.image.url }}');
 | 
			
		||||
    });
 | 
			
		||||
    {% else %}
 | 
			
		||||
    $('#part-image-delete').hide();
 | 
			
		||||
    {% endif %}
 | 
			
		||||
 | 
			
		||||
    function reloadImage(data) {
 | 
			
		||||
@@ -403,6 +405,7 @@
 | 
			
		||||
                showModalImage(data.image);
 | 
			
		||||
            });
 | 
			
		||||
 | 
			
		||||
            $("#part-image-delete").show();
 | 
			
		||||
        } else {
 | 
			
		||||
            // Otherwise, reload the page
 | 
			
		||||
            location.reload();
 | 
			
		||||
@@ -586,8 +589,8 @@
 | 
			
		||||
    {% if roles.part.change %}
 | 
			
		||||
 | 
			
		||||
    if (global_settings.INVENTREE_DOWNLOAD_FROM_URL) {
 | 
			
		||||
 | 
			
		||||
        $("#part-image-url").click(function() {
 | 
			
		||||
            event.stopPropagation();
 | 
			
		||||
            constructForm(
 | 
			
		||||
                '{% url "api-part-detail" part.pk %}',
 | 
			
		||||
                {
 | 
			
		||||
@@ -596,7 +599,9 @@
 | 
			
		||||
                    fields: {
 | 
			
		||||
                        remote_image: {},
 | 
			
		||||
                    },
 | 
			
		||||
                    onSuccess: onSelectImage,
 | 
			
		||||
                    onSuccess: function(data) {
 | 
			
		||||
                        reloadImage(data);
 | 
			
		||||
                    },
 | 
			
		||||
                }
 | 
			
		||||
            );
 | 
			
		||||
        });
 | 
			
		||||
 
 | 
			
		||||
@@ -13,9 +13,7 @@
 | 
			
		||||
            {% if allow_download %}
 | 
			
		||||
            <button type='button' class='btn btn-outline-secondary' title="{% trans 'Download image from URL' %}" id='part-image-url'><span class='fas fa-cloud-download-alt'></span></button>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
            {% if part.image %}
 | 
			
		||||
            <button type='button' class='btn btn-outline-secondary' title='{% trans "Delete image" %}' id='part-image-delete'><span class='fas fa-trash-alt icon-red'></span></button>
 | 
			
		||||
            {% endif %}
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    {% endif %}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user