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