228 lines
6.6 KiB
Text
228 lines
6.6 KiB
Text
<cfsetting showdebugoutput="false">
|
|
<cfsetting enablecfoutputonly="true">
|
|
|
|
<cfcontent type="text/html; charset=utf-8" reset="true">
|
|
|
|
<cfoutput>
|
|
<!doctype html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Payfrit Admin - ServicePoints</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; margin: 20px; }
|
|
input, button, select { padding: 8px; margin: 6px 0; width: 520px; max-width: 100%; }
|
|
button { width: auto; cursor: pointer; }
|
|
table { border-collapse: collapse; width: 100%; margin-top: 12px; }
|
|
th, td { border: 1px solid ##ddd; padding: 8px; }
|
|
th { background: ##f5f5f5; text-align: left; }
|
|
.row { display: flex; gap: 24px; flex-wrap: wrap; }
|
|
.card { border: 1px solid ##ddd; padding: 14px; border-radius: 10px; flex: 1; min-width: 320px; }
|
|
pre { background: ##111; color: ##0f0; padding: 10px; overflow: auto; border-radius: 8px; min-height: 140px; }
|
|
.warn { color: ##b00; font-weight: bold; }
|
|
.ok { color: ##060; font-weight: bold; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<h2>ServicePoints</h2>
|
|
<div class="warn">Required: ServicePointName</div>
|
|
<div class="ok" id="jsStatus">(JS not loaded yet)</div>
|
|
|
|
<div class="row">
|
|
<div class="card">
|
|
<h3>Create / Update</h3>
|
|
|
|
<div>
|
|
<label>ServicePointID (blank = create)</label><br>
|
|
<input id="ServicePointID" placeholder="e.g. 12">
|
|
</div>
|
|
|
|
<div>
|
|
<label>ServicePointName (required)</label><br>
|
|
<input id="ServicePointName" placeholder="Front Counter" required>
|
|
</div>
|
|
|
|
<div>
|
|
<label>ServicePointTypeID</label><br>
|
|
<input id="ServicePointTypeID" placeholder="0">
|
|
</div>
|
|
|
|
<div>
|
|
<label>ServicePointCode</label><br>
|
|
<input id="ServicePointCode" placeholder="COUNTER">
|
|
</div>
|
|
|
|
<div>
|
|
<label>Description</label><br>
|
|
<input id="Description" placeholder="">
|
|
</div>
|
|
|
|
<div>
|
|
<label>SortOrder</label><br>
|
|
<input id="SortOrder" placeholder="0">
|
|
</div>
|
|
|
|
<div>
|
|
<label>IsActive</label><br>
|
|
<select id="IsActive">
|
|
<option value="1" selected>1 (Active)</option>
|
|
<option value="0">0 (Inactive)</option>
|
|
</select>
|
|
</div>
|
|
|
|
<button type="button" onclick="saveSP()">Save</button>
|
|
<button type="button" onclick="refresh()">Refresh List</button>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<h3>Delete (soft)</h3>
|
|
<div>
|
|
<label>ServicePointID</label><br>
|
|
<input id="DelServicePointID" placeholder="e.g. 12">
|
|
</div>
|
|
<button type="button" onclick="deleteSP()">Delete</button>
|
|
|
|
<h3>Response</h3>
|
|
<pre id="resp"></pre>
|
|
</div>
|
|
</div>
|
|
|
|
<h3>ServicePoint List (click row to load)</h3>
|
|
<table>
|
|
<thead>
|
|
<tr>
|
|
<th>ServicePointID</th>
|
|
<th>Name</th>
|
|
<th>TypeID</th>
|
|
<th>Code</th>
|
|
<th>SortOrder</th>
|
|
<th>IsActive</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="rows"></tbody>
|
|
</table>
|
|
|
|
<script>
|
|
(function boot(){
|
|
document.getElementById("jsStatus").textContent = "JS loaded OK";
|
|
})();
|
|
|
|
function show(o){
|
|
document.getElementById("resp").textContent = JSON.stringify(o, null, 2);
|
|
}
|
|
|
|
const API_BASE = "/biz.payfrit.com/api";
|
|
|
|
async function api(path, bodyObj) {
|
|
const fullPath = API_BASE + path;
|
|
try {
|
|
const res = await fetch(fullPath, {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(bodyObj || {})
|
|
});
|
|
const txt = await res.text();
|
|
try {
|
|
const parsed = JSON.parse(txt);
|
|
parsed._httpStatus = res.status;
|
|
parsed._path = fullPath;
|
|
return parsed;
|
|
} catch {
|
|
return { OK:false, ERROR:"non_json", RAW:txt, _httpStatus: res.status, _path: fullPath };
|
|
}
|
|
} catch (e) {
|
|
return { OK:false, ERROR:"network_error", MESSAGE:String(e), _path: fullPath };
|
|
}
|
|
}
|
|
|
|
function valIntOrNull(id){
|
|
const v = (document.getElementById(id).value||"").trim();
|
|
if (!v) return null;
|
|
const n = parseInt(v, 10);
|
|
return isNaN(n) ? null : n;
|
|
}
|
|
function valIntOrZero(id){
|
|
const n = valIntOrNull(id);
|
|
return n ? n : 0;
|
|
}
|
|
function escapeHtml(s){
|
|
return (""+s)
|
|
.replaceAll("&","&")
|
|
.replaceAll("<","<")
|
|
.replaceAll(">",">")
|
|
.replaceAll('"',""")
|
|
.replaceAll("'","&##039;");
|
|
}
|
|
|
|
function loadIntoForm(sp){
|
|
document.getElementById("ServicePointID").value = sp.ServicePointID || "";
|
|
document.getElementById("ServicePointName").value = sp.ServicePointName || "";
|
|
document.getElementById("ServicePointTypeID").value = (sp.ServicePointTypeID ?? 0);
|
|
document.getElementById("ServicePointCode").value = sp.ServicePointCode || "";
|
|
document.getElementById("Description").value = sp.Description || "";
|
|
document.getElementById("SortOrder").value = (sp.SortOrder ?? 0);
|
|
document.getElementById("IsActive").value = ("" + (sp.IsActive ?? 1));
|
|
document.getElementById("DelServicePointID").value = sp.ServicePointID || "";
|
|
}
|
|
|
|
async function refresh() {
|
|
const out = await api("/servicepoints/list.cfm", {});
|
|
show(out);
|
|
|
|
const tbody = document.getElementById("rows");
|
|
tbody.innerHTML = "";
|
|
|
|
const items = out.SERVICEPOINTS || [];
|
|
for (const sp of items) {
|
|
const tr = document.createElement("tr");
|
|
tr.innerHTML = `
|
|
<td>${sp.ServicePointID}</td>
|
|
<td>${escapeHtml(sp.ServicePointName||"")}</td>
|
|
<td>${sp.ServicePointTypeID}</td>
|
|
<td>${escapeHtml(sp.ServicePointCode||"")}</td>
|
|
<td>${sp.SortOrder}</td>
|
|
<td>${sp.IsActive}</td>
|
|
`;
|
|
tr.style.cursor = "pointer";
|
|
tr.onclick = () => loadIntoForm(sp);
|
|
tbody.appendChild(tr);
|
|
}
|
|
}
|
|
|
|
async function saveSP() {
|
|
const name = (document.getElementById("ServicePointName").value || "").trim();
|
|
if (!name) {
|
|
show({ OK:false, ERROR:"missing_servicepoint_name", MESSAGE:"ServicePointName is required" });
|
|
return;
|
|
}
|
|
|
|
const body = {
|
|
ServicePointID: valIntOrNull("ServicePointID"),
|
|
ServicePointName: name,
|
|
ServicePointTypeID: valIntOrZero("ServicePointTypeID"),
|
|
ServicePointCode: (document.getElementById("ServicePointCode").value || "").trim(),
|
|
Description: (document.getElementById("Description").value || "").trim(),
|
|
SortOrder: valIntOrZero("SortOrder"),
|
|
IsActive: parseInt(document.getElementById("IsActive").value, 10)
|
|
};
|
|
if (!body.ServicePointID) delete body.ServicePointID;
|
|
|
|
const out = await api("/servicepoints/save.cfm", body);
|
|
show(out);
|
|
await refresh();
|
|
}
|
|
|
|
async function deleteSP() {
|
|
const id = valIntOrNull("DelServicePointID");
|
|
if (!id) { show({OK:false,ERROR:"missing_servicepoint_id"}); return; }
|
|
|
|
const out = await api("/servicepoints/delete.cfm", { ServicePointID: id });
|
|
show(out);
|
|
await refresh();
|
|
}
|
|
|
|
refresh();
|
|
</script>
|
|
</body>
|
|
</html>
|
|
</cfoutput>
|