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