Module: check_mk
Branch: master
Commit: 23327145ebf6c678b3e5623c93ad2780af4a7203
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=23327145ebf6c6…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Nov 12 15:33:07 2013 +0100
GUI Notify: Added notify method "popup" to really create popup windows
The messages were named popups before, but were not really poups, as they were
only shown at the bottom of the sidebar as small hints. Both functions are now
available as notification methods. Popups will show up as alert windows and be
marked as read after closing the alert window and hints are only shown at the
bottom of the sidebar now.
---
.werks/211 | 12 ++++++++++++
ChangeLog | 1 +
web/htdocs/js/sidebar.js | 31 +++++++++++++++++++++++--------
web/htdocs/notify.py | 33 +++++++++++++++++++--------------
web/htdocs/sidebar.py | 22 ++++++++++++++++------
5 files changed, 71 insertions(+), 28 deletions(-)
diff --git a/.werks/211 b/.werks/211
new file mode 100644
index 0000000..1277341
--- /dev/null
+++ b/.werks/211
@@ -0,0 +1,12 @@
+Title: GUI Notify: Added notify method "popup" to really create popup windows
+Level: 1
+Component: multisite
+Version: 1.2.3i7
+Date: 1384266662
+Class: feature
+
+The messages were named popups before, but were not really poups, as they were
+only shown at the bottom of the sidebar as small hints. Both functions are now
+available as notification methods. Popups will show up as alert windows and be
+marked as read after closing the alert window and hints are only shown at the
+bottom of the sidebar now.
diff --git a/ChangeLog b/ChangeLog
index 2b823af..938f481 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -19,6 +19,7 @@
Multisite:
* 0001 New filters for selecting several host/service-groups at once...
* 0050 New concept of favorite hosts and services plus matching filters and views...
+ * 0211 GUI Notify: Added notify method "popup" to really create popup
windows...
* 0043 FIX: LDAP: Improved error reporting during synchronisation...
* 0044 FIX: LDAP: Fixed error with empty groups during non nested group sync...
* 0045 FIX: LDAP: Fixed error when synchronizing non nested groups to roles
diff --git a/web/htdocs/js/sidebar.js b/web/htdocs/js/sidebar.js
index 71009c1..62f57d9 100644
--- a/web/htdocs/js/sidebar.js
+++ b/web/htdocs/js/sidebar.js
@@ -940,6 +940,7 @@ function handle_update_messages(_unused, code) {
var c = document.getElementById('messages');
if (c) {
c.innerHTML = code;
+ executeJSbyObject(c);
update_message_trigger();
}
}
@@ -955,12 +956,21 @@ function update_messages() {
get_url('sidebar_get_messages.py', handle_update_messages);
}
+function get_hint_messages(c) {
+ var hints;
+ if (c.getElementsByClassName)
+ hints = c.getElementsByClassName('popup_msg');
+ else
+ hints = document.getElementsByClassName('popup_msg', c);
+ return hints;
+}
+
function update_message_trigger() {
var c = document.getElementById('messages');
if (c) {
var b = document.getElementById('msg_button');
- var num = c.children.length;
- if (c.children.length > 0) {
+ var hints = get_hint_messages(c);
+ if (hints.length > 0) {
// are there pending messages? make trigger visible
b.style.display = 'inline';
@@ -972,7 +982,7 @@ function update_message_trigger() {
b.appendChild(l);
}
- l.innerHTML = '' + c.children.length;
+ l.innerHTML = '' + hints.length;
} else {
// no messages: hide the trigger
b.style.display = 'none';
@@ -980,13 +990,21 @@ function update_message_trigger() {
}
}
+function mark_message_read(msg_id) {
+ get_url('sidebar_message_read.py?id=' + msg_id);
+
+ // Update the button state
+ update_message_trigger();
+}
+
function read_message() {
var c = document.getElementById('messages');
if (!c)
return;
// extract message from teh message container
- var msg = c.children[0];
+ var hints = get_hint_messages(c);
+ var msg = hints[0];
c.removeChild(msg);
// open the next message in a window
@@ -994,10 +1012,7 @@ function read_message() {
// tell server that the message has been read
var msg_id = msg.id.replace('message-', '');
- get_url('sidebar_message_read.py?id=' + msg_id);
-
- // Update the button state
- update_message_trigger();
+ mark_message_read(msg_id);
}
function message_close(msg_id) {
diff --git a/web/htdocs/notify.py b/web/htdocs/notify.py
index 664ba9e..061c483 100644
--- a/web/htdocs/notify.py
+++ b/web/htdocs/notify.py
@@ -27,7 +27,7 @@
import config, forms, time, lib, userdb
from valuespec import *
-def get_popup_messages(user_id = None):
+def get_gui_messages(user_id = None):
if user_id is None:
user_id = config.user_id
path = config.config_dir + "/" + user_id + '/messages.mk'
@@ -47,23 +47,23 @@ def get_popup_messages(user_id = None):
updated = True
if updated:
- save_popup_messages(messages)
+ save_gui_messages(messages)
return messages
-def delete_popup_message(msg_id):
- messages = get_popup_messages()
+def delete_gui_message(msg_id):
+ messages = get_gui_messages()
for index, msg in enumerate(messages):
if msg['id'] == msg_id:
messages.pop(index)
- save_popup_messages(messages)
+ save_gui_messages(messages)
-def save_popup_messages(messages, user_id = None):
+def save_gui_messages(messages, user_id = None):
if user_id is None:
user_id = config.user_id
path = config.config_dir + "/" + user_id + '/messages.mk'
make_nagios_directory(os.path.dirname(path))
- file(path, 'w').write(repr(messages))
+ file(path, 'w').write(repr(messages) + "\n")
loaded_with_language = False
def load_plugins():
@@ -76,9 +76,13 @@ def load_plugins():
global notify_methods
notify_methods = {
- 'popup': {
- 'title': _('Popup Message in the GUI'),
- 'handler': notify_popup,
+ 'gui_popup': {
+ 'title': _('Popup Message in the GUI (shows up alert
window)'),
+ 'handler': notify_gui_msg,
+ },
+ 'gui_hint': {
+ 'title': _('Send hint to message inbox (bottom of
sidebar)'),
+ 'handler': notify_gui_msg,
},
}
@@ -218,7 +222,8 @@ def page_notify():
# | |___/ |___/ |
# +----------------------------------------------------------------------+
-def notify_popup(user_id, msg):
- messages = get_popup_messages(user_id)
- messages.append(msg)
- save_popup_messages(messages, user_id)
+def notify_gui_msg(user_id, msg):
+ messages = get_gui_messages(user_id)
+ if msg not in messages:
+ messages.append(msg)
+ save_gui_messages(messages, user_id)
diff --git a/web/htdocs/sidebar.py b/web/htdocs/sidebar.py
index 31ea29a..6322c19 100644
--- a/web/htdocs/sidebar.py
+++ b/web/htdocs/sidebar.py
@@ -155,17 +155,27 @@ def sidebar_head():
'</div>\n' % (_("Go to main overview"),
config.start_url, defaults.check_mk_version))
def render_messages():
- for msg in notify.get_popup_messages():
- html.write('<div class="popup_msg"
id="message-%s">' % msg['id'])
- html.write('<a href="javascript:void(0)" class="close"
onclick="message_close(\'%s\')">x</a>' %
msg['id'])
- html.write(html.attrencode(msg['text']).replace('\n', '<br
/>\n'))
- html.write('</div>\n')
+ for msg in notify.get_gui_messages():
+ if 'gui_hint' in msg['methods']:
+ html.write('<div class="popup_msg"
id="message-%s">' % msg['id'])
+ html.write('<a href="javascript:void(0)"
class="close"
onclick="message_close(\'%s\')">x</a>' %
msg['id'])
+ html.write(html.attrencode(msg['text']).replace('\n',
'<br />\n'))
+ html.write('</div>\n')
+ if 'gui_popup' in msg['methods']:
+ html.javascript('alert(\'%s\');
mark_message_read("%s")' %
+ (html.attrencode(msg['text']).replace('\n',
'\\n'), msg['id']))
def ajax_get_messages():
render_messages()
def ajax_message_read():
- notify.delete_popup_message(html.var('id'))
+ try:
+ notify.delete_gui_message(html.var('id'))
+ html.write("OK")
+ except:
+ if config.debug:
+ raise
+ html.write("ERROR")
def sidebar_foot():
html.write('<div id="side_footer">')