summaryrefslogtreecommitdiff
path: root/scripts/menu.pl
blob: 01343318441360261854cab7197cab36965f0c4d (plain)
  1. #!/usr/bin/perl
  2. =head1 NAME
  3. LedgerSMB::Scripts::menu - LedgerSMB controller script for menus
  4. =head1 SYOPSIS
  5. This script provides a controller class for generating menus. It can operate in
  6. two modes: One creates a standard expanding menu which works with or without
  7. javascript. The second creates drilldown menus for small-screen or text-only
  8. devices.
  9. =head1 METHODS
  10. =cut
  11. package LedgerSMB::Scripts::menu;
  12. our $VERSION = '1.0';
  13. use LedgerSMB::DBObject::Menu;
  14. use LedgerSMB::Template;
  15. use strict;
  16. =pod
  17. =over
  18. =item __default
  19. This pseudomethod is used to trap menu clicks that come back through the file
  20. and route to the appropriate function. If $request->{menubar} is set, it routes
  21. to the drilldown_menu. Otherwise, it routes to expanding_menu.
  22. =back
  23. =cut
  24. sub __default {
  25. my ($request) = @_;
  26. if ($request->{new}){
  27. root_doc($request);
  28. }
  29. if ($request->{menubar}){
  30. drilldown_menu($request);
  31. } else {
  32. expanding_menu($request);
  33. }
  34. }
  35. =pod
  36. =over
  37. =item root_doc
  38. If $request->{menubar} is set, this creates a drilldown menu. Otherwise, it
  39. creates the root document (currently a frameset).
  40. =back
  41. =cut
  42. sub root_doc {
  43. my ($request) = @_;
  44. my $template;
  45. $request->{title} = "LedgerSMB $request->{VERSION} -- ".
  46. "$request->{login} -- $request->{_user}->{dbname}";
  47. if ($request->{menubar}){
  48. drilldown_menu($request);
  49. return;
  50. } else {
  51. $request->{main} = "splash.html" if $request->{main} eq 'company_logo';
  52. $request->{main} = "am.pl?action=recurring_transactions"
  53. if $request->{main} eq 'recurring_transactions';
  54. $template = LedgerSMB::Template->new(
  55. user =>$request->{_user},
  56. locale => $request->{_locale},
  57. path => 'UI',
  58. template => 'frameset',
  59. format => 'HTML'
  60. );
  61. }
  62. $template->render($request);
  63. }
  64. =pod
  65. =over
  66. =item expanding_menu
  67. This function generates an expanding menu. By default all nodes are closed, but
  68. there nodes which are supposed to be open are marked.
  69. =back
  70. =cut
  71. sub expanding_menu {
  72. my ($request) = @_;
  73. if ($request->{'open'} !~ s/:$request->{id}:/:/){
  74. $request->{'open'} .= ":$request->{id}:";
  75. }
  76. # The above system can lead to extra colons.
  77. $request->{'open'} =~ s/:+/:/g;
  78. my $menu = LedgerSMB::DBObject::Menu->new({base => $request});
  79. $menu->generate();
  80. for my $item (@{$menu->{menu_items}}){
  81. if ($request->{'open'} =~ /:$item->{id}:/ ){
  82. $item->{'open'} = 'true';
  83. }
  84. }
  85. my $template = LedgerSMB::Template->new(
  86. user => $request->{_user},
  87. locale => $request->{_locale},
  88. path => 'UI/menu',
  89. template => 'expanding',
  90. format => 'HTML',
  91. );
  92. $template->render($menu);
  93. }
  94. =pod
  95. =over
  96. =item drillown_menu
  97. This function creates a single cross section of the menu. Currently this is
  98. most useful for generating menus for small screen devices or devices where a
  99. limited number of options are necessary (screen readers, text-only browsers and
  100. the like).
  101. =back
  102. =cut
  103. sub drilldown_menu {
  104. my ($request) = @_;
  105. my $menu = LedgerSMB::DBObject::Menu->new({base => $request});
  106. $menu->{parent_id} ||= 0;
  107. print STDERR "Testing";
  108. $menu->generate_section;
  109. my $template = LedgerSMB::Template->new(
  110. user => $request->{_user},
  111. locale => $request->{_locale},
  112. path => 'UI/menu',
  113. template => 'drilldown',
  114. format => 'HTML',
  115. );
  116. $template->render($menu);
  117. }
  118. =pod
  119. =head1 Copyright (C) 2007 The LedgerSMB Core Team
  120. Licensed under the GNU General Public License version 2 or later (at your
  121. option). For more information please see the included LICENSE and COPYRIGHT
  122. files.
  123. =cut
  124. eval { do "scripts/custom/menu.pl"};
  125. 1;