-sip_table = cbimap:section(Table, sip_peers, "SIP Trunks")
-sip_table.template = "cbi/tblsection"
-sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
+sip_table = cbimap:section(TypedSection, "sip", "SIP Trunks")
+sip_table.template = "cbi/tblsection"
+sip_table.extedit = luci.dispatcher.build_url("admin", "asterisk", "trunks", "sip", "%s")
+sip_table.addremove = true
+
+sip_table.hidden = {
+ type = "peer",
+ qualify = "yes"
+}
+
+function sip_table.filter(self, s)
+ return s and (
+ cbimap.uci:get("asterisk", s, "type") == "peer" or
+ cbimap.uci:get("asterisk", s, "type") == nil
+ )
+end
+
+function sip_table.create(self, section)
+ if TypedSection.create(self, section) then
+ created = section
+ else
+ self.invalid_cts = true
+ end
+end
+
+function sip_table.parse(self, ...)
+ TypedSection.parse(self, ...)
+ if created then
+ cbimap.uci:save("asterisk")
+ luci.http.redirect(luci.dispatcher.build_url(
+ "admin", "asterisk", "trunks", "sip", created
+ ))
+ end
+end
+