mirror of
https://github.com/inventree/InvenTree.git
synced 2025-07-01 11:10:54 +00:00
Replace StockItemAttachmentCreate form
- Also replace drag-and-drop - Add 'hidden' option for form fields - Adds renderer for StockItem model
This commit is contained in:
@ -288,6 +288,8 @@ class StockItemAttachmentSerializer(InvenTreeModelSerializer):
|
||||
|
||||
attachment = InvenTreeAttachmentSerializerField(required=True)
|
||||
|
||||
# TODO: Record the uploading user when creating or updating an attachment!
|
||||
|
||||
class Meta:
|
||||
model = StockItemAttachment
|
||||
|
||||
|
@ -21,10 +21,11 @@
|
||||
|
||||
enableDragAndDrop(
|
||||
'#attachment-dropzone',
|
||||
"{% url 'stock-item-attachment-create' %}",
|
||||
"{% url 'api-stock-attachment-list' %}",
|
||||
{
|
||||
data: {
|
||||
stock_item: {{ item.id }},
|
||||
user: {{ user.pk }},
|
||||
},
|
||||
label: 'attachment',
|
||||
success: function(data, status, xhr) {
|
||||
@ -34,10 +35,27 @@ enableDragAndDrop(
|
||||
);
|
||||
|
||||
$("#new-attachment").click(function() {
|
||||
launchModalForm("{% url 'stock-item-attachment-create' %}?item={{ item.id }}",
|
||||
|
||||
constructForm(
|
||||
'{% url "api-stock-attachment-list" %}',
|
||||
{
|
||||
reload: true,
|
||||
});
|
||||
method: 'POST',
|
||||
fields: {
|
||||
attachment: {},
|
||||
comment: {},
|
||||
stock_item: {
|
||||
value: {{ item.pk }},
|
||||
hidden: true,
|
||||
},
|
||||
user: {
|
||||
value: {{ user.pk }},
|
||||
hidden: true,
|
||||
}
|
||||
},
|
||||
reload: true,
|
||||
title: '{% trans "Add Attachment" %}',
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
$("#attachment-table").on('click', '.attachment-edit-button', function() {
|
||||
|
@ -64,7 +64,6 @@ stock_urls = [
|
||||
|
||||
# URLs for StockItem attachments
|
||||
url(r'^item/attachment/', include([
|
||||
url(r'^new/', views.StockItemAttachmentCreate.as_view(), name='stock-item-attachment-create'),
|
||||
url(r'^(?P<pk>\d+)/edit/', views.StockItemAttachmentEdit.as_view(), name='stock-item-attachment-edit'),
|
||||
url(r'^(?P<pk>\d+)/delete/', views.StockItemAttachmentDelete.as_view(), name='stock-item-attachment-delete'),
|
||||
])),
|
||||
|
@ -255,52 +255,6 @@ class StockLocationQRCode(QRCodeView):
|
||||
return None
|
||||
|
||||
|
||||
class StockItemAttachmentCreate(AjaxCreateView):
|
||||
"""
|
||||
View for adding a new attachment for a StockItem
|
||||
"""
|
||||
|
||||
model = StockItemAttachment
|
||||
form_class = StockForms.EditStockItemAttachmentForm
|
||||
ajax_form_title = _("Add Stock Item Attachment")
|
||||
ajax_template_name = "modal_form.html"
|
||||
|
||||
def save(self, form, **kwargs):
|
||||
""" Record the user that uploaded the attachment """
|
||||
|
||||
attachment = form.save(commit=False)
|
||||
attachment.user = self.request.user
|
||||
attachment.save()
|
||||
|
||||
def get_data(self):
|
||||
return {
|
||||
'success': _("Added attachment")
|
||||
}
|
||||
|
||||
def get_initial(self):
|
||||
"""
|
||||
Get initial data for the new StockItem attachment object.
|
||||
|
||||
- Client must provide a valid StockItem ID
|
||||
"""
|
||||
|
||||
initials = super().get_initial()
|
||||
|
||||
try:
|
||||
initials['stock_item'] = StockItem.objects.get(id=self.request.GET.get('item', None))
|
||||
except (ValueError, StockItem.DoesNotExist):
|
||||
pass
|
||||
|
||||
return initials
|
||||
|
||||
def get_form(self):
|
||||
|
||||
form = super().get_form()
|
||||
form.fields['stock_item'].widget = HiddenInput()
|
||||
|
||||
return form
|
||||
|
||||
|
||||
class StockItemAttachmentEdit(AjaxUpdateView):
|
||||
"""
|
||||
View for editing a StockItemAttachment object.
|
||||
|
Reference in New Issue
Block a user