2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-08-14 15:41:10 +00:00

Enable DnD for Company image

- Can actually use the existing form to do partial upload!
- Generecise the drag-and-drop upload function
- Remove some (now unnecessary) Python View code
This commit is contained in:
Oliver Walters
2019-05-07 14:47:31 +10:00
parent 39672d4e23
commit dcbd5d819c
6 changed files with 81 additions and 135 deletions

View File

@@ -13,17 +13,14 @@
<div class="col-sm-6">
<div class="media">
<div class="media-left">
<form id='upload-photo' method='post' action="{% url 'part-image-upload' part.id %}">
<div class='dropzone' id='part-thumb'>
<div class='dropzone' id='part-thumb'>
<img class="part-thumb"
{% if part.image %}
src="{{ part.image.url }}"
{% else %}
src="{% static 'img/blank_image.png' %}"
{% endif %}/>
</div>
{% csrf_token %}
</form>
</div>
</div>
<div class="media-body">
<h4>
@@ -102,34 +99,16 @@
{% block js_ready %}
{{ block.super }}
$('#part-thumb').on('drop', function(event) {
var transfer = event.originalEvent.dataTransfer;
var formData = new FormData();
if (isFileTransfer(transfer)) {
formData.append('image_file', transfer.files[0]);
} else if (isOnlineTransfer(transfer)) {
formData.append('image_url', getImageUrlFromTransfer(transfer));
} else {
console.log('Unknown transfer');
return;
}
inventreeFormDataUpload(
"{% url 'part-image-upload' part.id %}",
formData,
{
success: function(data, status, xhr) {
location.reload();
},
error: function(xhr, status, error) {
showAlertDialog('Error uploading image', renderErrorMessage(xhr));
}
enableDragAndDrop(
'#part-thumb',
"{% url 'part-image' part.id %}",
{
label: 'image',
success: function(data, status, xhr) {
location.reload();
}
);
});
}
);
$("#show-qr-code").click(function() {
launchModalForm(