menu link, RT#81809
[freeside.git] / httemplate / elements / dropdown-menu.html
1 <style type="text/css">
2
3 #<% $opt{id} %> {
4   font-size: smaller;
5   border: none;
6 }
7
8 #<% $opt{id} %> .ui-state-active {
9   color: inherit;
10   background-color: transparent;
11   border-color: transparent;
12 }
13
14 #<% $opt{id} %> li {
15   float: left;
16   padding: .25em;
17 }
18
19 /* #<% $opt{id} %> .ui-menu-item  */
20 #<% $opt{id} %> > li {
21   padding-left: 0px;
22 }
23     
24 /* #<% $opt{id} %> .ui-menu-item  */
25 #<% $opt{id} %> > li.ui-state-focus {
26   border: 1px solid transparent;
27 }
28   
29 #<% $opt{id} %> > li.ui-state-active {
30   border: 1px solid transparent;
31 }
32
33 #<% $opt{id} %> > li.ui-state-active > a {
34
35 /* if i could find something light enough that didn't look pink?
36      or is this too visually distracting and not the useful hint i think it is?
37   background: #ED55E7;
38 */
39 }
40
41 #<% $opt{id} %> a {
42   white-space: nowrap;
43 }
44
45 #<% $opt{id} %> ul {
46   border: 1px solid #7e0079;
47   border-radius: 2px;
48   box-shadow: #333333 1px 1px 2px;
49 }
50
51 #<% $opt{id} %> ul li {
52   float: none;
53   margin-right: 2px;
54   margin-left: 2px;
55 }
56
57 #<% $opt{id} %> ul a {
58   color: #333333;
59 }
60
61 #<% $opt{id} %> li.ui-menu-divider {
62   border-color: #7e0079;
63 }
64
65 #<% $opt{id} %> a:hover {
66   text-decoration: underline;
67   color: #7e0079;
68 }
69
70 #<% $opt{id} %> ul li.ui-state-focus {
71   background: transparent;
72   border: 1px solid transparent;
73   margin-right: 1px;
74   margin-left: 1px;
75 }
76
77 #<% $opt{id} %> ul li.ui-state-active {
78   background: #f8f0fc;
79   border: 1px solid #7e0079;
80   border-radius: 2px;
81   margin-right: 1px;
82   margin-left: 1px;
83 }
84
85 #<% $opt{id} %> a .arrow {
86   float: right;
87   background-image: url("<% $p %>images/arrow.right.black.png");
88   width: 3px;
89   height: 6px;
90   margin-top:4px;
91 }
92
93 /* Firefox hack
94 @-moz-document url-prefix() {
95   #<% $opt{id} %> a .arrow {
96     margin-top:-.8em;
97   }
98 }
99 */
100
101 </style>
102
103 <ul id="<% $opt{id} %>">
104 % foreach my $submenu (@processed_menu) {
105   <li <% $opt{bgcolor} ? 'STYLE="background:'. $opt{bgcolor}.'"' : '' %>>
106     <% shift @$submenu %>
107 %   if ( @$submenu ) {
108       <ul class="<% $opt{class} %>">
109 %     foreach my $link ( @$submenu ) {
110         <li><% $link %></li>
111 %     }
112       </ul>
113 %   }
114   </li>
115 % }
116 </ul>
117
118 <script type="text/javascript">
119
120   $("#<% $opt{id} %>").menu({
121     position: { my: "left top", at: "left+1 bottom+3" },
122     icons: { submenu: "ui-icon-blank" },
123     blur: function() {
124       $(this).menu("option", "position", { my:"left top", at:"left+1 bottom+3" } );
125     },
126     focus: function(e,ui) {
127       if ($("#<% $opt{id} %>").get(0) !== $(ui).get(0).item.parent().get(0)) {
128         $(this).menu("option", "position", { my:"left top", at:"right+2 top"} );
129       }
130     },
131   });
132
133 </script>
134
135 <%init>
136 my %opt = @_;
137
138 #my $cust_main = $opt{'cust_main'};
139 #my $custnum = $cust_main->custnum;
140 #my $curuser = $FS::CurrentUser::CurrentUser;
141 #my $conf = FS::Conf->new;
142 #
143 #my %payby = map { $_ => 1 } $conf->config('payby');
144 #
145 ## cached for conditions, to avoid looking it up twice
146 #my $invoicing_list_emailonly = $cust_main->invoicing_list_emailonly;
147
148 my @processed_menu;
149 foreach my $submenu (@{ $opt{menu} }) {
150
151   my @links;
152   my $first = 1;
153   foreach my $entry ( @$submenu ) {
154     # if the menu head was skipped, skip the whole menu
155     last if (!$first and !@links);
156     $first = 0;
157
158     my $a = entry2link($entry, \%opt);
159     push @links, $a if length($a);
160
161   } # foreach $entry
162
163   if (@links) {
164     push @processed_menu, \@links;
165   }
166
167 }
168
169 sub entry2link {
170     my( $entry, $opt ) = @_;
171
172     # check conditions
173     if ( $entry->{acl} ) {
174       return ''
175         unless $FS::CurrentUser::CurrentUser->access_right( $entry->{acl} );
176     }
177     if ( $entry->{confexists} ) {
178       if ( $entry->{confexists} =~ /^!(.*)/ ) {
179         # confexists => !foo, a negative condition
180         return '' if FS::Conf->new->exists( $1 );
181       } else {
182         return '' unless FS::Conf->new->exists( $entry->{confexists} );
183       }
184     }
185     if ( $entry->{condition} ) {
186       return '' unless &{ $entry->{condition} }($opt->{cust_main});
187     }
188
189     my $label = emt($entry->{label});
190
191     if ( $entry->{submenu} ) {
192
193       my $a = '<a href="javascript:void(0);">'. $label.
194               '<span class="arrow"></span>'.
195               '</a><ul class="customer_subsubmenu">';
196       foreach my $submenu (@{ $entry->{submenu} }) {
197         $a .= '<li>'. entry2link($submenu, $opt->{cust_main}, $opt->{show}), '</li>';
198       }
199
200       return $a. '</ul>';
201
202     }
203
204     my $target = $entry->{content}
205               || $entry->{popup}
206               || $entry->{url};
207
208     if ( ref($target) eq 'CODE' ) {
209       $target = &$target($opt->{cust_main});
210     }
211
212     return $target if $entry->{content}; #the coderef specified the whole thing
213
214     if ( $entry->{show} ) {
215
216       $target = $opt->{self_url}. $entry->{show};
217
218       my $a = qq[ <A HREF="$target"];
219       $a .= ' class="current_show"' if $opt->{show} eq $entry->{show};
220       return $a. qq[>$label</A> ];
221
222     } elsif ( $entry->{popup} ) {
223
224       #$target =~ s/\$custnum/$custnum/g;
225       $target = $p.$target;
226
227       return include('/elements/popup_link.html',
228         action  => $target,
229         width   => 616,
230         height  => 410,
231         %$entry,
232         label   => $label,
233       );
234
235     } elsif ( $entry->{url} ) {
236
237       #$target =~ s/\$custnum/$custnum/g;
238       $target = $p.$target;
239
240       return qq[ <A HREF="$target">$label</A> ];
241
242     } else {
243       die "bad entry ". join(',',%$entry). " in menu: no url, popup or content";
244     }
245
246 }
247
248 </%init>