Initial commit

This commit is contained in:
Manuel Cillero 2020-04-10 12:48:19 +02:00
commit f4bfb0e367
71 changed files with 10399 additions and 0 deletions

View file

@ -0,0 +1,124 @@
=head1 NAME
Dam::Components::Actions::Download
=head1 SYNOPSIS
my $download_mode = Component__Get(ACTION_DOWNLOAD, ['csv']);
=head1 DESCRIPTION
Action to execute a download.
=head1 ARGUMENTS
(
TYPE => 'Download',
ID => 'csv' (default),
LABEL => 'CSV' (default),
TOOLTIP => 'Download the current report in CSV format' (default),
ICON => 'download-alt' (default),
MODE_EXT => 'CSV' (default),
FILE_EXT => 'csv' (default)
)
=cut
package Dam::Components::Actions::Download;
use Exporter qw(import);
our @EXPORT = qw(
Action__html Action__js
);
use Dam::Util;
use Dam::DamLogic;
my $ID_DEFAULT = 'csv';
sub __arguments {
my $arg_ref = shift;
check_arguments($arg_ref,
TYPE => [ ARG_REQUIRED ],
ID => [ ARG_DEFAULT, $ID_DEFAULT ],
LABEL => [ ARG_DEFAULT, 'CSV' ],
TOOLTIP => [ ARG_DEFAULT, _t('Download current report in CSV format') ],
ICON => [ ARG_DEFAULT, 'download-alt' ],
MODE_EXT => [ ARG_DEFAULT, 'CSV' ],
FILE_EXT => [ ARG_DEFAULT, 'csv' ]
);
}
sub Action__html {
my ($self, $arg_ref, $info_ref) = @_;
__arguments($arg_ref);
return is_report() ? strval('
<button type="button" class="btn btn-info input-lg" id="', $$arg_ref{ID}, '" data-toggle="tooltip" title="', $$arg_ref{TOOLTIP}, '"><span class="glyphicon glyphicon-', $$arg_ref{ICON}, '"></span> ', $$arg_ref{LABEL}, '</button>
') : '';
}
sub Action__js {
my ($self, $arg_ref) = @_;
__arguments($arg_ref);
return is_report() ? strval('
$("#', $$arg_ref{ID}, '").click(function(){
$("#xt").val(3);
$("#dm").val("', $$arg_ref{MODE_EXT}, ',', $$arg_ref{FILE_EXT}, '");
$("#submit").click();
});
') : '';
}
sub Get {
my ($download_mode, $filename_extension) = split(',', cgiapp_param('dm'));
return is_download() ? $download_mode : '';
}
1;
=head1 AUTHOR
Manuel Cillero C<< <manuel@cillero.es> >>
=head1 COPYRIGHT
The MIT License (MIT)
Copyright (c) 2004-2020 Manuel Cillero. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=cut

View file

@ -0,0 +1,107 @@
=head1 NAME
App::api::actions::Action_Print
=head1 DESCRIPTION
Action to print.
=head1 ARGUMENTS
(
TYPE => 'Print',
ID => 'print' (default),
LABEL => 'Print' (default)
)
=cut
use strict;
use warnings;
use utf8;
package Dam::Components::Actions::Print;
use Exporter qw(import);
our @EXPORT = qw(
Action__html Action__js
);
use Dam::Util;
use Dam::DamLogic;
my $ID_DEFAULT = 'print';
sub __arguments {
my $arg_ref = shift;
check_arguments($arg_ref,
TYPE => [ ARG_REQUIRED ],
ID => [ ARG_DEFAULT, $ID_DEFAULT ],
LABEL => [ ARG_DEFAULT, _t('Print') ]
);
}
sub Action__html {
my ($self, $arg_ref, $info_ref) = @_;
__arguments($arg_ref);
return is_report() ? strval('
<button type="button" class="btn btn-success input-lg" id="', $$arg_ref{ID},'"><span class="glyphicon glyphicon-print"></span> ', $$arg_ref{LABEL},'</button>
') : '';
}
sub Action__js {
my ($self, $arg_ref) = @_;
__arguments($arg_ref);
return is_report() ? strval('
$("#', $$arg_ref{ID},'").click(function(){
window.print();
});
') : '';
}
1;
=head1 AUTHOR
Manuel Cillero C<< <manuel@cillero.es> >>
=head1 COPYRIGHT
The MIT License (MIT)
Copyright (c) 2004-2020 Manuel Cillero. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=cut

View file

@ -0,0 +1,122 @@
=head1 NAME
Dam::Components::Actions::Run
=head1 DESCRIPTION
Action to run a report.
=head1 ARGUMENTS
(
TYPE => 'Run',
ID => 'submit' (default),
LABEL => 'Run' (default)
)
=cut
use strict;
use warnings;
use utf8;
package Dam::Components::Actions::Run;
use Exporter qw(import);
our @EXPORT = qw(
Action__html Action__js
);
use Dam::Util;
use Dam::DamLogic;
my $ID_DEFAULT = 'submit';
sub __arguments {
my $arg_ref = shift;
check_arguments($arg_ref,
TYPE => [ ARG_REQUIRED ],
ID => [ ARG_DEFAULT, $ID_DEFAULT ],
LABEL => [ ARG_DEFAULT, _t('Run') ]
);
}
sub Action__html {
my ($self, $arg_ref, $info_ref) = @_;
__arguments($arg_ref);
return strval('
<button type="submit" class="btn btn-primary input-lg" id="', $$arg_ref{ID}, '"><span class="glyphicon glyphicon-repeat"></span> ', $$arg_ref{LABEL},'</button>
');
}
sub Action__js {
my ($self, $arg_ref) = @_;
__arguments($arg_ref);
# Required javascripts:
Component__Header(ADD => 'JS', RESOURCE => '/dam/js/spin.min.js', VERSION => '2.3.2' );
return strval('
$(function(){
var middle = Math.floor($(window).height() / 2) + "px";
var spin = { lines: 10, length: 28, width: 25, radius: 40, scale: 0.5, corners: 1, color: "#000", opacity: 0.3, rotate: 0, direction: 1, speed: 1, trail: 60, fps: 20, zIndex: 2e9, className: "spinner", top: middle, left: "50%", shadow: false, hwaccel: false, position: "absolute" }
$("#filter").on("submit", function(e) {
if ($("#nv").val() != 1 && $("#filter").valid()) {
if ($("#xt").val() == 2) $("#xt").val(1);
if ($("#xt").val() == 3) $("#xt").val(2);
if ($("#xt").val() < 2) {
var spinner = new Spinner(spin).spin(document.getElementById("loading"));
$("#loading").show();
}
}
$("#nv").val(0);
});
});
');
}
1;
=head1 AUTHOR
Manuel Cillero C<< <manuel@cillero.es> >>
=head1 COPYRIGHT
The MIT License (MIT)
Copyright (c) 2004-2020 Manuel Cillero. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=cut

View file

@ -0,0 +1,216 @@
=head1 NAME
Dam::Components::Actions::Sort
=head1 SYNOPSIS
my $orderby = Component__Get(ACTION_SORT);
=head1 DESCRIPTION
Action to order a list by columns.
=head1 ARGUMENTS
(
TYPE => 'Sort',
COLUMNS => { 'col1' => 'Column 1', 'col2' => 'Column 2' } (default),
DEFAULT => 'col1' (default valus is undef)
)
=cut
use strict;
use warnings;
use utf8;
package Dam::Components::Actions::Sort;
use Exporter qw(import);
our @EXPORT = qw(
Action__html Action__js
);
use Dam::Util;
use Dam::DamLogic;
my $ID_DEFAULT = 'sort';
sub __arguments {
my $arg_ref = shift;
check_arguments($arg_ref,
TYPE => [ ARG_REQUIRED ],
ID => [ ARG_DEFAULT, $ID_DEFAULT ],
COLUMNS => [ ARG_DEFAULT, { 'col1' => 'Column 1', 'col2' => 'Column 2' } ],
DEFAULT => [ ARG_OPTIONAL ]
);
}
sub Action__html {
my ($self, $arg_ref, $info_ref) = @_;
__arguments($arg_ref);
my $default = undef;
my %list_columns = %{$$arg_ref{COLUMNS}};
if (!is_empty($$arg_ref{DEFAULT})) {
my @default = split(' ', $$arg_ref{DEFAULT});
if (defined($list_columns{$default[0]}) && !defined($default[2])) {
my $dir = in_array(uc($default[1]), 'ASC', 'DESC') ? uc($default[1]) : 'ASC';
$default = strval($default[0], ' ', $dir);
}
}
# Order value:
my $orderby_value = cgiapp_param('orderby');
$orderby_value = $default if is_empty($orderby_value) && defined($default);
if (defined($orderby_value)) {
my @orderby = split(' ', $orderby_value);
if (defined($orderby[0]) && defined($list_columns{$orderby[0]})) {
my $orderby = $list_columns{$orderby[0]};
if (defined($orderby[1])) {
$orderby = strval($orderby, is_eq($orderby[1], 'ASC') ? strval(' (', _t('ascendant'), ')') : is_eq($orderby[1], 'DESC') ? strval(' (', _t('descendent'), ')') : '');
}
push(@{$info_ref}, { DATA => _t('Order by'), VALUE => $orderby });
}
else {
$orderby_value = '';
}
}
else {
$orderby_value = '';
}
return strval('
<input type="hidden" name="orderby" id="orderby" value="', $orderby_value, '" />
');
}
sub Action__js {
my ($self, $arg_ref) = @_;
__arguments($arg_ref);
my $default = undef;
my %list_columns = %{$$arg_ref{COLUMNS}};
if (!is_empty($$arg_ref{DEFAULT})) {
my @default = split(' ', $$arg_ref{DEFAULT});
if (defined($list_columns{$default[0]}) && !defined($default[2])) {
my $dir = in_array(uc($default[1]), 'ASC', 'DESC') ? uc($default[1]) : 'ASC';
$default = strval($default[0], ' ', $dir);
}
}
my $columns_id = '';
my $columns_name = '';
foreach my $column (keys(%list_columns)) {
$columns_id .= strval('#', $column, ',');
$columns_name .= strval($list_columns{$column}, ',');
}
chop($columns_id);
chop($columns_name);
return strval('
$(function(){
var current_orderby = $("#orderby").val().split(" ");
var columns_id = ["', strval_join('","', split(',', $columns_id)), '"];
var columns_name = ["', strval_join('","', split(',', $columns_name)), '"];
columns_id.forEach(function(value,index,array){
var glypho = "sort";
if (current_orderby[0] == value.substring(1)) {
if (current_orderby[1] == "ASC") {
glypho = "triangle-bottom";
}
else if (current_orderby[1] == "DESC") {
glypho = "triangle-top";
}
}
$(value).css("white-space","nowrap");
$(value).prepend("<span style=\"font-size: medium; color: #999;\" class=\"minitip glyphicon glyphicon-" + glypho + " hidden-print\" data-toggle=\"tooltip\" title=\"', _t('Sort by'), ' " + columns_name[index] + "\"></span>");
$(value).hover(function(){
$(this).css("cursor","pointer");
});
$(value).click(function(){
var current_column = $(this).attr("id");
if (current_column == current_orderby[0]) {
if (current_orderby[1] == "ASC") {
current_column += " DESC";
}
else if (current_orderby[1] != "DESC") {
current_column += " ASC";
}
else {
current_column = "', $default, '";
}
}
else {
current_column += " ASC";
}
$("#orderby").val(current_column);
$("#submit").click();
});
});
$(".minitip").tooltip();
});
');
}
sub Get {
my $orderby_value = cgiapp_param('orderby');
return undef if is_empty($orderby_value);
return $orderby_value;
}
sub Set {
my ($self, $value, $id) = @_;
cgiapp_param('orderby', $value);
}
1;
=head1 AUTHOR
Manuel Cillero C<< <manuel@cillero.es> >>
=head1 COPYRIGHT
The MIT License (MIT)
Copyright (c) 2004-2020 Manuel Cillero. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
=cut