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