LJSUP-17669: Login.bml form refactoring
[livejournal.git] / cgi-bin / LJ / Setting / FindByEmail.pm
blob3e6fbeacb1d40103a9937104691a4de4d0c3c803
1 package LJ::Setting::FindByEmail;
2 use base 'LJ::Setting';
3 use strict;
4 use warnings;
6 sub tags { qw(email search) }
8 sub helpurl {
9 my ($class, $u) = @_;
11 return "find_by_email";
14 *option = \&as_html;
15 sub as_html {
16 my ($class, $u, $errs, $args) = @_;
17 $args ||= {};
18 my $key = $class->pkgkey;
19 my $ret;
20 my $helper = (defined $args->{helper} and $args->{helper} == 0) ? 0 : 1;
21 my $faq = (defined $args->{faq} and $args->{faq} == 1) ? 1 : 0;
22 my $display_null = (defined $args->{display_null} and $args->{display_null} == 0) ? 0 : 1;
24 $ret .= "<label for='${key}opt_findbyemail'>" .
25 $class->ml('settings.findbyemail.question',
26 { sitename => $LJ::SITENAMESHORT }) . "</label>";
28 # Display learn more link?
29 $ret .= " (<a href='" . $LJ::HELPURL{$class->helpurl($u)} .
30 "'>" . $class->ml('settings.settingprod.learn') . "</a>)<br />"
31 if ($faq && $LJ::HELPURL{$class->helpurl($u)});
33 $ret .= "<br />";
34 my @options;
35 push @options, { text => $class->ml('settings.option.select'), value => '' }
36 if not $u->opt_findbyemail and $display_null;
37 my $default = $display_null ? '' : 'H';
38 push @options, { text => LJ::Lang::ml('settings.findbyemail.opt.Y'), value => "Y" };
39 push @options, { text => LJ::Lang::ml('settings.findbyemail.opt.H'), value => "H" };
40 push @options, { text => LJ::Lang::ml('settings.findbyemail.opt.N'), value => "N" };
41 $ret .= LJ::html_select({ 'name' => "${key}opt_findbyemail",
42 'id' => "${key}opt_findbyemail",
43 ### 'class' => "select",
44 'selected' => $u->opt_findbyemail || $default },
45 @options );
47 # Display helper text about setting?
48 $ret .= "<div class='helper'>" .
49 $class->ml('settings.findbyemail.helper', {
50 sitename => $LJ::SITENAMESHORT,
51 siteabbrev => $LJ::SITENAMEABBREV }) .
52 "</div>" if ($helper);
53 $ret .=
54 "<div class='helper'>" .
55 $class->ml('settings.findbyemail.notice', {siteroot => $LJ::SITEROOT}) .
56 "</div>";
58 $ret .= $class->errdiv($errs, "opt_findbyemail");
60 return $ret;
63 sub error_check {
64 my ($class, $u, $args) = @_;
65 my $opt_findbyemail = $class->get_arg($args, "opt_findbyemail");
66 $class->errors("opt_findbyemail" => $class->ml('settings.findbyemail.error.invalid')) unless $opt_findbyemail=~ /^[NHY]$/;
67 return 1;
70 sub save {
71 my ($class, $u, $args) = @_;
72 $class->error_check($u, $args);
74 my $opt_findbyemail = $class->get_arg($args, "opt_findbyemail");
75 return $u->set_prop('opt_findbyemail', $opt_findbyemail);
78 sub label {
79 my $class = shift;
80 $class->ml('settings.findbyemail.label');
83 # return key value pairs for field names and values chosen
84 sub settings {
85 my ($class, $args) = @_;
87 my @list;
88 push @list, "opt_findbyemail";
89 push @list, $class->get_arg($args, "opt_findbyemail") || '';
91 return @list;