diff --git a/wwwroot/add_service.ui b/wwwroot/add_service.ui index 4a222e6..3395f5c 100644 --- a/wwwroot/add_service.ui +++ b/wwwroot/add_service.ui @@ -68,8 +68,12 @@ { "wid": "self", "event": "click", - "actiontype": "script", - "script": "const formData = bricks.app.get_widget('add-service-form').get_data(); if (formData.name && formData.url) { fetch('/hermes-web-cli/services', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) }).then(response => response.json()).then(data => { bricks.app.load_widget('{{entire_url(\"services.ui\")}}', 'app.main-content', 'replace'); }); }" + "actiontype": "registerfunction", + "target": "app.main-content", + "rfname": "add_service", + "params": { + "form_data": "{{add-service-form.data}}" + } } ] }, diff --git a/wwwroot/edit_service.ui b/wwwroot/edit_service.ui index a9e8e90..ecef95e 100644 --- a/wwwroot/edit_service.ui +++ b/wwwroot/edit_service.ui @@ -69,8 +69,13 @@ { "wid": "self", "event": "click", - "actiontype": "script", - "script": "const formData = bricks.app.get_widget('edit-service-form').get_data(); const serviceId = '{{query.service_id}}'; if (formData.name && formData.url) { fetch(`/hermes-web-cli/hermes_services/?id=${serviceId}`, { method: 'PUT', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(formData) }).then(() => { bricks.app.load_widget('{{entire_url(\"services.ui\")}}', 'app.main-content', 'replace'); }); }" + "actiontype": "registerfunction", + "target": "app.main-content", + "rfname": "update_service", + "params": { + "form_data": "{{edit-service-form.data}}", + "service_id": "{{query.service_id}}" + } } ] }, diff --git a/wwwroot/services.js b/wwwroot/services.js index ad15c80..2d05166 100644 --- a/wwwroot/services.js +++ b/wwwroot/services.js @@ -1,4 +1,61 @@ // Register functions for services management +bricks.RF.register('add_service', async function(params) { + try { + const formData = params.form_data || {}; + + const response = await fetch('/hermes-web-cli/services', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(formData) + }); + const result = await response.json(); + + if (result.success) { + // Navigate back to services list + const mainContent = bricks.getWidgetById('app.main-content'); + if (mainContent) { + mainContent.loadURL(bricks.entire_url('services.ui')); + } + bricks.showMessage('Service added successfully', 'success'); + } else { + bricks.showMessage(result.error || 'Failed to add service', 'error'); + } + } catch (error) { + bricks.showMessage('Network error: ' + error.message, 'error'); + } +}); + +bricks.RF.register('update_service', async function(params) { + try { + const formData = params.form_data || {}; + const serviceId = params.service_id; + + const response = await fetch(`/hermes-web-cli/hermes_services/?id=${serviceId}`, { + method: 'PUT', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(formData) + }); + const result = await response.json(); + + if (result.success) { + // Navigate back to services list + const mainContent = bricks.getWidgetById('app.main-content'); + if (mainContent) { + mainContent.loadURL(bricks.entire_url('services.ui')); + } + bricks.showMessage('Service updated successfully', 'success'); + } else { + bricks.showMessage(result.error || 'Failed to update service', 'error'); + } + } catch (error) { + bricks.showMessage('Network error: ' + error.message, 'error'); + } +}); + bricks.RF.register('remove_service', async function(params) { try { const response = await fetch('/hermes-web-cli/services/remove/?id=' + params.service_id);