document.addEventListener("submit",function(e){if(e.target.id!=="listing-form")return;e.preventDefault();var fd=new FormData(e.target);var id=fd.get("id");var csrf=document.querySelector("meta[name=csrf-token]").content;var action=id&&id!=="0"?"modify":"post";var body="system_action="+action+"&entity=listing&id="+id+"&_csrf="+csrf;fd.forEach(function(v,k){if(k!=="_csrf"&&k!=="id")body+="&data["+k+"]="+encodeURIComponent(v);});fetch("index.php",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:body}).then(r=>r.json()).then(d=>{if(d.success){alert("Saved");location.reload();}else alert(d.error);});});
function cancelEdit(){document.getElementById("listing-editor").style.display="none";document.getElementById("listing-grid").style.display="block";}
