luci-app-travelmate: small bugfixes & optimizations
[project/luci.git] / applications / luci-app-travelmate / luasrc / model / cbi / travelmate / wifi_order.lua
index d53e1f5..5b6141e 100644 (file)
@@ -12,40 +12,26 @@ if cfg ~= nil then
        local section = ""
        local idx = ""
        local idx_change = ""
-       if dir == "up" then
-               uci:foreach("wireless", "wifi-iface", function(s)
-                       iface = s.network
-                       if iface == trmiface then
-                               section = s['.name']
-                               if cfg == section then
-                                       idx = s['.index']
-                               else
-                                       idx_change = s['.index']
-                               end
-                               if idx ~= "" and idx_change ~= "" and idx_change < idx then
-                                       uci:reorder("wireless", cfg, idx_change)
-                                       idx = ""
-                               end
+       local changed = ""
+       uci:foreach("wireless", "wifi-iface", function(s)
+               iface = s.network
+               if iface == trmiface then
+                       section = s['.name']
+                       if cfg == section then
+                               idx = s['.index']
+                       else
+                               idx_change = s['.index']
                        end
-               end)
-       elseif dir == "down" then
-               uci:foreach("wireless", "wifi-iface", function(s)
-                       iface = s.network
-                       if iface == trmiface then
-                               section = s['.name']
-                               if cfg == section then
-                                       idx = s['.index']
-                               else
-                                       idx_change = s['.index']
-                               end
-                               if idx ~= "" and idx_change ~= "" and idx_change > idx then
-                                       uci:reorder("wireless", cfg, idx_change)
-                                       idx = ""
-                               end
+                       if (dir == "up" and idx ~= "" and idx_change ~= "" and idx_change < idx) or
+                               (dir == "down" and idx ~= "" and idx_change ~= "" and idx_change > idx) then
+                               changed = uci:reorder("wireless", cfg, idx_change)
+                               idx = ""
                        end
-               end)
+               end
+       end)
+       if changed ~= "" then
+               uci:save("wireless")
+               uci:commit("wireless")
        end
-       uci:save("wireless")
-       uci:commit("wireless")
 end
 http.redirect(luci.dispatcher.build_url("admin/services/travelmate/stations"))