Merge branch 'master' of git.freeside.biz:/home/git/freeside
[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 </style>
101
102 <ul id="<% $opt{id} %>">
103 % foreach my $submenu (@processed_menu) {
104   <li <% $opt{bgcolor} ? 'STYLE="background:'. $opt{bgcolor}.'"' : '' %>>
105     <% shift @$submenu %>
106 %   if ( @$submenu ) {
107       <ul class="<% $opt{class} %>">
108 %     foreach my $link ( @$submenu ) {
109         <li><% $link %></li>
110 %     }
111       </ul>
112 %   }
113   </li>
114 % }
115 </ul>
116
117 <script type="text/javascript">
118
119   $("#<% $opt{id} %>").menu({
120     position: { my: "left top", at: "left+1 bottom+3" },
121     icons: { submenu: "ui-icon-blank" },
122     blur: function() {
123       $(this).menu("option", "position", { my:"left top", at:"left+1 bottom+3" } );
124     },
125     focus: function(e,ui) {
126       if ($("#<% $opt{id} %>").get(0) !== $(ui).get(0).item.parent().get(0)) {
127         $(this).menu("option", "position", { my:"left top", at:"right+2 top"} );
128       }
129     },
130   });
131
132 </script>
133
134 <%init>
135 my %opt = @_;
136
137 #my $cust_main = $opt{'cust_main'};
138 #my $custnum = $cust_main->custnum;
139 #my $curuser = $FS::CurrentUser::CurrentUser;
140 #my $conf = FS::Conf->new;
141 #
142 #my %payby = map { $_ => 1 } $conf->config('payby');
143 #
144 ## cached for conditions, to avoid looking it up twice
145 #my $invoicing_list_emailonly = $cust_main->invoicing_list_emailonly;
146
147 my @processed_menu;
148 foreach my $submenu (@{ $opt{menu} }) {
149
150   my @links;
151   my $first = 1;
152   foreach my $entry ( @$submenu ) {
153     # if the menu head was skipped, skip the whole menu
154     last if (!$first and !@links);
155     $first = 0;
156
157     my $a = entry2link($entry, \%opt);
158     push @links, $a if length($a);
159
160   } # foreach $entry
161
162   if (@links) {
163     push @processed_menu, \@links;
164   }
165
166 }
167
168 sub entry2link {
169     my( $entry, $opt ) = @_;
170
171     # check conditions
172     if ( $entry->{acl} ) {
173       return ''
174         unless $FS::CurrentUser::CurrentUser->access_right( $entry->{acl} );
175     }
176     if ( $entry->{confexists} ) {
177       if ( $entry->{confexists} =~ /^!(.*)/ ) {
178         # confexists => !foo, a negative condition
179         return '' if FS::Conf->new->exists( $1 );
180       } else {
181         return '' unless FS::Conf->new->exists( $entry->{confexists} );
182       }
183     }
184     if ( $entry->{condition} ) {
185       return '' unless &{ $entry->{condition} }($opt->{cust_main});
186     }
187
188     my $label = emt($entry->{label});
189
190     if ( $entry->{submenu} ) {
191
192       my $a = '<a href="javascript:void(0);">'. $label.
193               '<span class="arrow"></span>'.
194               '</a><ul class="customer_subsubmenu">';
195       foreach my $submenu (@{ $entry->{submenu} }) {
196         $a .= '<li>'. entry2link($submenu, $opt->{cust_main}, $opt->{show}), '</li>';
197       }
198
199       return $a. '</ul>';
200
201     }
202
203     my $target = $entry->{content}
204               || $entry->{popup}
205               || $entry->{url};
206
207     if ( ref($target) eq 'CODE' ) {
208       $target = &$target($opt->{cust_main});
209     }
210
211     return $target if $entry->{content}; #the coderef specified the whole thing
212
213     if ( $entry->{show} ) {
214
215       $target = $opt->{self_url}. $entry->{show};
216
217       my $a = qq[ <A HREF="$target"];
218       $a .= ' class="current_show"' if $opt->{show} eq $entry->{show};
219       return $a. qq[>$label</A> ];
220
221     } elsif ( $entry->{popup} ) {
222
223       #$target =~ s/\$custnum/$custnum/g;
224       $target = $p.$target;
225
226       return include('/elements/popup_link.html',
227         action  => $target,
228         width   => 616,
229         height  => 410,
230         %$entry,
231         label   => $label,
232       );
233
234     } elsif ( $entry->{url} ) {
235
236       #$target =~ s/\$custnum/$custnum/g;
237       $target = $p.$target;
238
239       return qq[ <A HREF="$target">$label</A> ];
240
241     } else {
242       die "bad entry ". join(',',%$entry). " in menu: no url, popup or content";
243     }
244
245 }
246
247 </%init>