Optimized UVL validation handling
authorSteven Barth <steven@midlink.org>
Sat, 30 Aug 2008 12:11:27 +0000 (12:11 +0000)
committerSteven Barth <steven@midlink.org>
Sat, 30 Aug 2008 12:11:27 +0000 (12:11 +0000)
i18n/english/luasrc/i18n/cbi.en.lua
i18n/english/luasrc/i18n/cbi.en.xml
i18n/german/luasrc/i18n/cbi.de.lua
i18n/german/luasrc/i18n/cbi.de.xml
libs/cbi/luasrc/cbi.lua

index 6b1168e..14d6309 100644 (file)
@@ -1,10 +1,10 @@
 cbi_add = [[Add entry]]
 cbi_del = [[Remove entry]]
-cbi_invalid = [[<strong>Error:</strong> Invalid input value]]
-cbi_invalid_section = [[<strong>Error:</strong> Validation failed]]
-cbi_missing = [[<strong>Error:</strong> This field is mandatory]]
-cbi_deperror = [[<strong>Error:</strong> At least one mandatory field has no or an invalid value]]
-cbi_reqerror = [[<strong>Error:</strong> A requirement for this option was not met]]
+cbi_invalid = [[Invalid input value]]
+cbi_invalid_section = [[<strong>Validation failed:</strong> Please check any input fields for mistakes.]]
+cbi_missing = [[This field is mandatory]]
+cbi_deperror = [[<strong>Validation failed:</strong> At least one mandatory field has no or an invalid value]]
+cbi_reqerror = [[A requirement for this option was not met]]
 cbi_addopt = [[-- Additional Field --]]
 cbi_optional = [[ (optional)]]
 cbi_sectempty = [[This section contains no values yet]]
index 35599d8..89484e4 100644 (file)
@@ -4,11 +4,11 @@
 
 <i18n:msg xml:id="cbi_add">Add entry</i18n:msg>
 <i18n:msg xml:id="cbi_del">Remove entry</i18n:msg>
-<i18n:msg xml:id="cbi_invalid"><strong>Error:</strong> Invalid input value</i18n:msg>
-<i18n:msg xml:id="cbi_invalid_section"><strong>Error:</strong> Validation failed</i18n:msg>
-<i18n:msg xml:id="cbi_missing"><strong>Error:</strong> This field is mandatory</i18n:msg>
-<i18n:msg xml:id="cbi_deperror"><strong>Error:</strong> At least one mandatory field has no or an invalid value</i18n:msg>
-<i18n:msg xml:id="cbi_reqerror"><strong>Error:</strong> A requirement for this option was not met</i18n:msg>
+<i18n:msg xml:id="cbi_invalid">Invalid input value</i18n:msg>
+<i18n:msg xml:id="cbi_invalid_section"><strong>Validation failed:</strong> Please check any input fields for mistakes.</i18n:msg>
+<i18n:msg xml:id="cbi_missing">This field is mandatory</i18n:msg>
+<i18n:msg xml:id="cbi_deperror"><strong>Validation failed:</strong> At least one mandatory field has no or an invalid value</i18n:msg>
+<i18n:msg xml:id="cbi_reqerror">A requirement for this option was not met</i18n:msg>
 <i18n:msg xml:id="cbi_addopt">-- Additional Field --</i18n:msg>
 <i18n:msg xml:id="cbi_optional"> (optional)</i18n:msg>
 <i18n:msg xml:id="cbi_sectempty">This section contains no values yet</i18n:msg>
index 075ed83..968d31c 100644 (file)
@@ -1,10 +1,10 @@
 cbi_add = [[Eintrag hinzufügen]]
 cbi_del = [[Eintrag entfernen]]
-cbi_invalid = [[Fehler: Ungültige Eingabe]]
-cbi_invalid_section = [[<strong>Fehler:</strong> Validierung fehlgeschlagen]]
-cbi_missing = [[Fehler: Dieses Feld muss ausgefüllt werden]]
-cbi_deperror = [[<strong>Fehler:</strong> Mindestens ein benötigtes Feld ist leer oder hat einen ungültigen Wert]]
-cbi_reqerror = [[<strong>Fehler:</strong> Nicht erfüllte Abhängigkeit für dieses Feld]]
+cbi_invalid = [[Ungültige Eingabe]]
+cbi_invalid_section = [[<strong>Validierung fehlgeschlagen:</strong> Bitte die Eingabefelder auf Fehler überprüfen.]]
+cbi_missing = [[Dieses Feld muss ausgefüllt werden]]
+cbi_deperror = [[<strong>Validierung fehlgeschlagen:</strong> Mindestens ein benötigtes Feld ist leer oder hat einen ungültigen Wert]]
+cbi_reqerror = [[Nicht erfüllte Abhängigkeit für dieses Feld]]
 cbi_addopt = [[-- Zusätzliches Feld --]]
 cbi_sectempty = [[Diese Sektion enthält noch keine Einträge]]
 cbi_manual = [[-- benutzerdefiniert --]]
index e1ecd2d..dd37f2f 100644 (file)
@@ -4,11 +4,11 @@
 
 <i18n:msg xml:id="cbi_add">Eintrag hinzufügen</i18n:msg>
 <i18n:msg xml:id="cbi_del">Eintrag entfernen</i18n:msg>
-<i18n:msg xml:id="cbi_invalid">Fehler: Ungültige Eingabe</i18n:msg>
-<i18n:msg xml:id="cbi_invalid_section"><strong>Fehler:</strong> Validierung fehlgeschlagen</i18n:msg>
-<i18n:msg xml:id="cbi_missing">Fehler: Dieses Feld muss ausgefüllt werden</i18n:msg>
-<i18n:msg xml:id="cbi_deperror"><strong>Fehler:</strong> Mindestens ein benötigtes Feld ist leer oder hat einen ungültigen Wert</i18n:msg>
-<i18n:msg xml:id="cbi_reqerror"><strong>Fehler:</strong> Nicht erfüllte Abhängigkeit für dieses Feld</i18n:msg>
+<i18n:msg xml:id="cbi_invalid">Ungültige Eingabe</i18n:msg>
+<i18n:msg xml:id="cbi_invalid_section"><strong>Validierung fehlgeschlagen:</strong> Bitte die Eingabefelder auf Fehler überprüfen.</i18n:msg>
+<i18n:msg xml:id="cbi_missing">Dieses Feld muss ausgefüllt werden</i18n:msg>
+<i18n:msg xml:id="cbi_deperror"><strong>Validierung fehlgeschlagen:</strong> Mindestens ein benötigtes Feld ist leer oder hat einen ungültigen Wert</i18n:msg>
+<i18n:msg xml:id="cbi_reqerror">Nicht erfüllte Abhängigkeit für dieses Feld</i18n:msg>
 <i18n:msg xml:id="cbi_addopt">-- Zusätzliches Feld --</i18n:msg>
 <i18n:msg xml:id="cbi_sectempty">Diese Sektion enthält noch keine Einträge</i18n:msg>
 <i18n:msg xml:id="cbi_manual">-- benutzerdefiniert --</i18n:msg>
index 9c5501d..6740141 100644 (file)
@@ -78,8 +78,37 @@ function load(cbimap, ...)
        return maps
 end
 
+local function _uvl_validate_section(node, name)
+       local co = node.map:get()
+       luci.uvl.STRICT_UNKNOWN_OPTIONS = false
+       local stat, err = node.map.validator:validate_section(node.config, name, co)
+       if err then
+               node.map.save = false
+               if err.code == luci.uvl.errors.ERR_DEPENDENCY then
+                       node.tag_deperror[name] = true
+               else
+                       node.tag_invalid[name] = true
+               end
+               for i, v in ipairs(err.childs) do
+                       if v.option and node.fields[v.option] then
+                               if v.code == luci.uvl.errors.ERR_OPTION then
+                                       local subcode = v.childs and v.childs[1] and v.childs[1].code
+                                       if subcode == luci.uvl.errors.ERR_DEPENDENCY then
+                                               node.fields[v.option].tag_reqerror[name] = true
+                                       elseif subcode == luci.uvl.errors.ERR_OPT_REQUIRED then
+                                               node.fields[v.option].tag_missing[name] = true
+                                               node.tag_deperror[name] = true
+                                       else
+                                               node.fields[v.option].tag_invalid[name] = true
+                                       end
+                               end
+                       end
+               end
+       end
+
+end
 
-function _uvl_strip_remote_dependencies(deps)
+local function _uvl_strip_remote_dependencies(deps)
        local clean = {}
 
        for k, v in pairs(deps) do
@@ -626,25 +655,7 @@ function NamedSection.parse(self)
                        Node.parse(self, s)
                        
                        if not self.override_scheme and self.map.scheme then
-                               local co = self.map:get()
-                               local stat, err = self.map.validator:validate_section(self.config, s, co)
-                               if err then
-                                       --self.map.save = false
-                                       if err.code == luci.uvl.errors.ERR_DEPENDENCY then
-                                               self.tag_deperror[s] = true
-                                       else
-                                               self.tag_invalid[s] = true
-                                       end
-                                       for i, v in ipairs(err.childs) do
-                                               if v.option and self.fields[v.option] then
-                                                       if v.code == luci.uvl.errors.ERR_DEPENDENCY then
-                                                               self.fields[v.option].tag_reqerror[s] = true
-                                                       elseif v.code == luci.uvl.errors.ERR_OPTION then
-                                                               self.fields[v.option].tag_invalid[s] = true
-                                                       end
-                                               end
-                                       end
-                               end
+                               _uvl_validate_section(self, s)
                        end
                end
                AbstractSection.parse_optionals(self, s)
@@ -716,25 +727,7 @@ function TypedSection.parse(self)
                        Node.parse(self, k)
                        
                        if not self.override_scheme and self.map.scheme then
-                               local co = self.map:get()
-                               local stat, err = self.map.validator:validate_section(self.config, k, co)
-                               if err then
-                                       --self.map.save = false
-                                       if err.code == luci.uvl.errors.ERR_DEPENDENCY then
-                                               self.tag_deperror[k] = true
-                                       else
-                                               self.tag_invalid[k] = true
-                                       end
-                                       for i, v in ipairs(err.childs) do
-                                               if v.option and self.fields[v.option] then
-                                                       if v.code == luci.uvl.errors.ERR_DEPENDENCY then
-                                                               self.fields[v.option].tag_reqerror[k] = true
-                                                       elseif v.code == luci.uvl.errors.ERR_OPTION then
-                                                               self.fields[v.option].tag_invalid[k] = true
-                                                       end
-                                               end
-                                       end
-                               end
+                               _uvl_validate_section(self, k)
                        end
                end
                AbstractSection.parse_optionals(self, k)