diff --git a/InvenTree/InvenTree/static/script/inventree/part.js b/InvenTree/InvenTree/static/script/inventree/part.js deleted file mode 100644 index 64849a30a6..0000000000 --- a/InvenTree/InvenTree/static/script/inventree/part.js +++ /dev/null @@ -1,59 +0,0 @@ -/* Part API functions - * Requires api.js to be loaded first - */ - -function toggleStar(options) { - /* Toggle the 'starred' status of a part. - * Performs AJAX queries and updates the display on the button. - * - * options: - * - button: ID of the button (default = '#part-star-icon') - * - part: pk of the part object - * - user: pk of the user - */ - - var url = '/api/part/star/'; - - inventreeGet( - url, - { - part: options.part, - user: options.user, - }, - { - success: function(response) { - if (response.length == 0) { - // Zero length response = star does not exist - // So let's add one! - inventreePut( - url, - { - part: options.part, - user: options.user, - }, - { - method: 'POST', - success: function(response, status) { - $(options.button).addClass('icon-yellow'); - }, - } - ); - } else { - var pk = response[0].pk; - // There IS a star (delete it!) - inventreePut( - url + pk + "/", - { - }, - { - method: 'DELETE', - success: function(response, status) { - $(options.button).removeClass('icon-yellow'); - }, - } - ); - } - }, - } - ); -} \ No newline at end of file diff --git a/InvenTree/InvenTree/static/script/inventree/stock.js b/InvenTree/InvenTree/static/script/inventree/stock.js deleted file mode 100644 index 950b0260e4..0000000000 --- a/InvenTree/InvenTree/static/script/inventree/stock.js +++ /dev/null @@ -1,140 +0,0 @@ -/* Stock API functions - * Requires api.js to be loaded first - */ - -/* Functions for interacting with stock management forms - */ - -function removeStockRow(e) { - // Remove a selected row from a stock modal form - - e = e || window.event; - var src = e.target || e.srcElement; - - var row = $(src).attr('row'); - - $('#' + row).remove(); -} - -function loadStockTrackingTable(table, options) { - - var cols = [ - { - field: 'pk', - visible: false, - }, - { - field: 'date', - title: 'Date', - sortable: true, - formatter: function(value, row, index, field) { - var m = moment(value); - if (m.isValid()) { - var html = m.format('dddd MMMM Do YYYY'); // + '
' + m.format('h:mm a'); - return html; - } - - return 'N/A'; - } - }, - ]; - - // If enabled, provide a link to the referenced StockItem - if (options.partColumn) { - cols.push({ - field: 'item', - title: 'Stock Item', - sortable: true, - formatter: function(value, row, index, field) { - return renderLink(value.part_name, value.url); - } - }); - } - - // Stock transaction description - cols.push({ - field: 'title', - title: 'Description', - sortable: true, - formatter: function(value, row, index, field) { - var html = "" + value + ""; - - if (row.notes) { - html += "
" + row.notes + ""; - } - - if (row.link) { - html += "
" + row.link + ""; - } - - return html; - } - }); - - cols.push({ - field: 'quantity', - title: 'Quantity', - formatter: function(value, row, index, field) { - return parseFloat(value); - }, - }); - - cols.push({ - sortable: true, - field: 'user', - title: 'User', - formatter: function(value, row, index, field) { - if (value) - { - // TODO - Format the user's first and last names - return value.username; - } - else - { - return "No user information"; - } - } - }); - - cols.push({ - sortable: false, - formatter: function(value, row, index, field) { - // Manually created entries can be edited or deleted - if (!row.system) { - var bEdit = ""; - var bDel = ""; - - return "
" + bEdit + bDel + "
"; - } else { - return ""; - } - } - }); - - table.inventreeTable({ - method: 'get', - queryParams: options.params, - columns: cols, - url: options.url, - }); - - if (options.buttons) { - linkButtonsToSelection(table, options.buttons); - } - - table.on('click', '.btn-entry-edit', function() { - var button = $(this); - - launchModalForm(button.attr('url'), { - reload: true, - }); - }); - - table.on('click', '.btn-entry-delete', function() { - var button = $(this); - - launchModalForm(button.attr('url'), { - reload: true, - }); - }); -} \ No newline at end of file diff --git a/InvenTree/templates/base.html b/InvenTree/templates/base.html index f734d47eba..f812376e67 100644 --- a/InvenTree/templates/base.html +++ b/InvenTree/templates/base.html @@ -102,12 +102,10 @@ InvenTree - - diff --git a/InvenTree/templates/js/part.js b/InvenTree/templates/js/part.js index c4d5960a7a..57e7fa5798 100644 --- a/InvenTree/templates/js/part.js +++ b/InvenTree/templates/js/part.js @@ -1,5 +1,65 @@ {% load i18n %} +/* Part API functions + * Requires api.js to be loaded first + */ + +function toggleStar(options) { + /* Toggle the 'starred' status of a part. + * Performs AJAX queries and updates the display on the button. + * + * options: + * - button: ID of the button (default = '#part-star-icon') + * - part: pk of the part object + * - user: pk of the user + */ + + var url = '/api/part/star/'; + + inventreeGet( + url, + { + part: options.part, + user: options.user, + }, + { + success: function(response) { + if (response.length == 0) { + // Zero length response = star does not exist + // So let's add one! + inventreePut( + url, + { + part: options.part, + user: options.user, + }, + { + method: 'POST', + success: function(response, status) { + $(options.button).addClass('icon-yellow'); + }, + } + ); + } else { + var pk = response[0].pk; + // There IS a star (delete it!) + inventreePut( + url + pk + "/", + { + }, + { + method: 'DELETE', + success: function(response, status) { + $(options.button).removeClass('icon-yellow'); + }, + } + ); + } + }, + } + ); +} + function loadPartTable(table, url, options={}) { /* Load part listing data into specified table. * diff --git a/InvenTree/templates/js/stock.js b/InvenTree/templates/js/stock.js index d986a19246..5645f9aa9c 100644 --- a/InvenTree/templates/js/stock.js +++ b/InvenTree/templates/js/stock.js @@ -1,5 +1,23 @@ {% load i18n %} +/* Stock API functions + * Requires api.js to be loaded first + */ + +/* Functions for interacting with stock management forms + */ + +function removeStockRow(e) { + // Remove a selected row from a stock modal form + + e = e || window.event; + var src = e.target || e.srcElement; + + var row = $(src).attr('row'); + + $('#' + row).remove(); +} + function loadStockTable(table, options) { /* Load data into a stock table with adjustable options. * Fetches data (via AJAX) and loads into a bootstrap table. @@ -358,3 +376,126 @@ function loadStockTable(table, options) { stockAdjustment('delete'); }); } + +function loadStockTrackingTable(table, options) { + + var cols = [ + { + field: 'pk', + visible: false, + }, + { + field: 'date', + title: '{% trans "Date" %}', + sortable: true, + formatter: function(value, row, index, field) { + var m = moment(value); + if (m.isValid()) { + var html = m.format('dddd MMMM Do YYYY'); // + '
' + m.format('h:mm a'); + return html; + } + + return 'N/A'; + } + }, + ]; + + // If enabled, provide a link to the referenced StockItem + if (options.partColumn) { + cols.push({ + field: 'item', + title: '{% trans "Stock Item" %}', + sortable: true, + formatter: function(value, row, index, field) { + return renderLink(value.part_name, value.url); + } + }); + } + + // Stock transaction description + cols.push({ + field: 'title', + title: '{% trans "Description" %}', + sortable: true, + formatter: function(value, row, index, field) { + var html = "" + value + ""; + + if (row.notes) { + html += "
" + row.notes + ""; + } + + if (row.link) { + html += "
" + row.link + ""; + } + + return html; + } + }); + + cols.push({ + field: 'quantity', + title: '{% trans "Quantity" %}', + formatter: function(value, row, index, field) { + return parseFloat(value); + }, + }); + + cols.push({ + sortable: true, + field: 'user', + title: '{% trans "User" %}', + formatter: function(value, row, index, field) { + if (value) + { + // TODO - Format the user's first and last names + return value.username; + } + else + { + return "{% trans "No user information" %}"; + } + } + }); + + cols.push({ + sortable: false, + formatter: function(value, row, index, field) { + // Manually created entries can be edited or deleted + if (!row.system) { + var bEdit = ""; + var bDel = ""; + + return "
" + bEdit + bDel + "
"; + } else { + return ""; + } + } + }); + + table.inventreeTable({ + method: 'get', + queryParams: options.params, + columns: cols, + url: options.url, + }); + + if (options.buttons) { + linkButtonsToSelection(table, options.buttons); + } + + table.on('click', '.btn-entry-edit', function() { + var button = $(this); + + launchModalForm(button.attr('url'), { + reload: true, + }); + }); + + table.on('click', '.btn-entry-delete', function() { + var button = $(this); + + launchModalForm(button.attr('url'), { + reload: true, + }); + }); +} \ No newline at end of file