refactor: delete KB uses PopupWindow confirm form instead of JS confirm (no inline script)
This commit is contained in:
parent
ee4bf7548a
commit
d9e1e77341
32
wwwroot/knowledge_bases_list/confirm_delete_form.dspy
Normal file
32
wwwroot/knowledge_bases_list/confirm_delete_form.dspy
Normal file
@ -0,0 +1,32 @@
|
||||
ns = params_kw.copy()
|
||||
kb_id = ns.get('kb_id', '')
|
||||
namestr = ns.get('name', '')
|
||||
|
||||
if not kb_id:
|
||||
return json.dumps({"status": "error", "error": "kb_id required"}, ensure_ascii=False)
|
||||
|
||||
result = {
|
||||
"widgettype": "VBox",
|
||||
"options": {"padding": "20px", "spacing": "14px", "width": "100%", "alignItems": "center"},
|
||||
"subwidgets": [
|
||||
{"widgettype": "Text", "options": {"text": "\u26a0\ufe0f \u786e\u8ba4\u5220\u9664\u77e5\u8bc6\u5e93",
|
||||
"cfontsize": 16, "fontWeight": "bold", "color": "#e74c3c", "halign": "center"}},
|
||||
{"widgettype": "Text", "options": {"text": "\u300c" + namestr + "\u300d",
|
||||
"cfontsize": 14, "color": "#333", "halign": "center"}},
|
||||
{"widgettype": "Text", "options": {"text": "\u8be5\u64cd\u4f5c\u4f1a\u5220\u9664\u77e5\u8bc6\u5e93\u5185\u6240\u6709\u6587\u4ef6\u3001\u6807\u7b7e\u548c\u6570\u636e\uff0c\u4e0d\u53ef\u6062\u590d\uff01",
|
||||
"cfontsize": 12, "color": "#999", "halign": "center"}},
|
||||
{"widgettype": "HBox", "options": {"spacing": "12px", "justifyContent": "center"},
|
||||
"subwidgets": [
|
||||
{"widgettype": "Button", "options": {"label": "\u53d6\u6d88",
|
||||
"bgcolor": "#f0f0f0", "color": "#666", "padding": "6px 20px", "borderRadius": "6px"},
|
||||
"binds": [{"wid": "self", "event": "click", "actiontype": "script",
|
||||
"script": "var pw=null;var w=this;while(w){if(w instanceof bricks.PopupWindow||w instanceof bricks.Popup){pw=w;break};w=w.parent};if(pw){pw.dismiss();pw.destroy()}"}]},
|
||||
{"widgettype": "Button", "options": {"label": "\u786e\u8ba4\u5220\u9664",
|
||||
"bgcolor": "#e74c3c", "color": "#fff", "padding": "6px 20px", "borderRadius": "6px"},
|
||||
"binds": [{"wid": "self", "event": "click", "actiontype": "urlwidget",
|
||||
"target": "app.rag_main_content", "mode": "replace",
|
||||
"options": {"url": "/rag/knowledge_bases_list/delete_kb.dspy?kb_id=" + kb_id}}]}
|
||||
]}
|
||||
]
|
||||
}
|
||||
return result
|
||||
@ -50,14 +50,17 @@ async with get_sor_context(env, 'rag') as sor:
|
||||
{"widgettype": "Text", "options": {"text": "\U0001f5d1\ufe0f \u5220\u9664",
|
||||
"cfontsize": 12, "color": "#e74c3c", "css": "clickable",
|
||||
"padding": "2px 8px", "borderRadius": "4px", "bgcolor": "#fee"},
|
||||
"binds": [{"wid": "self", "event": "click", "actiontype": "script",
|
||||
"script": "event.stopPropagation();"
|
||||
"var nm=" + safe_name + ";"
|
||||
"if(!confirm('\u786e\u8ba4\u5220\u9664\u77e5\u8bc6\u5e93\u300c'+nm+'\u300d\uff1f \u6b64\u64cd\u4f5c\u4e0d\u53ef\u6062\u590d\uff01'))return;"
|
||||
"fetch('/rag/knowledge_bases_list/delete_kb.dspy?kb_id=" + idstr + "').then(function(r){return r.json()}).then(function(d){"
|
||||
"if(d.status==='error'){alert('\u5220\u9664\u5931\u8d25\uff1a'+d.error);return;}"
|
||||
"window.location.href='/rag/knowledge_bases_list/index.ui';"
|
||||
"}).catch(function(){alert('\u7f51\u7edc\u9519\u8bef')});"}]}
|
||||
"binds": [
|
||||
{"wid": "self", "event": "click", "actiontype": "script",
|
||||
"script": "event.stopPropagation()"},
|
||||
{"wid": "self", "event": "click", "actiontype": "urlwidget",
|
||||
"target": "PopupWindow",
|
||||
"popup_options": {"title": "\u5220\u9664\u77e5\u8bc6\u5e93",
|
||||
"width": "28%", "height": "auto",
|
||||
"movable": True, "resizable": True, "modal": True},
|
||||
"options": {"url": "/rag/knowledge_bases_list/confirm_delete_form.dspy",
|
||||
"params": {"kb_id": idstr, "name": namestr}}}
|
||||
]}
|
||||
]}
|
||||
],
|
||||
"binds": [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user