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