borg RT menus, RT#1169
[freeside.git] / rt / html / Elements / PageLayout
1 %# BEGIN BPS TAGGED BLOCK {{{
2 %# 
3 %# COPYRIGHT:
4 %#  
5 %# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC 
6 %#                                          <jesse@bestpractical.com>
7 %# 
8 %# (Except where explicitly superseded by other copyright notices)
9 %# 
10 %# 
11 %# LICENSE:
12 %# 
13 %# This work is made available to you under the terms of Version 2 of
14 %# the GNU General Public License. A copy of that license should have
15 %# been provided with this software, but in any event can be snarfed
16 %# from www.gnu.org.
17 %# 
18 %# This work is distributed in the hope that it will be useful, but
19 %# WITHOUT ANY WARRANTY; without even the implied warranty of
20 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21 %# General Public License for more details.
22 %# 
23 %# You should have received a copy of the GNU General Public License
24 %# along with this program; if not, write to the Free Software
25 %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 %# 02110-1301 or visit their web page on the internet at
27 %# http://www.gnu.org/copyleft/gpl.html.
28 %# 
29 %# 
30 %# CONTRIBUTION SUBMISSION POLICY:
31 %# 
32 %# (The following paragraph is not intended to limit the rights granted
33 %# to you to modify and distribute this software under the terms of
34 %# the GNU General Public License and is only of importance to you if
35 %# you choose to contribute your changes and enhancements to the
36 %# community by submitting them to Best Practical Solutions, LLC.)
37 %# 
38 %# By intentionally submitting any modifications, corrections or
39 %# derivatives to this work, or any other work intended for use with
40 %# Request Tracker, to Best Practical Solutions, LLC, you confirm that
41 %# you are the copyright holder for those contributions and you grant
42 %# Best Practical Solutions,  LLC a nonexclusive, worldwide, irrevocable,
43 %# royalty-free, perpetual, license to use, copy, create derivative
44 %# works based on those contributions, and sublicense and distribute
45 %# those contributions and any derivatives thereof.
46 %# 
47 %# END BPS TAGGED BLOCK }}}
48 <table border=0 cellspacing=0 cellpadding=0 width="100%" height="100%">
49     <TR HEIGHT="100%">
50       <TD>
51
52 % if (0) { ##FREESIDE MENUS INSTEAD## if ( $show_menu ) {
53 %# if ( $show_menu ) {
54 <div id="nav">
55 <& /Elements/Menu, toptabs => $toptabs, current_toptab => $current_toptab &>
56 </div>
57 % }
58
59 <div id="header">
60 %#already shown  <h1><%$title%></h1>
61
62 % my $sep       = 0;
63 % my $postsep   = 0;
64 % my $count     = 0;
65 % my $class     = { };
66
67   <ul id="page-menu"<% (($actions && %$actions) || ($subactions && %$subactions)) && q[ class="actions-present"] | n %>>
68     <div><div><div>
69 % if ($page_tabs) {
70 %     foreach my $tab (sort keys %{$page_tabs}) {
71 %         next if $tab =~ /^(?:current_toptab|this)$/;
72 %         $count++;
73 %
74 %         my $current = $page_tabs->{current_toptab} || "";
75 %         my $path    = $page_tabs->{$tab}->{'path'} || "";
76 %         
77 %         $path    =~ s#/index.html$##gi;
78 %         $current =~ s#/index.html$##gi;
79 %         
80 %         $sep = $toptabs->{$tab}->{'separator'} ? 1 : 0;
81 %
82 %         $class->{a} = $path eq $current ? ' class="selected"' : undef;
83 %
84 %         my @li;
85 %         push @li, 'first'
86 %                if $count == 1;
87 %
88 %         push @li, 'pre-separator'
89 %                if $sep;
90 %
91 %         push @li, 'post-separator'
92 %                if $postsep;
93 %
94 %         $class->{li} = join ' ', @li;
95 %     
96 %
97     <li<% $class->{li} ? qq[ class="$class->{li}"] : ''|n %>><% $count > 1 && !$postsep && "&#183; "|n%><a href="<%$RT::WebPath%>/<%$page_tabs->{$tab}->{'path'}%>"<%$class->{a}|n%><% $class->{a} ? ' name="focus"' : ''|n %>><% $page_tabs->{$tab}->{'title'} %></a></li>
98 %
99 %         if ($sep) {
100     <li class="separator">&#183;&#183;&#183;</li>
101 %         }
102 %         $postsep = $sep;
103 %     }
104 % } else {
105 &nbsp;
106 % }
107     </div></div></div>
108   </ul>
109
110 % if (($actions && %$actions) || ($subactions && %$subactions)) {
111   <ul id="actions-menu">
112     <div><div><div>
113 % $sep       = 0;
114 % $postsep   = 0;
115 % $count     = 0;
116 % $class     = { };
117 %
118 % for my $type ($actions, $subactions) {
119 %
120 % if ($type && %$type) {
121 %     foreach my $action (sort keys %{$type}) {
122 %         $count++;
123 %
124 %         $sep = $type->{$action}->{'separator'} ? 1 : 0;
125 %
126 %         my @li;
127 %         push @li, 'first'
128 %                if $count == 1;
129 %
130 %         push @li, 'pre-separator'
131 %                if $sep;
132 %
133 %         push @li, 'post-separator'
134 %                if $postsep;
135 %
136 %         $class->{li} = join ' ', @li;
137 %
138     <li<% $class->{li} ? qq[ class="$class->{li}"] : ''|n %>><% $count > 1 && !$postsep && qq[<span class="bullet">&#183; </span>]|n%>
139 %         if ($type->{"$action"}->{'html'}) {
140       <% $type->{"$action"}->{'html'} | n %>
141 %         } else {
142       <a href="<%$RT::WebPath%>/<%$type->{$action}->{'path'}%>"<% $type->{$action}->{class} && ' class="'.$type->{$action}->{class}.'"' |n %><% $type->{$action}->{id} && ' id="'.$type->{$action}->{id}.'"' |n %>><%$type->{$action}->{'title'}%></a>
143 %         }
144     </li>
145 %         if ($sep) {
146     <li class="separator">&#183;&#183;&#183;</li>
147 %         }
148 %         $postsep = $sep;
149 %     }
150 % }
151 % }
152     </div></div></div>
153   </ul>
154 % }
155 </div>
156
157 <div id="body">
158 <& /Elements/Callback, _CallbackName => 'BeforeBody',  %ARGS &>
159 %$m->flush_buffer(); # we've got the page laid out, let's flush the buffer;
160
161 <%INIT>
162   foreach my $tab (sort keys %{$toptabs}) {
163     if ($current_toptab && $toptabs->{$tab}->{'path'} eq $current_toptab) {
164       $toptabs->{$tab}->{"subtabs"} = $tabs;
165       $toptabs->{$tab}->{"current_subtab"} = $current_tab;
166     }
167   }
168
169 if (! defined($AppName)) {
170   $AppName = loc("RT for [_1]", $RT::rtname);
171 }
172
173 my ($menu_depth, $almost_last, $page_tabs);
174
175 if ($RT::WebDefaultStylesheet ne '3.4-compat') {
176     ($menu_depth, $almost_last) = @{$m->comp('.menu_recurse', data => $toptabs)};
177
178     if (defined $almost_last->{subtabs} and %{$almost_last->{subtabs}}) {
179         $page_tabs = {
180             current_toptab => $almost_last->{current_subtab},
181             %{$almost_last->{subtabs}},
182         };
183
184         delete $almost_last->{subtabs};
185         delete $almost_last->{current_subtab};
186     }
187 }
188 </%INIT>
189
190 %# There's probably a better way to do this that involves three times as
191 %# much work and redoing the whole menu/tab system... which would seem a
192 %# bit out of scope.
193 %#
194 %# This function recurses through the menu and returns the second to
195 %# last menu, that is, the menu holding the last reference to
196 %# and submenu.  It also returns the number of menu levels minus
197 %# the last submenu.
198 <%def .menu_recurse>
199   <%args>
200       $data   => { }
201       $pdata  => { }
202       $ppdata => { }
203       $level  => 0
204   </%args>
205   <%init>
206       for my $key (keys %$data) {
207           return $m->comp('.menu_recurse', data   => $data->{$key}->{subtabs},
208                                            pdata  => $data->{$key},
209                                            ppdata => $pdata,
210                                            level  => $level+1)
211               if ref($data->{$key}) eq 'HASH'
212                  and defined $data->{$key}->{subtabs}
213                  and %{$data->{$key}->{subtabs}};
214       }
215       $ppdata->{last_system_menu_level}++;
216       return [$level, $pdata];
217   </%init>
218 </%def>
219
220 <%ARGS>
221 $current_toptab => undef
222 $current_tab => undef
223 $toptabs => undef
224 $topactions => undef
225 $tabs => undef
226 $actions => undef
227 $subactions => undef
228 $title => $m->callers(-1)->path
229 $AppName => undef
230 $show_menu => 1
231 </%ARGS>