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