cbi: Increare responsiveness of "Save & Apply"
[project/luci.git] / libs / cbi / luasrc / cbi.lua
index 7cde3c9..09ba553 100644 (file)
@@ -110,28 +110,8 @@ local function _uvl_validate_section(node, name)
        local stat, err = node.map.validator:validate_section(node.config, name, co)
        if err then
                node.map.save = false
-
                tag_fields(err)
                tag_section(err)
---[[
-               if err:is(luci.uvl.errors.ERR_DEPENDENCY) then
-                       node.tag_deperror[name] = err:string()
-               else
-                       node.tag_invalid[name] = err:string()
-               end
-               for i, v in ipairs(err.childs) do
-                       if v.option and node.fields[v.option] then
-                               if v:is(luci.uvl.errors.ERR_DEPENDENCY) then
-                                       node.fields[v.option].tag_deperror[name] = v:string()
-                               elseif v:is(luci.uvl.errors.ERR_OPT_REQUIRED) then
-                                       node.fields[v.option].tag_missing[name] = v:string()
-                                       node.tag_reqerror[name] = v:string()
-                               elseif v:is(luci.uvl.errors.ERR_OPTION) then
-                                       node.fields[v.option].tag_invalid[name] = v:string()
-                               end
-                       end
-               end
-]]
        end
 
 end
@@ -231,6 +211,7 @@ function Map.__init__(self, config, ...)
        self.config = config
        self.parsechain = {self.config}
        self.template = "cbi/map"
+       self.apply_on_parse = nil
        self.uci = uci.cursor()
        self.save = true
        if not self.uci:load(self.config) then
@@ -268,11 +249,18 @@ function Map.parse(self, ...)
                if luci.http.formvalue("cbi.apply") then
                        for i, config in ipairs(self.parsechain) do
                                self.uci:commit(config)
-                               self.uci:apply(config)
 
                                -- Refresh data because commit changes section names
                                self.uci:load(config)
                        end
+                       if self.apply_on_parse then
+                               self.uci:apply(self.parsechain)
+                       else
+                               self._apply = function()
+                                       local cmd = self.uci:apply(self.parsechain, true)
+                                       return io.popen(cmd)
+                               end
+                       end
 
                        -- Reparse sections
                        Node.parse(self, ...)
@@ -284,6 +272,15 @@ function Map.parse(self, ...)
        end
 end
 
+function Map.render(self, ...)
+       Node.render(self, ...)
+       if self._apply then
+               local fp = self._apply()
+               fp:read("*a")
+               fp:close()
+       end
+end
+
 -- Creates a child section
 function Map.section(self, class, ...)
        if instanceof(class, AbstractSection) then