module(..., package.seeall) -- Set variables local cfgfile -- ################################################################################ -- LOCAL FUNCTIONS local function list_redir (self) self.conf.action = "status" self.conf.type = "redir" error(self.conf) end -- ################################################################################ -- PUBLIC FUNCTIONS mvc={} function mvc.on_load (self, parent) cfgfile = self:new("cfgfile") if (self.worker[self.conf.action] == nil) or (self.conf.action == "init") then self.worker[self.conf.action] = list_redir(self) end end function status (self) local cmd = self.clientdata.cmd local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller local status, errors = self.model:getstatus() return ( {status = status, errors = errors, lbustatus = self.model:list(), url = url, } ) end function config (self) local errors = {} local cmdresult if (self.clientdata.cmd_delete_excluded) and (self.clientdata.lbu_excluded) then cmdresult = self.model:lbuincexcl("exclude", self.clientdata.lbu_excluded, "remove") end if (self.clientdata.cmd_delete_included) and (self.clientdata.lbu_included) then cmdresult = self.model:lbuincexcl("include", self.clientdata.lbu_included, "remove") end if (self.clientdata.config_submit) then local variables="ENCRYPTION LBU_MEDIA DEFAULT_CIPHER PASSWORD" cmdresult = {} for var in string.gmatch(variables, "%S+") do cmdresult[var] = self.model:editconfig(var, self.clientdata[var], "change_value") end end if (self.clientdata.cmd_add_included) and (self.clientdata.item_add_included) then cmdresult = self.model:lbuincexcl("include", self.clientdata.item_add_included, "add") end if (self.clientdata.cmd_add_excluded) and (self.clientdata.item_add_excluded) then cmdresult = self.model:lbuincexcl("exclude", self.clientdata.item_add_excluded, "add") end local config = self.model:getconfig() -- This needs to be done /after/ the editing of the config (done earlier in this code) local status = self.model:getstatus() -- Add submit and other buttons config["cmd_delete_included"] = cfe({ name="cmd_delete_included", value="Delete", label="Delete selected included-item", type="submit", descr="Mark a item in '" .. config.lbu_included.label .. "'-list before pressing [Delete]", }) config["item_add_included"] = cfe({ name="item_add_included", label="Item to add to included-list", }) config["cmd_add_included"] = cfe({ name="cmd_add_included", value="Add", label="Add the item into the included-list", type="submit", descr="Enter a value in '" .. config.item_add_included.label .. "'-input before pressing [Add]", }) config["cmd_delete_excluded"] = cfe({ name="cmd_delete_excluded", value="Delete", label="Delete selected excluded-item", type="submit", descr="Mark a item in '" .. config.lbu_excluded.label .. "'-list before pressing [Delete]", }) config["item_add_excluded"] = cfe({ name="item_add_excluded", label="Item to add to excluded-list", }) config["cmd_add_excluded"] = cfe({ name="cmd_add_excluded", value="Add", label="Add the item into the excluded-list", type="submit", descr="Enter a value in '" .. config.item_add_excluded.label .. "'-input before pressing [Add]", }) config["config_submit"] = cfe({ name="config_submit", value="Apply", label="Apply above settings", type="submit", }) if (self.clientdata.config_submit) then config.config_submit.descr="* Changes has been saved!" end -- Disable buttons/commands that is usable for som reason if (config.lbu_included.option) and (#config.lbu_included.option == 0) then config.cmd_delete_included.disabled= "yes" config.cmd_delete_included.descr= "" end if (config.lbu_excluded.option) and (#config.lbu_excluded.option == 0) then config.cmd_delete_excluded.disabled= "yes" config.cmd_delete_excluded.descr= "" end local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller return ( {status = status, cmdresult = cmdresult, errors = errors, clientdata = self.clientdata, config = config, url = url, } ) end function commit(self) local cmdresult, cmderror local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller local cmdflag = nil if (self.clientdata.lbucleanmedia) then cmdflag = "-d" else cmdflag = "" end if (self.clientdata.lbusimulate) then cmdresult, cmderror = self.model:getsimulate(cmdflag) end if (self.clientdata.lbucommit) then cmdresult, cmderror = self.model:getcommit(cmdflag) end -- If no clientdata then do a dryrun and see if it's going to work else report if not (cmdresult) then tmp_cmdresult, cmderror = self.model:getsimulate() end local status, errors = self.model:getstatus() -- Add buttons status["lbusimulate"] = cfe({ name="lbusimulate", value="Simulate", label="Simulate/Test a commit", type="submit", }) status["lbucommit"] = cfe({ name="lbucommit", value="Commit", label="Actually commit and save changes", type="submit", }) if (cmderror["-d"]) then status["lbucleanmedia"] = cfe({ name="lbucleanmedia", value="lbucleanmedia", label="Remove existing apk.ovls from media", type="checkbox", }) end return ( {status = status, cmdresult = cmdresult, cmdflag = cmdflag, cmderror = cmderror, clientdata = self.clientdata, url = url, } ) end function expert (self) local modifications = self.clientdata.filecontent or "" if ( self.clientdata.cmdsave) then modifications = self.model:update_filecontent(modifications) end local status = self.model.getstatus() local file = self.model:get_filedetails() -- Add submit and other buttons file["cmdsave"] = cfe({ name="cmdsave", value="Apply", label="Apply settings", type="submit", }) if (self.clientdata.cmdsave) then file.cmdsave.descr="* Changes has been saved!" end local url = ENV["SCRIPT_NAME"] .. self.conf.prefix .. self.conf.controller return { file = file, status = status, clientdata = self.clientdata, url = url, } end