invoice_sections_with_taxes per-agent, RT#79636
[freeside.git] / httemplate / elements / tr-input-date-field.html
index 0618fc9..f2a570b 100644 (file)
@@ -1,14 +1,36 @@
+<%doc>
 
-<LINK REL="stylesheet" TYPE="text/css" HREF="../elements/calendar-win2k-2.css" TITLE="win2k-2">
-<SCRIPT TYPE="text/javascript" SRC="../elements/calendar_stripped.js"></SCRIPT>
-<SCRIPT TYPE="text/javascript" SRC="../elements/calendar-en.js"></SCRIPT>
-<SCRIPT TYPE="text/javascript" SRC="../elements/calendar-setup.js"></SCRIPT>
+Example:
 
-<TR>
-  <TD ALIGN="right"><% $label %></TD>
-  <TD>
-    <INPUT TYPE="text" NAME="<% $name %>" ID="<% $name %>_text" VALUE="<% ($value eq '') ? '' : time2str($format, $value) %>">
-    <IMG SRC="../images/calendar.png" ID="<% $name  %>_button" STYLE="cursor: pointer" TITLE="Select date">
+  <& /elements/tr-input_date-field,
+       {
+          'name'  => 'field_name',
+          'value' => $current_value,
+          'label' => 'Label',
+
+          #optional
+          'format'      => '%m/%d/%Y', #overrides date_format config
+          'usedatetime' => 1, #use DateTime->strftime to format the date
+                              # instead of Date::Format->time2str
+          'noinit'      => 1,          #first one on the page is enough
+          'required'    => 1,
+       },
+  &>
+
+</%doc>
+% unless ( $noinit ) {
+<LINK REL="stylesheet" TYPE="text/css" HREF="<%$fsurl%>elements/calendar-win2k-2.css" TITLE="win2k-2">
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar_stripped.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-en.js"></SCRIPT>
+<SCRIPT TYPE="text/javascript" SRC="<%$fsurl%>elements/calendar-setup.js"></SCRIPT>
+% }
+
+<% include('/elements/tr-td-label.html',
+     'label'    => $label,
+     'required' => $required ) %>
+  <TD COLSPAN=<% $colspan %>>
+    <INPUT TYPE="text" NAME="<% $name %>" ID="<% $name %>_text" VALUE="<% $value %>">
+    <IMG SRC="<%$fsurl%>images/calendar.png" ID="<% $name  %>_button" STYLE="cursor: pointer" TITLE="<% mt('Select date') |h %>">
   </TD>
 </TR>
 
     ifFormat:   "<% $format %>",
     button:     "<% $name %>_button",
     align:      "BR"
+%   if ( $format =~ /\%r/ ) {
+      ,
+      showsTime: true,
+      timeFormat: 12
+%   }
   });
 </SCRIPT>
 
-
 <%init>
-my($name, $value, $label, $format) = @_;
 
-$format = "%m/%d/%Y" unless $format;
+my($name, $value, $label, $format, $usedatetime, $noinit, $colspan, $required);
+if ( ref($_[0]) ) {
+  my $opt = shift;
+  $name        = $opt->{'name'};
+  $value       = $opt->{'value'};
+  $label       = $opt->{'label'};
+  $format      = $opt->{'format'};
+  $usedatetime = $opt->{'usedatetime'};
+  $noinit      = $opt->{'noinit'};
+  $colspan     = $opt->{'colspan'} || 1;
+  $required    = $opt->{'required'};
+} else {
+  ($name, $value, $label, $format, $usedatetime) = @_;
+  $colspan = 1;
+}
+
+my $conf = new FS::Conf;
+
+$format ||= $conf->config('date_format') || '%m/%d/%Y';
+
 $label = $name unless $label;
 
+if ( $value =~ /\S/ ) {
+  if ( $usedatetime ) {
+    my $dt = DateTime->from_epoch(epoch => $value, time_zone => 'floating');
+    $value = $dt->strftime($format);
+  } elsif ( $value =~ /^\d+$/ ) {
+    $value = time2str($format, $value);
+  }
+} else {
+  $value = '';
+}
+
 </%init>