[freeside-commits] freeside/httemplate/elements select-discount.html, 1.1, 1.2 select-table.html, 1.19, 1.20 tr-select-discount.html, 1.1, 1.2 tr-select.html, 1.1, 1.2 tr-input-text.html, 1.6, 1.7

Ivan,,, ivan at wavetail.420.am
Thu Feb 4 12:39:58 PST 2010


Update of /home/cvs/cvsroot/freeside/httemplate/elements
In directory wavetail.420.am:/tmp/cvs-serv22915/httemplate/elements

Modified Files:
	select-discount.html select-table.html tr-select-discount.html 
	tr-select.html tr-input-text.html 
Log Message:
discounts, RT#6679

Index: tr-select-discount.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/elements/tr-select-discount.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- tr-select-discount.html	30 Jan 2010 08:55:11 -0000	1.1
+++ tr-select-discount.html	4 Feb 2010 20:39:56 -0000	1.2
@@ -1,20 +1,156 @@
-% if ( scalar(@{ $opt{'discount'} }) == 0 ) { 
+% if ( scalar(@{ $opt{'discount'} }) == 0
+%      && ! $curuser->access_right('Custom discount customer package') ) { 
 
-  <INPUT TYPE="hidden" NAME="<% $opt{'element_name'} || $opt{'field'} || 'discountnum' %>" VALUE="">
+  <INPUT TYPE="hidden" NAME="<% $name %>" VALUE="<% $discountnum %>">
 
 % } else { 
 
   <TR>
     <TD ALIGN="right"><% $opt{'label'} || '<B>Discount</B>' %></TD>
-    <TD>
+    <TD <% $colspan %>>
       <% include( '/elements/select-discount.html',
                     'curr_value' => $discountnum,
+                    'onchange'   => $name.'_changed',
                     %opt,
                 )
       %>
     </TD>
   </TR>
 
+% # a weird kind of false laziness w/edit/discount.html
+
+  <INPUT TYPE="hidden" NAME="<% $name %>_disabled" VALUE="Y">
+
+
+  <% include( '/elements/tr-select.html',
+                'label'      => '<B>Discount Type</B>',
+                'field'      => $name. '__type',
+                'id'         => $name. '__type',
+                'options'    => \@_type_options,
+                #XXX 'curr_value' => 
+                'onchange'   => '_type_changed',
+                'colspan'    => $opt{'colspan'},
+            )
+  %>
+
+  <% include( '/elements/tr-input-money.html',
+                'label'      => '<B>Discount Amount</B>',
+                'field'      => $name. '_amount',
+                'id'         => $name. '_amount',
+                'default'    => '0.00',
+                #XXX 'curr_value' =>
+                'colspan'    => $opt{'colspan'},
+            )
+  %>
+
+  <% include( '/elements/tr-input-percentage.html',
+                'label'      => '<B>Discount Percentage</B>',
+                'field'      => $name. '_percent',
+                'id'         => $name. '_percent',
+                'default'    => '0',
+                #XXX 'curr_value' =>
+                'colspan'    => $opt{'colspan'},
+            )
+  %>
+
+  <% include( '/elements/tr-input-text.html',
+                'label'   => '<B>Discount # of Months</B>',
+                'field'   => $name. '_months',
+                'id'      => $name. '_months',
+                'size'    => 2,
+                'postfix' => qq(<FONT SIZE="-1" ID="${name}_months_postfix"><I>(blank for non-expiring discount)</I></FONT>),
+                #XXX 'curr_value' =>
+                'colspan'    => $opt{'colspan'},
+           )
+  %>
+
+  <SCRIPT TYPE="text/javascript">
+
+%   my $ge = 'document.getElementById';
+
+    function <% $name %>_changed(what) {
+      var <% $name %> = what.options[what.selectedIndex].value;
+
+      if ( <% $name %> == '-1' ) {
+        <% $ge %>('<% $name %>__type_label0').style.display = '';
+        <% $ge %>('<% $name %>__type_label0').style.visibility = '';
+        <% $ge %>('<% $name %>__type').style.display = '';
+        <% $ge %>('<% $name %>__type').style.visibility = '';
+%       #XXX retrieve previous visibility for amount, percent :/
+        <% $ge %>('<% $name %>_months_label0').style.display = '';
+        <% $ge %>('<% $name %>_months_label0').style.visibility = '';
+        <% $ge %>('<% $name %>_months').style.display = '';
+        <% $ge %>('<% $name %>_months').style.visibility = '';
+        <% $ge %>('<% $name %>_months_postfix').style.display = '';
+        <% $ge %>('<% $name %>_months_postfix').style.visibility = '';
+      } else {
+
+        <% $ge %>('<% $name %>__type_label0').style.display = 'none';
+        <% $ge %>('<% $name %>__type_label0').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>__type').style.display = 'none';
+        <% $ge %>('<% $name %>__type').style.visibility = 'hidden';
+
+%       #XXX save visibility settings for amount, percent :/
+        <% $ge %>('<% $name %>_amount_label0').style.display = 'none';
+        <% $ge %>('<% $name %>_amount_label0').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_amount').style.display = 'none';
+        <% $ge %>('<% $name %>_amount').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_amount_input0').style.display = 'none';
+        <% $ge %>('<% $name %>_amount_input0').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_percent_label0').style.display = 'none';
+        <% $ge %>('<% $name %>_percent_label0').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_percent').style.display = 'none';
+        <% $ge %>('<% $name %>_percent').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_percent_input0').style.display = 'none';
+        <% $ge %>('<% $name %>_percent_input0').style.visibility = 'hidden';
+
+        <% $ge %>('<% $name %>_months_label0').style.display = 'none';
+        <% $ge %>('<% $name %>_months_label0').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_months').style.display = 'none';
+        <% $ge %>('<% $name %>_months').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_months_postfix').style.display = 'none';
+        <% $ge %>('<% $name %>_months_postfix').style.visibility = 'hidden';
+
+      }
+
+    }
+
+    function <% $name %>__type_changed(what) {
+      var _type = what.options[what.selectedIndex].value;
+
+      if ( <% $name %>__type == '<% $select %>' ) {
+        <% $ge %>('<% $name %>_amount_label0').style.display = 'none';
+        <% $ge %>('<% $name %>_amount_label0').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_amount').style.display = 'none';
+        <% $ge %>('<% $name %>_amount').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_percent_label0').style.display = 'none';
+        <% $ge %>('<% $name %>_percent_label0').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_percent').style.display = 'none';
+        <% $ge %>('<% $name %>_percent').style.visibility = 'hidden';
+      } else if ( <% $name %>__type == 'Amount' ) {
+        <% $ge %>('<% $name %>_amount_label0').style.display = '';
+        <% $ge %>('<% $name %>_amount_label0').style.visibility = '';
+        <% $ge %>('<% $name %>_amount').style.display = '';
+        <% $ge %>('<% $name %>_amount').style.visibility = '';
+        <% $ge %>('<% $name %>_percent_label0').style.display = 'none';
+        <% $ge %>('<% $name %>_percent_label0').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_percent').style.display = 'none';
+        <% $ge %>('<% $name %>_percent').style.visibility = 'hidden';
+      } else if ( <% $name %>__type == 'Percentage' ) {
+        <% $ge %>('<% $name %>_amount_label0').style.display = 'none';
+        <% $ge %>('<% $name %>_amount_label0').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_amount').style.display = 'none';
+        <% $ge %>('<% $name %>_amount').style.visibility = 'hidden';
+        <% $ge %>('<% $name %>_percent_label0').style.display = '';
+        <% $ge %>('<% $name %>_percent_label0').style.visibility = '';
+        <% $ge %>('<% $name %>_percent').style.display = '';
+        <% $ge %>('<% $name %>_percent').style.visibility = '';
+     }
+
+    }
+
+  </SCRIPT>
+
 % } 
 <%init>
 
@@ -23,5 +159,15 @@
 
 $opt{'discount'} ||= [ qsearch( 'discount', { disabled=>'' } ) ];
 
-</%init>
+my $curuser = $FS::CurrentUser::CurrentUser;
 
+my $name = $opt{'element_name'} || $opt{'field'} || 'discountnum';
+
+my $select = 'Select discount type';
+
+my @_type_options = ( 'Amount', 'Percentage' );
+unshift @_type_options, $select;
+
+my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : '';
+
+</%init>

Index: tr-input-text.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/elements/tr-input-text.html,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- tr-input-text.html	30 Jan 2010 07:38:32 -0000	1.6
+++ tr-input-text.html	4 Feb 2010 20:39:56 -0000	1.7
@@ -1,6 +1,6 @@
 <% include('tr-td-label.html', @_ ) %>
 
-  <TD <% $cell_style %> ID="<% $opt{input_id} || $opt{id}.'_input0' %>"><% include('input-text.html', @_ ) %></TD>
+  <TD <% $colspan %> <% $cell_style %> ID="<% $opt{input_id} || $opt{id}.'_input0' %>"><% include('input-text.html', @_ ) %></TD>
 
 </TR>
 
@@ -10,4 +10,6 @@
 
 my $cell_style = $opt{'cell_style'} ? 'STYLE="'. $opt{'cell_style'}. '"' : '';
 
+my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : '';
+
 </%init>

Index: select-discount.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/elements/select-discount.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- select-discount.html	30 Jan 2010 08:55:11 -0000	1.1
+++ select-discount.html	4 Feb 2010 20:39:56 -0000	1.2
@@ -1,10 +1,11 @@
 <% include( '/elements/select-table.html',
-                 'table'       => 'discount',
-                 'name_col'    => 'description',
-                 'order_by'    => 'ORDER BY discountnum', #XXX weight
-                 'value'       => $discountnum,
-                 'empty_label' => '(none)',
-                 'hashref'     => { 'disabled' => '' },
+                 'table'        => 'discount',
+                 'name_col'     => 'description',
+                 'order_by'     => 'ORDER BY discountnum', #XXX weight
+                 'value'        => $discountnum,
+                 'empty_label'  => '(none)',
+                 'hashref'      => { 'disabled' => '' },
+                 'post_options' => $post_options,
                  %opt,
              )
 %>
@@ -16,5 +17,12 @@
 $opt{'records'} = delete $opt{'discount'}
   if $opt{'discount'};
 
+my $curuser = $FS::CurrentUser::CurrentUser;
+
+#make an opt if we need to turn this off
+my $post_options = $curuser->access_right('Custom discount customer package')
+  ? [ -1 => 'Custom discount' ]
+  : [];
+
 </%init>
 

Index: tr-select.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/elements/tr-select.html,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- tr-select.html	1 Aug 2007 22:25:10 -0000	1.1
+++ tr-select.html	4 Feb 2010 20:39:56 -0000	1.2
@@ -1,6 +1,6 @@
 <% include('tr-td-label.html', @_ ) %>
 
-  <TD <% $style %>>
+  <TD <% $colspan %> <% $style %>>
 
     <SELECT NAME          = "<% $opt{field} %>"
             ID            = "<% $opt{id} %>"
@@ -58,4 +58,6 @@
 
 my $curr_value = $opt{'curr_value'};
 
+my $colspan = $opt{'colspan'} ? 'COLSPAN="'.$opt{'colspan'}.'"' : '';
+
 </%init>

Index: select-table.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/elements/select-table.html,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- select-table.html	30 Jan 2010 20:05:16 -0000	1.19
+++ select-table.html	4 Feb 2010 20:39:56 -0000	1.20
@@ -31,6 +31,7 @@
 
     #basic params controlling the resulting <SELECT>
     'pre_options'    => [ 'value' => 'option' ], #before normal options
+    'post_options'   => [ 'value' => 'option' ], #after normal options
     'empty_label'    => '', #better specify it though, the default might change
     'multiple'       => 0, # bool
     'disable_empty'  => 0, # bool (implied by multiple)
@@ -103,6 +104,16 @@
      %>
 % } 
 
+% while ( @post_options ) { 
+%   my $post_opt   = shift(@post_options);
+%   my $post_label = shift(@post_options);
+%   my $selected =    ( ref($value) && $value->{$post_opt} )
+%                  || ( $value eq $post_opt );
+    <OPTION VALUE="<% $post_opt %>"
+            <% $selected ? 'SELECTED' : '' %>
+    ><% $post_label %>
+% } 
+
 </SELECT>
 
 %}
@@ -180,6 +191,7 @@
   $value = { map { $_ => 1 } @$value };
 }
 
-my @pre_options = $opt{pre_options} ? @{ $opt{pre_options} } : ();
+my @pre_options  = $opt{pre_options}  ? @{ $opt{pre_options} } : ();
+my @post_options = $opt{post_options} ? @{ $opt{post_options} } : ();
 
 </%init>



More information about the freeside-commits mailing list