@@ -4869,6 +4869,62 @@ async function handleEditServerFormSubmit(e) {
4869
4869
}
4870
4870
}
4871
4871
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
+
4872
4928
// ===================================================================
4873
4929
// ENHANCED FORM VALIDATION for All Forms
4874
4930
// ===================================================================
@@ -5425,12 +5481,17 @@ function setupFormHandlers() {
5425
5481
5426
5482
const editResourceForm = safeGetElement ( "edit-resource-form" ) ;
5427
5483
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 ( ) ;
5431
5491
}
5432
5492
} ) ;
5433
5493
}
5494
+
5434
5495
const editToolForm = safeGetElement ( "edit-tool-form" ) ;
5435
5496
if ( editToolForm ) {
5436
5497
editToolForm . addEventListener ( "submit" , handleEditToolFormSubmit ) ;
0 commit comments