More fixes to lexical scan

This commit is contained in:
2024-05-06 10:05:43 +01:00
parent 228a42ed60
commit a5f8e153a2
12 changed files with 152 additions and 105 deletions

View File

@@ -10,6 +10,7 @@ package SrvMngr::Controller::${PackageName};
# name : ${lcPackageName}, method : get, url : /${lcPackageName}, ctlact : ${lcPackageName}#main
# name : ${lcPackageName}u, method : post, url : /${lcPackageName}u, ctlact : ${lcPackageName}#do_update
# name : ${lcPackageName}d, method : get, url : /${lcPackageName}d, ctlact : ${lcPackageName}#do_display
# name : ${lcPackageName}e, method : post, url : /${lcPackageName}d, ctlact : ${lcPackageName}#do_display
#
# routes : end
#
@@ -67,7 +68,7 @@ sub main {
$c->app->log->info( $c->log_req );
my %${prefix}_data = ();
my $title = $c->l("${prefix}_${MenuDescription}");
my $title = $c->l('${prefix}_${MenuDescription}');
my $modul = '';
$$${prefix}_data{'trt'} = '${firstPanel}';
@@ -91,7 +92,7 @@ sub main {
$c->render( template => "${PackageName}" );
}
# Post request with params - submit from a form
# Post request with params - submit from the form
sub do_update {
#
# Return after submit pushed on panel (this is a post) - route is "/<whatever>u"
@@ -121,7 +122,7 @@ sub do_update {
$c->app->log->info($c->log_req);
my %${prefix}_data = ();
my $title = $c->l("${prefix}_${MenuDescription}");
my $title = $c->l('${prefix}_${MenuDescription}');
# Accessing all POST parameters
my %params = $c->req->params->to_hash;
@@ -143,7 +144,7 @@ sub do_update {
<tal:block tal:repeat="panel panels">
if ($trt eq '${panel}'){
#Validate form parameters for panel ${panel}
$ret = validate_${panel}(\%${prefix}_data);
$ret = validate_${panel}($c,\%${prefix}_data);
$thispanel = '${panel}';
}
</tal:block>
@@ -157,13 +158,13 @@ sub do_update {
<tal:block tal:repeat="panel panels">
if ($trt eq '${panel}'){
#do whatever is required ...
$ret = perform_${panel}(\%${prefix}_data);
$ret = perform_${panel}($c,\%${prefix}_data);
if ($ret ne "ok") {
# return to the panel with error message
$c->stash(error => $c->l($ret));
$c->render("${PackageName}");
} else {
$c->stash( success => $c->l("${panel} panel action was successfull")); #A bit bland - edit it in the lex file
$c->stash( success => $c->l('${panel} panel action was successfull')); #A bit bland - edit it in the lex file
}
}
</tal:block>
@@ -189,6 +190,8 @@ sub do_display {
# Return after link clicked in table (this is a get) - route is "/<whatever>d"
# Expects ?trt=PANEL&selected="TableRowName" plus any other required
#
# OR it maybe a post from the main panel to add a new record
#
#load up all supplied params into prefix_data hash
#call get-selected-PANEL() - returns hash of all relevent parameters
#load up returned hash into prefix_data
@@ -198,14 +201,17 @@ sub do_display {
$c->app->log->info($c->log_req);
my %${prefix}_data = ();
my $title = $c->l("${prefix}_${MenuDescription}");
my $title = $c->l('${prefix}_${MenuDescription}');
# Accessing all POST parameters
# Accessing all parameters
my %params = $c->req->params->to_hash;
# Get number of POST parameters
# Get number of parameters
my $num_params = keys %params;
#Tag as Post or Get (ie. create new entry or edit existing one
my $is_new_record = ($c->req->method() eq 'POST');
#Params are available in the hash "params" - copy to the prefix_data hash
while (my ($key, $value) = each %{$c->req->params->to_hash}) {
$$${prefix}_data{$key} = $value;
@@ -215,11 +221,12 @@ sub do_display {
my $trt = $c->param('trt') || '${firstPanel}'; #Indicates where to go now
# Now add in the params from the selected row from the table
my %selectedrow;
<tal:block tal:repeat="panel panels">
if ($trt eq '${panel}'){
#Validate form parameters for panel ${panel}
%selectedrow = selected_${panel}($$${prefix}_data{'Selected'});
%selectedrow = get_selected_${panel}($c,$$${prefix}_data{'Selected'},$is_new_record);
}
</tal:block>