summaryrefslogtreecommitdiff
path: root/scripts/menu.pl
blob: ad362c1c4383bbedd1eafadef0ad537d45cf2adc (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. print STDERR 'Breakpoint\n';
  74. if ($request->{'open'} !~ s/:$request->{id}:/:/){
  75. $request->{'open'} .= ":$request->{id}:";
  76. }
  77. # The above system can lead to extra colons.
  78. $request->{'open'} =~ s/:+/:/g;
  79. my $menu = LedgerSMB::DBObject::Menu->new({base => $request});
  80. $menu->generate();
  81. for my $item (@{$menu->{menu_items}}){
  82. if ($request->{'open'} =~ /:$item->{id}:/ ){
  83. $item->{'open'} = 'true';
  84. }
  85. }
  86. my $template = LedgerSMB::Template->new(
  87. user => $request->{_user},
  88. locale => $request->{_locale},
  89. path => 'UI/menu',
  90. template => 'expanding',
  91. format => 'HTML',
  92. );
  93. $template->render($menu);
  94. }
  95. =pod
  96. =over
  97. =item drillown_menu
  98. This function creates a single cross section of the menu. Currently this is
  99. most useful for generating menus for small screen devices or devices where a
  100. limited number of options are necessary (screen readers, text-only browsers and
  101. the like).
  102. =back
  103. =cut
  104. sub drilldown_menu {
  105. my ($request) = @_;
  106. my $menu = LedgerSMB::DBObject::Menu->new({base => $request});
  107. $menu->{parent_id} ||= 0;
  108. print STDERR "Testing";
  109. $menu->generate_section;
  110. my $template = LedgerSMB::Template->new(
  111. user => $request->{_user},
  112. locale => $request->{_locale},
  113. path => 'UI/menu',
  114. template => 'drilldown',
  115. format => 'HTML',
  116. );
  117. $template->render($menu);
  118. }
  119. =pod
  120. =head1 Copyright (C) 2007 The LedgerSMB Core Team
  121. Licensed under the GNU General Public License version 2 or later (at your
  122. option). For more information please see the included LICENSE and COPYRIGHT
  123. files.
  124. =cut
  125. 1;