Module: check_mk
Branch: master
Commit: 0e349288694922eca45db6309740fb1201731252
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=0e349288694922…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Thu Nov 17 12:10:32 2016 +0100
TextAreaUnicode can now use available width, if Browser supports it
The ValueSpec TextAreaUnicode has the new argument "try_max_width". If it
is set to True, then the size of the area is allowed to grow beyond the
arguments cols (which is now a minimum size). This is done by using calc()
in CSS. Older browsers that do not handle calc() should simply ignore this
and keep to the old behaviour.
---
web/htdocs/htmllib.py | 9 ++++++---
web/htdocs/valuespec.py | 5 ++++-
web/htdocs/wato.py | 3 ++-
3 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index 63acf26..a74d3ad 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -1828,15 +1828,18 @@ class html(DeprecationWrapper):
self.text_input(varname, default_value, type="password", size = size,
**args)
- def text_area(self, varname, deflt="", rows=4, cols=30, attrs = {}):
+ def text_area(self, varname, deflt="", rows=4, cols=30, attrs = {},
try_max_width=False):
value = self.var(varname, deflt)
error = self.user_errors.get(varname)
if error:
self.write("<x class=inputerror>")
attributes = ' ' + ' '.join([ '%s="%s"' % (k,
v) for k, v in attrs.iteritems() ])
- self.write("<textarea style=\"width: %d.8ex\" rows=%d cols=%d
name=\"%s\"%s>%s</textarea>\n" % (
- cols, rows, cols, varname, attributes, self.attrencode(value)))
+ style = "width: %d.8ex;" % cols
+ if try_max_width:
+ style += "width: calc(100%% - 10px); min-width: %d.8ex;" % cols
+ self.write("<textarea style=\"%s\" rows=%d cols=%d
name=\"%s\"%s>%s</textarea>\n" % (
+ style, rows, cols, varname, attributes, self.attrencode(value)))
if error:
self.write("</x>")
self.set_focus(varname)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 9313257..b15b446 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -956,6 +956,7 @@ class TextAreaUnicode(TextUnicode):
def __init__(self, **kwargs):
TextUnicode.__init__(self, **kwargs)
self._cols = kwargs.get("cols", 60)
+ self._try_max_width = kwargs.get("try_max_width", False) # If set, uses
calc(100%-10px)
self._rows = kwargs.get("rows", 20) # Allowed: "auto" ->
Auto resizing
self._minrows = kwargs.get("minrows", 0) # Minimum number of initial
rows when "auto"
self._monospaced = kwargs.get("monospaced", False) # select TT font
@@ -986,7 +987,9 @@ class TextAreaUnicode(TextUnicode):
if self._prefix_buttons:
html.write('<div style="white-space: nowrap;">')
- html.text_area(varprefix, value, rows=rows, cols=self._cols, attrs = attrs)
+
+ html.text_area(varprefix, value, rows=rows, cols=self._cols,
+ attrs = attrs, try_max_width=self._try_max_width)
if self._prefix_buttons:
self.render_buttons()
html.write('</div>')
diff --git a/web/htdocs/wato.py b/web/htdocs/wato.py
index 7f1356c..e42770f 100644
--- a/web/htdocs/wato.py
+++ b/web/htdocs/wato.py
@@ -4852,7 +4852,8 @@ class ModeActivateChanges(WatoMode, ActivateChanges):
elements = [
("comment", TextAreaUnicode(
title = _("Comment (optional)"),
- cols = 93,
+ cols = 40,
+ try_max_width = True,
rows = 3,
help = _("You can provide an optional comment for the current
activation. "
"This can be useful to document the reason why the
changes you "