Refactor UI files to use registerfunction instead of inline script, following bricks-framework理念: minimize JS usage and use existing controls with auxiliary validation functions
This commit is contained in:
parent
63a3d3be59
commit
e726abcddb
@ -68,8 +68,12 @@
|
|||||||
{
|
{
|
||||||
"wid": "self",
|
"wid": "self",
|
||||||
"event": "click",
|
"event": "click",
|
||||||
"actiontype": "script",
|
"actiontype": "registerfunction",
|
||||||
"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'); }); }"
|
"target": "app.main-content",
|
||||||
|
"rfname": "add_service",
|
||||||
|
"params": {
|
||||||
|
"form_data": "{{add-service-form.data}}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -69,8 +69,13 @@
|
|||||||
{
|
{
|
||||||
"wid": "self",
|
"wid": "self",
|
||||||
"event": "click",
|
"event": "click",
|
||||||
"actiontype": "script",
|
"actiontype": "registerfunction",
|
||||||
"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'); }); }"
|
"target": "app.main-content",
|
||||||
|
"rfname": "update_service",
|
||||||
|
"params": {
|
||||||
|
"form_data": "{{edit-service-form.data}}",
|
||||||
|
"service_id": "{{query.service_id}}"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@ -1,4 +1,61 @@
|
|||||||
// Register functions for services management
|
// 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) {
|
bricks.RF.register('remove_service', async function(params) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('/hermes-web-cli/services/remove/?id=' + params.service_id);
|
const response = await fetch('/hermes-web-cli/services/remove/?id=' + params.service_id);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user