Files
webmin/ui-demo/edit_manual.cgi
Ilia Ross 20a487ca5a
Some checks failed
Tests / prove (push) Has been cancelled
Package and upload artifacts / build (push) Has been cancelled
Close inactive / close-inactive (push) Has been cancelled
Add UI widgets and demo module
ⓘ Add composable widgets, shared styling and interactions, sortable-table options, and a read-only UI gallery.
2026-09-05 03:52:39 +02:00

55 lines
2.3 KiB
Perl

#!/usr/local/bin/perl
# Manual editor for one of the demo's sample configuration files, laid
# out as edit_manual.cgi of the Linux Firewall (nftables) and Scheduled
# Cron Jobs modules : a small form with a select of the editable files and
# an Open button, then a second form holding the file contents in a large
# ui_textarea named "data" inside a borderless ui_table, ended by a Save
# button that submits to save_manual.cgi.
#
# This is a separate page rather than a tab of index.cgi because Authentic
# turns the text area into a code editor with line numbers and syntax
# colors, adds a "Save and close" button beside Save, and turns the Open
# button into a magnifier with a File Manager button next to it, only on
# pages it recognizes by name, and edit_manual.cgi is one of them. The
# same form inside a tab of index.cgi stays a plain text area.
#
# Nothing here reads a real file : the contents are generated by
# demo_config_contents, and save_manual.cgi writes nothing.
use strict;
use warnings;
require './ui-demo-lib.pl'; ## no critic
our (%in, %text);
ReadParse();
my @files = demo_config_files();
my $file = $in{'file'} && (grep { $_ eq $in{'file'} } @files) ?
$in{'file'} : $files[0];
ui_print_header(undef, $text{'edit_manual_title'}, "");
# File selector, reloading this page with the chosen file
print ui_form_start('edit_manual.cgi');
print ui_tag('b', html_escape($text{'index_e_file'}))." ";
print ui_select('file', $file, \@files)." ";
print ui_submit($text{'index_e_open'});
print ui_form_end();
# The file contents. A real module would lock the file and read it here
print ui_form_start('save_manual.cgi', 'form-data');
print ui_hidden('file', $file);
print ui_table_start(undef, undef, 2);
print ui_table_row(undef, ui_textarea('data', demo_config_contents($file),
20, 100), 2);
print ui_table_end();
print ui_form_end([ [ 'save', $text{'save'} ] ]);
# The links at the very bottom of a page come from ui_print_footer, as
# pairs of URL and text, the most specific place to return to first.
# Themes draw them as the buttons under the page (Authentic puts them in
# its page-footer-actions bar), so a page deep in a module gives both a
# way back to where it came from and to the module index.
ui_print_footer('index.cgi?mode=editor', $text{'index_return_editor'},
'index.cgi', $text{'index_return'});