| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Kwiki::UserPreferences; |
|
2
|
1
|
|
|
1
|
|
28008
|
use Kwiki::Plugin -Base; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use mixin 'Kwiki::Installer'; |
|
4
|
|
|
|
|
|
|
our $VERSION = '0.13'; |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
const class_id => 'user_preferences'; |
|
7
|
|
|
|
|
|
|
const class_title => 'User Preferences'; |
|
8
|
|
|
|
|
|
|
field preference_objects => []; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
|
11
|
|
|
|
|
|
|
my $registry = shift; |
|
12
|
|
|
|
|
|
|
$registry->add(action => 'user_preferences'); |
|
13
|
|
|
|
|
|
|
$registry->add(toolbar => 'user_preferences_button', |
|
14
|
|
|
|
|
|
|
template => 'user_preferences_button.html', |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
} |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub user_preferences { |
|
19
|
|
|
|
|
|
|
$self->get_preference_objects; |
|
20
|
|
|
|
|
|
|
my $errors = 0; |
|
21
|
|
|
|
|
|
|
$errors = $self->save |
|
22
|
|
|
|
|
|
|
if $self->cgi->button; |
|
23
|
|
|
|
|
|
|
return $self->render_screen(errors => $errors); |
|
24
|
|
|
|
|
|
|
} |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub save { |
|
27
|
|
|
|
|
|
|
my %cgi = $self->cgi->vars; |
|
28
|
|
|
|
|
|
|
my $settings = {}; |
|
29
|
|
|
|
|
|
|
my $errors = 0; |
|
30
|
|
|
|
|
|
|
for my $object (@{$self->preference_objects}) { |
|
31
|
|
|
|
|
|
|
$object->error(''); |
|
32
|
|
|
|
|
|
|
my $class_id = $object->owner_id; |
|
33
|
|
|
|
|
|
|
for (sort keys %cgi) { |
|
34
|
|
|
|
|
|
|
my $setting = $cgi{$_}; |
|
35
|
|
|
|
|
|
|
if (/^${class_id}__(.*)/) { |
|
36
|
|
|
|
|
|
|
my $pref = $1; |
|
37
|
|
|
|
|
|
|
$pref =~ s/-boolean$//; |
|
38
|
|
|
|
|
|
|
if (not exists $settings->{$pref}) { |
|
39
|
|
|
|
|
|
|
$settings->{$pref} = $setting; |
|
40
|
|
|
|
|
|
|
$object->new_value($setting); |
|
41
|
|
|
|
|
|
|
if ($object->edit) { |
|
42
|
|
|
|
|
|
|
my $method = $object->edit; |
|
43
|
|
|
|
|
|
|
$self->hub->$class_id->$method($object); |
|
44
|
|
|
|
|
|
|
$errors = 1, next if $object->error; |
|
45
|
|
|
|
|
|
|
} |
|
46
|
|
|
|
|
|
|
$object->value($setting); |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
} |
|
51
|
|
|
|
|
|
|
return 1 if $errors; |
|
52
|
|
|
|
|
|
|
$self->hub->cookie->jar->{preferences} = $settings; |
|
53
|
|
|
|
|
|
|
return 0; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub get_preference_objects { |
|
57
|
|
|
|
|
|
|
my %class_map = reverse %{$self->hub->registry->lookup->classes}; |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my @objects; |
|
60
|
|
|
|
|
|
|
my $objects_by_class = $self->users->current->preferences->objects_by_class; |
|
61
|
|
|
|
|
|
|
for (map $class_map{$_}, @{$self->hub->config->plugin_classes}) { |
|
62
|
|
|
|
|
|
|
push @objects, @{$objects_by_class->{$_}} |
|
63
|
|
|
|
|
|
|
if defined $objects_by_class->{$_}; |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
$self->preference_objects(\ @objects); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__DATA__ |