package ONO::Lib::UI::List;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
use strict;
use ONO::IO;
use ONO::Lib::UI::Label;
###############################################################################
# manifest
###############################################################################
sub list {
#: Display a list of elements, using a green check icon on the left of each
#: element. Default check icon may be replaced by custom icons.
my (
$self,
$list_ref,
$class1,
$class2,
$icons_ref,
) = @_;
my ($LIST,$counter,@icons);
if ($icons_ref) {
@icons = @$icons_ref;
}
foreach my $item (@$list_ref) {
my $ICON = "/ono/osr/images/icons/crystal/32x32/ono/ok.png";
if ($icons[$counter]) {
$ICON = $icons[$counter];
}
$LIST .= qq~<tr class="vtop">
<td><img class="block32" src="$ICON" alt=""></td>
<td class="p5 $class2">$item</td>
</tr>
~;
$counter++;
}
return qq~<table class="default_table $class1">$LIST</table>~;
}
sub droplist {
#: Display a droplist, which is a list that may collapse or expand.
#:
#: -a show all (more)
#: -A "view all" button
#: -b replace simple breaks by div spaces
#: -d droplist style
#: -f show first item
#: -l large
#: -s smaller titles
#: -S smaller text
my (
$self,
$color,
$mani_ref,
$BLK_ref,
$switches,
) = @_;
my @mani = @$mani_ref;
my %BLK = %$BLK_ref;
my ($MANI,$counter,$STYLE,$STYLE2);
my $size = 32;
my $size2 = int($size/2.4);
if ($switches =~ /l/) {
$STYLE = qq~ style="font-size:140%"~;
$STYLE2 = qq~;font-size:120%~;
}
my $COL_TITLE = "col6";
my $COL_TITLE2;
if ($color =~ s~:(.*)$~~) {
my $col = $1;
if ($col =~ /^#/) {
$COL_TITLE2 = qq~ style="color:$col"~;
} else {
$COL_TITLE = $col;
}
}
foreach my $man (@mani) {
$man =~ s~(\n|\r|\t)~~g;
$counter++;
my ($BUTTON,$ONCLICK,$TOP,$MORE,$HIDE1,$HIDE3);
if ($switches =~ /A/ && $counter == 1) {
$TOP = qq~<div class="fr mt10">
<a id="droplist_button_all" href="javascript:void(0);" onclick="onojs_ui_droplist_open_all();" class="button_green">$BLK{'show_all'}</a>
<a id="droplist_button_none" href="javascript:void(0);" onclick="onojs_ui_droplist_close_all();" class="button_orange hide">$BLK{'close'}</a>
</div>
~;
}
my $HIDE2 = " hide";
my $HIDE4 = " hide";
if ($man =~ s~::(.*)~~) {
$MORE = $1;
my $MORE_CLASS = "mt10";
if ($switches =~ /a/ || ($switches =~ /f/ && $counter == 1)) {
$HIDE1 = " hide";
$HIDE2 = "";
$HIDE3 = " hide";
$HIDE4 = "";
}
if ($switches =~ /b/) {
$MORE =~ s~\<br\>~\</div\>\<div class="mb10"\>~gi;
$MORE = qq~<div class="mb10">$MORE</div>~;
$MORE_CLASS = "box_paper";
}
$MORE = qq~<div id="droplist_view_$counter" class="$MORE_CLASS large col9 mb10$HIDE2" style="line-height:150%">$MORE</div>~;
}
my ($LABEL,$LABEL_PHONE,$TR_CLASS,$TR_STYLE);
if ($switches =~ /d/) {
$TR_CLASS = qq~ bt bb~;
# $TR_STYLE = "background-color:$color";
$STYLE2 .= ";padding-bottom:10px";
} else {
$LABEL = ONO::Lib::UI::Label->display("circle",$size,$color,$counter);
$LABEL_PHONE = $LABEL;
$LABEL = qq~ <td class="pad10_2 hide600">
<a href="javascript:void(0);" onclick="onojs_ui_droplist_open($counter);">$LABEL</a>
</td>
~;
}
my $TITLE_STYLE = " large";
my $ARROW_TOP = 13;
if ($switches !~ /s/) {
$TITLE_STYLE .= " xlarge";
$ARROW_TOP = 18;
}
$MANI .= qq~<tr class="vtop$TR_CLASS" style="$TR_STYLE">
<td class="p0"><a id="droplist_name_$counter"></a></td>
$LABEL
<td class="hide600">
<a href="javascript:void(0);" onclick="onojs_ui_droplist_open($counter);">
<img id="droplist_nav0_$counter" class="block16 mr10 rel$HIDE3" src="/ono/osr/images/arrows/nuvola/black/nav_next.png" style="top:${ARROW_TOP}px" alt="">
</a>
<a href="javascript:void(0);" onclick="onojs_ui_droplist_close($counter);">
<img id="droplist_nav1_$counter" class="block16 mr10 rel$HIDE4" src="/ono/osr/images/arrows/nuvola/black/nav_down.png" style="top:${ARROW_TOP}px" alt="">
</a>
</td>
<td class="w100 p0"$STYLE>
$TOP
<div class="fl mr10 mb5 hide block600">$LABEL_PHONE</div>
<div id="droplist_titl_$counter" class="col6 lh125$TITLE_STYLE" style="padding-top:${size2}px$STYLE2" onclick="onojs_ui_droplist_toggle($counter);">
<a href="javascript:void(0);" class="$COL_TITLE"$COL_TITLE2>$man</a>
</div>
$MORE
</td>
</tr>
~;
}
my $TABLE_STYLE;
if ($switches =~ /S/) {
$TABLE_STYLE .= " small";
}
return qq~<div class="rel">
<table class="wide_table$TABLE_STYLE">
$MANI
</table>
</div>
~;
}
sub droplist_compile {
#: Droplist compile, this will take data from a file on a DevStation
#: and prepare a reusable cache file that can be used with a droplist.
#:
#: -b lines start with a bullet
#: -d lines start with a dash
#: -D lines start with a dash (longer)
#: -m margin-bottom smaller (mb5 instead of md10)
#: -M margin-bottom even smaller (mb2 instead of md10)
my $MB = "mb10";
if ($_[2] =~ /m/) {
$MB = "mb5";
}
if ($_[2] =~ /M/) {
$MB = "mb2";
}
my @man;
if (ONO::IO->devstation) {
my $counter;
foreach my $line (ONO::IO->list($_[1])) {
$line =~ s~(\n|\r|\t)~~g;
if ($line =~ s/^(1|2|3|4|5|6|7|8|9|10)\. (.*)$//) {
$counter = $1 - 1;
$man[$counter] .= "$2::";
}
if ($counter ne "" && $line) {
if ($_[2] =~ /b/) {
$line = "• $line";
}
if ($_[2] =~ /d/) {
$line = "‐ $line";
}
if ($_[2] =~ /D/) {
$line = "— $line";
}
$man[$counter] .= qq~<div class="$MB">$line</div>~;
}
}
ONO::IO->rm("$_[1].cache");
foreach my $m (@man) {
ONO::IO->append("$_[1].cache","$m\n");
}
} else {
@man = ONO::IO->list("$_[1].cache");
}
return \@man;
}
###############################################################################
# end of script
###############################################################################
1;
__END__