LJSUP-17669: Login.bml form refactoring
[livejournal.git] / cgi-bin / LJ / Setting / MinSecurity.pm
blob8a8f0cfb06d762ac2df5ce3641d7ba2c76f7f5bc
1 package LJ::Setting::MinSecurity;
2 use base 'LJ::Setting';
3 use strict;
4 use warnings;
6 sub should_render {
7 my ($class, $u) = @_;
9 return $u && !$u->is_identity ? 1 : 0;
12 sub helpurl {
13 my ($class, $u) = @_;
15 return "minsecurity_full";
18 sub label {
19 my $class = shift;
21 return $class->ml('setting.minsecurity.label');
24 sub option {
25 my ($class, $u, $errs, $args) = @_;
26 my $key = $class->pkgkey;
28 my $minsecurity = $class->get_arg($args, "minsecurity") || $u->prop("newpost_minsecurity");
30 my @options = (
31 "" => $class->ml('setting.minsecurity.option.select.public'),
32 friends => $u->is_community ? $class->ml('setting.minsecurity.option.select.members') : $class->ml('setting.minsecurity.option.select.friends'),
34 push @options, ( private => $class->ml('setting.minsecurity.option.select.private') )
35 if $u->is_personal;
37 my $ret = "<label for='${key}minsecurity'>" . $class->ml('setting.minsecurity.option') . "</label> ";
38 $ret .= LJ::html_select({
39 name => "${key}minsecurity",
40 id => "${key}minsecurity",
41 selected => $minsecurity,
42 }, @options);
44 return $ret;
47 sub save {
48 my ($class, $u, $args) = @_;
50 my $val = $class->get_arg($args, "minsecurity");
51 if ($u->is_community) {
52 $val = "" unless $val =~ /^(friends)$/;
53 } else {
54 $val = "" unless $val =~ /^(friends|private)$/;
57 my $old_value = $u->prop("newpost_minsecurity");
58 $u->set_prop( newpost_minsecurity => $val );
60 return 1 if $old_value eq $val;
62 LJ::User::UserlogRecord::ChangeSetting->create( $u,
63 setting_name => 'newpost_minsecurity',
64 new_value => $val || 'public',
65 old_value => $old_value || 'public',
68 return 1;