Initial Upload
This commit is contained in:
parent
067259a2e0
commit
c62263d3b3
130
Templates/controller.pm.tem
Normal file
130
Templates/controller.pm.tem
Normal file
@ -0,0 +1,130 @@
|
||||
package SrvMngr::Controller::${PackageName};
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
# heading : ${MenuHeading}
|
||||
# description : ${MenuDescription}
|
||||
# navigation : ${MenuNavigation}
|
||||
#
|
||||
# name : ${lcPackageName}, method : get, url : /${lcPackageName}, ctlact : ${lcPackageName}#main
|
||||
# name : ${lcPackageName}d, method : post, url : /${lcPackageName}d, ctlact : ${lcPackageName}#do_update
|
||||
#
|
||||
# routes : end
|
||||
#
|
||||
# Documentation: https://wiki.contribs.org/{PackageName}
|
||||
#----------------------------------------------------------------------
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Mojo::Base 'Mojolicious::Controller';
|
||||
|
||||
use constant FALSE => 0;
|
||||
use constant TRUE => 1;
|
||||
|
||||
use Locale::gettext;
|
||||
use SrvMngr::I18N;
|
||||
use SrvMngr qw(theme_list init_session);
|
||||
|
||||
use Data::Dumper;
|
||||
|
||||
use esmith::util;
|
||||
use esmith::HostsDB;
|
||||
use esmith::AccountsDB;
|
||||
use esmith::NetworksDB;
|
||||
use esmith::HostsDB;
|
||||
use esmith::DomainsDB;
|
||||
|
||||
|
||||
#The most common ones
|
||||
our $db = esmith::ConfigDB->open() || die("Couldn't open config db");
|
||||
our $adb = esmith::AccountsDB->open() || die("Couldn't open Accounts db");
|
||||
our $ndb = esmith::NetworksDB->open() || die("Couldn't open Network db");
|
||||
our $hdb = esmith::HostsDB->open() || die("Couldn't open Hosts db");
|
||||
our $ddb = esmith::DomainsDB->open() || die("Couldn't open Domains db");
|
||||
|
||||
sub main {
|
||||
|
||||
my $c = shift;
|
||||
$c->app->log->info( $c->log_req );
|
||||
|
||||
my %${prefix}_data = ();
|
||||
my $title = $c->l("${prefix}_${MenuDescription}");
|
||||
my $modul = '';
|
||||
|
||||
$$${prefix}_data{trt} = '${firstPanel}';
|
||||
|
||||
$c->stash(
|
||||
title => $title,
|
||||
modul => $modul,
|
||||
${prefix}_data => \%${prefix}_data
|
||||
);
|
||||
$c->render( template => "${PackageName}" );
|
||||
}
|
||||
|
||||
sub do_update {
|
||||
my $c = shift;
|
||||
$c->app->log->info($c->log_req);
|
||||
|
||||
my %${prefix}_data = ();
|
||||
my $title = $c->l("${prefix}_${MenuDescription}");
|
||||
|
||||
# Accessing all POST parameters
|
||||
my %params = $c->req->params->to_hash;
|
||||
|
||||
# Get number of POST parameters
|
||||
my $num_params = keys %params;
|
||||
|
||||
#Params are available in the hash "params"
|
||||
# you may use:
|
||||
foreach my $key (keys %params) {
|
||||
my $value = $params{$key};
|
||||
$c->app->log->debug("$key: $value");
|
||||
}
|
||||
|
||||
# the value of trt will tell you which panel has returned
|
||||
my $trt = $c->param('trt') || '${firstPanel}' ; #hidden control on every form.
|
||||
my $ret = 'ok';
|
||||
#Validate the parameters accordingly
|
||||
<tal:block tal:repeat="condition conditions">
|
||||
if ($trt eq '${condition}'){
|
||||
#Validate for panel ${condition}
|
||||
# set $ret = $c->l(''Error message') if invalid'
|
||||
}
|
||||
</tal:block>
|
||||
if ($ret ne "ok"){
|
||||
$c->stash(error => $c->l($ret))
|
||||
} else {
|
||||
$c->stash( success => $c->l('ok message'))
|
||||
}
|
||||
if ($ret eq 'ok'){
|
||||
#Do whatever
|
||||
}
|
||||
# set ${prefix}_data{trt} = <route>;
|
||||
$c->stash(
|
||||
title => $title,
|
||||
${prefix}_data => \%${prefix}_data
|
||||
# Extra data in here - repeat for each stash data entry needed for panels
|
||||
);
|
||||
|
||||
$c->render("${PackageName}")
|
||||
}
|
||||
|
||||
# get routines for the stash contents here.
|
||||
|
||||
|
||||
1;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
10
Templates/html_controls.html.ep.tem
Normal file
10
Templates/html_controls.html.ep.tem
Normal file
@ -0,0 +1,10 @@
|
||||
{
|
||||
Text:"\n<p>\n<span class=label>\n%=l('${Label}'), class => 'label'\n</span><span class=data>\n%= ${Value}, class => 'data'\n</span>\n</p>",
|
||||
Selection:"\n\n<p><span class=label>\n%=l('${Label}')\n</span><span class=data>\n% my @${Name}_options = ${Value};\n% param '${Name}' => $$${prefix}_data->{${Name}} unless param '${Name}';\n%= select_field '${Name}' => @${Name}_options, class => 'input'\n<br></span></p>",
|
||||
Textarea:"\n\n<span class=label>\n%=l('${Label}')\n</span><span class=data>\n% param '${Name}' => $$${prefix}_data->{${Name}} unless param '${Name}';\n%= text_area '${Name}', cols=>50, rows=>15\n</span><br>",
|
||||
Date:"\n\n<span class=label>\n%=$%=l('${Label}')\n</span><span class=data>\n%=date_field '${Name}' =>$$${Name}\n</span><br>",
|
||||
Textinput:"\n\n<p><span class=label>\n%=l('${Label}')\n</span><span class=data>\n% param '${Name}' => $$${prefix}_data->{${Name}} unless param '${Name}';\n%= text_field '${Name}', size => '60', class => 'input'\n<br></span></p>",
|
||||
SubHeader:"\n<h2>${value}</h2>",
|
||||
Paragraph:"\n<p>${value}</p>",
|
||||
Submit:"\n<span class='data'>\n%= submit_button l('${value}'), class => 'action'\n</span>"
|
||||
}
|
54
Templates/html_controls.html.ep.xml
Normal file
54
Templates/html_controls.html.ep.xml
Normal file
@ -0,0 +1,54 @@
|
||||
<root>
|
||||
<Text><![CDATA[
|
||||
<p><span class=label>
|
||||
%=l('${Label}'), class => 'label'
|
||||
</span><span class=data>
|
||||
%= ${Value}, class => 'data'
|
||||
</span></p>
|
||||
]]></Text>
|
||||
|
||||
<Selection><![CDATA[
|
||||
<p><span class=label>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
% my @${Name}_options = ${Value};
|
||||
% param '${Name}' => $$${prefix}_data->{${Name}} unless param '${Name}';
|
||||
%= select_field '${Name}' => @${Name}_options, class => 'input'
|
||||
<br></span> </p>
|
||||
]]></Selection>
|
||||
|
||||
<Textarea><![CDATA[
|
||||
<span class=label>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
% param '${Name}' => $$${prefix}_data->{${Name}} unless param '${Name}';
|
||||
%= text_area '${Name}', cols=>50, rows=>15
|
||||
</span><br>
|
||||
]]></Textarea>
|
||||
|
||||
<Date><![CDATA[
|
||||
<span class=label>
|
||||
%=$%=l('${Label}')
|
||||
</span><span class=data>
|
||||
%=date_field '${Name}' =>$$${Name}
|
||||
</span><br>
|
||||
]]></Date>
|
||||
|
||||
<Textinput><![CDATA[
|
||||
<p><span class=label>
|
||||
%=l('${Label}')
|
||||
</span><span class=data>
|
||||
% param '${Name}' => $$${prefix}_data->{${Name}} unless param '${Name}';
|
||||
%= text_field '${Name}', size => '60', class => 'input'
|
||||
<br></span></p>
|
||||
]]></Textinput>
|
||||
|
||||
<SubHeader><![CDATA[<h2>${value}</h2>]]></SubHeader>
|
||||
<Paragraph><![CDATA[<p>${value}</p>]]></Paragraph>
|
||||
|
||||
<Submit><![CDATA[
|
||||
<span class='data'>
|
||||
%= submit_button l('${value}'), class => 'action'
|
||||
</span>]]>
|
||||
</Submit>
|
||||
</root>
|
46
Templates/layout.html.ep.tem
Normal file
46
Templates/layout.html.ep.tem
Normal file
@ -0,0 +1,46 @@
|
||||
% layout 'default', title => "Sme server 2 - ${MenuDescription}", share_dir => './';
|
||||
% content_for 'module' => begin
|
||||
<div id="module" class="module ${PackageName}-panel">
|
||||
|
||||
% if ($config->{debug} == 1) {
|
||||
<p>
|
||||
%= dumper $c->current_route
|
||||
</p>
|
||||
% }
|
||||
|
||||
<h1><%=$title%></h1>
|
||||
|
||||
% if ( stash('modul') ) {
|
||||
%= $c->render_to_string(inline => stash('modul') );
|
||||
% }
|
||||
|
||||
%if ($$${prefix}_data->{first}) {
|
||||
<br><p>
|
||||
%=$c->render_to_string(inline =>$c->l($$${prefix}_data->{first}))
|
||||
</p>
|
||||
|
||||
%} elsif ($$${prefix}_data->{success}) {
|
||||
<div class='sme-border'>
|
||||
<h2> Operation Status Report</h2><p>
|
||||
%= $c->l($$${prefix}_data->{success});
|
||||
</p>
|
||||
</div>
|
||||
|
||||
%} elsif ($$${prefix}_data->{error}) {
|
||||
<div class='sme-error'>
|
||||
<h2> Operation Status Report - error</h2><p>
|
||||
%= $c->l($$${prefix}_data->{error});
|
||||
</p>
|
||||
</div>
|
||||
%}
|
||||
|
||||
%#Routing to partials according to trt parameter.
|
||||
<tal:block tal:repeat="condition conditions">
|
||||
% if ($$${prefix}_data->{trt} eq "${condition}") {
|
||||
%= include 'partials/_${prefix}_${condition}'
|
||||
%}
|
||||
</tal:block>
|
||||
|
||||
|
||||
</div>
|
||||
%end
|
18
Templates/partial.html.ep.tem
Normal file
18
Templates/partial.html.ep.tem
Normal file
@ -0,0 +1,18 @@
|
||||
<div id="${PackageName}-${route}">
|
||||
<script>
|
||||
window.onload = function() {
|
||||
SelectInput();
|
||||
};
|
||||
</script>
|
||||
<h2>
|
||||
%= l("${prefix} Hello ${route}");
|
||||
</h2>
|
||||
% my $btn = l('APPLY');
|
||||
%= form_for "${PackageName}d" => (method => 'POST') => begin
|
||||
|
||||
% param 'trt' => $$${prefix}_data->{trt} unless param 'trt';
|
||||
%= hidden_field 'trt' => $$${prefix}_data->{trt}
|
||||
%# Inputs etc in here.
|
||||
%# Probably finally by a submit.
|
||||
% end
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user