Module: check_mk
Branch: master
Commit: 8fbbeff9c97f9cadb2580c53e18b6277e7b2e5b2
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8fbbeff9c97f9c…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Feb 14 07:20:40 2013 +0100
Command form: make enter submit the correct action
---
web/htdocs/htmllib.py | 45 +++++++++++++++-------------------------
web/htdocs/js/checkmk.js | 10 +++++++-
web/htdocs/views.py | 1 -
web/plugins/views/commands.py | 12 +++++-----
4 files changed, 31 insertions(+), 37 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index a039672..b5a7a25 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -503,8 +503,8 @@ class html:
self.write(r'''onmouseover='this.style.backgroundImage="url(\"images/contextlink%s_hi.png\")";'
''' % what)
self.write(r'''onmouseout='this.style.backgroundImage="url(\"images/contextlink%s.png\")";'
''' % what)
- def number_input(self, varname, deflt = "", size=8, style=""):
- self.text_input(varname, str(deflt), "number", size=size, style=style)
+ def number_input(self, varname, deflt = "", size=8, style="",
submit=None):
+ self.text_input(varname, str(deflt), "number", size=size, style=style,
submit=submit)
# Needed if input elements are put into forms without the helper
@@ -533,11 +533,12 @@ class html:
elif add_style:
addprops += " style=\"%s\"" % add_style
- if submit:
- addprops += " id='hirn' "
-
self.final_javascript('document.getElementById("hirn").onkeydown = '
- 'function(e) { if (!e) e = window.event;
textinput_enter_submit(e, "%s"); };' % submit)
-
+ if submit != None:
+ if not id:
+ id = "ti_%s" % varname
+ self.final_javascript('document.getElementById("%s").onkeydown
= '
+ 'function(e) { if (!e) e = window.event;
textinput_enter_submit(e, "%s"); };'
+ % (id, submit))
value = self.req.vars.get(varname, default_value)
error = self.user_errors.get(varname)
@@ -707,7 +708,7 @@ class html:
# Form filled in but variable missing -> Checkbox not checked
return False
- def datetime_input(self, varname, default_value):
+ def datetime_input(self, varname, default_value, submit=None):
try:
t = self.get_datetime_input(varname)
except:
@@ -719,31 +720,19 @@ class html:
self.set_focus(varname + "_date")
br = time.localtime(t)
- self.date_input(varname + "_date", br.tm_year, br.tm_mon, br.tm_mday)
+ self.date_input(varname + "_date", br.tm_year, br.tm_mon, br.tm_mday,
submit=submit)
self.write(" ")
- self.time_input(varname + "_time", br.tm_hour, br.tm_min)
+ self.time_input(varname + "_time", br.tm_hour, br.tm_min,
submit=submit)
self.form_vars.append(varname + "_date")
self.form_vars.append(varname + "_time")
- def time_input(self, varname, hours, mins):
- error = self.user_errors.get(varname)
- if error:
- self.write("<x class=inputerror>")
- self.write("<input type=text size=5 class=time name=%s
value=\"%02d:%02d\">" %
- (varname, hours, mins))
- if error:
- self.write("</x>")
- self.form_vars.append(varname)
+ def time_input(self, varname, hours, mins, submit=None):
+ self.text_input(varname, "%02d:%02d" % (hours, mins),
cssclass="time", size=5,
+ submit=submit)
- def date_input(self, varname, year, month, day):
- error = self.user_errors.get(varname)
- if error:
- self.write("<x class=inputerror>")
- self.write("<input type=text size=10 class=date name=%s
value=\"%04d-%02d-%02d\">" %
- (varname, year, month, day))
- if error:
- self.write("</x>")
- self.form_vars.append(varname)
+ def date_input(self, varname, year, month, day, submit=None):
+ self.text_input(varname, "%04d-%02d-%02d" % (year, month, day),
+ cssclass="date", size=11, submit=submit)
def get_datetime_input(self, varname):
t = self.var(varname + "_time")
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 58ed332..c13ba6a 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -103,7 +103,7 @@ if (!document.getElementsByClassName) {
}
}
return _nodeList;
-}
+ }
}
function getTarget(event) {
@@ -514,9 +514,15 @@ function pnp_hover_contents(url) {
function textinput_enter_submit(e, submit) {
var keyCode = e.which || e.keyCode;
if (keyCode == 13) {
- /* alert(submit); */
+ if (submit) {
+ var button = document.getElementById(submit);
+ if (button)
+ button.click();
+ }
+ if (e.preventDefault) e.preventDefault();
e.returnValue = false;
e.cancelBubble = true;
+ return false;
}
}
diff --git a/web/htdocs/views.py b/web/htdocs/views.py
index a32a96b..58ec06a 100644
--- a/web/htdocs/views.py
+++ b/web/htdocs/views.py
@@ -2073,7 +2073,6 @@ def show_command_form(is_open, datasource):
html.hidden_field("_do_actions", "yes")
html.hidden_field("actions", "yes")
html.hidden_fields() # set all current variables, exception action vars
- # html.write('<table class="form">')
# Show command forms, grouped by (optional) command group
by_group = {}
diff --git a/web/plugins/views/commands.py b/web/plugins/views/commands.py
index d526a9b..3155329 100644
--- a/web/plugins/views/commands.py
+++ b/web/plugins/views/commands.py
@@ -212,7 +212,7 @@ multisite_commands.append({
"title" : _("Custom notification"),
"render" : lambda: \
html.write(_('Comment') + ": ") == \
- html.text_input("_cusnot_comment", "TEST", size=20) == \
+ html.text_input("_cusnot_comment", "TEST", size=20,
submit="_customnotification") == \
html.write(" ") == \
html.checkbox("_cusnot_forced", False, label=_("forced")) ==
\
html.checkbox("_cusnot_broadcast", False,
label=_("broadcast")) == \
@@ -287,7 +287,7 @@ multisite_commands.append({
"title" : _("Add comment"),
"render" : lambda: \
html.write(_('Comment')+": ") == \
- html.text_input("_comment", size=33) == \
+ html.text_input("_comment", size=33, submit="_add_comment")
== \
html.write(" ") == \
html.button("_add_comment", _("Add comment")),
"action" : command_comment,
@@ -415,7 +415,7 @@ def get_child_hosts(site, hosts, recurse):
def paint_downtime_buttons(what):
html.write(_('Downtime Comment')+": ")
- html.text_input("_down_comment", size=40)
+ html.text_input("_down_comment", size=40, submit="")
html.write("<hr>")
html.button("_down_2h", _("2 hours"))
html.button("_down_today", _("Today"))
@@ -426,13 +426,13 @@ def paint_downtime_buttons(what):
html.button("_down_remove", _("Remove all"))
html.write("<hr>")
html.button("_down_custom", _("Custom time range"))
- html.datetime_input("_down_from", time.time())
+ html.datetime_input("_down_from", time.time(),
submit="_down_custom")
html.write(" "+_('to')+" ")
- html.datetime_input("_down_to", time.time() + 7200)
+ html.datetime_input("_down_to", time.time() + 7200,
submit="_down_custom")
html.write("<hr>")
html.button("_down_from_now", _("From now for"))
html.write(" ")
- html.number_input("_down_minutes", 60, size=4, style="text-align:
right")
+ html.number_input("_down_minutes", 60, size=4,
submit="_down_from_now")
html.write(" " + _("minutes"))
html.write("<hr>")
html.checkbox("_down_flexible", False, label=_('flexible with max.
duration')+" ")