diff --git a/Example1-Custom.pm b/Example1-Custom.pm new file mode 100644 index 0000000..25c3aa1 --- /dev/null +++ b/Example1-Custom.pm @@ -0,0 +1,192 @@ +# +# Generated by SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-09-05 16:05:03 +# +# +# Routines to be edited by the developer to provide content and validation for parameters +# and provison of the control data for table(s) +# +use esmith::util; +use esmith::util::network; +use esmith::ConfigDB::UTF8; +use esmith::AccountsDB; +use esmith::NetworksDB::UTF8; +use esmith::HostsDB; +use esmith::DomainsDB::UTF8; + +use constant FALSE => 0; +use constant TRUE => 1; + + +#The most common ones - open DB when required. +#my $cdb; +#my $adb; +#my $ndb; +#my $hdb; +#my $ddb; + +#The most common ones - you might want to use these if you need to make sure that the DB is refreshed. +#$cdb = esmith::ConfigDB::UTF8->open() || die("Couldn't open config db"); +#$adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db"); +#$ndb = esmith::NetworksDB->open() || die("Couldn't open Network db"); +#$hdb = esmith::HostsDB::UTF8->open() || die("Couldn't open Hosts db"); +#$ddb = esmith::DomainsDB::UTF8->open() || die("Couldn't open Domains db"); + + +# Validation routines - parameters for each panel + + sub validate_PARAMS { + my $c = shift; + my $ex1_data = shift; #Data hash as parameter + # Validation for each field + my $ret = ''; + + if (! TRUE) #validate $c->param('IbayName') + {$ret .= 'Validation for IbayName failed';} + if (! TRUE) #validate $c->param('ShareOwnerGrp') + {$ret .= 'Validation for ShareOwnerGrp failed';} + if ($ret eq '') {$ret = 'ok';} + return $ret; + } + + sub validate_TABLE { + my $c = shift; + my $ex1_data = shift; #Data hash as parameter + # Validation for each field + my $ret = ''; + + if ($ret eq '') {$ret = 'ok';} + return $ret; + } + + +# Get singleton data for each panel + + sub get_data_for_panel_PARAMS { + # Return a hash with the fields required which will be loaded into the shared data + my $c = shift; + my %ret = ( + 'Data1'=>'Data for PARAMS', #Example + # fields from Inputs in PARAMS $fields['PARAMS'] + 'IbayName'=>'IbayName contents', + 'ShareOwnerGrp'=>'ShareOwnerGrp contents', + + ); + return %ret; + } + + sub get_data_for_panel_TABLE { + # Return a hash with the fields required which will be loaded into the shared data + my $c = shift; + my %ret = ( + 'Data1'=>'Data for TABLE', #Example + # fields from Inputs in TABLE $fields['TABLE'] + + ); + return %ret; + } + + + +# Get control data for table(s) + + # Define a constant hash for field name mapping + use constant ibays_FIELD_MAPPING => ( + 'Name' => 'Source-for-Name', + 'Description' => 'Source-for-Description', + 'flag' => 'Source-for-flag', + 'Modify' => 'Source-for-Modify' + #'target_field2' => 'source_field2', + # Add more mappings as needed + ); + +sub actual_ibays { + my $c = shift; + my @ret = (); + # Actual code for extracting ibays + return @ret; +} + +sub get_ibays { + # Return an array of hashes of the contents for each row and column for ibays + my $c = shift; + my @source_records = $c->actual_ibays(); + my @transformed_records; + my %Field_Mapping = ibays_FIELD_MAPPING(); + # Iterate over each record in the source array + for my $source_record (@source_records) { + my %transformed_record; + # Iterate over each key-value pair in the $Field_Mapping constant + while (my ($target, $source) = each %Field_Mapping) { + # Check if the source field exists in the source record + if (exists $source_record->{$source}) { + # Assign the source field value to the target field in the transformed record + $transformed_record{$target} = $source_record->{$source}; + } + } + # Add transformed record to the array if it's not empty + push @transformed_records, \%transformed_record if %transformed_record; + } + return \@transformed_records; +} + + + +# Return hash with values from row in which link clicked on table + + sub get_selected_PARAMS { + my $c = shift; + my $selected = shift; #Parameter is name of selected row. + my $is_new_record = shift; #Indicates new record required (defaults) + my %ret = (); + #gather the values here + return %ret; + } + + sub get_selected_TABLE { + my $c = shift; + my $selected = shift; #Parameter is name of selected row. + my $is_new_record = shift; #Indicates new record required (defaults) + my %ret = (); + #gather the values here + return %ret; + } + + +#after sucessful modify or create or whatever and submit then perfom (if the params validate) + + sub perform_PARAMS { + my $c = shift; + my $ex1_data = shift; #Data hash as parameter + my $ret = ''; + my $db = $cdb; #maybe one of the others + my $dbkey = 'ChangeThis'; + # To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g." + + if (! TRUE) #copy or perform with value: IbayName e.g. $db->set_prop($dbkey,'IbayName',$c->param('IbayName'),type=>'service')) + {$ret .= 'Perform/save failed for IbayName';} + if (! TRUE) #copy or perform with value: ShareOwnerGrp e.g. $db->set_prop($dbkey,'ShareOwnerGrp',$c->param('ShareOwnerGrp'),type=>'service')) + {$ret .= 'Perform/save failed for ShareOwnerGrp';} + if ($ret eq '') {$ret = 'ok';} + return $ret; + } + + sub perform_TABLE { + my $c = shift; + my $ex1_data = shift; #Data hash as parameter + my $ret = ''; + my $db = $cdb; #maybe one of the others + my $dbkey = 'ChangeThis'; + # To make it write to DB as comment, delete this (regex) string in each if statement "TRUE\) \#copy or perform with value: .* e.g." + + if ($ret eq '') {$ret = 'ok';} + return $ret; + } + + +sub create_link{ + # WIP + my ($c,$route, $panel, $index) = @_; + my $link = "$route?trt=$panel&Selected=$index"; + return $link; +} +1; \ No newline at end of file diff --git a/example1.css b/example1.css new file mode 100644 index 0000000..70bca68 --- /dev/null +++ b/example1.css @@ -0,0 +1,20 @@ +/* +Generated by: SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-09-05 16:05:03 +*/ +.Example1-panel {} +.name {} +.rout {} +.head {} +.subh {} +.para1 {} +.text1 {} +.sele2 {} +.name {} +.rout {} +.head {} +.subh {} +.next {} +.tabl1 {} +thead .tabl1 {} +tbody .tabl1 {} +.next {} diff --git a/example1.js b/example1.js new file mode 100644 index 0000000..2e12d89 --- /dev/null +++ b/example1.js @@ -0,0 +1,5 @@ +// +//Generated by: SM2Gen version:0.9(20Jan2025) Chameleon version:4.5.4 On Python:3.12.3 at 2025-09-05 16:05:03 +// +$(document).ready(function() { +});