From ec98f7829eca604560cf25ec2d1846ab83429c0a Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 15 Apr 2019 18:32:15 +1000 Subject: [PATCH] Add context flag to enable editing mode - pass ?edit=1 to the BOM - Display page differently if in editing mode - --- InvenTree/part/models.py | 2 + InvenTree/part/templates/part/bom.html | 188 +++++++++++++++++-------- InvenTree/part/views.py | 11 ++ 3 files changed, 146 insertions(+), 55 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index afafaac240..2f65744139 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -288,6 +288,7 @@ class Part(models.Model): header.append('Part') header.append('Description') header.append('Quantity') + header.append('Note') lines.append(header) @@ -297,6 +298,7 @@ class Part(models.Model): line.append(it.sub_part.name) line.append(it.sub_part.description) line.append(it.quantity) + line.append(it.note) lines.append([str(x) for x in line]) diff --git a/InvenTree/part/templates/part/bom.html b/InvenTree/part/templates/part/bom.html index 3debd65076..90d7dd4b61 100644 --- a/InvenTree/part/templates/part/bom.html +++ b/InvenTree/part/templates/part/bom.html @@ -9,69 +9,47 @@ {% include 'part/tabs.html' with tab='bom' %} -

Bill of Materials

+

Bill of Materials{% if editing_enabled %} (Edit Mode){% endif %}

-
- -
+

-
- +{% if editing_enabled %} +
+ +
+{% else %} + +{% endif %} {% endblock %} + +{% block js_load %} +{{ block.super }} + + + +{% endblock %} + {% block js_ready %} {{ block.super }} function reloadBom() { $("#bom-table").bootstrapTable('refresh'); } - $('#bom-table').on('click', '.delete-button', function () { - var button = $(this); - - launchDeleteForm( - button.attr('url'), - { - success: reloadBom - }); - }); - - $("#bom-table").on('click', '.edit-button', function () { - var button = $(this); - - launchModalForm( - button.attr('url'), - { - success: reloadBom - }); - - }); - - $("#new-bom-item").click(function () { - launchModalForm( - "{% url 'bom-item-create' %}", - { - reload: true, - data: { - parent: {{ part.id }} - } - }); - }); - - $("#export-bom").click(function () { - /* - launchModalForm( - "{% url 'bom-export' part.id %}", - { - }); - */ - //TODO - Select format of the data - location.href = "{% url 'bom-export' part.id %}"; - }); - + // Load the BOM data $("#bom-table").bootstrapTable({ sortable: true, search: true, @@ -102,7 +80,29 @@ field: 'quantity', title: 'Required', searchable: false, - sortable: true + sortable: true, + formatter: function(value, row, index, field) { + return renderEditable(value, + { + _pk: row.pk, + _title: 'Quantity', + } + ); + } + }, + { + field: 'note', + title: 'Note', + searchable: true, + sortable: false, + formatter: function(value, row, index, field) { + return renderEditable(value, + { + _pk: row.pk, + _title: 'Note', + _empty: 'Enter note', + }); + } }, { field: 'sub_part.available_stock', @@ -123,12 +123,90 @@ return renderLink(text, row.sub_part.url + "stock/"); } }, - { - formatter: function(value, row, index, field) { - return editButton(row.url + 'edit') + ' ' + deleteButton(row.url + 'delete'); - } - } ], url: "{% url 'api-bom-list' %}" }); + + /* + $('#bom-table').on('click', '.delete-button', function () { + var button = $(this); + + launchDeleteForm( + button.attr('url'), + { + success: reloadBom + }); + }); + + $("#bom-table").on('click', '.edit-button', function () { + var button = $(this); + + launchModalForm( + button.attr('url'), + { + success: reloadBom + }); + + }); + */ + + {% if editing_enabled %} + $("#editing-finish").click(function() { + alert("Finished!"); + location.href = "{% url 'part-bom' part.id %}"; + }); + + $("#editing-cancel").click(function() { + alert("Cancelled!"); + location.href = "{% url 'part-bom' part.id %}"; + }); + + // Inline mode + //$.fn.editable.defaults.mode = 'inline'; + + $("#bom-table").on('load-success.bs.table', function() { + // Make the table elements editable + $("#bom-table").find('.editable-item').editable(); + }); + + {% else %} + + $("#edit-bom").click(function () { + + location.href = "{% url 'part-bom' part.id %}?edit=1"; + + /* + editBOM( + { + url: "{% url 'api-bom-list' %}", + part_name: "{{ part.name }}", + part_id: "{{ part.id }}", + } + ); + */ + /* + launchModalForm( + "{% url 'bom-item-create' %}", + { + reload: true, + data: { + parent: {{ part.id }} + } + }); + */ + }); + + $("#export-bom").click(function () { + /* + launchModalForm( + "{% url 'bom-export' part.id %}", + { + }); + */ + //TODO - Select format of the data + location.href = "{% url 'bom-export' part.id %}"; + }); + + {% endif %} + {% endblock %} \ No newline at end of file diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index d9897f82d4..f956c28ddc 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -90,6 +90,17 @@ class PartDetail(DetailView): queryset = Part.objects.all() template_name = 'part/detail.html' + # Add in some extra context information based on query params + def get_context_data(self, **kwargs): + context = super(PartDetail, self).get_context_data(**kwargs) + + if str(self.request.GET.get('edit', None)) == '1': + context['editing_enabled'] = True + else: + context['editing_enabled'] = False + + return context + class PartImage(AjaxUpdateView):