LJSUP-17669: Login.bml form refactoring
[livejournal.git] / cgi-bin / LJ / Setting / UserMessaging.pm
blobcb95f48bec788293f28663ac6d9b519e4184c6e4
1 package LJ::Setting::UserMessaging;
2 use base 'LJ::Setting';
3 use strict;
4 use warnings;
6 sub tags { qw(email message contact) }
8 sub as_html {
9 my ($class, $u, $errs, $args) = @_;
10 my $key = $class->pkgkey;
11 my $ret;
13 $ret .= "<label for='${key}opt_usermsg'>" . $class->ml('settings.usermessaging.question') . "</label>";
14 $ret .= LJ::html_select({ 'name' => "${key}opt_usermsg",
15 'id' => "${key}opt_usermsg",
16 'class' => "select",
17 'selected' => $u->opt_usermsg },
18 { text => LJ::Lang::ml('settings.usermessaging.opt.Y'),
19 value => "Y",
20 disabled => $u->is_child,},
21 { text => LJ::Lang::ml('settings.usermessaging.opt.F'),
22 value => "F",
23 disabled => $u->is_child,},
24 ($LJ::DISABLED{'new_friends_and_subscriptions'} ?
25 { text => LJ::Lang::ml('settings.usermessaging.opt.M'),
26 value => "M",} : ()),
27 { text => LJ::Lang::ml('settings.usermessaging.opt.N'),
28 value => "N",});
29 $ret .= "<div class='helper'>" .
30 $class->ml('settings.usermessaging.helper', {
31 sitename => $LJ::SITENAMESHORT }) .
32 "</div>";
33 $ret .= $class->errdiv($errs, "opt_usermsg");
35 return $ret;
38 sub error_check {
39 my ($class, $u, $args) = @_;
40 my $opt_usermsg= $class->get_arg($args, "opt_usermsg");
41 $class->errors("opt_usermsg" => $class->ml('settings.usermessaging.error.invalid')) unless $opt_usermsg=~ /^[MFNY]$/;
42 return 1;
45 sub save {
46 my ($class, $u, $args) = @_;
47 $class->error_check($u, $args);
49 my $opt_usermsg = $class->get_arg($args, "opt_usermsg");
50 return $u->set_prop('opt_usermsg', $opt_usermsg);