191 lines
6.4 KiB
Perl
191 lines
6.4 KiB
Perl
# Selima Website Content Management System
|
|
# Link.pm: The related-link form.
|
|
|
|
# Copyright (c) 2004-2018 imacat.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
# Author: imacat <imacat@mail.imacat.idv.tw>
|
|
# First written: 2004-10-24
|
|
|
|
package Selima::Form::Link;
|
|
use 5.008;
|
|
use strict;
|
|
use warnings;
|
|
use base qw(Selima::Form);
|
|
|
|
use Selima::ChkFunc;
|
|
use Selima::CommText;
|
|
use Selima::FormFunc;
|
|
use Selima::HTTP;
|
|
use Selima::Links;
|
|
use Selima::MarkAbbr;
|
|
use Selima::ShortCut;
|
|
|
|
# new: Initialize the HTML form table displayer
|
|
sub new : method {
|
|
local ($_, %_);
|
|
my ($class, $status, $args, $self);
|
|
($class, $status, $args) = @_;
|
|
$args = {} if !defined $args;
|
|
|
|
# $args must be a hash reference
|
|
http_500 "type of argument 2 must be a hash reference"
|
|
if ref($args) ne "HASH";
|
|
$$args{"type"} = form_type
|
|
if !exists $$args{"type"};
|
|
$$args{"table"} = "links"
|
|
if !exists $$args{"table"};
|
|
$$args{"deltext"} = C_("Delete this related link")
|
|
if !exists $$args{"deltext"};
|
|
if (!exists $$args{"summary"}) {
|
|
# A form to create a new item
|
|
if ($$args{"type"} eq "new") {
|
|
$$args{"summary"} = C_("This table provides you a form to add a new related link.");
|
|
# A form to edit a current item
|
|
} elsif ($$args{"type"} eq "cur") {
|
|
$$args{"summary"} = C_("This table provides you a form to edit a current related link.");
|
|
# A form to delete a current item
|
|
} elsif ($$args{"type"} eq "del") {
|
|
$$args{"summary"} = C_("This table provides you a form to delete a related link.");
|
|
}
|
|
}
|
|
if (!exists $$args{"cols"}) {
|
|
# A form to create a new item
|
|
if ($$args{"type"} eq "new") {
|
|
$$args{"cols"} = [qw(title title_2ln url icon email
|
|
addr tel fax dsc hid cats)];
|
|
# A form to edit a current item
|
|
# A form to delete a current item
|
|
} elsif ($$args{"type"} eq "cur" || $$args{"type"} eq "del") {
|
|
$$args{"cols"} = [qw(sn title title_2ln url icon email
|
|
addr tel fax dsc hid cats
|
|
created createdby updated updatedby)];
|
|
}
|
|
}
|
|
if (!exists $$args{"title"}) {
|
|
# A form to create a new item
|
|
if ($$args{"type"} eq "new") {
|
|
$$args{"title"} = C_("Add a New Related Link");
|
|
# A form to edit a current item
|
|
} elsif ($$args{"type"} eq "cur") {
|
|
$$args{"title"} = C_("Edit a Current Related Link");
|
|
# A form to delete a current item
|
|
} elsif ($$args{"type"} eq "del") {
|
|
$$args{"title"} = C_("Delete a Related Link");
|
|
}
|
|
}
|
|
$self = $class->SUPER::new($status, $args);
|
|
return $self;
|
|
}
|
|
|
|
# _html_col_cats: The categories
|
|
sub _html_col_cats : method {
|
|
$_[0]->_html_coltmpl_select_multi("cat",
|
|
h_abbr(C_("[numerate,_1,Category,Categories]:", $_[0]->_delcolcount("cat"))),
|
|
\&linkcat_options);
|
|
}
|
|
|
|
# _html_col_hid: Hide?
|
|
sub _html_col_hid : method {
|
|
$_[0]->_html_coltmpl_bool("hid", h_abbr(C_("Hide?")),
|
|
h_abbr(C_("Hide this related link")), h_abbr(C_("Show this related link")),
|
|
h_abbr(C_("Hide this related link currently.")));
|
|
}
|
|
|
|
# _html_col_icon: The link icon
|
|
sub _html_col_icon : method {
|
|
local ($_, %_);
|
|
my ($self, $label, $alt, $size, $mark, $colspan);
|
|
my ($cur, $preview, $val, $orig, $new);
|
|
$self = $_[0];
|
|
$mark = $self->_mark("icon");
|
|
$colspan = $self->_colspan;
|
|
$label = h_abbr(C_("Link icon:"));
|
|
$alt = h(C_("Link icon unavailable"));
|
|
$size = h($self->{"defsize"});
|
|
$self->{"form"}->param("icon", "http://")
|
|
if $self->{"is_first_form"} && !defined $self->{"form"}->param("icon");
|
|
|
|
# A form to create a new item
|
|
if ($self->{"type"} eq "new") {
|
|
$val = $self->_val_text("icon", "icon");
|
|
if (is_url_wellformed $self->{"form"}->param("icon")) {
|
|
$preview = "<img src=\"" . h($self->{"form"}->param("icon"))
|
|
. "\" alt=\"$alt\" /><br />\n";
|
|
} else {
|
|
$preview = "";
|
|
}
|
|
print << "EOT";
|
|
<tr>
|
|
<th class="th" scope="row"><label for="icon">$mark$label</label></th>
|
|
<td$colspan>$preview<input id="icon" class="text" type="text" name="icon" size="$size"$val /></td>
|
|
</tr>
|
|
EOT
|
|
|
|
# A form to edit a current item
|
|
} elsif ($self->{"type"} eq "cur") {
|
|
$cur = $self->{"cur"}->param("icon");
|
|
if (defined $cur) {
|
|
$cur = "<img src=\"" . h($cur) . "\" alt=\"$alt\" /><br />\n"
|
|
. " " . h($cur);
|
|
} else {
|
|
$cur = h_abbr(t_none);
|
|
}
|
|
$val = $self->_val_text("icon", "icon");
|
|
if (is_url_wellformed $self->{"form"}->param("icon")) {
|
|
$preview = "<img src=\"" . h($self->{"form"}->param("icon"))
|
|
. "\" alt=\"$alt\" /><br />\n";
|
|
} else {
|
|
$preview = "";
|
|
}
|
|
$orig = h_abbr(C_("Original:"));
|
|
$new = h_abbr(C_("New:"));
|
|
print << "EOT";
|
|
<tr>
|
|
<th class="th" rowspan="2" scope="row"><label for="icon">$mark$label</label></th>
|
|
<th class="oldnew" scope="row">$orig</th>
|
|
<td$colspan>$cur</td>
|
|
</tr>
|
|
<tr>
|
|
<th class="oldnew" scope="row"><label for="icon">$new</label></th>
|
|
<td$colspan>$preview<input id="icon" class="text" type="text" name="icon" size="$size"$val /></td>
|
|
</tr>
|
|
EOT
|
|
|
|
# A form to delete a current item
|
|
} elsif ($self->{"type"} eq "del") {
|
|
$cur = $self->{"cur"}->param("icon");
|
|
if (defined $cur) {
|
|
$cur = "<img src=\"" . h($cur) . "\" alt=\"$alt\" /><br />\n"
|
|
. " " . h($cur);
|
|
} else {
|
|
$cur = h_abbr(t_none);
|
|
}
|
|
print << "EOT";
|
|
<tr>
|
|
<th class="th" scope="row">$mark$label</th>
|
|
<td$colspan>$cur</td>
|
|
</tr>
|
|
EOT
|
|
}
|
|
return;
|
|
}
|
|
|
|
# _html_col_title_2ln: Title in the second language
|
|
sub _html_col_title_2ln : method {
|
|
$_[0]->_html_coltmpl_text("title_2ln", h_abbr(C_("2nd language title:")));
|
|
}
|
|
|
|
return 1;
|