fix nit sorting out tops earchboxes
[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
49 <table class="black" border=0 cellspacing=0 cellpadding=0 width="100%">
50 <tr>
51   <TD colspan=5 WIDTH="100%" STYLE="padding:0"><IMG BORDER=0 ALT="" SRC="<% $RT::URI::freeside::URL %>/images/black-gradient.png" HEIGHT="13" WIDTH="100%"></TD>
52 </tr>
53 <tr>
54
55   <div id="topactions">
56 %  my $notfirst = 0; foreach my $action (sort keys %{$topactions}) {
57     <span class="topaction">
58     <td class="blackright" ALIGN="right" VALIGN="center">
59 % $m->out($topactions->{"$action"}->{'html'});
60     </td>
61     </span>
62 % }
63   </div>
64
65 </tr>
66 </table>
67
68 %# End of div#quickbar from /Elements/Header
69 </div>
70
71 <div id="nav">
72 <& /Elements/Menu, toptabs => $toptabs, current_toptab => $current_toptab &>
73 </div>
74
75 <div id="header">
76   <h1><%$title%></h1>
77
78 % my $sep       = 0;
79 % my $postsep   = 0;
80 % my $count     = 0;
81 % my $class     = { };
82
83   <ul id="page-menu"<% (($actions && %$actions) || ($subactions && %$subactions)) && q[ class="actions-present"] | n %>>
84     <div><div><div>
85 % if ($page_tabs) {
86 %     foreach my $tab (sort keys %{$page_tabs}) {
87 %         next if $tab =~ /^(?:current_toptab|this)$/;
88 %         $count++;
89 %
90 %         my $current = $page_tabs->{current_toptab} || "";
91 %         my $path    = $page_tabs->{$tab}->{'path'} || "";
92 %         
93 %         $path    =~ s#/index.html$##gi;
94 %         $current =~ s#/index.html$##gi;
95 %         
96 %         $sep = $toptabs->{$tab}->{'separator'} ? 1 : 0;
97 %
98 %         $class->{a} = $path eq $current ? ' class="selected"' : undef;
99 %
100 %         my @li;
101 %         push @li, 'first'
102 %                if $count == 1;
103 %
104 %         push @li, 'pre-separator'
105 %                if $sep;
106 %
107 %         push @li, 'post-separator'
108 %                if $postsep;
109 %
110 %         $class->{li} = join ' ', @li;
111 %     
112 %
113     <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>
114 %
115 %         if ($sep) {
116     <li class="separator">&#183;&#183;&#183;</li>
117 %         }
118 %         $postsep = $sep;
119 %     }
120 % } else {
121 &nbsp;
122 % }
123     </div></div></div>
124   </ul>
125
126 % if (($actions && %$actions) || ($subactions && %$subactions)) {
127   <ul id="actions-menu">
128     <div><div><div>
129 % $sep       = 0;
130 % $postsep   = 0;
131 % $count     = 0;
132 % $class     = { };
133 %
134 % for my $type ($actions, $subactions) {
135 %
136 % if ($type && %$type) {
137 %     foreach my $action (sort keys %{$type}) {
138 %         $count++;
139 %
140 %         $sep = $type->{$action}->{'separator'} ? 1 : 0;
141 %
142 %         my @li;
143 %         push @li, 'first'
144 %                if $count == 1;
145 %
146 %         push @li, 'pre-separator'
147 %                if $sep;
148 %
149 %         push @li, 'post-separator'
150 %                if $postsep;
151 %
152 %         $class->{li} = join ' ', @li;
153 %
154     <li<% $class->{li} ? qq[ class="$class->{li}"] : ''|n %>><% $count > 1 && !$postsep && qq[<span class="bullet">&#183; </span>]|n%>
155 %         if ($type->{"$action"}->{'html'}) {
156       <% $type->{"$action"}->{'html'} | n %>
157 %         } else {
158       <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>
159 %         }
160     </li>
161 %         if ($sep) {
162     <li class="separator">&#183;&#183;&#183;</li>
163 %         }
164 %         $postsep = $sep;
165 %     }
166 % }
167 % }
168     </div></div></div>
169   </ul>
170 % }
171 </div>
172
173 <div id="body">
174 <& /Elements/Callback, _CallbackName => 'BeforeBody',  %ARGS &>
175 %$m->flush_buffer(); # we've got the page laid out, let's flush the buffer;
176
177 <%INIT>
178   foreach my $tab (sort keys %{$toptabs}) {
179     if ($current_toptab && $toptabs->{$tab}->{'path'} eq $current_toptab) {
180       $toptabs->{$tab}->{"subtabs"} = $tabs;
181       $toptabs->{$tab}->{"current_subtab"} = $current_tab;
182     }
183   }
184
185 if (! defined($AppName)) {
186   $AppName = loc("RT for [_1]", $RT::rtname);
187 }
188
189 my ($menu_depth, $almost_last, $page_tabs);
190
191 if ($RT::WebDefaultStylesheet ne '3.4-compat') {
192     ($menu_depth, $almost_last) = @{$m->comp('.menu_recurse', data => $toptabs)};
193
194     if (defined $almost_last->{subtabs} and %{$almost_last->{subtabs}}) {
195         $page_tabs = {
196             current_toptab => $almost_last->{current_subtab},
197             %{$almost_last->{subtabs}},
198         };
199
200         delete $almost_last->{subtabs};
201         delete $almost_last->{current_subtab};
202     }
203 }
204 </%INIT>
205
206 %# There's probably a better way to do this that involves three times as
207 %# much work and redoing the whole menu/tab system... which would seem a
208 %# bit out of scope.
209 %#
210 %# This function recurses through the menu and returns the second to
211 %# last menu, that is, the menu holding the last reference to
212 %# and submenu.  It also returns the number of menu levels minus
213 %# the last submenu.
214 <%def .menu_recurse>
215   <%args>
216       $data   => { }
217       $pdata  => { }
218       $ppdata => { }
219       $level  => 0
220   </%args>
221   <%init>
222       for my $key (keys %$data) {
223           return $m->comp('.menu_recurse', data   => $data->{$key}->{subtabs},
224                                            pdata  => $data->{$key},
225                                            ppdata => $pdata,
226                                            level  => $level+1)
227               if ref($data->{$key}) eq 'HASH'
228                  and defined $data->{$key}->{subtabs}
229                  and %{$data->{$key}->{subtabs}};
230       }
231       $ppdata->{last_system_menu_level}++;
232       return [$level, $pdata];
233   </%init>
234 </%def>
235
236 <%ARGS>
237 $current_toptab => undef
238 $current_tab => undef
239 $toptabs => undef
240 $topactions => undef
241 $tabs => undef
242 $actions => undef
243 $subactions => undef
244 $title => $m->callers(-1)->path
245 $AppName => undef
246 </%ARGS>