[luci] Help with a map.parse function not displaying error messages
Chris Martin
chris at martin.cc
Mon Jul 12 04:55:04 CEST 2010
I am trying to validate all VLAN ids to ensure that the last 4 bytes are
unique, using the following parse function to perform the validation. The
parse function is based on an example the JoW provided (Thanks JoW)
The map has 3 NamedSections, and a TypedSection, as shown in the the
attached screen image
I have 2 issues
First - The error messages on line 64 & 68 are never displayed
Second - If conflicting VLAN IDs are configured in the TypedSection, only
one of the fields is maked in red
I would really appreciate if someone could take a look at this. I have
looked over both cbi.lua and uvl.lua and I just can't see what I am doing
wrong. Any comments / insights will be greatly appreciated.
1. -- Load the vlan config file
2. m = Map("vlans", "VLANs", "")
3.
4. -- override the parse function
5. function m.parse(self, ...)
6.
7. -- do custom processing before we call the origional parse routine
8. -- that way we can turn off the ".save" flag
9.
10. -- only do custom processing if we are being asked to save the config
11. if self.save then
12. local section_obj
13.
14. -- empty table, to be populated as we process each vlan slot
15. local vlan_table = {}
16.
17. -- loop over each section
18. for _, section_obj in ipairs(self.children) do
19.
20. local section_ids -- NOTE: there may be more than 1 Id, (expecially
TypesSections)
21. -- check section type
22. if util.instanceof(section_obj, NamedSection) then
23. -- this is a named section,
24. -- the uci id of this section is
25. -- stored in section_obj.section
26. section_ids = { section_obj.section }
27. elseif util.instanceof(section_obj, TypedSection) then
28. -- this is a typed section,
29. -- it may map to multiple uci ids
30. section_ids = section_obj:cfgsections()
31. end
32.
33. -- now validate the fields within this section
34. -- for each associated config section
35.
36. local sid
37.
38. for _, sid in ipairs(section_ids) do
39. local fld
40. for _, fld in ipairs(section_obj.children) do
41. -- get the value for a specific field in the section.
42. -- I am only interested in the VLAN ID field for now
43. if fld.option == "id" then
44. -- do the custom checks on the vlan ID,
45. -- The last 4 bits of each Vlan ID MUST be unique as There are only
16 slots in the the switch Vlan table.
46. -- If two vlans have the last 4 bits the same the second will
overwrite the first
47. local vlan_id = fld:formvalue(sid)
48. if vlan_id ~= nil then
49. local vlan_index = vlan_id % 16
50. local vlan_entry = vlan_table[vlan_index]
51. if vlan_entry == nil then
52. vlan_table[vlan_index] = {}
53. vlan_table[vlan_index].sid = sid
54. vlan_table[vlan_index].fld = fld
55. vlan_table[vlan_index].vlan_id = vlan_id
56. else
57. -- The slot is already occupied
58. -- So don't save this config
59. self.save = false
60. -- set the error massage
61. if fld.error == nil then
62. fld.error = {}
63. end
64. fld.error[sid] = "The last 4 bits of Vlan ID "..vlan_id.."
conflicts with vlan id ".. vlan_entry.vlan_id
65. if vlan_entry.fld.error == nil then
66. vlan_entry.fld.error = {}
67. end
68. vlan_entry.fld.error[vlan_entry.sid]
= "The last 4 bits of VLAN ID "..vlan_entry.vlan_id.." conflicts with VLAN
Id "..vlan_id
69. end
70. end
71. end
72. end
73. end
74. end
75. end
76.
77. -- call the original function
78. Map.parse(self, ...)
79.
80. end
Cheers
----------------------------------------------------------
Chris Martin
m: 0419812371
----------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.subsignal.org/pipermail/luci/attachments/20100712/9f90bb39/attachment-0001.htm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vlans.jpg
Type: image/jpeg
Size: 53604 bytes
Desc: not available
Url : http://lists.subsignal.org/pipermail/luci/attachments/20100712/9f90bb39/attachment-0001.jpg
More information about the luci
mailing list