Merge pull request #1311 from dibdot/dnscrypt-proxy
[project/luci.git] / applications / luci-app-travelmate / luasrc / model / cbi / travelmate / wifi_order.lua
1 -- Copyright 2017 Dirk Brenken (dev@brenken.org)
2 -- This is free software, licensed under the Apache License, Version 2.0
3
4 local http = require("luci.http")
5 local cfg = http.formvalue("cfg")
6 local dir = http.formvalue("dir")
7 local uci = require("luci.model.uci").cursor()
8 local trmiface = uci:get("travelmate", "global", "trm_iface") or "trm_wwan"
9
10 if cfg ~= nil then
11         local section = ""
12         local idx = ""
13         local idx_change = ""
14         local changed = ""
15         uci:foreach("wireless", "wifi-iface", function(s)
16                 local iface = s.network or ""
17                 if iface == trmiface then
18                         section = s['.name']
19                         if cfg == section then
20                                 idx = s['.index']
21                         else
22                                 idx_change = s['.index']
23                         end
24                         if (dir == "up" and idx ~= "" and idx_change ~= "" and idx_change < idx) or
25                                 (dir == "down" and idx ~= "" and idx_change ~= "" and idx_change > idx) then
26                                 changed = uci:reorder("wireless", cfg, idx_change)
27                                 idx = ""
28                         end
29                 end
30         end)
31         if changed ~= "" then
32                 uci:save("wireless")
33                 uci:commit("wireless")
34         end
35 end
36 http.redirect(luci.dispatcher.build_url("admin/services/travelmate/stations"))