mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #803 from SchrodingersGat/attachment-drag-and-drop
Attachment drag and drop
This commit is contained in:
commit
65f081d252
@ -56,7 +56,7 @@ class InvenTreeAttachment(models.Model):
|
||||
attachment = models.FileField(upload_to=rename_attachment,
|
||||
help_text=_('Select file to attach'))
|
||||
|
||||
comment = models.CharField(max_length=100, help_text=_('File comment'))
|
||||
comment = models.CharField(blank=True, max_length=100, help_text=_('File comment'))
|
||||
|
||||
user = models.ForeignKey(
|
||||
User,
|
||||
|
@ -346,9 +346,11 @@
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
/*
|
||||
.dropzone * {
|
||||
pointer-events: none;
|
||||
}
|
||||
*/
|
||||
|
||||
.dragover {
|
||||
background-color: #55A;
|
||||
|
@ -140,10 +140,13 @@ function enableDragAndDrop(element, url, options) {
|
||||
url - URL to POST the file to
|
||||
options - object with following possible values:
|
||||
label - Label of the file to upload (default='file')
|
||||
data - Other form data to upload
|
||||
success - Callback function in case of success
|
||||
error - Callback function in case of error
|
||||
*/
|
||||
|
||||
data = options.data || {};
|
||||
|
||||
$(element).on('drop', function(event) {
|
||||
|
||||
var transfer = event.originalEvent.dataTransfer;
|
||||
@ -152,6 +155,11 @@ function enableDragAndDrop(element, url, options) {
|
||||
|
||||
var formData = new FormData();
|
||||
|
||||
// Add the extra data
|
||||
for (var key in data) {
|
||||
formData.append(key, data[key]);
|
||||
}
|
||||
|
||||
if (isFileTransfer(transfer)) {
|
||||
formData.append(label, transfer.files[0]);
|
||||
|
||||
|
23
InvenTree/order/migrations/0035_auto_20200513_0016.py
Normal file
23
InvenTree/order/migrations/0035_auto_20200513_0016.py
Normal file
@ -0,0 +1,23 @@
|
||||
# Generated by Django 3.0.5 on 2020-05-13 00:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('order', '0034_auto_20200512_1054'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='purchaseorderattachment',
|
||||
name='comment',
|
||||
field=models.CharField(blank=True, help_text='File comment', max_length=100),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='salesorderattachment',
|
||||
name='comment',
|
||||
field=models.CharField(blank=True, help_text='File comment', max_length=100),
|
||||
),
|
||||
]
|
@ -20,6 +20,20 @@
|
||||
{% block js_ready %}
|
||||
{{ block.super }}
|
||||
|
||||
enableDragAndDrop(
|
||||
'#attachment-dropzone',
|
||||
"{% url 'po-attachment-create' %}",
|
||||
{
|
||||
data: {
|
||||
order: {{ order.id }},
|
||||
},
|
||||
label: 'attachment',
|
||||
success: function(data, status, xhr) {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$("#new-attachment").click(function() {
|
||||
launchModalForm("{% url 'po-attachment-create' %}?order={{ order.id }}",
|
||||
{
|
||||
|
@ -19,6 +19,20 @@
|
||||
{% block js_ready %}
|
||||
{{ block.super }}
|
||||
|
||||
enableDragAndDrop(
|
||||
'#attachment-dropzone',
|
||||
"{% url 'so-attachment-create' %}",
|
||||
{
|
||||
data: {
|
||||
order: {{ order.id }},
|
||||
},
|
||||
label: 'attachment',
|
||||
success: function(data, status, xhr) {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$("#new-attachment").click(function() {
|
||||
launchModalForm("{% url 'so-attachment-create' %}?order={{ order.id }}",
|
||||
{
|
||||
|
@ -112,7 +112,10 @@ class PurchaseOrderAttachmentCreate(AjaxCreateView):
|
||||
|
||||
initials = super(AjaxCreateView, self).get_initial()
|
||||
|
||||
try:
|
||||
initials["order"] = PurchaseOrder.objects.get(id=self.request.GET.get('order', -1))
|
||||
except (ValueError, PurchaseOrder.DoesNotExist):
|
||||
pass
|
||||
|
||||
return initials
|
||||
|
||||
@ -149,7 +152,10 @@ class SalesOrderAttachmentCreate(AjaxCreateView):
|
||||
def get_initial(self):
|
||||
initials = super().get_initial().copy()
|
||||
|
||||
try:
|
||||
initials['order'] = SalesOrder.objects.get(id=self.request.GET.get('order', None))
|
||||
except (ValueError, SalesOrder.DoesNotExist):
|
||||
pass
|
||||
|
||||
return initials
|
||||
|
||||
|
18
InvenTree/part/migrations/0038_auto_20200513_0016.py
Normal file
18
InvenTree/part/migrations/0038_auto_20200513_0016.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.5 on 2020-05-13 00:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('part', '0037_partattachment_upload_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='partattachment',
|
||||
name='comment',
|
||||
field=models.CharField(blank=True, help_text='File comment', max_length=100),
|
||||
),
|
||||
]
|
@ -16,6 +16,20 @@
|
||||
{% block js_ready %}
|
||||
{{ block.super }}
|
||||
|
||||
enableDragAndDrop(
|
||||
'#attachment-dropzone',
|
||||
"{% url 'part-attachment-create' %}",
|
||||
{
|
||||
data: {
|
||||
part: {{ part.id }},
|
||||
},
|
||||
label: 'attachment',
|
||||
success: function(data, status, xhr) {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$("#new-attachment").click(function() {
|
||||
launchModalForm("{% url 'part-attachment-create' %}?part={{ part.id }}",
|
||||
{
|
||||
|
18
InvenTree/stock/migrations/0039_auto_20200513_0016.py
Normal file
18
InvenTree/stock/migrations/0039_auto_20200513_0016.py
Normal file
@ -0,0 +1,18 @@
|
||||
# Generated by Django 3.0.5 on 2020-05-13 00:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('stock', '0038_stockitemattachment_upload_date'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='stockitemattachment',
|
||||
name='comment',
|
||||
field=models.CharField(blank=True, help_text='File comment', max_length=100),
|
||||
),
|
||||
]
|
@ -17,6 +17,20 @@
|
||||
{% block js_ready %}
|
||||
{{ block.super }}
|
||||
|
||||
enableDragAndDrop(
|
||||
'#attachment-dropzone',
|
||||
"{% url 'stock-item-attachment-create' %}",
|
||||
{
|
||||
data: {
|
||||
stock_item: {{ item.id }},
|
||||
},
|
||||
label: 'attachment',
|
||||
success: function(data, status, xhr) {
|
||||
location.reload();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
$("#new-attachment").click(function() {
|
||||
launchModalForm("{% url 'stock-item-attachment-create' %}?item={{ item.id }}",
|
||||
{
|
||||
|
@ -6,6 +6,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='dropzone' id='attachment-dropzone'>
|
||||
<table class='table table-striped table-condensed' data-toolbar='#attachment-buttons' id='attachment-table'>
|
||||
<thead>
|
||||
<tr>
|
||||
@ -38,3 +39,4 @@
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user