Skip to content

Commit c22f12e

Browse files
committed
js update
Signed-off-by: RAKHI DUTTA <[email protected]>
1 parent 2d61f02 commit c22f12e

File tree

1 file changed

+64
-3
lines changed

1 file changed

+64
-3
lines changed

mcpgateway/static/admin.js

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4869,6 +4869,62 @@ async function handleEditServerFormSubmit(e) {
48694869
}
48704870
}
48714871

4872+
async function handleEditResourceFormSubmit(e) {
4873+
e.preventDefault();
4874+
const form = e.target;
4875+
const formData = new FormData(form);
4876+
4877+
try {
4878+
// Validate inputs
4879+
const name = formData.get("name");
4880+
const uri = formData.get("uri");
4881+
const nameValidation = validateInputName(name, "resource");
4882+
const uriValidation = validateInputName(uri, "resource URI");
4883+
4884+
if (!nameValidation.valid) {
4885+
showErrorMessage(nameValidation.error);
4886+
return;
4887+
}
4888+
4889+
if (!uriValidation.valid) {
4890+
showErrorMessage(uriValidation.error);
4891+
return;
4892+
}
4893+
4894+
// Save CodeMirror editors' contents if present
4895+
if (window.promptToolHeadersEditor) {
4896+
window.promptToolHeadersEditor.save();
4897+
}
4898+
if (window.promptToolSchemaEditor) {
4899+
window.promptToolSchemaEditor.save();
4900+
}
4901+
4902+
const isInactiveCheckedBool = isInactiveChecked("resources");
4903+
formData.append("is_inactive_checked", isInactiveCheckedBool);
4904+
// Submit via fetch
4905+
const response = await fetch(form.action, {
4906+
method: "POST",
4907+
body: formData,
4908+
});
4909+
4910+
const result = await response.json();
4911+
if (!result.success) {
4912+
throw new Error(result.message || "An error occurred");
4913+
}
4914+
// Only redirect on success
4915+
else {
4916+
// Redirect to the appropriate page based on inactivity checkbox
4917+
const redirectUrl = isInactiveCheckedBool
4918+
? `${window.ROOT_PATH}/admin?include_inactive=true#resources`
4919+
: `${window.ROOT_PATH}/admin#resources`;
4920+
window.location.href = redirectUrl;
4921+
}
4922+
} catch (error) {
4923+
console.error("Error:", error);
4924+
showErrorMessage(error.message);
4925+
}
4926+
}
4927+
48724928
// ===================================================================
48734929
// ENHANCED FORM VALIDATION for All Forms
48744930
// ===================================================================
@@ -5425,12 +5481,17 @@ function setupFormHandlers() {
54255481

54265482
const editResourceForm = safeGetElement("edit-resource-form");
54275483
if (editResourceForm) {
5428-
editResourceForm.addEventListener("submit", () => {
5429-
if (window.editResourceContentEditor) {
5430-
window.editResourceContentEditor.save();
5484+
editResourceForm.addEventListener(
5485+
"submit",
5486+
handleEditResourceFormSubmit,
5487+
);
5488+
editResourceForm.addEventListener("click", () => {
5489+
if (getComputedStyle(editResourceForm).display !== "none") {
5490+
refreshEditors();
54315491
}
54325492
});
54335493
}
5494+
54345495
const editToolForm = safeGetElement("edit-tool-form");
54355496
if (editToolForm) {
54365497
editToolForm.addEventListener("submit", handleEditToolFormSubmit);

0 commit comments

Comments
 (0)