kivitendo/bin/mozilla/menu.pl @ ae2e9adf
d319704a | Moritz Bunkus | #=====================================================================
|
||
# LX-Office ERP
|
||||
# Copyright (C) 2004
|
||||
# Based on SQL-Ledger Version 2.1.9
|
||||
# Web http://www.lx-office.org
|
||||
#
|
||||
######################################################################
|
||||
# SQL-Ledger Accounting
|
||||
# Copyright (c) 1998-2002
|
||||
#
|
||||
# Author: Dieter Simader
|
||||
# Email: dsimader@sql-ledger.org
|
||||
# Web: http://www.sql-ledger.org
|
||||
#
|
||||
# Contributors: Christopher Browne
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#######################################################################
|
||||
#
|
||||
08b6539d | Sven Donath | # the frame layout with refractured menu
|
||
d319704a | Moritz Bunkus | #
|
||
# CHANGE LOG:
|
||||
# DS. 2002-03-25 Created
|
||||
# 2004-12-14 - New Optik - Marco Welter <mawe@linux-studio.de>
|
||||
da80eb32 | Sven Donath | # 2010-08-19 - Icons for sub entries and single click behavior, unlike XUL-Menu
|
||
08b6539d | Sven Donath | # JS switchable HTML-menu - Sven Donath <lxo@dexo.de>
|
||
d319704a | Moritz Bunkus | #######################################################################
|
||
3289bcb2 | Sven Schöling | use strict;
|
||
d319704a | Moritz Bunkus | use SL::Menu;
|
||
f2078516 | Sven Schöling | use URI;
|
||
d319704a | Moritz Bunkus | |||
829f6742 | Sven Schöling | use List::MoreUtils qw(apply);
|
||
my $nbsp = ' ';
|
||||
9f4b866c | Sven Schöling | |||
d319704a | Moritz Bunkus | # end of main
|
||
sub display {
|
||||
829f6742 | Sven Schöling | $::lxdebug->enter_sub;
|
||
d319704a | Moritz Bunkus | |||
829f6742 | Sven Schöling | my $callback = $::form->unescape($::form->{callback});
|
||
da80eb32 | Sven Donath | $callback = URI->new($callback)->rel($callback) if $callback;
|
||
$callback = "login.pl?action=company_logo" if $callback =~ /^(\.\/)?$/;
|
||||
my $framesize = _calc_framesize();
|
||||
40255f36 | Sven Schöling | |||
7ef8fa08 | Sven Schöling | $::form->header(doctype => 'frameset');
|
||
d319704a | Moritz Bunkus | |||
print qq|
|
||||
54e4131e | Moritz Bunkus | <frameset rows="28px,*" cols="*" framespacing="0" frameborder="0">
|
||
6fb7bcc9 | Moritz Bunkus | <frame src="controller.pl?action=FrameHeader/header" scrolling="NO">
|
||
08b6539d | Sven Donath | <frameset cols="$framesize,*" framespacing="0" frameborder="0" border="0" id="menuframe" name="menuframe">
|
||
829f6742 | Sven Schöling | <frame src="$::form->{script}?action=acc_menu" name="acc_menu" scrolling="auto" noresize marginwidth="0">
|
||
f2078516 | Sven Schöling | <frame src="$callback" name="main_window" scrolling="auto">
|
||
d319704a | Moritz Bunkus | </frameset>
|
||
<noframes>
|
||||
You need a browser that can read frames to see this page.
|
||||
</noframes>
|
||||
</frameset>
|
||||
</HTML>
|
||||
|;
|
||||
829f6742 | Sven Schöling | $::lxdebug->leave_sub;
|
||
d319704a | Moritz Bunkus | }
|
||
sub acc_menu {
|
||||
829f6742 | Sven Schöling | $::lxdebug->enter_sub;
|
||
d319704a | Moritz Bunkus | |||
829f6742 | Sven Schöling | my $framesize = _calc_framesize() - 2;
|
||
d29b0238 | Moritz Bunkus | my $menu = Menu->new("menu.ini");
|
||
ce83fab9 | Sven Schöling | $::form->{title} = $::locale->text('kivitendo');
|
||
829f6742 | Sven Schöling | $::form->header;
|
||
d319704a | Moritz Bunkus | |||
7adc5519 | Sven Schöling | my $sections = section_menu($menu);
|
||
c6a27f90 | Sven Schöling | print $::form->parse_html_template('menu/menu', {
|
||
framesize => $framesize,
|
||||
7adc5519 | Sven Schöling | sections => $sections,
|
||
c6a27f90 | Sven Schöling | });
|
||
d319704a | Moritz Bunkus | |||
829f6742 | Sven Schöling | $::lxdebug->leave_sub;
|
||
d319704a | Moritz Bunkus | }
|
||
sub section_menu {
|
||||
829f6742 | Sven Schöling | $::lxdebug->enter_sub;
|
||
d319704a | Moritz Bunkus | my ($menu, $level) = @_;
|
||
829f6742 | Sven Schöling | my @menuorder = $menu->access_control(\%::myconfig, $level);
|
||
c6a27f90 | Sven Schöling | my @items;
|
||
829f6742 | Sven Schöling | |||
for my $item (@menuorder) {
|
||||
my $menuitem = $menu->{$item};
|
||||
my $label = apply { s/.*--// } $item;
|
||||
my $ml = apply { s/--.*// } $item;
|
||||
c5657fe8 | Sven Schöling | my $spacer = "spacer" . (0 + $item =~ s/--/--/g);
|
||
005b4d9b | Sven Schöling | my $label_icon = $level . "--" . $label . ".png";
|
||
829f6742 | Sven Schöling | next if $level && $item ne "$level--$label";
|
||
$label = $::locale->text($label);
|
||||
62d7ed6e | Sven Schöling | $menuitem->{module} ||= $::form->{script};
|
||
$menuitem->{action} ||= "section_menu";
|
||||
$menuitem->{target} ||= "main_window";
|
||||
fdd40c9d | Sven Schöling | $menuitem->{href} ||= "$menuitem->{module}?action=$menuitem->{action}";
|
||
62d7ed6e | Sven Schöling | |||
# add other params
|
||||
fdd40c9d | Sven Schöling | foreach my $key (keys %$menuitem) {
|
||
62d7ed6e | Sven Schöling | next if $key =~ /target|module|action|href/;
|
||
$menuitem->{href} .= "&" . $::form->escape($key, 1) . "=";
|
||||
fdd40c9d | Sven Schöling | my ($value, $conf) = split(/=/, $menuitem->{$key}, 2);
|
||
62d7ed6e | Sven Schöling | $value = $::myconfig{$value} . "/$conf" if ($conf);
|
||
fdd40c9d | Sven Schöling | $menuitem->{href} .= $::form->escape($value, 1);
|
||
62d7ed6e | Sven Schöling | }
|
||
829f6742 | Sven Schöling | |||
88bd305a | Sven Schöling | my $anchor = $menuitem->{href};
|
||
829f6742 | Sven Schöling | |||
if (!$level) { # toplevel
|
||||
7adc5519 | Sven Schöling | push @items, make_item(
|
||
img => make_image(icon => $item . '.png', size => 24, label => $label),
|
||||
label => $label,
|
||||
height => 24,
|
||||
class => 'menu',
|
||||
c5657fe8 | Sven Schöling | spacer => $spacer,
|
||
7adc5519 | Sven Schöling | subitems => section_menu($menu, $item)
|
||
);
|
||||
829f6742 | Sven Schöling | } elsif ($menuitem->{submenu}) {
|
||
7adc5519 | Sven Schöling | push @items, make_item(
|
||
target => $menuitem->{target},
|
||||
spacer => $spacer,
|
||||
img => make_image(submenu => 1),
|
||||
label => $label,
|
||||
class => 'submenu',
|
||||
subitems => section_menu($menu, $item),
|
||||
);
|
||||
829f6742 | Sven Schöling | } elsif ($menuitem->{module}) {
|
||
7adc5519 | Sven Schöling | push @items, make_item(
|
||
target => $menuitem->{target},
|
||||
img => make_image(label => $label, icon => $label_icon),
|
||||
href => $anchor,
|
||||
spacer => $spacer,
|
||||
label => $label,
|
||||
class => 'item',
|
||||
);
|
||||
829f6742 | Sven Schöling | }
|
||
}
|
||||
$::lxdebug->leave_sub;
|
||||
7adc5519 | Sven Schöling | return \@items;
|
||
829f6742 | Sven Schöling | }
|
||
sub make_item {
|
||||
my %params = @_;
|
||||
c6a27f90 | Sven Schöling | $params{spacer} ||= '';
|
||
$params{height} ||= 16;
|
||||
return {
|
||||
%params,
|
||||
c5657fe8 | Sven Schöling | # chunks => [ multiline($params{label}) ],
|
||
c6a27f90 | Sven Schöling | };
|
||
829f6742 | Sven Schöling | }
|
||
# multi line hack, sschoeling jul06
|
||||
# if a label is too long, try to split it at whitespaces, then join it to chunks of less
|
||||
# than 20 chars and store it in an array.
|
||||
# use this array later instead of the -ed label
|
||||
sub multiline {
|
||||
my ($label) = @_;
|
||||
my @chunks;
|
||||
my $l = 20;
|
||||
for (split / /, $label) {
|
||||
$l += length $_;
|
||||
if ($l < 20) {
|
||||
$chunks[-1] .= " $_";
|
||||
25b37b7f | Sven Schöling | } else {
|
||
829f6742 | Sven Schöling | $l = length $_;
|
||
push @chunks, $_;
|
||||
d319704a | Moritz Bunkus | }
|
||
}
|
||||
829f6742 | Sven Schöling | return @chunks;
|
||
}
|
||||
sub make_image {
|
||||
my (%params) = @_;
|
||||
my $icon = $params{icon};
|
||||
my $size = $params{size} || 16;
|
||||
return unless _show_images();
|
||||
my $icon_found = $icon && -f _icon_path($icon, $size);
|
||||
1a3569b9 | Sven Schöling | my $padding = $size == 16 && $icon_found ? $nbsp x 2
|
||
: $size == 24 ? $nbsp
|
||||
: '';
|
||||
return {
|
||||
src => $icon_found ? _icon_path($icon, $size) : "image/unterpunkt.png",
|
||||
alt => $params{label},
|
||||
width => $icon_found ? $size : 24,
|
||||
c5657fe8 | Sven Schöling | height => $icon_found ? $size : 15,
|
||
1a3569b9 | Sven Schöling | }
|
||
d319704a | Moritz Bunkus | }
|
||
3289bcb2 | Sven Schöling | |||
sub _calc_framesize {
|
||||
my $is_lynx_browser = $ENV{HTTP_USER_AGENT} =~ /links/i;
|
||||
my $is_mobile_browser = $ENV{HTTP_USER_AGENT} =~ /mobile/i;
|
||||
my $is_mobile_style = $::form->{stylesheet} =~ /mobile/i;
|
||||
return $is_mobile_browser && $is_mobile_style ? 130
|
||||
: $is_lynx_browser ? 240
|
||||
da80eb32 | Sven Donath | : 200;
|
||
3289bcb2 | Sven Schöling | }
|
||
829f6742 | Sven Schöling | sub _show_images {
|
||
# don't show images in links
|
||||
_calc_framesize() != 240;
|
||||
}
|
||||
sub _icon_path {
|
||||
my ($label, $size) = @_;
|
||||
$size ||= 16;
|
||||
return "image/icons/${size}x${size}/$label";
|
||||
}
|
||||
3289bcb2 | Sven Schöling | 1;
|
||
__END__
|