All of lore.kernel.org
 help / color / mirror / Atom feed
From: kupcevic@sourceware.org <kupcevic@sourceware.org>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] conga/luci site/luci/Extensions/HelperFunction ...
Date: 6 Oct 2006 22:08:17 -0000	[thread overview]
Message-ID: <20061006220817.3993.qmail@sourceware.org> (raw)

CVSROOT:	/cvs/cluster
Module name:	conga
Changes by:	kupcevic at sourceware.org	2006-10-06 22:08:13

Modified files:
	luci/site/luci/Extensions: HelperFunctions.py StorageReport.py 
	luci/storage   : form-macros validate_html 

Log message:
	luci storage: display size in appropriate units (instead of bytes), taking preferred size into account

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/HelperFunctions.py.diff?cvsroot=cluster&r1=1.3&r2=1.4
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/site/luci/Extensions/StorageReport.py.diff?cvsroot=cluster&r1=1.9&r2=1.10
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/storage/form-macros.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/conga/luci/storage/validate_html.diff?cvsroot=cluster&r1=1.1&r2=1.2

--- conga/luci/site/luci/Extensions/HelperFunctions.py	2006/10/05 23:21:39	1.3
+++ conga/luci/site/luci/Extensions/HelperFunctions.py	2006/10/06 22:08:13	1.4
@@ -90,3 +90,49 @@
                        expires='Tue, 30 Jun 2060 12:00:00 GMT')
     
     return value
+
+
+
+
+# returns (str(float), units) that fits best,
+# ignores prefered units
+def bytes_to_value_units(bytes):
+    units = 'TB'
+    if float(convert_bytes(bytes, 'GB')) < 1024:
+        units = 'GB'
+    if float(convert_bytes(bytes, 'MB')) < 1024:
+        units = 'MB'
+    if float(convert_bytes(bytes, 'KB')) < 1024:
+        units = 'KB'
+    if float(convert_bytes(bytes, 'bytes')) < 1024:
+        units = 'bytes'
+    return (convert_bytes(bytes, units), units)
+
+# returns (str(float), units) that fits best,
+# takes prefered units into account
+def bytes_to_value_prefunits(self, bytes):
+    p_units = self.REQUEST.SESSION.get('preferred_size_units')
+    dummy, units = bytes_to_value_units(bytes)
+    if get_units_multiplier(units) > get_units_multiplier(p_units):
+        units = p_units
+    return (convert_bytes(bytes, units), units)
+
+def get_units_multiplier(units):
+    if units.lower() == 'bytes':
+        return 1.0
+    elif units.lower() == 'kb':
+        return 1024.0
+    elif units.lower() == 'mb':
+        return 1024*1024.0
+    elif units.lower() == 'gb':
+        return 1024*1024*1024.0
+    elif units.lower() == 'tb':
+        return 1024*1024*1024*1024.0
+    else:
+        raise "invalid size unit"
+
+def convert_bytes(bytes, units):
+    c = int(bytes) / get_units_multiplier(units)
+    c = str(c)
+    c = c[:c.find('.') + 3]
+    return c
--- conga/luci/site/luci/Extensions/StorageReport.py	2006/10/05 23:21:39	1.9
+++ conga/luci/site/luci/Extensions/StorageReport.py	2006/10/06 22:08:13	1.10
@@ -232,7 +232,7 @@
     try:
         rep = get_storage_report(ricci_comm, session)
         if rep == None:
-            raise Exception, 'Unable to communicate to host'
+            raise Exception, 'Unable to communicate with host (either system down or ricci not running on it)'
         else:
             return True
     except Exception, e:
@@ -300,7 +300,7 @@
     if module_r_status != '0':
         #raise Exception, 'error retrieving storage report'
         if module_r_status == '3':
-            raise Exception, 'Unable to find storage module: reinstall it'
+            raise Exception, 'Unable to find storage module on host (reinstall it)'
     resp_r = None
     for node in module_r.childNodes:
         if node.nodeType == xml.dom.Node.ELEMENT_NODE:
@@ -334,9 +334,9 @@
     if succ_v.get_value() != True:
         # error
         if err_code_v.get_value() == -1:
-            raise Exception, 'Generic error:\n\n' + err_desc_v.get_value()
+            raise Exception, 'Generic error on host:\n\n' + err_desc_v.get_value()
         else:
-            raise Exception, err_desc_v.get_value()
+            raise Exception, 'Host responded: ' + err_desc_v.get_value()
     
     #xml_report = fr_r.toxml()
     xml_report = fr_r
@@ -765,17 +765,17 @@
         pass
     
     if props != None:
-        res = check_props(props, request)
+        res = check_props(self, props, request)
         if res[0] == False:
             return res[1] + ' ' + res[2]
     
     if content_props != None:
-        res = check_props(content_props, request)
+        res = check_props(self, content_props, request)
         if res[0] == False:
             return res[1] + ' ' + res[2]
     
     return 'OK'
-def check_props(props, request):
+def check_props(self, props, request):
     valid = True
     var_name = ''
     msg = 'no message - BUG :('
@@ -785,23 +785,43 @@
             prop = props[prop_name]
             req_value = request[prop_name]
             if prop['type'] == 'int':
-                try:
-                    req_value = int(req_value)
-                except:
-                    msg = prop['pretty_name'] + ' is missing an integer value'
-                    var_name = prop_name
-                    valid = False
-                    break
-                min = int(prop['validation']['min'])
-                max = int(prop['validation']['max'])
-                step = int(prop['validation']['step'])
-                r_val = (req_value / step) * step
-                if r_val > max or r_val < min:
-                    msg = prop['pretty_name'] + ' has to be within range ' + str(min) + ' - ' + str(max) + ' ' + prop['units']
-                    var_name = prop_name
-                    valid = False
-                    break
-            
+                if prop['units'] != 'bytes':
+                    try:
+                        req_value = int(req_value)
+                    except:
+                        msg = prop['pretty_name'] + ' is missing an integer value'
+                        var_name = prop_name
+                        valid = False
+                        break
+                    min = int(prop['validation']['min'])
+                    max = int(prop['validation']['max'])
+                    step = int(prop['validation']['step'])
+                    r_val = (req_value / step) * step
+                    if r_val > max or r_val < min:
+                        msg = prop['pretty_name'] + ' has to be within range ' + str(min) + ' - ' + str(max) + ' ' + prop['units']
+                        var_name = prop_name
+                        valid = False
+                        break
+                else:
+                    try:
+                        req_value = float(req_value)
+                    except:
+                        msg = prop['pretty_name'] + ' is missing a float value'
+                        var_name = prop_name
+                        valid = False
+                        break
+                    dummy, units = bytes_to_value_prefunits(self, prop['value'])
+                    min  = float(convert_bytes(prop['validation']['min'], units))
+                    max  = float(convert_bytes(prop['validation']['max'], units))
+                    step = float(convert_bytes(prop['validation']['step'], units))
+                    if step < 0.000001:
+                        step = 0.000001
+                    r_val = (req_value / step) * step
+                    if r_val > max or r_val < min:
+                        msg = prop['pretty_name'] + ' has to be within range ' + str(min) + ' - ' + str(max) + ' ' + units
+                        var_name = prop_name
+                        valid = False
+                        break
             elif prop['type'] == 'text':
                 if len(req_value) < int(prop['validation']['min_length']):
                     msg = prop['pretty_name'] + ' has to have minimum length of ' + prop['validation']['min_length']
@@ -893,9 +913,23 @@
                             var_name = node.getAttribute('name')
                             if var_name in request:
                                 if bd_data['props'][var_name]['type'] == 'int':
-                                    val = int(request[var_name])
-                                    step = int(bd_data['props'][var_name]['validation']['step'])
-                                    val = (val / step) * step
+                                    if bd_data['props'][var_name]['units'] != 'bytes':
+                                        val = int(request[var_name])
+                                        step = int(bd_data['props'][var_name]['validation']['step'])
+                                        val = (val / step) * step
+                                    else:
+                                        dummy, units = bytes_to_value_prefunits(self,
+                                                                                bd_data['props'][var_name]['value'])
+                                        min  = int(bd_data['props'][var_name]['validation']['min'])
+                                        max  = int(bd_data['props'][var_name]['validation']['max'])
+                                        step = int(bd_data['props'][var_name]['validation']['step'])
+                                        val_units = float(request[var_name])
+                                        val = int(val_units * get_units_multiplier(units))
+                                        val = (val / step) * step
+                                        if val < min:
+                                            val = min
+                                        if val > max:
+                                            val = max
                                     node.setAttribute('value', str(val))
                                 else:
                                     node.setAttribute('value', request[var_name])
@@ -925,9 +959,23 @@
                             req_name = 'content_variable_' + selected_content_id + '_' + var_name
                             if req_name in request:
                                 if selected_content_data['props'][req_name]['type'] == 'int':
-                                    val = int(request[req_name])
-                                    step = int(selected_content_data['props'][req_name]['validation']['step'])
-                                    val = (val / step) * step
+                                    if selected_content_data['props'][req_name]['units'] != 'bytes':
+                                        val = int(request[req_name])
+                                        step = int(selected_content_data['props'][req_name]['validation']['step'])
+                                        val = (val / step) * step
+                                    else:
+                                        dummy, units = bytes_to_value_prefunits(self,
+                                                                                selected_content_data['props'][req_name]['value'])
+                                        min  = int(selected_content_data['props'][req_name]['validation']['min'])
+                                        max  = int(selected_content_data['props'][req_name]['validation']['max'])
+                                        step = int(selected_content_data['props'][req_name]['validation']['step'])
+                                        val_units = float(request[req_name])
+                                        val = int(val_units * get_units_multiplier(units))
+                                        val = (val / step) * step
+                                        if val < min:
+                                            val = min
+                                        if val > max:
+                                            val = max
                                     node.setAttribute('value', str(val))
                                 else:
                                     node.setAttribute('value', request[req_name])
@@ -1035,9 +1083,23 @@
                             var_name = node.getAttribute('name')
                             if var_name in request:
                                 if bd_data['props'][var_name]['type'] == 'int':
-                                    val = int(request[var_name])
-                                    step = int(bd_data['props'][var_name]['validation']['step'])
-                                    val = (val / step) * step
+                                    if bd_data['props'][var_name]['units'] != 'bytes':
+                                        val = int(request[var_name])
+                                        step = int(bd_data['props'][var_name]['validation']['step'])
+                                        val = (val / step) * step
+                                    else:
+                                        dummy, units = bytes_to_value_prefunits(self,
+                                                                                bd_data['props'][var_name]['value'])
+                                        min  = int(bd_data['props'][var_name]['validation']['min'])
+                                        max  = int(bd_data['props'][var_name]['validation']['max'])
+                                        step = int(bd_data['props'][var_name]['validation']['step'])
+                                        val_units = float(request[var_name])
+                                        val = int(val_units * get_units_multiplier(units))
+                                        val = (val / step) * step
+                                        if val < min:
+                                            val = min
+                                        if val > max:
+                                            val = max
                                     node.setAttribute('value', str(val))
                                 else:
                                     node.setAttribute('value', request[var_name])
@@ -1068,9 +1130,23 @@
                                 req_name = 'content_variable_' + selected_content_id + '_' + var_name
                                 if req_name in request:
                                     if selected_content_data['props'][req_name]['type'] == 'int':
-                                        val = int(request[req_name])
-                                        step = int(selected_content_data['props'][req_name]['validation']['step'])
-                                        val = (val / step) * step
+                                        if selected_content_data['props'][req_name]['units'] != 'bytes':
+                                            val = int(request[req_name])
+                                            step = int(selected_content_data['props'][req_name]['validation']['step'])
+                                            val = (val / step) * step
+                                        else:
+                                            dummy, units = bytes_to_value_prefunits(self,
+                                                                                    selected_content_data['props'][req_name]['value'])
+                                            min  = int(selected_content_data['props'][req_name]['validation']['min'])
+                                            max  = int(selected_content_data['props'][req_name]['validation']['max'])
+                                            step = int(selected_content_data['props'][req_name]['validation']['step'])
+                                            val_units = float(request[req_name])
+                                            val = int(val_units * get_units_multiplier(units))
+                                            val = (val / step) * step
+                                            if val < min:
+                                                val = min
+                                            if val > max:
+                                                val = max
                                         node.setAttribute('value', str(val))
                                     else:
                                         node.setAttribute('value', request[req_name])
@@ -1200,9 +1276,23 @@
                             var_name = node.getAttribute('name')
                             if var_name in request:
                                 if mapper_data['props'][var_name]['type'] == 'int':
-                                    val = int(request[var_name])
-                                    step = int(mapper_data['props'][var_name]['validation']['step'])
-                                    val = (val / step) * step
+                                    if mapper_data['props'][var_name]['units'] != 'bytes':
+                                        val = int(request[var_name])
+                                        step = int(mapper_data['props'][var_name]['validation']['step'])
+                                        val = (val / step) * step
+                                    else:
+                                        dummy, units = bytes_to_value_prefunits(self,
+                                                                                mapper_data['props'][var_name]['value'])
+                                        min  = int(mapper_data['props'][var_name]['validation']['min'])
+                                        max  = int(mapper_data['props'][var_name]['validation']['max'])
+                                        step = int(mapper_data['props'][var_name]['validation']['step'])
+                                        val_units = float(request[var_name])
+                                        val = int(val_units * get_units_multiplier(units))
+                                        val = (val / step) * step
+                                        if val < min:
+                                            val = min
+                                        if val > max:
+                                            val = max
                                     node.setAttribute('value', str(val))
                                 else:
                                     node.setAttribute('value', request[var_name])
@@ -1288,9 +1378,23 @@
                             var_name = node.getAttribute('name')
                             if request.has_key(var_name):
                                 if mapper_data['props'][var_name]['type'] == 'int':
-                                    val = int(request[var_name])
-                                    step = int(mapper_data['props'][var_name]['validation']['step'])
-                                    val = (val / step) * step
+                                    if mapper_data['props'][var_name]['units'] != 'bytes':
+                                        val = int(request[var_name])
+                                        step = int(mapper_data['props'][var_name]['validation']['step'])
+                                        val = (val / step) * step
+                                    else:
+                                        dummy, units = bytes_to_value_prefunits(self,
+                                                                                mapper_data['props'][var_name]['value'])
+                                        min  = int(mapper_data['props'][var_name]['validation']['min'])
+                                        max  = int(mapper_data['props'][var_name]['validation']['max'])
+                                        step = int(mapper_data['props'][var_name]['validation']['step'])
+                                        val_units = float(request[var_name])
+                                        val = int(val_units * get_units_multiplier(units))
+                                        val = (val / step) * step
+                                        if val < min:
+                                            val = min
+                                        if val > max:
+                                            val = max
                                     node.setAttribute('value', str(val))
                                 else:
                                     node.setAttribute('value', request[var_name])
@@ -1422,7 +1526,8 @@
     type = bd_xml.getAttribute('mapper_type')
     pretty_name = path.replace('/dev/','')
     pretty_type = 'Block Device'
-    description = props['size']['value'] + ' ' + props['size']['units']
+    size_in_units, units = bytes_to_value_units(props['size']['value'])
+    description = str(size_in_units) + ' ' + units
     icon_name = ''
     color = 'black'
     if type == MAPPER_SYS_TYPE:
@@ -1553,10 +1658,6 @@
             min  = var.getAttribute('min')
             max  = var.getAttribute('max')
             step = var.getAttribute('step')
-            if d_units == 'bytes':
-                # modify units
-                
-                pass
             validation_data['min']  = str(min)
             validation_data['max']  = str(max)
             validation_data['step'] = str(step)
--- conga/luci/storage/form-macros	2006/10/05 23:21:40	1.5
+++ conga/luci/storage/form-macros	2006/10/06 22:08:13	1.6
@@ -189,10 +189,16 @@
        </td>
        <td>
         <select name="preferred_size_units" onchange="this.form.submit()">
+         <option value="bytes" 
+                 tal:attributes="selected python:preferred_size_units == 'bytes'">Bytes</option>
+         <option value="KB" 
+                 tal:attributes="selected python:preferred_size_units == 'KB'">KB - KiloBytes</option>
          <option value="MB" 
                  tal:attributes="selected python:preferred_size_units == 'MB'">MB - MegaBytes</option>
          <option value="GB" 
                  tal:attributes="selected python:preferred_size_units == 'GB'">GB - GigaBytes</option>
+         <option value="TB" 
+                 tal:attributes="selected python:preferred_size_units == 'TB'">TB - TeraBytes</option>
         </select>
        </td>
       </tr>
@@ -201,7 +207,9 @@
         Display Devices by
        </td>
        <td>
-        <select name="preferred_path_display" onchange="this.form.submit()">
+        <select name="preferred_path_display"
+                onchange="this.form.submit()"
+                style="width: 100%;">
          <option value="path" 
                  tal:attributes="selected python:preferred_path_display == 'path'">Device Path</option>
          <option value="scsi" 
@@ -629,7 +637,8 @@
                    prefix                  python:'create_mapper_template_' + mapper['mapper_type'] + '_'; 
                    properties_span_id      string:; 
                    mapper_template_form_id python:prefix + 'mapper_template_form_id'; 
-                   create_mapper_button_id python:prefix + 'mapper_template_apply_button_id'">
+                   create_mapper_button_id python:prefix + 'mapper_template_apply_button_id';
+                   form_submit_button_id   create_mapper_button_id">
    <div metal:use-macro="here/form-macros/macros/forms-css"/>
    <div metal:use-macro="here/form-macros/macros/form-scripts"/>
    <form tal:attributes="id      mapper_template_form_id; 
@@ -702,8 +711,11 @@
               <input tal:attributes="type string:checkbox; 
                                      name python:'source_bd_' + bd['path']"/>
              </td>
-             <td>
-              <span tal:replace="bd/path"/> (<span tal:replace="bd/props/size/value"/> <span tal:replace="bd/props/size/units"/> - <span tal:replace="bd/pretty_type"/>)
+             <td tal:define="bytes  bd/props/size/value;
+                             dummy  python:here.bytes_to_value_units(bytes);
+                             size   python:dummy[0];
+                             units  python:dummy[1]">
+              <span tal:replace="bd/path"/> (<span tal:replace="size"/> <span tal:replace="units"/> - <span tal:replace="bd/pretty_type"/>)
              </td>
             </tr>
            </span>
@@ -792,8 +804,16 @@
              </span>
             </select>
            </span>
-           <span tal:condition="not: prop/replacements|nothing"
-                 tal:replace="prop/value"/>
+           <span tal:omit-tag=""
+                 tal:condition="not: prop/replacements|nothing">
+            <span tal:condition="python: prop_units == 'bytes'">
+             <span tal:define="dummy python: here.bytes_to_value_units(prop['value']);
+                               value python: str(dummy[0]) + ' ' + str(dummy[1])"
+                   tal:replace="value"/>
+            </span>
+            <span tal:condition="python: prop_units != 'bytes'"
+                  tal:replace="prop/value"/>
+           </span>
           </span>
 
 
@@ -803,16 +823,32 @@
                                  type        string:text; 
                                  value       prop/value;
                                  onkeypress  python:'return validate_text_keypress(this, event, 2, \'' + prop['validation']['illegal_chars'] + '\', ' + str(prop['validation']['max_length']) + ')';
-                                 onblur      python:'validate_text(this, 2, \'' + prop['validation']['illegal_chars'] + '\', \'' + prop['validation']['reserved_words'] + '\', ' + str(prop['validation']['min_length']) + ', ' + str(prop['validation']['max_length']) + ')'"/>
+                                 onblur      python:'validate_text(this, 2, \'' + prop['validation']['illegal_chars'] + '\', \'' + prop['validation']['reserved_words'] + '\', ' + str(prop['validation']['min_length']) + ', ' + str(prop['validation']['max_length']) + ', \'' + form_submit_button_id + '\')'"/>
           
           
           
-          <input tal:condition="python:prop_type == 'int'"
+          <input tal:condition="python:prop_type == 'int' and prop_units != 'bytes'"
                  tal:attributes="name   p; 
                                  type   string:text; 
                                  value  prop/value;
-                                 onblur python:'validate_int(this, 2, ' + str(prop['validation']['min']) + ', ' + str(prop['validation']['max']) + ', ' + str(prop['validation']['step']) + ')'"
+                                 onblur python:'validate_int(this, 2, ' + str(prop['validation']['min']) + ', ' + str(prop['validation']['max']) + ', ' + str(prop['validation']['step']) + ', \'' + prop_units + '\', \'' + form_submit_button_id + '\')'"
                  onkeypress="return validate_int_keypress(this, event, 2)"/>
+          <span tal:condition="python:prop_type == 'int' and prop_units == 'bytes'">
+           <span tal:define="bytes  prop/value;
+                             dummy  python:here.bytes_to_value_prefunits(bytes);
+                             value  python:dummy[0];
+                             units  python:dummy[1];
+                             minim  python:here.convert_bytes(prop['validation']['min'], units);
+                             maxim  python:here.convert_bytes(prop['validation']['max'], units);
+                             step   python:here.convert_bytes(prop['validation']['step'], units)">
+            <input tal:attributes="name   p; 
+                                   type   string:text; 
+                                   value  value;
+                                   onblur python:'validate_float(this, 2, ' + str(minim) + ', ' + str(maxim) + ', ' + str(step) + ', \'' + units + '\', \'' + form_submit_button_id + '\')'"
+                   onkeypress="return validate_float_keypress(this, event, 2)"/>
+            <span tal:replace="units"/>
+           </span>
+          </span>
           
           
           
@@ -820,14 +856,23 @@
            <select tal:define="prop_options prop/value"
                    tal:attributes="name p">
             <span tal:omit-tag="" 
+                  tal:condition="python: prop_units != 'bytes'"
                   tal:repeat="prop_opt prop_options">
              <option tal:attributes="value prop_opt"/><span tal:replace="prop_opt"/>
             </span>
+            <span tal:omit-tag="" 
+                  tal:condition="python: prop_units == 'bytes'"
+                  tal:repeat="prop_opt prop_options">
+             <option tal:attributes="value prop_opt"/><span tal:define="dummy python: here.bytes_to_value_units(prop_opt);
+                                                                        value python: str(dummy[0]) + ' ' + str(dummy[1])"
+                                                            tal:replace="value"/>
+            </span>
            </select>
           </span>
          </td>
          <td>
-          <span tal:replace="prop_units"/>
+          <span tal:condition="python: prop_units != 'bytes'"
+                tal:replace="prop_units"/>
          </td>
         </tr>
        </table>
@@ -912,13 +957,15 @@
 
 // validations
 
-function validate_text(elem, timeout, illegal_chars, reserved_words, min_length, max_length)
+function validate_text(elem, timeout, illegal_chars, reserved_words, min_length, max_length, button_id)
 {
+   document.getElementById(button_id).disabled = true;
+   
    var value = elem.value;
    
    for (var i=0; i<value.length; i++) {
       if (illegal_chars.indexOf(value[i]) != -1) {
-         return;
+         //return;
          elem.className = 'validation_error';
          display_warning(elem, timeout, 'Illegal characters are: \'' + illegal_chars + '\'');
          return;
@@ -928,7 +975,7 @@
    var res_list = reserved_words.split(';');
    for (var i=0; i<res_list.length; i++) {
       if (value == res_list[i] && value != '') {
-         return;
+         //return;
          elem.className = 'validation_error';
          display_warning(elem, timeout, 'Reserved words are: ' + res_list);
          return;
@@ -936,55 +983,103 @@
    }
    
    if (value.length < min_length) {
-      return;
+      //return;
       elem.className = 'validation_error';
       display_warning(elem, timeout, 'Minimum length is ' + min_length);
       return;
    }
    
    if (value.length > max_length) {
-      return;
+      //return;
       elem.className = 'validation_error';
       display_warning(elem, timeout, 'Maximum length is ' + max_length);
       return;
    }
    
    elem.className = '';
+   document.getElementById(button_id).disabled = false;
 }
 
 
-function validate_int(elem, timeout, min, max, step)
+function validate_int(elem, timeout, min, max, step, units, button_id)
 {
-   var value = elem.value;
+   document.getElementById(button_id).disabled = true;
    
+   var value = elem.value;
    for (var i=0; i<value.length; i++) {
       if ('0123456789'.indexOf(value[i]) == -1) {
-         return;
+         //return;
          elem.className = 'validation_error';
          display_warning(elem, timeout, 'Only whole numbers are allowed');
          return;
       }
    }
    
-   value = ((value - 0) / step) * step;
+   min  = parseInt(min);
+   max  = parseInt(max);
+   step = parseInt(step);
+   if (step == 0)
+      step = 1;
+   value = parseInt(value);
+   value = (value / step) * step;
    
    if (value < min) {
-      return;
+      //return;
       elem.className = 'validation_error';
-      display_warning(elem, timeout, 'Minimum allowed value is ' + min);
+      display_warning(elem, timeout, 'Minimum allowed value is ' + min + ' ' + units);
       return;
    }
    
    if (value > max) {
-      return;
+      //return;
       elem.className = 'validation_error';
-      display_warning(elem, timeout, 'Maximum allowed value is ' + max);
+      display_warning(elem, timeout, 'Maximum allowed value is ' + max + ' ' + units);
       return;
    }
    
    elem.className = '';
+   document.getElementById(button_id).disabled = false;
 }
 
+function validate_float(elem, timeout, min, max, step, units, button_id)
+{
+   document.getElementById(button_id).disabled = true;
+   
+   var value = elem.value;
+   for (var i=0; i<value.length; i++) {
+      if ('0123456789.'.indexOf(value[i]) == -1) {
+         //return;
+         elem.className = 'validation_error';
+         display_warning(elem, timeout, 'Only whole digits and dot are allowed');
+         return;
+      }
+   }
+   
+   min  = parseFloat(min);
+   max  = parseFloat(max);
+   step = parseFloat(step);
+   if (step == 0.0)
+      step = 0.00001;
+   value = parseFloat(value);
+   value = (value / step) * step;
+   
+   if (value < min) {
+      //return;
+      elem.className = 'validation_error';
+      display_warning(elem, timeout, 'Minimum allowed value is ' + min + ' ' + units);
+      return;
+   }
+   
+   if (value > max) {
+      //return;
+      elem.className = 'validation_error';
+      display_warning(elem, timeout, 'Maximum allowed value is ' + max + ' ' + units);
+      return;
+   }
+   
+   elem.className = '';
+   document.getElementById(button_id).disabled = false;
+}
 
 
 function validate_text_keypress(elem, event, timeout, illegal_chars, max_length)
@@ -1034,6 +1129,38 @@
    return true;
 }
 
+function validate_float_keypress(elem, event, timeout)
+{
+   var ev = event;
+   if (!ev) ev = window.event;
+   var key = get_keycode(ev);
+   
+   if (key == 8 || key == 9) return true;
+   else if (ev.which) ;
+   else if (document.selection) ;
+   else return true;
+   
+   var ch = String.fromCharCode(key);
+   
+   if ('0123456789.'.indexOf(ch) == -1) {
+//      display_warning(elem, timeout, 'Only digits and dot are allowed');
+      return false;
+   }
+   
+   if (ch == '.') {
+      txt = elem.value;
+      c = 0;
+      for (i=0; i<txt.length; i++) {
+         if (txt[i] == '.')
+            c++;
+      }
+      if (c != 0)
+         return false;
+   }
+   
+   return true;
+}
+
 function get_keycode(ev)
 {
     if (ev.keyCode)
@@ -1093,8 +1220,10 @@
 function reset_form(form) {
    if (confirm('Do you really want to reset the form?')) {
       form.reset();
-      for (i=0; i<form.length; i++)
-          form.elements[i].className = '';
+      for (i=0; i<form.length; i++) {
+         form.elements[i].className = '';
+         form.elements[i].disabled  = false;
+      }
       return true;
    }
    return false;
@@ -1237,6 +1366,7 @@
                      bd_form_id                 python:prefix + 'bd_form';
                      select_content_id          python:prefix + 'select_content_id';
                      apply_button_id            python:prefix + 'apply_button_id';
+                     form_submit_button_id      apply_button_id;
                      content_span_id            python:prefix + 'content_span_id'">
     <form tal:attributes="id      bd_form_id;
                           method  string:get">
@@ -1460,7 +1590,8 @@
    <form tal:define="prefix                     prefix|mapper/mapper_id;
                      prefix                     python:prefix + '_';
                      mapper_form_id             python:prefix + 'mapper_form_id';
-                     apply_button_id            python:prefix + 'apply_button_id'"
+                     apply_button_id            python:prefix + 'apply_button_id';
+                     form_submit_button_id      apply_button_id"
          tal:attributes="id     mapper_form_id;
                          method string:get">
     <input tal:attributes="type  string:hidden; 
--- conga/luci/storage/validate_html	2006/06/30 17:00:02	1.1
+++ conga/luci/storage/validate_html	2006/10/06 22:08:13	1.2
@@ -12,6 +12,9 @@
 <span tal:omit-tag="" 
       tal:define="global action_type request/action_type|nothing"/>
 
+<span tal:omit-tag=""
+      tal:define="global preferred_size_units python:here.set_persistant_var('preferred_size_units', 'GB')"/>
+
 
 <span tal:omit-tag=""
       tal:condition="not: access_to_host_allowed">



             reply	other threads:[~2006-10-06 22:08 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-10-06 22:08 kupcevic [this message]
  -- strict thread matches above, loose matches on Subject: below --
2006-10-05 23:21 [Cluster-devel] conga/luci site/luci/Extensions/HelperFunction kupcevic

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20061006220817.3993.qmail@sourceware.org \
    --to=kupcevic@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.