web: let the merged config be edited before it is written

Save to flash showed the merged startup config read-only, so a stray line
had to be fixed afterwards in the System section. The preview is now a
textarea: the size and unknown-line notes follow the edits, the write
button is disabled above 2048 bytes, and what is written is the edited
text.
This commit is contained in:
bloqaudio committed 2026-09-14 08:03:36 -05:00
1 parent 65417433eb
commit ff7b517491
1 file changed
+17 -21
+17 -21
View File
@@ -1655,28 +1655,24 @@ function mergeConf(base,texts){
return conf; return conf;
} }
function writeConfig(txt,title){ function writeConfig(txt,title){
txt=txt.replace(/\r\n/g,"\n"); var info=h("p",{class:"small mut"}),warn=h("p",{class:"small"});
if(txt&&txt.slice(-1)!=="\n")txt+="\n"; var ed=h("textarea",{class:"cfg",spellcheck:"false",placeholder:t("cw_empty"),style:"min-height:45vh"});
var bytes=new Blob([txt]).size; ed.value=txt.replace(/\r\n/g,"\n");
var lines=txt.split("\n").filter(function(l){return l.trim()}); var ok=h("button",{class:"ctl pri",text:t("sy_write"),onclick:function(){closeModal();doWriteConfig(cfgText(ed.value))}});
var unknown=lines.filter(function(l){return!isConfCmd(l.trim().replace(/\s+/g," "))}); function refresh(){
var body=h("div"); var v=cfgText(ed.value),bytes=new Blob([v]).size;
body.appendChild(h("p",{class:"small mut",text:t("cw_info",{n:bytes})})); var unknown=v.split("\n").filter(function(l){return l.trim()&&!isConfCmd(l.trim().replace(/\s+/g," "))});
if(bytes>2048){ info.textContent=t("cw_info",{n:bytes});
body.appendChild(h("p",{class:"small",style:"color:var(--bad)",text:t("cw_toolarge")})); ok.disabled=bytes>2048;
modal(title,body,[h("button",{class:"ctl",text:t("c_close"),onclick:closeModal})]); warn.style.color=ok.disabled?"var(--bad)":"var(--warn)";
return; warn.textContent=ok.disabled?t("cw_toolarge"):(unknown.length?t("cw_unknown")+unknown.join(" | "):"");
} }
if(unknown.length) ed.addEventListener("input",refresh);refresh();
body.appendChild(h("p",{class:"small",style:"color:var(--warn)",text:t("cw_unknown")+unknown.join(" | ")})); modal(title,h("div",null,[info,warn,ed]),[h("button",{class:"ctl",text:t("c_cancel"),onclick:closeModal}),ok]);
body.appendChild(h("pre",{class:"cfg",text:txt||t("cw_empty")})); }
modal(title,body,[ function cfgText(txt){
h("button",{class:"ctl",text:t("c_cancel"),onclick:closeModal}), txt=txt.replace(/\r\n/g,"\n");
h("button",{class:"ctl pri",text:t("sy_write"),onclick:function(){ return txt&&txt.slice(-1)!=="\n"?txt+"\n":txt;
closeModal();
doWriteConfig(txt);
}}),
]);
} }
function doWriteConfig(txt){ function doWriteConfig(txt){
var form=new FormData(); var form=new FormData();