Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b6fd15a8

Von Sven Schöling vor etwa 12 Jahren hinzugefügt

  • ID b6fd15a8dc44f9b09d5a2bce766cda14b87c6e13
  • Vorgänger fb005f3f
  • Nachfolger aee7eda0

Layout package names refactored

SL::Controller::Layout::* -> SL::Layout::*
SL::Controller::Layout -> SL::Layout::Dispatcher

Unterschiede anzeigen:

SL/Controller/Layout.pm
1
package SL::Controller::Layout;
2

  
3
use strict;
4
use parent qw(SL::Controller::Base);
5

  
6
use SL::Menu;
7
use SL::Controller::Layout::Admin;
8
use SL::Controller::Layout::Login;
9
use SL::Controller::Layout::Classic;
10
use SL::Controller::Layout::V3;
11
use SL::Controller::Layout::V4;
12
use SL::Controller::Layout::Javascript;
13

  
14
my %menu_cache;
15

  
16
sub new {
17
  my ($class, %params) = @_;
18

  
19
  return SL::Controller::Layout::Classic->new    if $params{style} eq 'old';
20
  return SL::Controller::Layout::V3->new         if $params{style} eq 'v3';
21
  return SL::Controller::Layout::V4->new         if $params{style} eq 'v4';
22
  return SL::Controller::Layout::Javascript->new if $params{style} eq 'neu';
23
  return SL::Controller::Layout::Admin->new      if $params{style} eq 'admin';
24
  return SL::Controller::Layout::Login->new      if $params{style} eq 'login';
25
  return SL::Controller::Layout::None->new;
26
}
27

  
28
1;
SL/Controller/Layout/Admin.pm
1
package SL::Controller::Layout::Admin;
2

  
3
use strict;
4
use parent qw(SL::Controller::Layout::Base);
5

  
6
sub new {
7
  my ($class, @slurp) = @_;
8

  
9
  my $self = $class->SUPER::new(@slurp);
10

  
11
  $self->add_sub_layouts([
12
    SL::Controller::Layout::None->new,
13
  ]);
14

  
15
  $self;
16
}
17

  
18
sub start_content {
19
  "<div id='admin' class='admin'>\n";
20
}
21

  
22
sub end_content {
23
  "</div>\n";
24
}
25

  
26
1;
SL/Controller/Layout/Base.pm
1
package SL::Controller::Layout::Base;
2

  
3
use strict;
4
use parent qw(SL::Controller::Base);
5

  
6
use Rose::Object::MakeMethods::Generic (
7
  'scalar --get_set_init' => qw(menu),
8
  'scalar'                => qw(focus),
9
  'array'                 => [
10
    'add_stylesheets_inline' => { interface => 'add', hash_key => 'stylesheets_inline' },
11
    'add_javascripts_inline' => { interface => 'add', hash_key => 'javascripts_inline' },
12
    'sub_layouts',
13
    'add_sub_layouts'         => { interface => 'add', hash_key => 'sub_layouts' },
14
  ],
15
);
16

  
17
use SL::Menu;
18

  
19
my %menu_cache;
20

  
21
sub new {
22
  my ($class, @slurp) = @_;
23

  
24
  my $self = $class->SUPER::new(@slurp);
25
}
26

  
27
sub init_menu {
28
  Menu->new('menu.ini');
29
}
30

  
31
##########################################
32
#  inheritable/overridable
33
##########################################
34

  
35
sub pre_content {
36
  join '', map { $_->pre_content } $_[0]->sub_layouts;
37
}
38

  
39
sub start_content {
40
  join '', map { $_->start_content } $_[0]->sub_layouts;
41
}
42

  
43
sub end_content {
44
  join '', map { $_->end_content } $_[0]->sub_layouts;
45
}
46

  
47
sub post_content {
48
  join '', map { $_->post_content } $_[0]->sub_layouts;
49
}
50

  
51
sub stylesheets_inline {
52
  ( map { $_->stylesheets_inline } $_[0]->sub_layouts ),
53
  @{ $_[0]->{stylesheets_inline} || [] };
54
}
55

  
56
sub javascripts_inline {
57
  ( map { $_->javascripts_inline } $_[0]->sub_layouts ),
58
  @{ $_[0]->{javascripts_inline} || [] };
59
}
60

  
61

  
62
#########################################
63
# Interface
64
########################################
65

  
66
sub use_stylesheet {
67
  my $self = shift;
68
  push @{ $self->{stylesheets} ||= [] }, @_ if @_;
69
  @{ $self->{stylesheets} ||= [] };
70
}
71

  
72
sub stylesheets {
73
  my ($self) = @_;
74
  my $css_path = $self->get_stylesheet_for_user;
75

  
76
  return grep { $_ } map { $self->_find_stylesheet($_, $css_path)  }
77
    $self->use_stylesheet, map { $_->stylesheets } $self->sub_layouts;
78
}
79

  
80
sub _find_stylesheet {
81
  my ($self, $stylesheet, $css_path) = @_;
82

  
83
  return "$css_path/$stylesheet" if -f "$css_path/$stylesheet";
84
  return "css/$stylesheet"       if -f "css/$stylesheet";
85
  return $stylesheet             if -f $stylesheet;
86
}
87

  
88
sub get_stylesheet_for_user {
89
  my $css_path = 'css';
90
  if (my $user_style = $::myconfig{stylesheet}) {
91
    $user_style =~ s/\.css$//; # nuke trailing .css, this is a remnand of pre 2.7.0 stylesheet handling
92
    if (-d "$css_path/$user_style" &&
93
        -f "$css_path/$user_style/main.css") {
94
      $css_path = "$css_path/$user_style";
95
    } else {
96
      $css_path = "$css_path/lx-office-erp";
97
    }
98
  } else {
99
    $css_path = "$css_path/lx-office-erp";
100
  }
101
  $::myconfig{css_path} = $css_path; # needed for menunew, FIXME: don't do this here
102

  
103
  return $css_path;
104
}
105

  
106

  
107
sub use_javascript {
108
  my $self = shift;
109
  push @{ $self->{javascripts} ||= [] }, @_ if @_;
110
  @{ $self->{javascripts} ||= [] };
111
}
112

  
113
sub javascripts {
114
  my ($self) = @_;
115

  
116
  return map { $self->_find_javascript($_)  }
117
    $self->use_javascript, map { $_->javascripts } $self->sub_layouts;
118
}
119

  
120
sub _find_javascript {
121
  my ($self, $javascript) = @_;
122

  
123
  return "js/$javascript"        if -f "js/$javascript";
124
  return $javascript             if -f $javascript;
125
}
126

  
127

  
128
############################################
129
# track state of form header
130
############################################
131

  
132
sub header_done {
133
  $_[0]{_header_done} = 1;
134
}
135

  
136
sub need_footer {
137
  $_[0]{_header_done};
138
}
139

  
140
1;
SL/Controller/Layout/Classic.pm
1
package SL::Controller::Layout::Classic;
2

  
3
use strict;
4
use parent qw(SL::Controller::Layout::Base);
5

  
6
use SL::Controller::Layout::Top;
7
use SL::Controller::Layout::MenuLeft;
8

  
9
sub new {
10
  my ($class, @slurp) = @_;
11

  
12
  my $self = $class->SUPER::new(@slurp);
13

  
14
  $self->add_sub_layouts([
15
    SL::Controller::Layout::Top->new,
16
    SL::Controller::Layout::MenuLeft->new,
17
    SL::Controller::Layout::None->new,
18
  ]);
19

  
20
  $self;
21
}
22

  
23
1;
SL/Controller/Layout/Css.pm
1
package SL::Controller::Layout::Css;
2

  
3
use strict;
4

  
5
use List::Util qw(max);
6
use Exporter qw(import);
7

  
8
our @EXPORT = qw(clock_line print_menu menuitem_v3);
9

  
10
sub clock_line {
11
  my ($Sekunden, $Minuten,   $Stunden,   $Monatstag, $Monat,
12
      $Jahr,     $Wochentag, $Jahrestag, $Sommerzeit)
13
    = localtime(time);
14
  $Monat     += 1;
15
  $Jahrestag += 1;
16
  $Monat     = $Monat < 10     ? $Monat     = "0" . $Monat     : $Monat;
17
  $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
18
  $Jahr += 1900;
19
  my @Wochentage = ("Sonntag",    "Montag",  "Dienstag", "Mittwoch",
20
                    "Donnerstag", "Freitag", "Samstag");
21
  my @Monatsnamen = ("",       "Januar",    "Februar", "M&auml;rz",
22
                     "April",  "Mai",       "Juni",    "Juli",
23
                     "August", "September", "Oktober", "November",
24
                     "Dezember");
25
  return
26
      $Wochentage[$Wochentag] . ", der "
27
    . $Monatstag . "."
28
    . $Monat . "."
29
    . $Jahr . " - ";
30
}
31

  
32
sub print_menu {
33
  my ($self, $parent, $depth) = @_;
34

  
35
  my $html;
36

  
37
  die if ($depth * 1 > 5);
38

  
39
  my @menuorder;
40
  my $menu = $self->menu;
41

  
42
  @menuorder = $menu->access_control(\%::myconfig, $parent);
43

  
44
  $parent .= "--" if ($parent);
45

  
46
  foreach my $item (@menuorder) {
47
    substr($item, 0, length($parent)) = "";
48
    next if (($item eq "") || ($item =~ /--/));
49

  
50
    my $menu_item = $menu->{"${parent}${item}"};
51
    my $menu_title = $::locale->text($item);
52
    my $menu_text = $menu_title;
53

  
54
    if ($menu_item->{"submenu"} || !defined($menu_item->{"module"}) ||
55
        ($menu_item->{"module"} eq "menu.pl")) {
56

  
57
      my $h = $self->print_menu("${parent}${item}", $depth * 1 + 1)."\n";
58
      if (!$parent) {
59
        $html .= qq|<ul><li><h2>${menu_text}</h2><ul>${h}</ul></li></ul>\n|;
60
      } else {
61
        $html .= qq|<li><div class="x">${menu_text}</div><ul>${h}</ul></li>\n|;
62
      }
63
    } else {
64
      if ($self->{sub_class} && $depth > 1) {
65
        $html .= qq|<li class='sub'>|;
66
      } else {
67
        $html .= qq|<li>|;
68
      }
69
      $html .= $self->menuitem_v3("${parent}$item", { "title" => $menu_title });
70
      $html .= qq|${menu_text}</a></li>\n|;
71
    }
72
  }
73

  
74
  return $html;
75
}
76

  
77
sub menuitem_v3 {
78
  $main::lxdebug->enter_sub();
79

  
80
  my ($self, $item, $other) = @_;
81
  my $menuitem = $self->menu->{$item};
82

  
83
  my $action = "section_menu";
84
  my $module;
85

  
86
  if ($menuitem->{module}) {
87
    $module = $menuitem->{module};
88
  }
89
  if ($menuitem->{action}) {
90
    $action = $menuitem->{action};
91
  }
92

  
93
  my $level = $::form->escape($item);
94

  
95
  my $str = qq|<a href="$module?action=| . $::form->escape($action) . qq|&level=| . $::form->escape($level);
96

  
97
  my @vars = qw(module action target href);
98

  
99
  if ($menuitem->{href}) {
100
    $str  = qq|<a href=$menuitem->{href}|;
101
    @vars = qw(module target href);
102
  }
103

  
104
  map { delete $menuitem->{$_} } @vars;
105

  
106
  # add other params
107
  foreach my $key (keys %{ $menuitem }) {
108
    $str .= "&" . $::form->escape($key, 1) . "=";
109
    my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
110
    $value = $::myconfig{$value} . "/$conf" if ($conf);
111
    $str .= $::form->escape($value, 1);
112
  }
113

  
114
  $str .= '"';
115

  
116
  if ($other) {
117
    foreach my $key (keys(%{$other})) {
118
      $str .= qq| ${key}="| . $::form->quote($other->{$key}) . qq|"|;
119
    }
120
  }
121

  
122
  $str .= ">";
123

  
124
  $main::lxdebug->leave_sub();
125

  
126
  return $str;
127
}
128

  
129
1;
SL/Controller/Layout/Javascript.pm
1
package SL::Controller::Layout::Javascript;
2

  
3
use strict;
4
use parent qw(SL::Controller::Layout::Base);
5

  
6
use List::Util qw(max);
7
use URI;
8

  
9
sub new {
10
  my ($class, @slurp) = @_;
11

  
12
  my $self = $class->SUPER::new(@slurp);
13

  
14
  $self->add_sub_layouts([
15
    SL::Controller::Layout::None->new,
16
  ]);
17

  
18
  $self;
19
}
20

  
21
sub pre_content {
22
  &display
23
}
24

  
25
sub start_content {
26
  "<div id='content'>\n";
27
}
28

  
29
sub end_content {
30
  "</div>\n";
31
}
32

  
33
sub display {
34
  my ($self) = @_;
35
  my $form     = $main::form;
36

  
37
  my $callback            = $form->unescape($form->{callback});
38
  $callback               = URI->new($callback)->rel($callback) if $callback;
39
  $callback               = "login.pl?action=company_logo"      if $callback =~ /^(\.\/)?$/;
40

  
41
  $form->parse_html_template("menu/menunew", {
42
#  $self->render("menu/menunew", { no_menu => 1, no_output => 1 }, # buggy, no idea why
43
    force_ul_width  => 1,
44
    date            => $self->clock_line,
45
    menu_items      => $self->acc_menu,
46
    callback        => $callback,
47
  });
48
}
49

  
50
sub clock_line {
51
  my $form     = $main::form;
52

  
53
  my ($Sekunden, $Minuten,   $Stunden,   $Monatstag, $Monat,
54
      $Jahr,     $Wochentag, $Jahrestag, $Sommerzeit)
55
    = localtime(time);
56
  $Monat     += 1;
57
  $Jahrestag += 1;
58
  $Monat     = $Monat < 10     ? $Monat     = "0" . $Monat     : $Monat;
59
  $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
60
  $Jahr += 1900;
61
  my @Wochentage = ("Sonntag",    "Montag",  "Dienstag", "Mittwoch",
62
                    "Donnerstag", "Freitag", "Samstag");
63
  my @Monatsnamen = ("",       "Januar",    "Februar", "M&auml;rz",
64
                     "April",  "Mai",       "Juni",    "Juli",
65
                     "August", "September", "Oktober", "November",
66
                     "Dezember");
67
  return
68
      $Wochentage[$Wochentag] . ", der "
69
    . $Monatstag . "."
70
    . $Monat . "."
71
    . $Jahr . " - ";
72
}
73

  
74
sub acc_menu {
75
  my ($self) = @_;
76

  
77
  my $menu      = $self->menu;
78

  
79
  my $all_items = [];
80
  $self->create_menu($menu, $all_items);
81

  
82
  my $item = { 'subitems' => $all_items };
83
  calculate_width($item);
84

  
85
  return $all_items;
86
}
87

  
88
sub calculate_width {
89
  my $item           = shift;
90

  
91
  $item->{max_width} = max map { length $_->{title} } @{ $item->{subitems} };
92

  
93
  foreach my $subitem (@{ $item->{subitems} }) {
94
    calculate_width($subitem) if ($subitem->{subitems});
95
  }
96
}
97

  
98
sub create_menu {
99
  my ($self, $menu, $all_items, $parent, $depth) = @_;
100
  my $html;
101

  
102
  my $form     = $main::form;
103
  my %myconfig = %main::myconfig;
104

  
105
  die if ($depth * 1 > 5);
106

  
107
  my @menuorder  = $menu->access_control(\%myconfig, $parent);
108
  $parent       .= "--" if ($parent);
109

  
110
  foreach my $name (@menuorder) {
111
    substr($name, 0, length($parent), "");
112
    next if (($name eq "") || ($name =~ /--/));
113

  
114
    my $menu_item = $menu->{"${parent}${name}"};
115
    my $item      = { 'title' => $::locale->text($name) };
116
    push @{ $all_items }, $item;
117

  
118
    if ($menu_item->{submenu} || !defined($menu_item->{module}) || ($menu_item->{module} eq "menu.pl")) {
119
      $item->{subitems} = [];
120
      $item->{image} = _icon_path("$name.png");
121
      $self->create_menu($menu, $item->{subitems}, "${parent}${name}", $depth * 1 + 1);
122

  
123
    } else {
124
      $item->{image} = _icon_path("${parent}${name}.png");
125
      $menu->menuitem_new("${parent}${name}", $item);
126
    }
127
  }
128
}
129

  
130
sub _icon_path {
131
  my ($label, $size) = @_;
132

  
133
  $size ||= 16;
134

  
135
  my $img = "image/icons/${size}x${size}/$label";
136

  
137
  return unless -f $img;
138
  return $img;
139
}
140

  
141
1;
SL/Controller/Layout/Login.pm
1
package SL::Controller::Layout::Login;
2

  
3
use strict;
4
use parent qw(SL::Controller::Layout::Base);
5

  
6
sub new {
7
  my ($class, @slurp) = @_;
8

  
9
  my $self = $class->SUPER::new(@slurp);
10

  
11
  $self->add_sub_layouts([
12
    SL::Controller::Layout::None->new,
13
  ]);
14

  
15
  $self;
16
}
17

  
18
sub start_content {
19
  "<div id='login' class='login'>\n";
20
}
21

  
22
sub end_content {
23
  "</div>\n";
24
}
25

  
26
1;
SL/Controller/Layout/MenuLeft.pm
1
package SL::Controller::Layout::MenuLeft;
2

  
3
use strict;
4
use parent qw(SL::Controller::Layout::Base);
5

  
6
use URI;
7

  
8
use List::MoreUtils qw(apply);
9

  
10
sub stylesheets {
11
  qw(css/icons16.css css/icons24.css)
12
}
13

  
14
sub javascripts_inline {
15
  my $self = shift;
16
  my $sections = [ section_menu($self->menu) ];
17
  $self->render('menu/menu', { no_menu => 1, no_output => 1 },
18
    sections  => $sections,
19
  )
20
}
21

  
22
sub pre_content {
23
  "<div id='html-menu'></div>\n";
24
}
25

  
26
sub start_content {
27
  "<div id='content' class='html-menu'>\n";
28
}
29

  
30
sub end_content {
31
  "</div>\n";
32
}
33

  
34
sub section_menu {
35
  $::lxdebug->enter_sub(2);
36
  my ($menu, $level, $id_prefix) = @_;
37
  my @menuorder = $menu->access_control(\%::myconfig, $level);
38
  my @items;
39

  
40
  my $id = 0;
41

  
42
  for my $item (@menuorder) {
43
    my $menuitem   = $menu->{$item};
44
    my $olabel     = apply { s/.*--// } $item;
45
    my $ml         = apply { s/--.*// } $item;
46
    my $icon_class = apply { y/ /-/   } $item;
47
    my $spacer     = "s" . (0 + $item =~ s/--/--/g);
48

  
49
    next if $level && $item ne "$level--$olabel";
50

  
51
    my $label         = $::locale->text($olabel);
52

  
53
    $menuitem->{module} ||= $::form->{script};
54
    $menuitem->{action} ||= "section_menu";
55
    $menuitem->{href}   ||= "$menuitem->{module}?action=$menuitem->{action}";
56

  
57
    # add other params
58
    foreach my $key (keys %$menuitem) {
59
      next if $key =~ /target|module|action|href/;
60
      $menuitem->{href} .= "&" . $::form->escape($key, 1) . "=";
61
      my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
62
      $value = $::myconfig{$value} . "/$conf" if ($conf);
63
      $menuitem->{href} .= $::form->escape($value, 1);
64
    }
65

  
66
    my $anchor = $menuitem->{href};
67

  
68
    my @common_args = ($label, $spacer, "$id_prefix\_$id");
69

  
70
    if (!$level) { # toplevel
71
      push @items, [ @common_args, "icon24 $icon_class", 'm' ];
72
      #  make_image(size => 24, label => $item),
73
      push @items, section_menu($menu, $item, "$id_prefix\_$id");
74
    } elsif ($menuitem->{submenu}) {
75
      push @items, [ @common_args, "icon16 submenu", 'sm' ];
76
      #make_image(label => 'submenu'),
77
      push @items, section_menu($menu, $item, "$id_prefix\_$id");
78
    } elsif ($menuitem->{module}) {
79
      push @items, [ @common_args, "icon16 $icon_class", 'i', $anchor ];
80
      #make_image(size => 16, label => $item),
81
    }
82
  } continue {
83
    $id++;
84
  }
85

  
86
  $::lxdebug->leave_sub(2);
87
  return @items;
88
}
89

  
90
sub _calc_framesize {
91
  my $is_lynx_browser   = $ENV{HTTP_USER_AGENT} =~ /links/i;
92
  my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i;
93
  my $is_mobile_style   = $::form->{stylesheet} =~ /mobile/i;
94

  
95
  return  $is_mobile_browser && $is_mobile_style ?  130
96
        : $is_lynx_browser                       ?  240
97
        :                                           200;
98
}
99

  
100
sub _show_images {
101
  # don't show images in links
102
  _calc_framesize() != 240;
103
}
104

  
105
1;
SL/Controller/Layout/None.pm
1
package SL::Controller::Layout::None;
2

  
3
use strict;
4
use parent qw(SL::Controller::Layout::Base);
5

  
6
sub javascripts_inline {
7
  _setup_formats(),
8
  _setup_focus(),
9
}
10

  
11

  
12
sub _setup_formats {
13
  $::form->parse_html_template('generic/javascript_setup')
14
}
15

  
16
sub _setup_focus {
17
  if ($::request->{layout}->focus || $::form->{fokus}) {
18
    return $::form->parse_html_template('generic/focus_setup', {
19
      focus => $::request->{layout}->focus,
20
      fokus => $::form->{fokus},
21
    })
22
  } else {
23
    return ();
24
  }
25
}
26

  
27
1;
SL/Controller/Layout/Top.pm
1
package SL::Controller::Layout::Top;
2

  
3
use strict;
4
use parent qw(SL::Controller::Layout::Base);
5

  
6
sub pre_content {
7
  my ($self) = @_;
8

  
9
  $self->SUPER::render('menu/header', { partial => 1, no_output => 1 },
10
                now        => DateTime->now_local,
11
                is_fastcgi => scalar($::dispatcher->interface_type =~ /fastcgi/i),
12
                is_links   => scalar($ENV{HTTP_USER_AGENT}         =~ /links/i));
13
}
14

  
15
sub stylesheets {
16
# 'frame_header/header.css';
17
}
18

  
19
1;
SL/Controller/Layout/V3.pm
1
package SL::Controller::Layout::V3;
2

  
3
use strict;
4
use parent qw(SL::Controller::Layout::Base);
5
use SL::Controller::Layout::Css;
6

  
7
use URI;
8

  
9
sub new {
10
  my ($class, @slurp) = @_;
11

  
12
  my $self = $class->SUPER::new(@slurp);
13

  
14
  $self->add_sub_layouts([
15
    SL::Controller::Layout::None->new,
16
  ]);
17

  
18
  $self;
19
}
20

  
21
sub pre_content {
22
  &render;
23
}
24

  
25
sub start_content {
26
  "<div id='content'>\n";
27
}
28

  
29
sub end_content {
30
  "</div>\n";
31
}
32

  
33
sub render {
34
  my ($self) = @_;
35

  
36
  my $callback            = $::form->unescape($::form->{callback});
37
  $callback               = URI->new($callback)->rel($callback) if $callback;
38
  $callback               = "login.pl?action=company_logo"      if $callback =~ /^(\.\/)?$/;
39

  
40
  $self->SUPER::render('menu/menuv3', { no_menu => 1, no_output => 1 },
41
    force_ul_width => 1,
42
    date           => $self->clock_line,
43
    menu           => $self->print_menu,
44
    callback       => $callback,
45
  );
46
}
47

  
48
1;
SL/Controller/Layout/V4.pm
1
package SL::Controller::Layout::V4;
2

  
3
use strict;
4
use parent qw(SL::Controller::Layout::Base);
5
use SL::Controller::Layout::Css;
6
use SL::Controller::Layout::Top;
7

  
8
use URI;
9

  
10
sub new {
11
  my ($class, @slurp) = @_;
12

  
13
  my $self = $class->SUPER::new(@slurp);
14
  $self->add_sub_layouts(
15
    SL::Controller::Layout::Top->new,
16
    SL::Controller::Layout::None->new,
17
  );
18
  $self;
19
}
20

  
21
sub start_content {
22
  "<div id='content'>\n";
23
}
24

  
25
sub end_content {
26
  "</div>\n";
27
}
28

  
29
sub pre_content {
30
  my ($self) = @_;
31

  
32
  $self->{sub_class} = 1;
33

  
34
  my $callback            = $::form->unescape($::form->{callback});
35
  $callback               = URI->new($callback)->rel($callback) if $callback;
36
  $callback               = "login.pl?action=company_logo"      if $callback =~ /^(\.\/)?$/;
37

  
38
  $self->SUPER::pre_content .
39

  
40
  $self->SUPER::render('menu/menuv4', { no_menu => 1, no_output => 1 },
41
    force_ul_width => 1,
42
    date           => $self->clock_line,
43
    menu           => $self->print_menu,
44
    callback       => $callback,
45
  );
46
}
47

  
48
1;
SL/Controller/LoginScreen.pm
39 39
  $::form->{login} = $::myconfig{login};
40 40
  $::locale        = Locale->new($::myconfig{countrycode}) if $::myconfig{countrycode};
41 41
  my $user         = User->new(login => $::myconfig{login});
42
  $::request->{layout} = SL::Controller::Layout->new(style => $user->{menustyle});
42
  $::request->{layout} = SL::Layout->new(style => $user->{menustyle});
43 43

  
44 44
  # if we get an error back, bale out
45 45
  my $result = $user->login($::form);
......
118 118
}
119 119

  
120 120
sub set_layout {
121
  $::request->{layout} = SL::Controller::Layout->new(style => 'login');
121
  $::request->{layout} = SL::Layout::Dispatcher->new(style => 'login');
122 122
}
123 123

  
124 124
1;
SL/Dispatcher.pm
35 35
use SL::Helper::DateTime;
36 36
use SL::InstanceConfiguration;
37 37
use SL::Template::Plugin::HTMLFixes;
38
use SL::Controller::Layout::None;
38
use SL::Layout::None;
39 39

  
40 40
# Trailing new line is added so that Perl will not add the line
41 41
# number 'die' was called in.
......
184 184
  $::instance_conf = SL::InstanceConfiguration->new;
185 185
  $::request       = {
186 186
    cgi => CGI->new({}),
187
    layout => SL::Controller::Layout::None->new,
187
    layout => SL::Layout::None->new,
188 188
  };
189 189

  
190 190
  my $session_result = $::auth->restore_session;
SL/Dispatcher/AuthHandler/Admin.pm
3 3
use strict;
4 4
use parent qw(Rose::Object);
5 5

  
6
use SL::Controller::Layout;
6
use SL::Layout::Dispatcher;
7 7

  
8 8
sub handle {
9 9
  %::myconfig = ();
......
11 11
  return if  $::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::form->{'{AUTH}admin_password'})            == $::auth->OK());
12 12
  return if !$::form->{'{AUTH}admin_password'} && ($::auth->authenticate_root($::auth->get_session_value('admin_password')) == $::auth->OK());
13 13

  
14
  $::request->{layout} = SL::Controller::Layout->new(style => 'admin');
14
  $::request->{layout} = SL::Layout::Dispatcher->new(style => 'admin');
15 15

  
16 16
  $::auth->punish_wrong_login;
17 17
  $::auth->delete_session_value('admin_password');
SL/Dispatcher/AuthHandler/User.pm
3 3
use strict;
4 4
use parent qw(Rose::Object);
5 5

  
6
use SL::Controller::Layout;
6
use SL::Layout::Dispatcher;
7 7

  
8 8
sub handle {
9 9
  my ($self, %param) = @_;
......
16 16
  $self->_error(%param) unless $::myconfig{login};
17 17

  
18 18
  $::locale = Locale->new($::myconfig{countrycode});
19
  $::request->{layout} = SL::Controller::Layout->new(style => $::myconfig{menustyle});
19
  $::request->{layout} = SL::Layout::Dispatcher->new(style => $::myconfig{menustyle});
20 20

  
21 21
  my $ok   =  $::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, $::form->{'{AUTH}password'}));
22 22
  $ok    ||= !$::form->{'{AUTH}login'} && (SL::Auth::OK() == $::auth->authenticate($::myconfig{login}, undef));
SL/Form.pm
56 56
use SL::DO;
57 57
use SL::IC;
58 58
use SL::IS;
59
use SL::Layout::Dispatcher;
59 60
use SL::Locale;
60 61
use SL::Mailer;
61 62
use SL::Menu;
......
457 458
  $::lxdebug->leave_sub and return if !$ENV{HTTP_USER_AGENT} || $self->{header}++;
458 459

  
459 460
  if ($params{no_layout}) {
460
    $::request->{layout} = SL::Controller::Layout->new(style => 'none');
461
    $::request->{layout} = SL::Layout::Dispatcher->new(style => 'none');
461 462
  }
462 463

  
463 464
  my $layout = $::request->{layout};
SL/Layout/Admin.pm
1
package SL::Layout::Admin;
2

  
3
use strict;
4
use parent qw(SL::Layout::Base);
5

  
6
sub new {
7
  my ($class, @slurp) = @_;
8

  
9
  my $self = $class->SUPER::new(@slurp);
10

  
11
  $self->add_sub_layouts([
12
    SL::Layout::None->new,
13
  ]);
14

  
15
  $self;
16
}
17

  
18
sub start_content {
19
  "<div id='admin' class='admin'>\n";
20
}
21

  
22
sub end_content {
23
  "</div>\n";
24
}
25

  
26
1;
SL/Layout/Base.pm
1
package SL::Layout::Base;
2

  
3
use strict;
4
use parent qw(SL::Controller::Base);
5

  
6
use Rose::Object::MakeMethods::Generic (
7
  'scalar --get_set_init' => qw(menu),
8
  'scalar'                => qw(focus),
9
  'array'                 => [
10
    'add_stylesheets_inline' => { interface => 'add', hash_key => 'stylesheets_inline' },
11
    'add_javascripts_inline' => { interface => 'add', hash_key => 'javascripts_inline' },
12
    'sub_layouts',
13
    'add_sub_layouts'         => { interface => 'add', hash_key => 'sub_layouts' },
14
  ],
15
);
16

  
17
use SL::Menu;
18

  
19
my %menu_cache;
20

  
21
sub new {
22
  my ($class, @slurp) = @_;
23

  
24
  my $self = $class->SUPER::new(@slurp);
25
}
26

  
27
sub init_menu {
28
  Menu->new('menu.ini');
29
}
30

  
31
##########################################
32
#  inheritable/overridable
33
##########################################
34

  
35
sub pre_content {
36
  join '', map { $_->pre_content } $_[0]->sub_layouts;
37
}
38

  
39
sub start_content {
40
  join '', map { $_->start_content } $_[0]->sub_layouts;
41
}
42

  
43
sub end_content {
44
  join '', map { $_->end_content } $_[0]->sub_layouts;
45
}
46

  
47
sub post_content {
48
  join '', map { $_->post_content } $_[0]->sub_layouts;
49
}
50

  
51
sub stylesheets_inline {
52
  ( map { $_->stylesheets_inline } $_[0]->sub_layouts ),
53
  @{ $_[0]->{stylesheets_inline} || [] };
54
}
55

  
56
sub javascripts_inline {
57
  ( map { $_->javascripts_inline } $_[0]->sub_layouts ),
58
  @{ $_[0]->{javascripts_inline} || [] };
59
}
60

  
61

  
62
#########################################
63
# Interface
64
########################################
65

  
66
sub use_stylesheet {
67
  my $self = shift;
68
  push @{ $self->{stylesheets} ||= [] }, @_ if @_;
69
  @{ $self->{stylesheets} ||= [] };
70
}
71

  
72
sub stylesheets {
73
  my ($self) = @_;
74
  my $css_path = $self->get_stylesheet_for_user;
75

  
76
  return grep { $_ } map { $self->_find_stylesheet($_, $css_path)  }
77
    $self->use_stylesheet, map { $_->stylesheets } $self->sub_layouts;
78
}
79

  
80
sub _find_stylesheet {
81
  my ($self, $stylesheet, $css_path) = @_;
82

  
83
  return "$css_path/$stylesheet" if -f "$css_path/$stylesheet";
84
  return "css/$stylesheet"       if -f "css/$stylesheet";
85
  return $stylesheet             if -f $stylesheet;
86
}
87

  
88
sub get_stylesheet_for_user {
89
  my $css_path = 'css';
90
  if (my $user_style = $::myconfig{stylesheet}) {
91
    $user_style =~ s/\.css$//; # nuke trailing .css, this is a remnand of pre 2.7.0 stylesheet handling
92
    if (-d "$css_path/$user_style" &&
93
        -f "$css_path/$user_style/main.css") {
94
      $css_path = "$css_path/$user_style";
95
    } else {
96
      $css_path = "$css_path/lx-office-erp";
97
    }
98
  } else {
99
    $css_path = "$css_path/lx-office-erp";
100
  }
101
  $::myconfig{css_path} = $css_path; # needed for menunew, FIXME: don't do this here
102

  
103
  return $css_path;
104
}
105

  
106

  
107
sub use_javascript {
108
  my $self = shift;
109
  push @{ $self->{javascripts} ||= [] }, @_ if @_;
110
  @{ $self->{javascripts} ||= [] };
111
}
112

  
113
sub javascripts {
114
  my ($self) = @_;
115

  
116
  return map { $self->_find_javascript($_)  }
117
    $self->use_javascript, map { $_->javascripts } $self->sub_layouts;
118
}
119

  
120
sub _find_javascript {
121
  my ($self, $javascript) = @_;
122

  
123
  return "js/$javascript"        if -f "js/$javascript";
124
  return $javascript             if -f $javascript;
125
}
126

  
127

  
128
############################################
129
# track state of form header
130
############################################
131

  
132
sub header_done {
133
  $_[0]{_header_done} = 1;
134
}
135

  
136
sub need_footer {
137
  $_[0]{_header_done};
138
}
139

  
140
1;
SL/Layout/Classic.pm
1
package SL::Layout::Classic;
2

  
3
use strict;
4
use parent qw(SL::Layout::Base);
5

  
6
use SL::Layout::Top;
7
use SL::Layout::MenuLeft;
8

  
9
sub new {
10
  my ($class, @slurp) = @_;
11

  
12
  my $self = $class->SUPER::new(@slurp);
13

  
14
  $self->add_sub_layouts([
15
    SL::Layout::Top->new,
16
    SL::Layout::MenuLeft->new,
17
    SL::Layout::None->new,
18
  ]);
19

  
20
  $self;
21
}
22

  
23
1;
SL/Layout/Css.pm
1
package SL::Layout::Css;
2

  
3
use strict;
4

  
5
use List::Util qw(max);
6
use Exporter qw(import);
7

  
8
our @EXPORT = qw(clock_line print_menu menuitem_v3);
9

  
10
sub clock_line {
11
  my ($Sekunden, $Minuten,   $Stunden,   $Monatstag, $Monat,
12
      $Jahr,     $Wochentag, $Jahrestag, $Sommerzeit)
13
    = localtime(time);
14
  $Monat     += 1;
15
  $Jahrestag += 1;
16
  $Monat     = $Monat < 10     ? $Monat     = "0" . $Monat     : $Monat;
17
  $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
18
  $Jahr += 1900;
19
  my @Wochentage = ("Sonntag",    "Montag",  "Dienstag", "Mittwoch",
20
                    "Donnerstag", "Freitag", "Samstag");
21
  my @Monatsnamen = ("",       "Januar",    "Februar", "M&auml;rz",
22
                     "April",  "Mai",       "Juni",    "Juli",
23
                     "August", "September", "Oktober", "November",
24
                     "Dezember");
25
  return
26
      $Wochentage[$Wochentag] . ", der "
27
    . $Monatstag . "."
28
    . $Monat . "."
29
    . $Jahr . " - ";
30
}
31

  
32
sub print_menu {
33
  my ($self, $parent, $depth) = @_;
34

  
35
  my $html;
36

  
37
  die if ($depth * 1 > 5);
38

  
39
  my @menuorder;
40
  my $menu = $self->menu;
41

  
42
  @menuorder = $menu->access_control(\%::myconfig, $parent);
43

  
44
  $parent .= "--" if ($parent);
45

  
46
  foreach my $item (@menuorder) {
47
    substr($item, 0, length($parent)) = "";
48
    next if (($item eq "") || ($item =~ /--/));
49

  
50
    my $menu_item = $menu->{"${parent}${item}"};
51
    my $menu_title = $::locale->text($item);
52
    my $menu_text = $menu_title;
53

  
54
    if ($menu_item->{"submenu"} || !defined($menu_item->{"module"}) ||
55
        ($menu_item->{"module"} eq "menu.pl")) {
56

  
57
      my $h = $self->print_menu("${parent}${item}", $depth * 1 + 1)."\n";
58
      if (!$parent) {
59
        $html .= qq|<ul><li><h2>${menu_text}</h2><ul>${h}</ul></li></ul>\n|;
60
      } else {
61
        $html .= qq|<li><div class="x">${menu_text}</div><ul>${h}</ul></li>\n|;
62
      }
63
    } else {
64
      if ($self->{sub_class} && $depth > 1) {
65
        $html .= qq|<li class='sub'>|;
66
      } else {
67
        $html .= qq|<li>|;
68
      }
69
      $html .= $self->menuitem_v3("${parent}$item", { "title" => $menu_title });
70
      $html .= qq|${menu_text}</a></li>\n|;
71
    }
72
  }
73

  
74
  return $html;
75
}
76

  
77
sub menuitem_v3 {
78
  $main::lxdebug->enter_sub();
79

  
80
  my ($self, $item, $other) = @_;
81
  my $menuitem = $self->menu->{$item};
82

  
83
  my $action = "section_menu";
84
  my $module;
85

  
86
  if ($menuitem->{module}) {
87
    $module = $menuitem->{module};
88
  }
89
  if ($menuitem->{action}) {
90
    $action = $menuitem->{action};
91
  }
92

  
93
  my $level = $::form->escape($item);
94

  
95
  my $str = qq|<a href="$module?action=| . $::form->escape($action) . qq|&level=| . $::form->escape($level);
96

  
97
  my @vars = qw(module action target href);
98

  
99
  if ($menuitem->{href}) {
100
    $str  = qq|<a href=$menuitem->{href}|;
101
    @vars = qw(module target href);
102
  }
103

  
104
  map { delete $menuitem->{$_} } @vars;
105

  
106
  # add other params
107
  foreach my $key (keys %{ $menuitem }) {
108
    $str .= "&" . $::form->escape($key, 1) . "=";
109
    my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
110
    $value = $::myconfig{$value} . "/$conf" if ($conf);
111
    $str .= $::form->escape($value, 1);
112
  }
113

  
114
  $str .= '"';
115

  
116
  if ($other) {
117
    foreach my $key (keys(%{$other})) {
118
      $str .= qq| ${key}="| . $::form->quote($other->{$key}) . qq|"|;
119
    }
120
  }
121

  
122
  $str .= ">";
123

  
124
  $main::lxdebug->leave_sub();
125

  
126
  return $str;
127
}
128

  
129
1;
SL/Layout/Dispatcher.pm
1
package SL::Layout::Dispatcher;
2

  
3
use strict;
4

  
5
use SL::Menu;
6
use SL::Layout::Admin;
7
use SL::Layout::Login;
8
use SL::Layout::Classic;
9
use SL::Layout::V3;
10
use SL::Layout::V4;
11
use SL::Layout::Javascript;
12

  
13
my %menu_cache;
14

  
15
sub new {
16
  my ($class, %params) = @_;
17

  
18
  return SL::Layout::Classic->new    if $params{style} eq 'old';
19
  return SL::Layout::V3->new         if $params{style} eq 'v3';
20
  return SL::Layout::V4->new         if $params{style} eq 'v4';
21
  return SL::Layout::Javascript->new if $params{style} eq 'neu';
22
  return SL::Layout::Admin->new      if $params{style} eq 'admin';
23
  return SL::Layout::Login->new      if $params{style} eq 'login';
24
  return SL::Layout::None->new;
25
}
26

  
27
1;
SL/Layout/Javascript.pm
1
package SL::Layout::Javascript;
2

  
3
use strict;
4
use parent qw(SL::Layout::Base);
5

  
6
use List::Util qw(max);
7
use URI;
8

  
9
sub new {
10
  my ($class, @slurp) = @_;
11

  
12
  my $self = $class->SUPER::new(@slurp);
13

  
14
  $self->add_sub_layouts([
15
    SL::Layout::None->new,
16
  ]);
17

  
18
  $self;
19
}
20

  
21
sub pre_content {
22
  &display
23
}
24

  
25
sub start_content {
26
  "<div id='content'>\n";
27
}
28

  
29
sub end_content {
30
  "</div>\n";
31
}
32

  
33
sub display {
34
  my ($self) = @_;
35
  my $form     = $main::form;
36

  
37
  my $callback            = $form->unescape($form->{callback});
38
  $callback               = URI->new($callback)->rel($callback) if $callback;
39
  $callback               = "login.pl?action=company_logo"      if $callback =~ /^(\.\/)?$/;
40

  
41
  $form->parse_html_template("menu/menunew", {
42
#  $self->render("menu/menunew", { no_menu => 1, no_output => 1 }, # buggy, no idea why
43
    force_ul_width  => 1,
44
    date            => $self->clock_line,
45
    menu_items      => $self->acc_menu,
46
    callback        => $callback,
47
  });
48
}
49

  
50
sub clock_line {
51
  my $form     = $main::form;
52

  
53
  my ($Sekunden, $Minuten,   $Stunden,   $Monatstag, $Monat,
54
      $Jahr,     $Wochentag, $Jahrestag, $Sommerzeit)
55
    = localtime(time);
56
  $Monat     += 1;
57
  $Jahrestag += 1;
58
  $Monat     = $Monat < 10     ? $Monat     = "0" . $Monat     : $Monat;
59
  $Monatstag = $Monatstag < 10 ? $Monatstag = "0" . $Monatstag : $Monatstag;
60
  $Jahr += 1900;
61
  my @Wochentage = ("Sonntag",    "Montag",  "Dienstag", "Mittwoch",
62
                    "Donnerstag", "Freitag", "Samstag");
63
  my @Monatsnamen = ("",       "Januar",    "Februar", "M&auml;rz",
64
                     "April",  "Mai",       "Juni",    "Juli",
65
                     "August", "September", "Oktober", "November",
66
                     "Dezember");
67
  return
68
      $Wochentage[$Wochentag] . ", der "
69
    . $Monatstag . "."
70
    . $Monat . "."
71
    . $Jahr . " - ";
72
}
73

  
74
sub acc_menu {
75
  my ($self) = @_;
76

  
77
  my $menu      = $self->menu;
78

  
79
  my $all_items = [];
80
  $self->create_menu($menu, $all_items);
81

  
82
  my $item = { 'subitems' => $all_items };
83
  calculate_width($item);
84

  
85
  return $all_items;
86
}
87

  
88
sub calculate_width {
89
  my $item           = shift;
90

  
91
  $item->{max_width} = max map { length $_->{title} } @{ $item->{subitems} };
92

  
93
  foreach my $subitem (@{ $item->{subitems} }) {
94
    calculate_width($subitem) if ($subitem->{subitems});
95
  }
96
}
97

  
98
sub create_menu {
99
  my ($self, $menu, $all_items, $parent, $depth) = @_;
100
  my $html;
101

  
102
  my $form     = $main::form;
103
  my %myconfig = %main::myconfig;
104

  
105
  die if ($depth * 1 > 5);
106

  
107
  my @menuorder  = $menu->access_control(\%myconfig, $parent);
108
  $parent       .= "--" if ($parent);
109

  
110
  foreach my $name (@menuorder) {
111
    substr($name, 0, length($parent), "");
112
    next if (($name eq "") || ($name =~ /--/));
113

  
114
    my $menu_item = $menu->{"${parent}${name}"};
115
    my $item      = { 'title' => $::locale->text($name) };
116
    push @{ $all_items }, $item;
117

  
118
    if ($menu_item->{submenu} || !defined($menu_item->{module}) || ($menu_item->{module} eq "menu.pl")) {
119
      $item->{subitems} = [];
120
      $item->{image} = _icon_path("$name.png");
121
      $self->create_menu($menu, $item->{subitems}, "${parent}${name}", $depth * 1 + 1);
122

  
123
    } else {
124
      $item->{image} = _icon_path("${parent}${name}.png");
125
      $menu->menuitem_new("${parent}${name}", $item);
126
    }
127
  }
128
}
129

  
130
sub _icon_path {
131
  my ($label, $size) = @_;
132

  
133
  $size ||= 16;
134

  
135
  my $img = "image/icons/${size}x${size}/$label";
136

  
137
  return unless -f $img;
138
  return $img;
139
}
140

  
141
1;
SL/Layout/Login.pm
1
package SL::Layout::Login;
2

  
3
use strict;
4
use parent qw(SL::Layout::Base);
5

  
6
sub new {
7
  my ($class, @slurp) = @_;
8

  
9
  my $self = $class->SUPER::new(@slurp);
10

  
11
  $self->add_sub_layouts([
12
    SL::Layout::None->new,
13
  ]);
14

  
15
  $self;
16
}
17

  
18
sub start_content {
19
  "<div id='login' class='login'>\n";
20
}
21

  
22
sub end_content {
23
  "</div>\n";
... Dieser Diff wurde abgeschnitten, weil er die maximale Anzahl anzuzeigender Zeilen überschreitet.

Auch abrufbar als: Unified diff