{% load i18n %} {% load static %} {% load inventree_extras %} /* globals attachSelect, closeModal, constructForm, getFormFieldValue, inventreeGet, makeOptionsList, modalEnable, modalSetContent, modalSetTitle, modalShowSubmitButton, modalSubmit, openModal, showAlertDialog, showApiError, showMessage, updateForm, user_settings, */ /* exported printLabels, */ const defaultLabelTemplates = { part: user_settings.DEFAULT_PART_LABEL_TEMPLATE, location: user_settings.DEFAULT_LOCATION_LABEL_TEMPLATE, item: user_settings.DEFAULT_ITEM_LABEL_TEMPLATE, line: user_settings.DEFAULT_LINE_LABEL_TEMPLATE, } /* * Print label(s) for the selected items: * * - Retrieve a list of matching label templates from the server * - Present the available templates to the user (if more than one available) * - Request printed labels * * Required options: * - url: The list URL for the particular template type * - items: The list of items to be printed * - key: The key to use in the query parameters * - plural_name: The plural name of the item type */ function printLabels(options) { if (!options.items || options.items.length == 0) { showAlertDialog( '{% trans "Select Items" %}', '{% trans "No items selected for printing" %}', ); return; } let params = { enabled: true, }; params[options.key] = options.items; // Request a list of available label templates from the server let labelTemplates = []; inventreeGet(options.url, params, { async: false, success: function (response) { if (response.length == 0) { showAlertDialog( '{% trans "No Labels Found" %}', '{% trans "No label templates found which match the selected items" %}', ); return; } labelTemplates = response; } }); // Request a list of available label printing plugins from the server let plugins = []; inventreeGet(`/api/plugins/`, { mixin: 'labels' }, { async: false, success: function (response) { plugins = response; } }); let header_html = ""; // show how much items are selected if there is more than one item selected if (options.items.length > 1) { header_html += `