Torsten Irländer avatar Torsten Irländer committed 247001b Merge

Merged.

Comments (0)

Files changed (13)

 =====
 - Added "time" fields. Will take the time in the form "HH:MM:SS" and converts
   it into the total amount of seconds.
+- Fixed error in rule evaluation with non ascii values. The values are now
+  converted to ascii (non ascii values are replace with '?') before
+  evaluating.
 
 0.4.2
 =====

examples/bootstrap/css/formbar.css

 /* Formbar Style */
 
 /* Make all field elements expand to 100% on default */
-input, select, textarea {
+.formbar-form input, select, textarea {
   width: 100%;
   /* Fix width and height of the fields by setting it to the border-box modell
    * (CSS3) Does not work in IE */
                 token = values.get(token.strip('$'))
                 if isinstance(token, basestring):
                     token = "'%s'" % token
-            rule.append(str(token))
+            try:
+                rule.append(str(token))
+            except UnicodeEncodeError:
+                # eval only seems to like ascii strings. Convert
+                # it to ascii before actually evaluate it. Replace non
+                # ascii chars
+                rule.append(token.encode("ascii","replace"))
         try:
-            rule_str = " ".join(rule)
+            rule_str = u" ".join(rule)
             result = eval(rule_str)
             log.debug("Rule: %s -> %s" % (rule_str, result))
             return result
         except Exception, e:
             log.error(
-                'Evaluation of "%s" failed with error "%s"' % (rule, e))
+                'Evaluation of "%s" failed with error "%s"' % (rule_str, e))
             return False
 
 

formbar/templates/datefield.mako

+% if field.is_readonly():
+  <div class="readonlyfield">
+    ${field.get_value("")}
+  </div>
+% else:
+  <input class="formbar-datepicker" type="text" name="${field.name}" value="${field.get_value()}"/>
+% endif

formbar/templates/dropdown.mako

 % if field.is_readonly():
-  <div class="readonlyfield">
+  <div class="readonlyfield" name="${field.name}">
     ${field.get_value(expand=True) or "&nbsp;"}
   </div>
 % else:
-  <select name="${field.name}">
+  <select id="${field.id}" name="${field.name}">
     % for option in field.get_options():
       <option value="${option[1]}">${option[0]}</option>
     % endfor

formbar/templates/filefield.mako

 % if field.is_readonly():
-  <div class="readonlyfield">
+  <div class="readonlyfield" name="${field.name}">
   </div>
 % else:
   <input id="${field.id}" name="${field.name}" type="file" value=""/>

formbar/templates/formbar.js

 /*
  * Evaluate when values in the form changes 
 */
-$('div.formbar-form form input').change(function() {
+evaluateFields();
+$('div.formbar-form form input').change(evaluateFields);
+
+function evaluateFields() {
     var fieldsToEvaluate = $('.formbar-evaluate');
     for (var i = fieldsToEvaluate.length - 1; i >= 0; i--){
         var field = fieldsToEvaluate[i];
         var tokens = expr.split(" ");
         var eval_expr = "";
         for (var j = tokens.length - 1; j >= 0; j--){
-            var tfield = null
-            var value = null
+            var tfield = null;
+            var value = null;
             if (tokens[j].contains("$")) {
                 tfield = tokens[j].replace('$', '');
                 value = $('input[name='+tfield+']').val();
+                // If we can not get a value from an input fields the field my
+                // be readonly. So get the value from the readonly element.
+                if (!value) {
+                    value = $('div[name='+tfield+']').text();
+                }
                 console.log(tokens[j].replace('$', ''));
                 eval_expr += value;
             } else {
                 eval_expr += tokens[j];
             }
-        };
+        }
         try {
             var eval_value = eval(eval_expr);
             $('#'+id).text(eval_value);
             console.log(e);
             $('#'+id).text("");
         }
-    };
-});
+    }
+}

formbar/templates/password.mako

 % if field.is_readonly():
-  <div class="readonlyfield">
+  <div class="readonlyfield" name="${field.name}">
     ${field.get_value("")}
   </div>
 % else:
-  <input type="password" name="${field.name}" value="${field.get_value()}"/>
+  <input type="password" id="${field.id}" name="${field.name}" value="${field.get_value()}"/>
 % endif

formbar/templates/selection.mako

 % if field.is_readonly():
-  <div class="readonlyfield">
+  <div class="readonlyfield" name="${field.name}">
     ${field.get_value(expand=True) or "&nbsp;"}
   </div>
 % else:
-  <select name="${field.name}" size="5" multiple>
+  <select id="${field.id}" name="${field.name}" size="5" multiple>
     % for option in field.get_options():
       <option value="${option[1]}">${option[0]}</option>
     % endfor

formbar/templates/textarea.mako

 % if field.is_readonly():
-  <div class="readonlyfield">
+  <div class="readonlyfield" name="${field.name}">
     ${field.get_value("").replace('\n', '<br>')}
   </div>
 % else:
-  <textarea name="${field.name}">${field.get_value()}</textarea>
+  <textarea id="${field.id}" name="${field.name}">${field.get_value()}</textarea>
 % endif

formbar/templates/textfield.mako

 % if field.is_readonly():
-  <div class="readonlyfield">
+  <div class="readonlyfield" name="${field.name}">
     ${field.get_value("")}
   </div>
 % else:
-  <input type="text" name="${field.name}" value="${field.get_value()}"/>
+  <input type="text" id="${field.id}" name="${field.name}" value="${field.get_value()}"/>
 % endif
       multiple rows. Further the will check if there are further html
       tags allowed.</help>
     </entity>
-    <entity id="e4" name="date" label="Date field" type="date" autocomplete="off" css="datefield" number="1" readonly="true">
+    <entity id="e4" name="date" label="Date field" type="date" autocomplete="off" css="datefield" number="1">
       <help>This is my helptext</help>
     </entity>
     <entity id="e8" name="select">
   </form>
   <form id="testform">
   </form>
-  <form id="customform" css="testcss" readonly="true" autocomplete="off" method="GET" action="http://" enctype="multipart/form-data">
+  <form id="customform" css="testcss" readonly="false" autocomplete="off" method="GET" action="http://" enctype="multipart/form-data">
     <row>
       <col><field ref="e1"/></col>
     </row>
       <col><field ref="e2"/></col>
     </row>
   </snippet>
+  <form id="customform-readonly" css="testcss" readonly="false" autocomplete="off" method="GET" action="http://" enctype="multipart/form-data">
+    <row>
+      <col><field ref="e1"/></col>
+    </row>
+    <snippet ref="s1"/>
+  </form>
 </configuration>

test/test_configparser.py

         self.assertEqual(self.dform.readonly, False)
 
     def test_readonly_custom(self):
-        self.assertEqual(self.cform.readonly, True)
+        self.assertEqual(self.cform.readonly, False)
 
     def test_id_default(self):
         self.assertEqual(self.dform.id, 'testform')
         self.assertEqual(self.sfield.readonly, False)
 
     def test_readonly_custom(self):
-        self.assertEqual(self.dfield.readonly, True)
+        self.assertEqual(self.dfield.readonly, False)
 
     def test_css_default(self):
         self.assertEqual(self.dfield.css, '')
         self.assertEqual(self.cfield.number, '1')
 
     def test_type_default(self):
-        self.assertEqual(self.dfield.type, 'string')
+        self.assertEqual(self.dfield.type, None)
 
     def test_type_custom(self):
         self.assertEqual(self.cfield.type, 'date')
         self.assertEqual(len(self.dfield.rules), 0)
 
     def test_rules_custom(self):
-        self.assertEqual(len(self.ifield.rules), 2)
+        self.assertEqual(len(self.ifield.rules), 1)
 
 if __name__ == '__main__':
     unittest.main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.