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