default to a session cookie instead of setting an explicit timeout, weird timezone...
[freeside.git] / httemplate / elements / part_pkg_usageprice.html
1 % unless ( $opt{'js_only'} ) {
2
3   <INPUT TYPE="hidden" NAME="<%$name%>" ID="<%$id%>" VALUE="<% $curr_value %>">
4
5   <TABLE STYLE="display:inline">
6     <TR>
7
8 %     ###
9 %     # price
10 %     ###
11       <TD>
12         <TABLE STYLE="display:inline">
13           <TR>
14             <TD>Price</TD>
15             <TD><% $money_char %><INPUT
16               TYPE  = "text"
17               NAME  = "<%$name%>_price"
18               ID    = "<%$id%>_price"
19               VALUE = "<% scalar($cgi->param($name.'_price'))
20                             || $part_pkg_usageprice->price
21                        %>"
22               <% $onchange %>
23             ></TD>
24           </TR>
25
26 % #XXX lots more work for multi-currency...  maybe larger UI changes :/
27 %         foreach my $currency ( () ) {
28 %         #foreach my $currency ( sort $conf->config('currencies') ) {
29             <TR>
30               <TD><% $currency %></TD>
31               <TD><% currency_symbol($currency, SYM_HTML) %><INPUT
32                 TYPE  = "text"
33                 NAME  = "<%$name%>_price_<%$currency%>"
34                 ID    = "<%$id%>_price_<%$currency%>"
35                 VALUE = "<% scalar($cgi->param($name.'_price_'.$currency))
36                               || $part_pkg_usageprice->price #XXX
37                          %>"
38                 <% $onchange %>
39               ></TD>
40             </TR>
41 %         }
42
43         </TABLE>
44       </TD>
45
46 %     ###
47 %     # action
48 %     ###
49       <TD>
50         <SELECT NAME = "<%$name%>_action"
51                 ID   = "<%$id%>_action"
52                 <% $onchange %>
53         >
54           <OPTION VALUE="increment">Increment
55 %#no set yet          <OPTION VALUE="set" <% ($cgi->param($name.'_action') || $part_pkg_usageprice->action) eq 'set' ? 'SELECTED' : '' %>>Set
56         </SELECT>
57       </TD>
58
59 %     ###
60 %     # target
61 %     ###
62       <TD>
63         <SELECT NAME = "<%$name%>_target"
64                 ID   = "<%$id%>_target"
65                 <% $onchange %>
66         >
67 %       foreach my $target (keys %$targets) {
68           <OPTION VALUE="<% $target %>"
69                   <% ($cgi->param($name.'_target') || $part_pkg_usageprice->target) eq $target ? 'SELECTED' : '' %>
70           ><% $targets->{$target}->{label} %>
71 %       }
72       </TD>
73
74 %     ###
75 %     # amount
76 %     ###
77 %     my $amount =
78 %       scalar($cgi->param($name.'_amount'))
79 %         || ( $part_pkg_usageprice->amount
80 %               / ($targets->{$part_pkg_usageprice->target}{multiplier} || 1) );
81 %     $amount = '' unless $amount > 0;
82       <TD>
83         <INPUT TYPE = "text"
84                NAME = "<%$name%>_amount"
85                ID   = "<%$id%>_amount"
86                SIZE = 5
87                VALUE = "<% $amount %>"
88                <% $onchange %>
89         >
90       </TD>
91
92     </TR>
93   </TABLE>
94
95 % }
96 <%init>
97
98 my $targets = FS::part_pkg_usageprice->targets;
99
100 my( %opt ) = @_;
101
102 my $conf = new FS::Conf;
103 my $money_char = $conf->config('money_char') || '$';
104
105 my $name = $opt{'element_name'} || $opt{'field'} || 'usagepricepart';
106 my $id = $opt{'id'} || 'usagepricepart';
107
108 my $curr_value = $opt{'curr_value'} || $opt{'value'};
109
110 my $onchange = '';
111 if ( $opt{'onchange'} ) {
112   $onchange = $opt{'onchange'};
113   $onchange .= '(this)' unless $onchange =~ /\(\w*\);?$/;
114   $onchange =~ s/\(what\);/\(this\);/g; #ugh, terrible hack.  all onchange
115                                         #callbacks should act the same
116   $onchange = 'onChange="'. $onchange. '"';
117 }
118
119 my $part_pkg_usageprice = $curr_value
120   ? qsearchs('part_pkg_usageprice', { 'usagepricepart' => $curr_value } )
121   : new FS::part_pkg_usageprice {};
122
123 </%init>