Module: check_mk
Branch: master
Commit: b085ae98a2df6b71475577c08622697bd3ffd525
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b085ae98a2df6b…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Wed Jul 31 14:40:36 2013 +0200
Added button to rule comment for inserting date and user
---
web/htdocs/images/button_insertdate_hi.png | Bin 0 -> 3626 bytes
web/htdocs/images/button_insertdate_lo.png | Bin 0 -> 5063 bytes
web/htdocs/js/checkmk.js | 11 +++++++++++
web/htdocs/valuespec.py | 15 +++++++++++++++
web/htdocs/wato.py | 4 ++++
5 files changed, 30 insertions(+)
diff --git a/web/htdocs/images/button_insertdate_hi.png
b/web/htdocs/images/button_insertdate_hi.png
new file mode 100644
index 0000000..349e1ff
Binary files /dev/null and b/web/htdocs/images/button_insertdate_hi.png differ
diff --git a/web/htdocs/images/button_insertdate_lo.png
b/web/htdocs/images/button_insertdate_lo.png
new file mode 100644
index 0000000..17e760a
Binary files /dev/null and b/web/htdocs/images/button_insertdate_lo.png differ
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 98e010c..abc32f9 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -1707,6 +1707,17 @@ function valuespec_listof_fixarrows(oTbody) {
}
}
+function vs_textascii_button(img, text, how) {
+ var oInput = img.previousElementSibling;
+ while (oInput.tagName == "A")
+ oInput = oInput.previousElementSibling;
+ if (oInput.tagName != "INPUT")
+ oInput = oInput.firstChild; // complain mode
+ oInput.value = text + oInput.value; // TODO: how
+ oInput.focus();
+}
+
+
function vs_passwordspec_randomize(img) {
password = "";
while (password.length < 8) {
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index e28f597..082419f 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -319,6 +319,8 @@ class TextAscii(ValueSpec):
if type(self._regex) == str:
self._regex = re.compile(self._regex)
+ self._prefix_buttons = kwargs.get("prefix_buttons", [])
+
def canonical_value(self):
return ""
@@ -331,6 +333,18 @@ class TextAscii(ValueSpec):
html.write(" ")
html.text_input(varprefix, str(value), size = self._size,
read_only = self._read_only)
+ self.render_buttons()
+
+ def render_buttons(self):
+ if self._prefix_buttons:
+ html.write(" ")
+ for icon, textfunc, help in self._prefix_buttons:
+ try:
+ text = textfunc()
+ except:
+ text = textfunc
+ html.icon_button("#", help, icon,
onclick="vs_textascii_button(this, '%s', 'prefix');" % text)
+
def value_to_text(self, value):
if value == None:
@@ -374,6 +388,7 @@ class TextUnicode(TextAscii):
def render_input(self, varprefix, value):
html.text_input(varprefix, value, size = self._size)
+ self.render_buttons()
def from_html_vars(self, varprefix):
return html.var_utf8(varprefix, "").strip()
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index b598315..855b82d 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -10759,6 +10759,9 @@ def get_rule_conditions(ruleset):
+def date_and_user():
+ return time.strftime("%F", time.localtime()) + " " +
config.user_id + ": "
+
def mode_edit_rule(phase, new = False):
# Due to localization this cannot be defined in the global context!
vs_rule_options = Dictionary(
@@ -10773,6 +10776,7 @@ def mode_edit_rule(phase, new = False):
"this rule"),
size = 80,
attrencode = True,
+ prefix_buttons = [ ("insertdate", date_and_user, _("Prefix
date and your name to the comment")) ]
)
),
( "docu_url",