Revision 63181547
Von Bernd Bleßmann vor fast 6 Jahren hinzugefügt
SL/Helper/UserPreferences/DisplayableName.pm | ||
---|---|---|
1 |
package SL::Helper::UserPreferences::DisplayableName; |
|
2 |
|
|
3 |
use strict; |
|
4 |
use parent qw(Rose::Object); |
|
5 |
|
|
6 |
use Carp; |
|
7 |
use List::MoreUtils qw(none); |
|
8 |
|
|
9 |
use SL::Helper::UserPreferences; |
|
10 |
|
|
11 |
use Rose::Object::MakeMethods::Generic ( |
|
12 |
'scalar --get_set_init' => [ qw(module default_prefs user_prefs data) ], |
|
13 |
); |
|
14 |
|
|
15 |
sub get { |
|
16 |
$_[0]->data; |
|
17 |
} |
|
18 |
|
|
19 |
sub _store { |
|
20 |
my ($self, $val, $target) = @_; |
|
21 |
|
|
22 |
return if $self->data eq $val; |
|
23 |
|
|
24 |
$self->data($val); |
|
25 |
$self->$target->store($self->module, $self->data); |
|
26 |
} |
|
27 |
|
|
28 |
sub init_default_prefs { |
|
29 |
SL::Helper::UserPreferences->new( |
|
30 |
login => $_[0]->default_login, |
|
31 |
namespace => $_[0]->namespace, |
|
32 |
) |
|
33 |
} |
|
34 |
|
|
35 |
sub init_user_prefs { |
|
36 |
SL::Helper::UserPreferences->new( |
|
37 |
namespace => $_[0]->namespace, |
|
38 |
) |
|
39 |
} |
|
40 |
|
|
41 |
sub init_data { |
|
42 |
my $data; |
|
43 |
$data = $_[0]->user_prefs ->get($_[0]->module); |
|
44 |
$data //= $_[0]->default_prefs->get($_[0]->module); |
|
45 |
|
|
46 |
return $data; |
|
47 |
} |
|
48 |
|
|
49 |
sub init_module { |
|
50 |
die 'need module'; |
|
51 |
} |
|
52 |
|
|
53 |
# proxy to user prefs |
|
54 |
sub delete { $_[0]->user_prefs->delete($_[0]->module); $_[0]->data($_[0]->init_data()) } |
|
55 |
sub login { $_[0]->user_prefs->login } |
|
56 |
|
|
57 |
# proxy to default prefs |
|
58 |
sub get_default { $_[0]->default_prefs->get($_[0]->module) } |
|
59 |
|
|
60 |
# aliases |
|
61 |
sub store_value { _store(@_, 'user_prefs') } |
|
62 |
sub store_default { _store(@_, 'default_prefs') } |
|
63 |
|
|
64 |
# read only stuff |
|
65 |
sub default_login { '#default#' } |
|
66 |
sub namespace { 'DisplayableName' } |
|
67 |
sub version { 1 } |
|
68 |
|
|
69 |
1; |
|
70 |
|
|
71 |
__END__ |
|
72 |
|
|
73 |
=pod |
|
74 |
|
|
75 |
=encoding utf-8 |
|
76 |
|
|
77 |
=head1 NAME |
|
78 |
|
|
79 |
SL::Helper::UserPreferences::DisplayableName - hybrid preferences intended |
|
80 |
for two tiered (user over default) displayable name preferences |
|
81 |
|
|
82 |
=head1 SYNOPSIS |
|
83 |
|
|
84 |
use SL::Helper::UserPreferences::DisplayableName; |
|
85 |
my $prefs = SL::Helper::UserPreferences::DisplayableName->new( |
|
86 |
module => 'SL::DB::Customer' |
|
87 |
); |
|
88 |
|
|
89 |
my $value = $prefs->get; |
|
90 |
my $value = $prefs->store_value('<%number%> <%name%> (PLZ <%zipcode%>)'); |
|
91 |
my $value = $prefs->store_default('<%number%> <%name%>'); |
|
92 |
|
|
93 |
=head1 DESCRIPTION |
|
94 |
|
|
95 |
This module proxies two L<SL::Helper::UserPreferences> instances, one global and |
|
96 |
one for the current user. |
|
97 |
It is intended to be used with the C<SL::DB::SomeObject> classes via |
|
98 |
L<SL::DB::Helper::DisplayableNamePreferences> (see there). |
|
99 |
|
|
100 |
=head1 BUGS |
|
101 |
|
|
102 |
None yet :) |
|
103 |
|
|
104 |
=head1 AUTHOR |
|
105 |
|
|
106 |
Bernd Bleßmann E<lt>bernd@kivitendo-premium.deE<gt> |
|
107 |
|
|
108 |
=cut |
Auch abrufbar als: Unified diff
DisplayableNamePrefs: UserPreferences-Helper f. DisplayableName