From: Steven Barth Date: Sat, 30 Aug 2008 12:11:27 +0000 (+0000) Subject: Optimized UVL validation handling X-Git-Tag: 0.8.0~239 X-Git-Url: https://git.archive.openwrt.org/?p=project%2Fluci.git;a=commitdiff_plain;h=055cef53361aad1135dddc789352f832832828b0 Optimized UVL validation handling --- diff --git a/i18n/english/luasrc/i18n/cbi.en.lua b/i18n/english/luasrc/i18n/cbi.en.lua index 6b1168e2e..14d630901 100644 --- a/i18n/english/luasrc/i18n/cbi.en.lua +++ b/i18n/english/luasrc/i18n/cbi.en.lua @@ -1,10 +1,10 @@ cbi_add = [[Add entry]] cbi_del = [[Remove entry]] -cbi_invalid = [[Error: Invalid input value]] -cbi_invalid_section = [[Error: Validation failed]] -cbi_missing = [[Error: This field is mandatory]] -cbi_deperror = [[Error: At least one mandatory field has no or an invalid value]] -cbi_reqerror = [[Error: A requirement for this option was not met]] +cbi_invalid = [[Invalid input value]] +cbi_invalid_section = [[Validation failed: Please check any input fields for mistakes.]] +cbi_missing = [[This field is mandatory]] +cbi_deperror = [[Validation failed: 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]] diff --git a/i18n/english/luasrc/i18n/cbi.en.xml b/i18n/english/luasrc/i18n/cbi.en.xml index 35599d87e..89484e4ae 100644 --- a/i18n/english/luasrc/i18n/cbi.en.xml +++ b/i18n/english/luasrc/i18n/cbi.en.xml @@ -4,11 +4,11 @@ Add entry Remove entry -Error: Invalid input value -Error: Validation failed -Error: This field is mandatory -Error: At least one mandatory field has no or an invalid value -Error: A requirement for this option was not met +Invalid input value +Validation failed: Please check any input fields for mistakes. +This field is mandatory +Validation failed: At least one mandatory field has no or an invalid value +A requirement for this option was not met -- Additional Field -- (optional) This section contains no values yet diff --git a/i18n/german/luasrc/i18n/cbi.de.lua b/i18n/german/luasrc/i18n/cbi.de.lua index 075ed834a..968d31cff 100644 --- a/i18n/german/luasrc/i18n/cbi.de.lua +++ b/i18n/german/luasrc/i18n/cbi.de.lua @@ -1,10 +1,10 @@ cbi_add = [[Eintrag hinzufügen]] cbi_del = [[Eintrag entfernen]] -cbi_invalid = [[Fehler: Ungültige Eingabe]] -cbi_invalid_section = [[Fehler: Validierung fehlgeschlagen]] -cbi_missing = [[Fehler: Dieses Feld muss ausgefüllt werden]] -cbi_deperror = [[Fehler: Mindestens ein benötigtes Feld ist leer oder hat einen ungültigen Wert]] -cbi_reqerror = [[Fehler: Nicht erfüllte Abhängigkeit für dieses Feld]] +cbi_invalid = [[Ungültige Eingabe]] +cbi_invalid_section = [[Validierung fehlgeschlagen: Bitte die Eingabefelder auf Fehler überprüfen.]] +cbi_missing = [[Dieses Feld muss ausgefüllt werden]] +cbi_deperror = [[Validierung fehlgeschlagen: 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 --]] diff --git a/i18n/german/luasrc/i18n/cbi.de.xml b/i18n/german/luasrc/i18n/cbi.de.xml index e1ecd2df6..dd37f2f49 100644 --- a/i18n/german/luasrc/i18n/cbi.de.xml +++ b/i18n/german/luasrc/i18n/cbi.de.xml @@ -4,11 +4,11 @@ Eintrag hinzufügen Eintrag entfernen -Fehler: Ungültige Eingabe -Fehler: Validierung fehlgeschlagen -Fehler: Dieses Feld muss ausgefüllt werden -Fehler: Mindestens ein benötigtes Feld ist leer oder hat einen ungültigen Wert -Fehler: Nicht erfüllte Abhängigkeit für dieses Feld +Ungültige Eingabe +Validierung fehlgeschlagen: Bitte die Eingabefelder auf Fehler überprüfen. +Dieses Feld muss ausgefüllt werden +Validierung fehlgeschlagen: Mindestens ein benötigtes Feld ist leer oder hat einen ungültigen Wert +Nicht erfüllte Abhängigkeit für dieses Feld -- Zusätzliches Feld -- Diese Sektion enthält noch keine Einträge -- benutzerdefiniert -- diff --git a/libs/cbi/luasrc/cbi.lua b/libs/cbi/luasrc/cbi.lua index 9c5501d69..6740141ac 100644 --- a/libs/cbi/luasrc/cbi.lua +++ b/libs/cbi/luasrc/cbi.lua @@ -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)