Module: check_mk
Branch: master
Commit: ec2cab485585db9c5b03e743c25723c83bcd8724
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ec2cab485585db…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Jan 22 17:36:32 2013 +0100
ValueSpec TextAreaUnicode: new auto-size feature
---
web/htdocs/htmllib.py | 7 ++++---
web/htdocs/js/checkmk.js | 5 +++++
web/htdocs/valuespec.py | 13 +++++++++++--
3 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/web/htdocs/htmllib.py b/web/htdocs/htmllib.py
index bdb7081..6b7b05e 100644
--- a/web/htdocs/htmllib.py
+++ b/web/htdocs/htmllib.py
@@ -557,14 +557,15 @@ class html:
def password_input(self, varname, default_value = "", size=12, **args):
self.text_input(varname, default_value, type="password", size = size,
**args)
- def text_area(self, varname, deflt="", rows=4, cols=30):
+ def text_area(self, varname, deflt="", rows=4, cols=30, attrs = {}):
value = self.req.vars.get(varname, deflt)
error = self.user_errors.get(varname)
if error:
self.write("<x class=inputerror>")
- self.write("<textarea rows=%d cols=%d
name=\"%s\">%s</textarea>\n" % (
- rows, cols, varname, attrencode(value)))
+ attributes = ' ' + ' '.join([ '%s="%s"' % (k,
v) for k, v in attrs.iteritems() ])
+ self.write("<textarea rows=%d cols=%d
name=\"%s\"%s>%s</textarea>\n" % (
+ rows, cols, varname, attributes, attrencode(value)))
if error:
self.write("</x>")
self.set_focus(varname)
diff --git a/web/htdocs/js/checkmk.js b/web/htdocs/js/checkmk.js
index 492b0f4..2d165b5 100644
--- a/web/htdocs/js/checkmk.js
+++ b/web/htdocs/js/checkmk.js
@@ -1553,6 +1553,11 @@ function valuespec_cascading_change(oSelect, varprefix, count) {
}
}
+function valuespec_textarea_resize(oArea) {
+ var rows = oArea.value.split(/\r?\n|\r/).length;
+ oArea.rows = rows;
+}
+
function valuespec_listof_add(varprefix, magic) {
var oCountInput = document.getElementById(varprefix + "_count");
var count = parseInt(oCountInput.value);
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 37ec526..51c964f 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -484,13 +484,22 @@ class TextAreaUnicode(TextUnicode):
def __init__(self, **kwargs):
TextUnicode.__init__(self, **kwargs)
self._cols = kwargs.get("cols", 60)
- self._rows = kwargs.get("rows", 20)
+ self._rows = kwargs.get("rows", 20) # Allowed: "auto" ->
Auto resizing
def value_to_text(self, value):
return "<pre class=ve_textarea>%s</pre>" % value
def render_input(self, varprefix, value):
- html.text_area(varprefix, value, rows=self._rows, cols=self._cols)
+ if self._rows == "auto":
+ attrs = { "onkeyup" : 'valuespec_textarea_resize(this);' }
+ if html.has_var(varprefix):
+ rows = len(html.var(varprefix).splitlines())
+ else:
+ rows = len(value.splitlines())
+ else:
+ attrs = {}
+ rows = self._rows
+ html.text_area(varprefix, value, rows=rows, cols=self._cols, attrs = attrs)
# Overridded because we do not want to strip() here and remove '\r'
def from_html_vars(self, varprefix):