From 9fc006e2272fec83eaa650024366ad8bcd48c437 Mon Sep 17 00:00:00 2001 From: Carsten Grohmann Date: Tue, 5 Nov 2019 20:29:02 +0100 Subject: [PATCH] Eliminate duplicate code to show the notification box --- OOMAnalyser.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/OOMAnalyser.py b/OOMAnalyser.py index 26b4500..ebb3d2d 100644 --- a/OOMAnalyser.py +++ b/OOMAnalyser.py @@ -34,21 +34,25 @@ def toggle(element_id): def error(msg): """Show the error box and add the error message""" - show_element('notify_box') - notify_box = document.getElementById('notify_box') - notification = document.createElement('div') - notification.classList.add('js-notify_box__msg--error') - notification.innerHTML = 'ERROR: {}
'.format(msg) - notify_box.appendChild(notification) + show_notifybox('ERROR', msg) def warning(msg): """Show the error box and add the warning message""" + show_notifybox('WARNING', msg) + + +def show_notifybox(prefix, msg): + """Show the error box and the message""" + if prefix == 'WARNING': + css_class = 'js-notify_box__msg--warning' + else: + css_class = 'js-notify_box__msg--error' show_element('notify_box') notify_box = document.getElementById('notify_box') notification = document.createElement('div') - notification.classList.add('js-notify_box__msg--warning') - notification.innerHTML = 'WARNING: {}
'.format(msg) + notification.classList.add(css_class) + notification.innerHTML = '{}: {}
'.format(prefix, msg) notify_box.appendChild(notification)