Replace PartImageUpload form

This commit is contained in:
Oliver 2021-06-30 00:18:25 +10:00
parent 293b5d4c07
commit 26eafe242c
4 changed files with 33 additions and 38 deletions

View File

@ -133,6 +133,14 @@
});
});
function reloadImage(data) {
if (data.image) {
$('#company-image').attr('src', data.image);
} else {
location.reload();
}
}
enableDragAndDrop(
"#company-thumb",
"{% url 'api-company-detail' company.id %}",
@ -140,12 +148,7 @@
label: 'image',
method: 'PATCH',
success: function(data, status, xhr) {
if (data.image) {
$('#company-image').attr('src', data.image);
} else {
location.reload();
}
reloadImage(data);
}
}
);
@ -167,11 +170,7 @@
},
title: '{% trans "Upload Image" %}',
onSuccess: function(data) {
if (data.image) {
$('#company-image').attr('src', data.image);
} else {
location.reload();
}
reloadImage(data);
}
}
);

View File

@ -237,6 +237,16 @@
});
{% endif %}
function reloadImage(data) {
// If image / thumbnail data present, live update
if (data.image) {
$('#part-image').attr('src', data.image);
} else {
// Otherwise, reload the page
location.reload();
}
}
enableDragAndDrop(
'#part-thumb',
"{% url 'api-part-detail' part.id %}",
@ -244,14 +254,7 @@
label: 'image',
method: 'PATCH',
success: function(data, status, xhr) {
// If image / thumbnail data present, live update
if (data.image) {
$('#part-image').attr('src', data.image);
} else {
// Otherwise, reload the page
location.reload();
}
reloadImage(data);
}
}
);
@ -293,11 +296,20 @@
});
$("#part-image-upload").click(function() {
launchModalForm("{% url 'part-image-upload' part.id %}",
constructForm(
'{% url "api-part-detail" part.pk %}',
{
reload: true
method: 'PATCH',
fields: {
image: {},
},
title: '{% trans "Upload Image" %}',
onSuccess: function(data) {
reloadImage(data);
}
}
);
)
});

View File

@ -81,7 +81,6 @@ part_detail_urls = [
url(r'^qr_code/?', views.PartQRCode.as_view(), name='part-qr'),
# Normal thumbnail with form
url(r'^thumbnail/?', views.PartImageUpload.as_view(), name='part-image-upload'),
url(r'^thumb-select/?', views.PartImageSelect.as_view(), name='part-image-select'),
url(r'^thumb-download/', views.PartImageDownloadFromURL.as_view(), name='part-image-download'),

View File

@ -1186,21 +1186,6 @@ class PartImageDownloadFromURL(AjaxUpdateView):
)
class PartImageUpload(AjaxUpdateView):
""" View for uploading a new Part image """
model = Part
ajax_template_name = 'modal_form.html'
ajax_form_title = _('Upload Part Image')
form_class = part_forms.PartImageForm
def get_data(self):
return {
'success': _('Updated part image'),
}
class PartImageSelect(AjaxUpdateView):
""" View for selecting Part image from existing images. """