From 676cca89a1745058986dcc6f3dc3868e95a230b8 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 15 Jul 2021 21:32:46 +1000 Subject: [PATCH] Refactor ManufacturerPart pages --- .../templates/company/manufacturer_part.html | 330 ++++++++++++++++++ .../company/manufacturer_part_base.html | 143 -------- .../company/manufacturer_part_detail.html | 38 -- .../company/manufacturer_part_navbar.html | 13 +- .../company/manufacturer_part_suppliers.html | 187 ---------- InvenTree/company/urls.py | 3 +- 6 files changed, 341 insertions(+), 373 deletions(-) create mode 100644 InvenTree/company/templates/company/manufacturer_part.html delete mode 100644 InvenTree/company/templates/company/manufacturer_part_base.html delete mode 100644 InvenTree/company/templates/company/manufacturer_part_detail.html delete mode 100644 InvenTree/company/templates/company/manufacturer_part_suppliers.html diff --git a/InvenTree/company/templates/company/manufacturer_part.html b/InvenTree/company/templates/company/manufacturer_part.html new file mode 100644 index 0000000000..da5ea36173 --- /dev/null +++ b/InvenTree/company/templates/company/manufacturer_part.html @@ -0,0 +1,330 @@ +{% extends "two_column.html" %} +{% load static %} +{% load i18n %} + +{% block page_title %} +InvenTree | {% trans "Manufacturer Part" %} +{% endblock %} + +{% block menubar %} +{% include "company/manufacturer_part_navbar.html" %} +{% endblock %} + +{% block thumbnail %} + +{% endblock %} + +{% block page_data %} +

{% trans "Manufacturer Part" %}

+
+

+ {{ part.part.full_name }} + {% if user.is_staff and perms.company.change_company %} + + + + {% endif %} +

+

{{ part.manufacturer.name }} - {{ part.MPN }}

+ +{% if roles.purchase_order.change %} +
+
+ {% comment "for later" %} + {% if roles.purchase_order.add %} + + {% endif %} + {% endcomment %} + + {% if roles.purchase_order.delete %} + + {% endif %} +
+
+{% endif %} + +{% endblock %} + +{% block page_details %} + +

{% trans "Manufacturer Part Details" %}

+ + + + + + + + {% if part.description %} + + + + + + {% endif %} + {% if part.link %} + + + + + + {% endif %} + + + + + + + + + +
{% trans "Internal Part" %} + {% if part.part %} + {{ part.part.full_name }}{% include "clip.html"%} + {% endif %} +
{% trans "Description" %}{{ part.description }}{% include "clip.html"%}
{% trans "External Link" %}{{ part.link }}{% include "clip.html"%}
{% trans "Manufacturer" %}{{ part.manufacturer.name }}{% include "clip.html"%}
{% trans "MPN" %}{{ part.MPN }}{% include "clip.html"%}
+{% endblock %} + +{% block page_content %} + +
+
+

{% trans "Suppliers" %}

+
+
+
+
+ +
+ + +
+
+
+ + +
+
+
+ +
+
+

{% trans "Parameters" %}

+
+
+
+
+ +
+ + +
+
+
+ +
+
+
+ +{% endblock %} + + +{% block js_ready %} +{{ block.super }} + +enableNavbar({ + label: 'manufacturer-part', + toggleId: '#manufacturer-part-menu-toggle' +}); + +function reloadParameters() { + $("#parameter-table").bootstrapTable("refresh"); +} + +$('#parameter-create').click(function() { + + constructForm('{% url "api-manufacturer-part-parameter-list" %}', { + method: 'POST', + fields: { + name: {}, + value: {}, + units: {}, + manufacturer_part: { + value: {{ part.pk }}, + hidden: true, + } + }, + title: '{% trans "Add Parameter" %}', + onSuccess: reloadParameters + }); +}); + +$('#supplier-create').click(function () { + launchModalForm( + "{% url 'supplier-part-create' %}", + { + reload: true, + data: { + manufacturer_part: {{ part.id }} + }, + secondary: [ + { + field: 'supplier', + label: '{% trans "New Supplier" %}', + title: '{% trans "Create new supplier" %}', + }, + ] + }); +}); + +$("#supplier-part-delete").click(function() { + + var selections = $("#supplier-table").bootstrapTable("getSelections"); + + var parts = []; + + selections.forEach(function(item) { + parts.push(item.pk); + }); + + launchModalForm("{% url 'supplier-part-delete' %}", { + data: { + parts: parts, + }, + reload: true, + }); +}); + +$("#multi-parameter-delete").click(function() { + + var selections = $("#parameter-table").bootstrapTable("getSelections"); + + var text = ` +
+

{% trans "Selected parameters will be deleted" %}:

+ +
`; + + showQuestionDialog( + '{% trans "Delete Parameters" %}', + text, + { + accept_text: '{% trans "Delete" %}', + accept: function() { + // Delete each parameter via the API + var requests = []; + + selections.forEach(function(item) { + var url = `/api/company/part/manufacturer/parameter/${item.pk}/`; + + requests.push(inventreeDelete(url)); + }); + + $.when.apply($, requests).then(function() { + $('#parameter-table').bootstrapTable('refresh'); + }); + } + } + ); +}); + +loadSupplierPartTable( + "#supplier-table", + "{% url 'api-supplier-part-list' %}", + { + params: { + part: {{ part.part.id }}, + manufacturer_part: {{ part.id }}, + part_detail: false, + supplier_detail: true, + manufacturer_detail: false, + }, + } +); + +loadManufacturerPartParameterTable( + "#parameter-table", + "{% url 'api-manufacturer-part-parameter-list' %}", + { + params: { + manufacturer_part: {{ part.id }}, + } + } +); + +linkButtonsToSelection($("#supplier-table"), ['#supplier-part-options']); + +linkButtonsToSelection($("#parameter-table"), ['#parameter-options']); + +$('#order-part, #order-part2').click(function() { + launchModalForm( + "{% url 'order-parts' %}", + { + data: { + part: {{ part.part.id }}, + }, + reload: true, + }, + ); +}); + +$('#edit-part').click(function () { + + constructForm('{% url "api-manufacturer-part-detail" part.pk %}', { + fields: { + part: {}, + manufacturer: {}, + MPN: { + icon: 'fa-hashtag', + }, + description: {}, + link: { + icon: 'fa-link', + }, + }, + title: '{% trans "Edit Manufacturer Part" %}', + reload: true, + }); +}); + +$('#delete-part').click(function() { + + constructForm('{% url "api-manufacturer-part-detail" part.pk %}', { + method: 'DELETE', + title: '{% trans "Delete Manufacturer Part" %}', + redirect: "{% url 'company-detail' part.manufacturer.id %}", + }); +}); + +attachNavCallbacks({ + name: 'manufacturerpart', + default: 'parameters' +}); + +{% endblock %} \ No newline at end of file diff --git a/InvenTree/company/templates/company/manufacturer_part_base.html b/InvenTree/company/templates/company/manufacturer_part_base.html deleted file mode 100644 index c54401b172..0000000000 --- a/InvenTree/company/templates/company/manufacturer_part_base.html +++ /dev/null @@ -1,143 +0,0 @@ -{% extends "two_column.html" %} -{% load static %} -{% load i18n %} - -{% block page_title %} -InvenTree | {% trans "Manufacturer Part" %} -{% endblock %} - -{% block thumbnail %} - -{% endblock %} - -{% block page_data %} -

{% trans "Manufacturer Part" %}

-
-

- {{ part.part.full_name }} - {% if user.is_staff and perms.company.change_company %} - - - - {% endif %} -

-

{{ part.manufacturer.name }} - {{ part.MPN }}

- -{% if roles.purchase_order.change %} -
-
- {% comment "for later" %} - {% if roles.purchase_order.add %} - - {% endif %} - {% endcomment %} - - {% if roles.purchase_order.delete %} - - {% endif %} -
-
-{% endif %} - -{% endblock %} - -{% block page_details %} - -

{% trans "Manufacturer Part Details" %}

- - - - - - - - {% if part.description %} - - - - - - {% endif %} - {% if part.link %} - - - - - - {% endif %} - - - - - - - - - -
{% trans "Internal Part" %} - {% if part.part %} - {{ part.part.full_name }}{% include "clip.html"%} - {% endif %} -
{% trans "Description" %}{{ part.description }}{% include "clip.html"%}
{% trans "External Link" %}{{ part.link }}{% include "clip.html"%}
{% trans "Manufacturer" %}{{ part.manufacturer.name }}{% include "clip.html"%}
{% trans "MPN" %}{{ part.MPN }}{% include "clip.html"%}
-{% endblock %} - -{% block js_ready %} -{{ block.super }} - -enableNavbar({ - label: 'manufacturer-part', - toggleId: '#manufacturer-part-menu-toggle' -}) - -$('#order-part, #order-part2').click(function() { - launchModalForm( - "{% url 'order-parts' %}", - { - data: { - part: {{ part.part.id }}, - }, - reload: true, - }, - ); -}); - -$('#edit-part').click(function () { - - constructForm('{% url "api-manufacturer-part-detail" part.pk %}', { - fields: { - part: {}, - manufacturer: {}, - MPN: { - icon: 'fa-hashtag', - }, - description: {}, - link: { - icon: 'fa-link', - }, - }, - title: '{% trans "Edit Manufacturer Part" %}', - reload: true, - }); -}); - -$('#delete-part').click(function() { - - constructForm('{% url "api-manufacturer-part-detail" part.pk %}', { - method: 'DELETE', - title: '{% trans "Delete Manufacturer Part" %}', - redirect: "{% url 'company-detail' part.manufacturer.id %}", - }); -}); - -{% endblock %} \ No newline at end of file diff --git a/InvenTree/company/templates/company/manufacturer_part_detail.html b/InvenTree/company/templates/company/manufacturer_part_detail.html deleted file mode 100644 index e25fb9dca3..0000000000 --- a/InvenTree/company/templates/company/manufacturer_part_detail.html +++ /dev/null @@ -1,38 +0,0 @@ -{% extends "company/manufacturer_part_base.html" %} -{% load static %} -{% load i18n %} - -{% block menubar %} -{% include "company/manufacturer_part_navbar.html" with tab='details' %} -{% endblock %} - -{% block heading %} -{% trans "Manufacturer Part Details" %} -{% endblock %} - - -{% block details %} - - - - - - - - -{% if part.link %} - -{% endif %} -
{% trans "Internal Part" %} - {% if part.part %} - {{ part.part.full_name }} - {% endif %} -
{% trans "Manufacturer" %}{{ part.manufacturer.name }}
{% trans "MPN" %}{{ part.MPN }}
{% trans "External Link" %}{{ part.link }}
- -{% endblock %} - -{% block js_ready %} -{{ block.super }} - - -{% endblock %} \ No newline at end of file diff --git a/InvenTree/company/templates/company/manufacturer_part_navbar.html b/InvenTree/company/templates/company/manufacturer_part_navbar.html index 3eae30afaf..893374858f 100644 --- a/InvenTree/company/templates/company/manufacturer_part_navbar.html +++ b/InvenTree/company/templates/company/manufacturer_part_navbar.html @@ -8,8 +8,15 @@ -
  • - +
  • + + + {% trans "Parameters" %} + +
  • + +
  • + {% trans "Suppliers" %} @@ -22,7 +29,7 @@ {% trans "Stock" %}
  • - +
  • diff --git a/InvenTree/company/templates/company/manufacturer_part_suppliers.html b/InvenTree/company/templates/company/manufacturer_part_suppliers.html deleted file mode 100644 index f706ca90ba..0000000000 --- a/InvenTree/company/templates/company/manufacturer_part_suppliers.html +++ /dev/null @@ -1,187 +0,0 @@ -{% extends "company/manufacturer_part_base.html" %} -{% load static %} -{% load i18n %} - -{% block menubar %} -{% include "company/manufacturer_part_navbar.html" with tab='suppliers' %} -{% endblock %} - -{% block heading %} -{% trans "Suppliers" %} -{% endblock %} - -{% block details %} - - - -
    - -{% endblock %} - -{% block post_content_panels %} - -
    -
    -

    {% trans "Parameters" %}

    -
    -
    -
    -
    - -
    - - -
    -
    -
    - -
    -
    -
    - -{% endblock %} - -{% block js_ready %} -{{ block.super }} - -function reloadParameters() { - $("#parameter-table").bootstrapTable("refresh"); -} - -$('#parameter-create').click(function() { - - constructForm('{% url "api-manufacturer-part-parameter-list" %}', { - method: 'POST', - fields: { - name: {}, - value: {}, - units: {}, - manufacturer_part: { - value: {{ part.pk }}, - hidden: true, - } - }, - title: '{% trans "Add Parameter" %}', - onSuccess: reloadParameters - }); -}); - -$('#supplier-create').click(function () { - launchModalForm( - "{% url 'supplier-part-create' %}", - { - reload: true, - data: { - manufacturer_part: {{ part.id }} - }, - secondary: [ - { - field: 'supplier', - label: '{% trans "New Supplier" %}', - title: '{% trans "Create new supplier" %}', - }, - ] - }); -}); - -$("#supplier-part-delete").click(function() { - - var selections = $("#supplier-table").bootstrapTable("getSelections"); - - var parts = []; - - selections.forEach(function(item) { - parts.push(item.pk); - }); - - launchModalForm("{% url 'supplier-part-delete' %}", { - data: { - parts: parts, - }, - reload: true, - }); -}); - -$("#multi-parameter-delete").click(function() { - - var selections = $("#parameter-table").bootstrapTable("getSelections"); - - var text = ` -
    -

    {% trans "Selected parameters will be deleted" %}:

    -
      `; - - selections.forEach(function(item) { - text += `
    • ${item.name} - ${item.value}
    • `; - }); - - text += ` -
    -
    `; - - showQuestionDialog( - '{% trans "Delete Parameters" %}', - text, - { - accept_text: '{% trans "Delete" %}', - accept: function() { - // Delete each parameter via the API - var requests = []; - - selections.forEach(function(item) { - var url = `/api/company/part/manufacturer/parameter/${item.pk}/`; - - requests.push(inventreeDelete(url)); - }); - - $.when.apply($, requests).then(function() { - $('#parameter-table').bootstrapTable('refresh'); - }); - } - } - ); -}); - -loadSupplierPartTable( - "#supplier-table", - "{% url 'api-supplier-part-list' %}", - { - params: { - part: {{ part.part.id }}, - manufacturer_part: {{ part.id }}, - part_detail: false, - supplier_detail: true, - manufacturer_detail: false, - }, - } -); - -loadManufacturerPartParameterTable( - "#parameter-table", - "{% url 'api-manufacturer-part-parameter-list' %}", - { - params: { - manufacturer_part: {{ part.id }}, - } - } -); - -linkButtonsToSelection($("#supplier-table"), ['#supplier-part-options']) -linkButtonsToSelection($("#parameter-table"), ['#parameter-options']) -{% endblock %} \ No newline at end of file diff --git a/InvenTree/company/urls.py b/InvenTree/company/urls.py index 817ee27988..7d2b6fb609 100644 --- a/InvenTree/company/urls.py +++ b/InvenTree/company/urls.py @@ -31,8 +31,7 @@ company_urls = [ manufacturer_part_urls = [ url(r'^(?P\d+)/', include([ - url(r'^suppliers/', views.ManufacturerPartDetail.as_view(template_name='company/manufacturer_part_suppliers.html'), name='manufacturer-part-suppliers'), - url('^.*$', views.ManufacturerPartDetail.as_view(template_name='company/manufacturer_part_suppliers.html'), name='manufacturer-part-detail'), + url('^.*$', views.ManufacturerPartDetail.as_view(template_name='company/manufacturer_part.html'), name='manufacturer-part-detail'), ])), ]