Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Projets publics
Sympa
Commits
d44f14b1
Commit
d44f14b1
authored
Apr 30, 2017
by
IKEDA Soji
Browse files
Refactoring: Description of list topics are handled by templates mostly.
parent
6acc12b6
Changes
8
Hide whitespace changes
Inline
Side-by-side
default/web_tt2/create_list_request.tt2
View file @
d44f14b1
...
...
@@ -39,44 +39,32 @@
<label for="subject">[%|loc%]Subject:[%END%]</label> <input type="text" name="subject" id="subject" size="60" value="[% saved.subject %]" />
[% SET single_topic =
"other"
%]
[% FOREACH topic = list_of_topics %]
[% IF loop.size > 1 || (topic.key && topic.key != "other") %]
[% SET single_topic =
""
%]
[% SET single_topic =
1 ~
%]
[% FOREACH topic = list_of_topics
~
%]
[% IF loop.size > 1 || (topic.key && topic.key != "other")
~
%]
[% SET single_topic =
0 ~
%]
[% LAST %]
[% ELSIF topic.value.sub %]
[% FOREACH subtopic = topic.value.sub %]
[% SET single_topic = "" %]
[% LAST %]
[% END %]
[% END %]
[% END %]
[% IF single_topic != "" %]
<input id="topics" name="topics" type="hidden" value="[% single_topic %]" />
[% ELSE %]
[%~ END ~%]
[%~ END ~%]
[% IF single_topic ~%]
<input id="topics" name="topics" type="hidden" value="other" />
[%~ ELSE ~%]
<label for="topics">[%|loc%]Audience:[%END%]</label>
<select id="topics" name="topics">
<option value="">[%|loc%]-- Select an Audience --[%END%]</option>
[% SET topic_other = 0 %]
[% FOREACH topic = list_of_topics %]
[% IF topic.key == "other" %][% SET topic_other = 1 %][% END %]
<option value="[% topic.key %]"
[% IF topic.value.selected %]
selected="selected"
[% END %]
>[% topic.value.current_title %]</option>
[% IF topic.value.sub %]
[% FOREACH subtopic = topic.value.sub %]
<option value="[% topic.key %]/[% subtopic.key %]">[% topic.value.current_title %] / [% subtopic.value.current_title %]</option>
[% END %]
[% END %]
[% END %]
[% UNLESS topic_other %]
<option value="other">[%|loc%]Other[%END%]</option>
[% END %]
</select>
<br />
[% END %]
<select id="topics" name="topics">
<option value="">[%|loc%]-- Select an Audience --[%END%]</option>
[% FOREACH topic = list_of_topics ~%]
[% IF topic.key == "other" ~%]
[% NEXT %]
[%~ END ~%]
<option value="[% topic.key %]"
[%~ IF topic.value.selected %] selected="selected"[% END %]>
[%~ topic.key | optdesc('listtopic') ~%]
</option>
[% END %]
<option value="other">[%|loc%]Other[%END%]</option>
</select>
<br />
[%~ END %]
<label for="info" class="align_top">[%|loc%]Description:[%END%]</label><textarea class="desc" id="info" name="info" rows="10" cols="80">[% saved.info %]</textarea>
<input class="MainMenuLinks" type="submit" name="action_create_list" value="[%|loc%]Submit your creation request[%END%]" />
...
...
default/web_tt2/edit_list_request.tt2
View file @
d44f14b1
...
...
@@ -231,11 +231,7 @@
<option value="[% enum.key %]"
[%~ IF enum.value.selected == '1' %] selected="selected"[% END %]
[%~ IF pitem.field_type == 'lang' %] lang="[%enum.key%]" xml:lang="[%enum.key%]"[% END %]>
[%~ IF enum.value.title ~%]
[% enum.value.title %]
[%~ ELSE ~%]
[% enum.key | optdesc(pitem.field_type,is_listmaster) %]
[%~ END ~%]
[%~ enum.key | optdesc(pitem.field_type,is_listmaster) ~%]
</option>
[% END %]
</select>
...
...
@@ -245,11 +241,7 @@
[%~ IF pitem.field_type == 'lang' ~%]
<span class="neutral" lang="[%enum.key%]" xml:lang="[%enum.key%]">
[%~ END ~%]
[% IF enum.value.title ~%]
[% enum.value.title %]
[%~ ELSE ~%]
[% enum.key | optdesc(pitem.field_type,is_listmaster) %]
[%~ END %]
[% enum.key | optdesc(pitem.field_type,is_listmaster) %]
[%~ IF pitem.field_type == 'lang' ~%]
</span>
[%~ END %]
...
...
default/web_tt2/lists.tt2
View file @
d44f14b1
<!-- $Id$ -->
[%- IF subtitle %]<h3>[% subtitle %]</h3>[% END -%]
[% IF topic ~%]
<h3>[% topic | optdesc('listtopic') %]</h3>
[%~ ELSIF subtitle ~%]
<h3>[% subtitle %]</h3>
[%~ END %]
[% letters = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','others' ] %]
[% all_letters = [] %]
...
...
src/cgi/wwsympa.fcgi.in
View file @
d44f14b1
...
...
@@ -4527,36 +4527,16 @@ sub do_lists {
$all_lists = [map { $lists{$_} } sort keys %lists];
$param->{'subtitle'} = $language->gettext('Your lists');
} elsif ($in{'topic'}) {
my %topics = Sympa::Robot::load_topics($robot);
$param->{'topic'} = $in{'topic'};
if ($in{'subtopic'}) {
$param->{'subtopic'} = $in{'subtopic'};
$param->{'subtitle'} = $language->gettext_sprintf(
'%s / %s',
$topics{$in{'topic'}}{'current_title'},
$topics{$in{'topic'}}{'sub'}{$in{'subtopic'}}{'current_title'}
|| $in{'subtopic'}
);
} elsif ($topics{$in{'topic'}}{'current_title'}) {
$param->{'subtitle'} = $topics{$in{'topic'}}{'current_title'};
} elsif ($in{'topic'} eq 'others' or $in{'topic'} eq 'topicsless') {
$param->{'subtitle'} = $language->gettext('Others');
} else {
$param->{'subtitle'} = $in{'topic'};
}
my $topic = join '/', grep {$_} ($in{'topic'}, $in{'subtopic'});
$param->{'topic'} = $topic;
#
#
Filter lists by topic.
#
#
topic argument 'topicsless' or 'other' means 'lists with topic
#
#
"other" or without topics'.
#
#
no topic argument; List all lists
# Filter lists by topic.
# topic argument 'topicsless' or 'other' means 'lists with topic
# "other" or without topics'.
# no topic argument; List all lists
my $options = {};
if ($in{'topic'}) {
if ($in{'subtopic'}) {
$options->{'filter'} =
['topics' => "$in{'topic'}/$in{'subtopic'}"];
} else {
$options->{'filter'} = ['topics' => $in{'topic'}];
}
if ($topic) {
$options->{'filter'} = ['topics' => $topic];
}
$all_lists = Sympa::List::get_lists($robot, %$options);
} else {
...
...
@@ -10889,23 +10869,11 @@ sub do_create_list_request {
|| [];
#XXX}
my %topics;
unless (%topics = Sympa::Robot::load_topics($robot)) {
Sympa::Report::reject_report_web('intern',
'unable_to_load_list_of_topics',
{}, $param->{'action'}, '', $param->{'user'}{'email'}, $robot);
}
$param->{'list_of_topics'} = \%topics;
if ($in{'topics'}) {
my ($topic, $subtopic) = split('/', $in{'topics'});
if ($subtopic) {
$param->{'list_of_topics'}{$topic}{'sub'}{$subtopic}{'selected'}
= 1;
} else {
$param->{'list_of_topics'}{$topic}{'selected'} = 1;
}
my %topics = map { ($_ => {}) } Sympa::Robot::topic_keys($robot);
if ($in{'topics'} and exists $topics{$in{'topics'}}) {
$topics{$in{'topics'}}->{selected} = 1;
}
$param->{'list_of_topics'} = {%topics};
unless ($param->{'list_list_tpl'} =
Sympa::Tools::WWW::get_list_list_tpl($robot)) {
...
...
@@ -11984,8 +11952,11 @@ sub _prepare_edit_form {
}
}
my $config = Sympa::List::Config->new($list, config => $list->{'admin'});
my $pinfo = $config->get_schema($param->{'user'}{'email'});
## For each parameter defined in List.pm, retrieve and prepare for editing
foreach my $pname (
sort Sympa::List::by_order keys %{$pinfo}
) {
foreach my $pname (
$config->keys
) {
# Skip comments and default values.
next if grep { $pname eq $_ } qw(comment defaults);
...
...
@@ -12018,45 +11989,8 @@ sub _prepare_edit_form {
## variable %changed_params.
$p->{'changed'} = $::changed_params{$pname};
## Exceptions...too many
if ($pname eq 'topics') {
$p->{'type'} = 'enum';
my @topics;
foreach my $topic (sort keys %{$p->{'value'}}) {
push @topics, $topic if $p->{'value'}{$topic}{'selected'};
}
delete $p->{'value'};
my %list_of_topics = Sympa::Robot::load_topics($robot);
if (defined $p->{'constraint'}) {
_restrict_values(\%list_of_topics, $p->{'constraint'});
}
foreach my $topic (keys %list_of_topics) {
$p->{'value'}{$topic}{'selected'} = 0;
$p->{'value'}{$topic}{'title'} =
$list_of_topics{$topic}{'current_title'};
if ($list_of_topics{$topic}{'sub'}) {
foreach
my $subtopic (keys %{$list_of_topics{$topic}{'sub'}})
{
$p->{'value'}{"$topic/$subtopic"}{'selected'} = 0;
$p->{'value'}{"$topic/$subtopic"}{'title'} =
"$list_of_topics{$topic}{'current_title'}/$list_of_topics{$topic}{'sub'}{$subtopic}{'current_title'}";
}
}
}
foreach my $selected_topic (@topics) {
next unless (defined $selected_topic);
$p->{'value'}{$selected_topic}{'selected'} = 1;
$p->{'value'}{$selected_topic}{'title'} =
$language->gettext_sprintf("Unknown (%s)",
$selected_topic)
unless (defined $p->{'value'}{$selected_topic}{'title'});
}
} elsif ($pname eq 'digest') {
# Exception.
if ($pname eq 'digest') {
foreach my $v (@{$p->{'value'}}) {
next unless ($v->{'name'} eq 'days');
if (ref($v->{'value'}) eq 'ARRAY') {
...
...
@@ -12308,7 +12242,7 @@ sub _prepare_data {
}
} else {
if ($restrict
&& ($name ne 'topics')
) {
if ($restrict) {
$p_glob->{'type'} = 'enum';
foreach my $elt (keys %{$constraint}) {
...
...
src/lib/Sympa/ListDef.pm
View file @
d44f14b1
...
...
@@ -230,7 +230,8 @@ our %pinfo = (
order
=>
10.07
,
'
group
'
=>
'
description
',
'
gettext_id
'
=>
"
Topics for the list
",
'
format
'
=>
[]
,
# Sympa::Robot::load_topics() called later
'
format
'
=>
[]
,
# Sympa::Robot::topic_keys() called later
'
field_type
'
=>
'
listtopic
',
'
split_char
'
=>
'
,
',
'
occurrence
'
=>
'
0-n
'
},
...
...
@@ -2585,6 +2586,10 @@ Reception mode of list member.
Status of list.
=item C<'listtopic'>
List topic.
=item C<'unixtime'>
The time in second from Unix epoch.
...
...
src/lib/Sympa/ListOpt.pm
View file @
d44f14b1
...
...
@@ -256,7 +256,9 @@ my %list_status = (
);
# Old name: Sympa::List::get_option_title().
sub
get_title
{
# Old name: Sympa::ListOpt::get_title().
sub
get_option_description
{
my
$that
=
shift
;
my
$option
=
shift
;
my
$type
=
shift
||
'';
my
$withval
=
shift
||
0
;
...
...
@@ -278,6 +280,20 @@ sub get_title {
$title
=
$language
->
native_name
;
}
$language
->
pop_lang
;
}
elsif
(
$type
eq
'
listtopic
'
or
$type
eq
'
listtopic:leaf
')
{
my
$robot_id
;
if
(
ref
$that
eq
'
Sympa::List
')
{
$robot_id
=
$that
->
{'
domain
'};
}
elsif
(
$that
and
$that
ne
'
*
')
{
$robot_id
=
$that
;
}
else
{
$robot_id
=
'
*
';
}
if
(
$type
eq
'
listtopic
')
{
$title
=
Sympa::Robot::
topic_get_title
(
$robot_id
,
$option
);
}
else
{
$title
=
[
Sympa::Robot::
topic_get_title
(
$robot_id
,
$option
)]
->
[
-
1
];
}
}
elsif
(
$type
eq
'
password
')
{
return
'
*
'
x
length
(
$option
);
# return
}
elsif
(
$type
eq
'
unixtime
')
{
...
...
@@ -323,7 +339,7 @@ configuration.
=over
=item get_
title (
$value, [ $type, [ $withval ] ] )
=item get_
option_description ( $that,
$value, [ $type, [ $withval ] ] )
I<Function>.
Gets i18n-ed title of option.
...
...
@@ -333,6 +349,10 @@ Parameters:
=over
=item $that
Context, instance of L<Sympa::List>, Robot or Site.
=item $value
Value of option.
...
...
src/lib/Sympa/Robot.pm
View file @
d44f14b1
...
...
@@ -183,7 +183,7 @@ sub load_topics {
unless
(
$conf_file
)
{
$log
->
syslog
('
err
',
'
No topics.conf defined
');
return
undef
;
return
;
}
my
$topics
=
{};
...
...
@@ -198,12 +198,12 @@ sub load_topics {
unless
(
-
r
$conf_file
)
{
$log
->
syslog
('
err
',
'
Unable to read %s
',
$conf_file
);
return
undef
;
return
;
}
unless
(
open
(
FILE
,
"
<
",
$conf_file
))
{
$log
->
syslog
('
err
',
'
Unable to open config file %s
',
$conf_file
);
return
undef
;
return
;
}
## Rough parsing
...
...
@@ -243,7 +243,7 @@ sub load_topics {
unless
(
$#rough_data
>
-
1
)
{
$log
->
syslog
('
notice
',
'
No topic defined in %s
',
$conf_file
);
return
undef
;
return
;
}
## Analysis
...
...
@@ -251,7 +251,7 @@ sub load_topics {
my
@tree
=
split
'
/
',
$topic
->
{'
name
'};
if
(
$#tree
==
0
)
{
my
$title
=
_
get
_topic_title
s
(
$topic
);
my
$title
=
_
load
_topic
s_get
_title
(
$topic
);
$list_of_topics
{
$robot
}{
$tree
[
0
]}{'
title
'}
=
$title
;
$list_of_topics
{
$robot
}{
$tree
[
0
]}{'
visibility
'}
=
$topic
->
{'
visibility
'}
||
'
default
';
...
...
@@ -260,7 +260,7 @@ sub load_topics {
$topic
->
{'
order
'};
}
else
{
my
$subtopic
=
join
('
/
',
@tree
[
1
..
$#tree
]);
my
$title
=
_
get
_topic_title
s
(
$topic
);
my
$title
=
_
load
_topic
s_get
_title
(
$topic
);
my
$visibility
=
$topic
->
{'
visibility
'}
||
'
default
';
$list_of_topics
{
$robot
}{
$tree
[
0
]}{'
sub
'}{
$subtopic
}
=
_add_topic
(
$subtopic
,
$title
,
$visibility
);
...
...
@@ -322,7 +322,8 @@ sub load_topics {
return
%
{
$list_of_topics
{
$robot
}};
}
sub
_get_topic_titles
{
# Old name: _get_topic_titles().
sub
_load_topics_get_title
{
my
$topic
=
shift
;
my
$title
;
...
...
@@ -357,6 +358,72 @@ sub _add_topic {
}
}
sub
topic_keys
{
my
$robot_id
=
shift
;
my
%topics
=
Sympa::Robot::
load_topics
(
$robot_id
);
return
map
{
my
$topic
=
$_
;
if
(
$topics
{
$topic
}
->
{
sub
})
{
(
$topic
,
map
{
$topic
.
'
/
'
.
$_
}
sort
keys
%
{
$topics
{
$topic
}
->
{
sub
}}
);
}
else
{
(
$topic
);
}
}
sort
keys
%topics
;
}
sub
topic_get_title
{
my
$robot_id
=
shift
;
my
$topic
=
shift
;
my
$tinfo
=
{
Sympa::Robot::
load_topics
(
$robot_id
)};
return
unless
%$tinfo
;
my
@ttitles
;
my
@tpaths
=
split
'
/
',
$topic
;
while
(
1
)
{
my
$t
=
shift
@tpaths
;
unless
(
exists
$tinfo
->
{
$t
})
{
@ttitles
=
();
last
;
}
elsif
(
not
@tpaths
)
{
push
@ttitles
,
(
_topic_get_title
(
$tinfo
->
{
$t
})
||
$t
);
last
;
}
elsif
(
not
$tinfo
->
{
$t
}
->
{
sub
})
{
@ttitles
=
();
last
;
}
else
{
push
@ttitles
,
(
_topic_get_title
(
$tinfo
->
{
$t
})
||
$t
);
$tinfo
=
$tinfo
->
{
$t
}
->
{
sub
};
}
}
return
@ttitles
if
wantarray
;
return
join
'
/
',
@ttitles
;
}
sub
_topic_get_title
{
my
$titem
=
shift
;
return
undef
unless
$titem
and
exists
$titem
->
{
title
};
foreach
my
$lang
(
Sympa::Language::
implicated_langs
(
$language
->
get_lang
))
{
return
$titem
->
{
title
}
->
{
$lang
}
if
$titem
->
{
title
}
->
{
$lang
};
}
if
(
$titem
->
{
title
}
->
{
gettext
})
{
return
$language
->
gettext
(
$titem
->
{
title
}
->
{
gettext
});
}
elsif
(
$titem
->
{
title
}
->
{
default
})
{
return
$titem
->
{
title
}
->
{
default
};
}
else
{
return
undef
;
}
}
=over 4
=item list_params
...
...
@@ -375,17 +442,7 @@ sub list_params {
my
$pinfo
=
Sympa::Tools::Data::
clone_var
(
\
%
Sympa::ListDef::
pinfo
);
$pinfo
->
{
lang
}{
format
}
=
[
Sympa::
get_supported_languages
(
$robot_id
)];
my
%topics
=
Sympa::Robot::
load_topics
(
$robot_id
);
my
@topics
=
map
{
my
$topic
=
$_
;
if
(
$topics
{
$topic
}
->
{
sub
})
{
(
$topic
,
map
{
$topic
.
'
/
'
.
$_
}
sort
keys
%
{
$topics
{
$topic
}
->
{
sub
}}
);
}
else
{
(
$topic
);
}
}
sort
keys
%topics
;
my
@topics
=
Sympa::Robot::
topic_keys
(
$robot_id
);
$pinfo
->
{
topics
}{
format
}
=
[
@topics
];
# Compat.
$pinfo
->
{
topics
}{
file_format
}
=
sprintf
'
(%s)(,(%s))*
',
...
...
src/lib/Sympa/Template.pm
View file @
d44f14b1
...
...
@@ -238,6 +238,7 @@ sub _optdesc_func {
my
$type
=
shift
;
my
$withval
=
shift
;
my
$that
=
$self
->
{
context
};
my
$encode_html
=
(
$self
->
{
subdir
}
&&
$self
->
{
subdir
}
eq
'
web_tt2
');
return
sub
{
...
...
@@ -246,7 +247,8 @@ sub _optdesc_func {
return
undef
unless
$x
=~
/\S/
;
$x
=~
s/^\s+//
;
$x
=~
s/\s+$//
;
my
$title
=
Sympa::ListOpt::
get_title
(
$x
,
$type
,
$withval
);
my
$title
=
Sympa::ListOpt::
get_option_description
(
$that
,
$x
,
$type
,
$withval
);
$encode_html
?
Sympa::Tools::Text::
encode_html
(
$title
)
:
$title
;
};
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment