summaryrefslogtreecommitdiff
path: root/scripts/menu.pl
blob: dec086719e7dce842cb1c6d2b9d6254575b7fe84 (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->{menubar}){
  27. drilldown_menu($request);
  28. } else {
  29. expanding_menu($request);
  30. }
  31. }
  32. =pod
  33. =over
  34. =item root_doc
  35. If $request->{menubar} is set, this creates a drilldown menu. Otherwise, it
  36. creates the root document (currently a frameset).
  37. =back
  38. =cut
  39. sub root_doc {
  40. my ($request) = @_;
  41. my $template;
  42. $request->{title} = "LedgerSMB $request->{VERSION} -- ".
  43. "$request->{login} -- $request->{_user}->{dbname}";
  44. if (!$request->{menubar}){
  45. $request->{main} = "splash.html" if $request->{main} eq 'company_logo';
  46. $request->{main} = "am.pl?action=recurring_transactions"
  47. if $request->{main} eq 'recurring_transactions';
  48. $template = LedgerSMB::Template->new(
  49. user =>$request->{_user},
  50. locale => $request->{_locale},
  51. path => 'UI',
  52. template => 'frameset',
  53. format => 'HTML'
  54. );
  55. } else {
  56. drilldown_menu($request);
  57. return;
  58. }
  59. $template->render($request);
  60. }
  61. =pod
  62. =over
  63. =item expanding_menu
  64. This function generates an expanding menu. By default all nodes are closed, but
  65. there nodes which are supposed to be open are marked.
  66. =back
  67. =cut
  68. sub expanding_menu {
  69. my ($request) = @_;
  70. if ($request->{'open'} !~ s/:$request->{id}:/:/){
  71. $request->{'open'} .= ":$request->{id}:";
  72. }
  73. # The above system can lead to extra colons.
  74. $request->{'open'} =~ s/:+/:/g;
  75. my $menu = LedgerSMB::DBObject::Menu->new({base => $request});
  76. $menu->generate();
  77. for my $item (@{$menu->{menu_items}}){
  78. if ($request->{'open'} =~ /:$item->{id}:/ ){
  79. $item->{'open'} = 'true';
  80. }
  81. }
  82. my $template = LedgerSMB::Template->new(
  83. user => $request->{_user},
  84. locale => $request->{_locale},
  85. path => 'UI/menu',
  86. template => 'expanding',
  87. format => 'HTML',
  88. );
  89. $template->render($menu);
  90. }
  91. =pod
  92. =over
  93. =item drillown_menu
  94. This function creates a single cross section of the menu. Currently this is
  95. most useful for generating menus for small screen devices or devices where a
  96. limited number of options are necessary (screen readers, text-only browsers and
  97. the like).
  98. =back
  99. =cut
  100. sub drilldown_menu {
  101. my ($request) = @_;
  102. my $menu = LedgerSMB::DBObject::Menu->new({base => $request});
  103. $menu->{parent_id} ||= 0;
  104. print STDERR "Testing";
  105. $menu->generate_section;
  106. my $template = LedgerSMB::Template->new(
  107. user => $request->{_user},
  108. locale => $request->{_locale},
  109. path => 'UI/menu',
  110. template => 'drilldown',
  111. format => 'HTML',
  112. );
  113. $template->render($menu);
  114. }
  115. =pod
  116. =head1 Copyright (C) 2007 The LedgerSMB Core Team
  117. Licensed under the GNU General Public License version 2 or later (at your
  118. option). For more information please see the included LICENSE and COPYRIGHT
  119. files.
  120. =cut
  121. 1;