diff --git a/InvenTree/InvenTree/static/css/inventree.css b/InvenTree/InvenTree/static/css/inventree.css index 273f2ec527..a686b5c512 100644 --- a/InvenTree/InvenTree/static/css/inventree.css +++ b/InvenTree/InvenTree/static/css/inventree.css @@ -28,9 +28,8 @@ padding: 20px; padding-bottom: 35px; background-color: rgba(50, 50, 50, 0.75); - width: 100%; - max-width: 330px; + max-width: 550px; margin: auto; } diff --git a/InvenTree/templates/js/dynamic/inventree.js b/InvenTree/InvenTree/static/script/inventree/inventree.js similarity index 74% rename from InvenTree/templates/js/dynamic/inventree.js rename to InvenTree/InvenTree/static/script/inventree/inventree.js index 1774ba6f3d..5d393a085a 100644 --- a/InvenTree/templates/js/dynamic/inventree.js +++ b/InvenTree/InvenTree/static/script/inventree/inventree.js @@ -1,5 +1,3 @@ -{% load inventree_extras %} - /* globals ClipboardJS, inventreeFormDataUpload, @@ -130,66 +128,68 @@ function inventreeDocReady() { attachClipboard('.clip-btn-version', 'modal-about', 'about-copy-text'); // Add autocomplete to the search-bar - $('#search-bar').autocomplete({ - source: function(request, response) { - $.ajax({ - url: '/api/part/', - data: { - search: request.term, - limit: user_settings.SEARCH_PREVIEW_RESULTS, - offset: 0 - }, - success: function(data) { + if ($('#search-bar').exists()) { + $('#search-bar').autocomplete({ + source: function(request, response) { + $.ajax({ + url: '/api/part/', + data: { + search: request.term, + limit: user_settings.SEARCH_PREVIEW_RESULTS, + offset: 0 + }, + success: function(data) { - var transformed = $.map(data.results, function(el) { - return { - label: el.full_name, - id: el.pk, - thumbnail: el.thumbnail, - data: el, - }; - }); - response(transformed); - }, - error: function() { - response([]); - } - }); - }, - create: function() { - $(this).data('ui-autocomplete')._renderItem = function(ul, item) { + var transformed = $.map(data.results, function(el) { + return { + label: el.full_name, + id: el.pk, + thumbnail: el.thumbnail, + data: el, + }; + }); + response(transformed); + }, + error: function() { + response([]); + } + }); + }, + create: function() { + $(this).data('ui-autocomplete')._renderItem = function(ul, item) { - var html = ``; + var html = ``; - html += ` `; - html += item.label; + html += ` `; + html += item.label; - html += ''; - - if (user_settings.SEARCH_SHOW_STOCK_LEVELS) { - html += partStockLabel( - item.data, - { - classes: 'badge-right', - } - ); - } + html += ''; + + if (user_settings.SEARCH_SHOW_STOCK_LEVELS) { + html += partStockLabel( + item.data, + { + classes: 'badge-right', + } + ); + } - html += ''; + html += ''; - return $('
  • ').append(html).appendTo(ul); - }; - }, - select: function( event, ui ) { - window.location = '/part/' + ui.item.id + '/'; - }, - minLength: 2, - classes: { - 'ui-autocomplete': 'dropdown-menu search-menu', - }, - }); + return $('
  • ').append(html).appendTo(ul); + }; + }, + select: function( event, ui ) { + window.location = '/part/' + ui.item.id + '/'; + }, + minLength: 2, + classes: { + 'ui-autocomplete': 'dropdown-menu search-menu', + }, + }); + } // Generate brand-icons $('.brand-icon').each(function(i, obj) { @@ -202,6 +202,9 @@ function inventreeDocReady() { location.href = url; }); + + // Display any cached alert messages + showCachedAlerts(); } function isFileTransfer(transfer) { diff --git a/InvenTree/InvenTree/static/script/inventree/notification.js b/InvenTree/InvenTree/static/script/inventree/notification.js index 4ed1333ac6..399ba1d359 100644 --- a/InvenTree/InvenTree/static/script/inventree/notification.js +++ b/InvenTree/InvenTree/static/script/inventree/notification.js @@ -1,10 +1,43 @@ +/* + * Add a cached alert message to sesion storage + */ +function addCachedAlert(message, style) { -function showAlertOrCache(alertType, message, cache, timeout=5000) { - if (cache) { - sessionStorage.setItem("inventree-" + alertType, message); + var alerts = sessionStorage.getItem('inventree-alerts'); + + if (alerts) { + alerts = JSON.parse(alerts); + } else { + alerts = []; } - else { - showMessage('#' + alertType, message, timeout); + + alerts.push({ + message: message, + style: style + }); + + sessionStorage.setItem('inventree-alerts', JSON.stringify(alerts)); +} + + +/* + * Remove all cached alert messages + */ +function clearCachedAlerts() { + sessionStorage.removeItem('inventree-alerts'); +} + + +/* + * Display an alert, or cache to display on reload + */ +function showAlertOrCache(message, style, cache=false) { + + if (cache) { + addCachedAlert(message, style); + } else { + + showMessage(message, {style: style}); } } @@ -14,25 +47,13 @@ function showAlertOrCache(alertType, message, cache, timeout=5000) { */ function showCachedAlerts() { - var styles = [ - 'primary', - 'secondary', - 'success', - 'info', - 'warning', - 'danger', - ]; + var alerts = JSON.parse(sessionStorage.getItem('inventree-alerts')) || []; - styles.forEach(function(style) { - - var msg = sessionStorage.getItem(`inventree-alert-${style}`); - - if (msg) { - showMessage(msg, { - style: style, - }); - } + alerts.forEach(function(alert) { + showMessage(alert.message, {style: alert.style}); }); + + clearCachedAlerts(); } @@ -54,6 +75,12 @@ function showMessage(message, options={}) { var timeout = options.timeout || 5000; + var details = ''; + + if (options.details) { + details = `

    ${options.details}

    `; + } + // Hacky function to get the next available ID var id = 1; @@ -64,14 +91,15 @@ function showMessage(message, options={}) { var icon = ''; if (options.icon) { - icon = ``; } // Construct the alert var html = ` `; @@ -82,4 +110,4 @@ function showMessage(message, options={}) { $(`#alert-${id}`).delay(timeout).slideUp(200, function() { $(this).alert(close); }); -} \ No newline at end of file +} diff --git a/InvenTree/InvenTree/urls.py b/InvenTree/InvenTree/urls.py index 77a0e06a0c..053ba05264 100644 --- a/InvenTree/InvenTree/urls.py +++ b/InvenTree/InvenTree/urls.py @@ -94,7 +94,6 @@ settings_urls = [ # These javascript files are served "dynamically" - i.e. rendered on demand dynamic_javascript_urls = [ - url(r'^inventree.js', DynamicJsView.as_view(template_name='js/dynamic/inventree.js'), name='inventree.js'), url(r'^calendar.js', DynamicJsView.as_view(template_name='js/dynamic/calendar.js'), name='calendar.js'), url(r'^nav.js', DynamicJsView.as_view(template_name='js/dynamic/nav.js'), name='nav.js'), url(r'^settings.js', DynamicJsView.as_view(template_name='js/dynamic/settings.js'), name='settings.js'), diff --git a/InvenTree/templates/account/base.html b/InvenTree/templates/account/base.html index 048496c4a5..fa2a34f79d 100644 --- a/InvenTree/templates/account/base.html +++ b/InvenTree/templates/account/base.html @@ -10,6 +10,26 @@ + + + + + + + + + + + + + + + + + + + + @@ -33,16 +53,23 @@ +
    +
    + +
    +
    +