mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-30 02:35:13 +08:00
💐 Sync 2026-09-30 01:19:34
This commit is contained in:
1 parent
67427d9030
commit
a64d55f7c5
50 files changed
+2837
-589
No files matched your search
@@ -201,13 +201,18 @@ function action_delete()
|
||||
end
|
||||
|
||||
-- 节点页返回链接:保留当前筛选参数
|
||||
local function back_to_nodes(http)
|
||||
-- 返回节点页。err 非空时把失败原因带到页面显示(§18:失败必须让用户看见,
|
||||
-- 不能「失败了却看起来像成功」)。与 back_to_list 同一套约定。
|
||||
local function back_to_nodes(http, err)
|
||||
local id = http.formvalue("id") or ""
|
||||
local qs = "?id=" .. luci.util.urlencode(id)
|
||||
for _, k in ipairs({ "proto", "keyword", "group", "sort", "desc" }) do
|
||||
local v = http.formvalue(k)
|
||||
if v and v ~= "" then qs = qs .. "&" .. k .. "=" .. luci.util.urlencode(v) end
|
||||
end
|
||||
if err ~= nil and tostring(err) ~= "" then
|
||||
qs = qs .. "&err=" .. luci.util.urlencode(tostring(err))
|
||||
end
|
||||
http.redirect(luci.dispatcher.build_url("admin", "services", "substore", "nodes") .. qs)
|
||||
end
|
||||
|
||||
@@ -221,16 +226,29 @@ function action_node_save()
|
||||
local idx = tonumber(http.formvalue("idx") or "")
|
||||
local content = http.formvalue("content") or ""
|
||||
local nodes = core.read_nodes(id)
|
||||
if idx and nodes[idx] and content ~= "" then
|
||||
local res = parser.parse_local(content, "form")
|
||||
local newn = res and res.nodes and res.nodes[1]
|
||||
if newn then
|
||||
nodes[idx] = core.merge_form_node(nodes[idx], newn)
|
||||
if core.write_nodes(id, nodes) then
|
||||
core.refresh_combos(id)
|
||||
end
|
||||
end
|
||||
-- §18:任何一条失败路径都必须把原因带回页面。
|
||||
-- 原来只在成功分支里做事,其余情况一律静默重定向,
|
||||
-- 用户提交了坏数据却看到「已保存」的样子。
|
||||
if not idx or not nodes[idx] then
|
||||
back_to_nodes(http, "节点不存在或下标无效")
|
||||
return
|
||||
end
|
||||
if content == "" then
|
||||
back_to_nodes(http, "提交内容为空")
|
||||
return
|
||||
end
|
||||
local res, perr = parser.parse_local(content, "form")
|
||||
local newn = res and res.nodes and res.nodes[1]
|
||||
if not newn then
|
||||
back_to_nodes(http, perr or "表单数据解析失败")
|
||||
return
|
||||
end
|
||||
nodes[idx] = core.merge_form_node(nodes[idx], newn)
|
||||
if not core.write_nodes(id, nodes) then
|
||||
back_to_nodes(http, "写入节点数据失败")
|
||||
return
|
||||
end
|
||||
core.refresh_combos(id)
|
||||
end
|
||||
back_to_nodes(http)
|
||||
end
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<% for _, x in ipairs(srcs) do %>
|
||||
<div style="margin:0.25em 0">
|
||||
<input type="checkbox" id="src_<%=x.id%>" name="src_<%=x.id%>" value="1" <%=sel[x.id] and "checked" or ""%>/>
|
||||
<label for="src_<%=x.id%>"><%=x.name%>(<%=x.node_count or 0%>)</label>
|
||||
<label for="src_<%=x.id%>"><%=luci.util.pcdata(x.name or "")%>(<%=x.node_count or 0%>)</label>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if #srcs == 0 then %>
|
||||
|
||||
@@ -36,6 +36,16 @@
|
||||
nodes = node.sort(nodes, sort_by, sort_desc)
|
||||
local node_edit_base = luci.dispatcher.build_url('admin/services/substore/node_edit')
|
||||
%>
|
||||
<%
|
||||
-- §18:控制器把失败原因放在 ?err= 上带回来,这里渲染成可见的提示。
|
||||
-- pcdata 转义:err 可能包含用户提交的内容,不能直接当 HTML 输出。
|
||||
local flash_err = http.formvalue("err")
|
||||
if flash_err and flash_err ~= "" then
|
||||
%>
|
||||
<div class="cbi-section" style="border-left:4px solid #cc0000;padding:0.5em 0.75em;background:#fdf0f0;color:#cc0000">
|
||||
<strong><%:操作失败%>:</strong> <%=luci.util.pcdata(flash_err)%>
|
||||
</div>
|
||||
<% end %>
|
||||
<h2><%:Nodes%> — <%=luci.util.pcdata(meta and meta.name or "")%></h2>
|
||||
<div style="margin:0.5em 0">
|
||||
<a class="cbi-button cbi-button-reset" href="<%=luci.dispatcher.build_url('admin/services/substore/list')%>"><%:Back%></a>
|
||||
@@ -56,7 +66,7 @@
|
||||
<select name="group">
|
||||
<option value=""><%:All%></option>
|
||||
<% for _, g in ipairs(group_list) do %>
|
||||
<option value="<%=luci.util.pcdata(g)%>" <%=group==g and "selected" or ""%>><%=g%></option>
|
||||
<option value="<%=luci.util.pcdata(g)%>" <%=group==g and "selected" or ""%>><%=luci.util.pcdata(g)%></option>
|
||||
<% end %>
|
||||
</select>
|
||||
</label>
|
||||
|
||||
Reference in new issue
Block a user