mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +00:00 
			
		
		
		
	Improvements for alert notifications
- Dismissable - Delete after a certain amount of time
This commit is contained in:
		@@ -745,13 +745,7 @@ input[type="submit"] {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.notification-area {
 | 
					.notification-area {
 | 
				
			||||||
    position: fixed;
 | 
					    opacity: 0.8;
 | 
				
			||||||
    top: 0px;
 | 
					 | 
				
			||||||
    margin-top: 20px;
 | 
					 | 
				
			||||||
    width: 100%;
 | 
					 | 
				
			||||||
    padding: 20px;
 | 
					 | 
				
			||||||
    z-index: 5000;
 | 
					 | 
				
			||||||
    pointer-events: none; /* Prevent this div from blocking links underneath */
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.notes {
 | 
					.notes {
 | 
				
			||||||
@@ -761,7 +755,6 @@ input[type="submit"] {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.alert {
 | 
					.alert {
 | 
				
			||||||
    display: none;
 | 
					 | 
				
			||||||
    border-radius: 5px;
 | 
					    border-radius: 5px;
 | 
				
			||||||
    opacity: 0.9;
 | 
					    opacity: 0.9;
 | 
				
			||||||
    pointer-events: all;
 | 
					    pointer-events: all;
 | 
				
			||||||
@@ -771,9 +764,8 @@ input[type="submit"] {
 | 
				
			|||||||
    display: block;
 | 
					    display: block;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.btn {
 | 
					.navbar .btn {
 | 
				
			||||||
    margin-left: 2px;
 | 
					    margin-left: 5px;
 | 
				
			||||||
    margin-right: 2px;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.btn-secondary {
 | 
					.btn-secondary {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -16,29 +16,83 @@ function showAlertOrCache(alertType, message, cache, timeout=5000) {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*
 | 
				
			||||||
 | 
					 * Display cached alert messages when loading a page
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
function showCachedAlerts() {
 | 
					function showCachedAlerts() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Success Message
 | 
					    var styles = [
 | 
				
			||||||
    if (sessionStorage.getItem("inventree-alert-success")) {
 | 
					        'primary',
 | 
				
			||||||
        showAlert("#alert-success", sessionStorage.getItem("inventree-alert-success"));
 | 
					        'secondary',
 | 
				
			||||||
        sessionStorage.removeItem("inventree-alert-success");
 | 
					        'success',
 | 
				
			||||||
 | 
					        'info',
 | 
				
			||||||
 | 
					        'warning',
 | 
				
			||||||
 | 
					        'danger',
 | 
				
			||||||
 | 
					    ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    styles.forEach(function(style) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        var msg = sessionStorage.getItem(`inventree-alert-${style}`);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (msg) {
 | 
				
			||||||
 | 
					            showMessage(msg, {
 | 
				
			||||||
 | 
					                style: style,
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 
 | 
				
			||||||
 | 
					 * Display an alert message at the top of the screen.
 | 
				
			||||||
 | 
					 * The message will contain a "close" button,
 | 
				
			||||||
 | 
					 * and also dismiss automatically after a certain amount of time.
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * arguments:
 | 
				
			||||||
 | 
					 * - message: Text / HTML content to display
 | 
				
			||||||
 | 
					 * 
 | 
				
			||||||
 | 
					 * options:
 | 
				
			||||||
 | 
					 * - style: alert style e.g. 'success' / 'warning'
 | 
				
			||||||
 | 
					 * - timeout: Time (in milliseconds) after which the message will be dismissed
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					function showMessage(message, options={}) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var style = options.style || 'info';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    var timeout = options.timeout || 5000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Hacky function to get the next available ID
 | 
				
			||||||
 | 
					    var id = 1;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    while ($(`#alert-${id}`).exists()) {
 | 
				
			||||||
 | 
					        id++;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Info Message
 | 
					    var icon = '';
 | 
				
			||||||
    if (sessionStorage.getItem("inventree-alert-info")) {
 | 
					
 | 
				
			||||||
        showAlert("#alert-info", sessionStorage.getItem("inventree-alert-info"));
 | 
					    if (options.icon) {
 | 
				
			||||||
        sessionStorage.removeItem("inventree-alert-info");
 | 
					        icon = `<span class='${options.icon}></span>`;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Warning Message
 | 
					    // Construct the alert
 | 
				
			||||||
    if (sessionStorage.getItem("inventree-alert-warning")) {
 | 
					    var html = `
 | 
				
			||||||
        showAlert("#alert-warning", sessionStorage.getItem("inventree-alert-warning"));
 | 
					    <div id='alert-${id}' class='alert alert-${style} alert-dismissible fade show' role='alert'>
 | 
				
			||||||
        sessionStorage.removeItem("inventree-alert-warning");
 | 
					        ${icon}
 | 
				
			||||||
    }
 | 
					        ${message}
 | 
				
			||||||
 | 
					        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>  
 | 
				
			||||||
 | 
					    </div>
 | 
				
			||||||
 | 
					    `;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Danger Message
 | 
					    $('#alerts').append(html);
 | 
				
			||||||
    if (sessionStorage.getItem("inventree-alert-danger")) {
 | 
					
 | 
				
			||||||
        showAlert("#alert-danger", sessionStorage.getItem("inventree-alert-danger"));
 | 
					    // Remove the alert automatically after a specified period of time
 | 
				
			||||||
        sessionStorage.removeItem("inventree-alert-danger");
 | 
					    setInterval(function() {
 | 
				
			||||||
    }
 | 
					        $(`#alert-${id}`).animate({
 | 
				
			||||||
 | 
					            'opacity': 0.0,
 | 
				
			||||||
 | 
					            'height': '0px',
 | 
				
			||||||
 | 
					        }, 250, function() {
 | 
				
			||||||
 | 
					            $(`#alert-${id}`).remove();
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }, timeout);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
@@ -23,13 +23,15 @@
 | 
				
			|||||||
{% include "admin_button.html" with url=url %}
 | 
					{% include "admin_button.html" with url=url %}
 | 
				
			||||||
{% endif %}
 | 
					{% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<button type='button' class='btn btn-outline-secondary' id='toggle-starred' title='{% trans "Subscribe to nofications for this part" %}'>
 | 
					{% if starred %}
 | 
				
			||||||
    {% if starred %}
 | 
					<button type='button' class='btn btn-outline-secondary' id='toggle-starred' title='{% trans "You are subscribed to nofications for this part" %}'>
 | 
				
			||||||
    <span id='part-star-icon' class='fas fa-bell icon-green'/>
 | 
					    <span id='part-star-icon' class='fas fa-bell icon-green'/>
 | 
				
			||||||
    {% else %}
 | 
					 | 
				
			||||||
    <span id='part-star-icon' class='fa fa-bell-slash'/>
 | 
					 | 
				
			||||||
    {% endif %}
 | 
					 | 
				
			||||||
</button>
 | 
					</button>
 | 
				
			||||||
 | 
					{% else %}
 | 
				
			||||||
 | 
					<button type='button' class='btn btn-outline-secondary' id='toggle-starred' title='{% trans "Subscribe to nofications for this part" %}'>
 | 
				
			||||||
 | 
					    <span id='part-star-icon' class='fa fa-bell-slash'/>
 | 
				
			||||||
 | 
					</button>
 | 
				
			||||||
 | 
					{% endif %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
{% if barcodes %}
 | 
					{% if barcodes %}
 | 
				
			||||||
<!-- Barcode actions menu -->
 | 
					<!-- Barcode actions menu -->
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -84,6 +84,13 @@
 | 
				
			|||||||
            </div>
 | 
					            </div>
 | 
				
			||||||
        </div>
 | 
					        </div>
 | 
				
			||||||
        <main class='col ps-md-2 pt-2'>
 | 
					        <main class='col ps-md-2 pt-2'>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            {% block alerts %}
 | 
				
			||||||
 | 
					            <div class='notification-area' id='alerts'>
 | 
				
			||||||
 | 
					                <!-- Div for displayed alerts -->
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					            {% endblock %}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            {% block breadcrumb_list %}
 | 
					            {% block breadcrumb_list %}
 | 
				
			||||||
            <div class='container-fluid navigation'>
 | 
					            <div class='container-fluid navigation'>
 | 
				
			||||||
                <nav aria-label='breadcrumb'>
 | 
					                <nav aria-label='breadcrumb'>
 | 
				
			||||||
@@ -102,7 +109,6 @@
 | 
				
			|||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
    {% include 'modals.html' %}
 | 
					    {% include 'modals.html' %}
 | 
				
			||||||
    {% include 'about.html' %}
 | 
					    {% include 'about.html' %}
 | 
				
			||||||
    {% include 'notification.html' %}
 | 
					 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
<!-- Scripts -->
 | 
					<!-- Scripts -->
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -399,8 +399,18 @@ function toggleStar(options) {
 | 
				
			|||||||
                    success: function(response) {
 | 
					                    success: function(response) {
 | 
				
			||||||
                        if (response.starred) {
 | 
					                        if (response.starred) {
 | 
				
			||||||
                            $(options.button).removeClass('fa fa-bell-slash').addClass('fas fa-bell icon-green');
 | 
					                            $(options.button).removeClass('fa fa-bell-slash').addClass('fas fa-bell icon-green');
 | 
				
			||||||
 | 
					                            $(options.button).attr('title', '{% trans "You are subscribed to notifications for this part" %}');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            showMessage('{% trans "You have subscribed to notifications for this part" %}', {
 | 
				
			||||||
 | 
					                                style: 'success',
 | 
				
			||||||
 | 
					                            });
 | 
				
			||||||
                        } else {
 | 
					                        } else {
 | 
				
			||||||
                            $(options.button).removeClass('fas fa-bell icon-green').addClass('fa fa-bell-slash');
 | 
					                            $(options.button).removeClass('fas fa-bell icon-green').addClass('fa fa-bell-slash');
 | 
				
			||||||
 | 
					                            $(options.button).attr('title', '{% trans "Subscribe to notifications for this part" %}');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            showMessage('{% trans "You have unsubscribed to notifications for this part" %}', {
 | 
				
			||||||
 | 
					                                style: 'warning',
 | 
				
			||||||
 | 
					                            });
 | 
				
			||||||
                        }
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,18 +0,0 @@
 | 
				
			|||||||
<div class='notification-area'>
 | 
					 | 
				
			||||||
<div class="alert alert-success alert-dismissable" id="alert-success">
 | 
					 | 
				
			||||||
     <a href="#" class="close" data-bs-dismiss="alert" aria-label="close">×</a>
 | 
					 | 
				
			||||||
     <div class='alert-msg'>Success alert</div>
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
<div class='alert alert-info alert-dismissable' id='alert-info'>
 | 
					 | 
				
			||||||
     <a href="#" class="close" data-bs-dismiss="alert" aria-label="close">×</a>
 | 
					 | 
				
			||||||
     <div class='alert-msg'>Info alert</div>
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
<div class='alert alert-warning alert-dismissable' id='alert-warning'>
 | 
					 | 
				
			||||||
     <a href="#" class="close" data-bs-dismiss="alert" aria-label="close">×</a>
 | 
					 | 
				
			||||||
     <div class='alert-msg'>Warning alert</div>
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
<div class='alert alert-danger alert-dismissable' id='alert-danger'>
 | 
					 | 
				
			||||||
    <a href="#" class="close" data-bs-dismiss="alert" aria-label="close">×</a>
 | 
					 | 
				
			||||||
    <div class='alert-msg'>Danger alert</div>
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
</div>
 | 
					 | 
				
			||||||
		Reference in New Issue
	
	Block a user