[freeside-commits] freeside/httemplate/elements location.html, 1.8, 1.9 city.html, NONE, 1.1 select-county.html, 1.3, 1.4 tr-select-cust_location.html, 1.4, 1.5

Ivan,,, ivan at wavetail.420.am
Sun Oct 11 18:45:14 PDT 2009


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

Modified Files:
	location.html select-county.html tr-select-cust_location.html 
Added Files:
	city.html 
Log Message:
UI for per-city taxes (setup and assigning to customers/package locations), RT#5852

Index: tr-select-cust_location.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/elements/tr-select-cust_location.html,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- tr-select-cust_location.html	19 Jan 2009 06:39:10 -0000	1.4
+++ tr-select-cust_location.html	12 Oct 2009 01:45:12 -0000	1.5
@@ -21,7 +21,7 @@
     var locationnum = what.options[what.selectedIndex].value;
     if ( locationnum == -1 ) {
 
-%     for (@location_fields) { 
+%     for (@location_fields, 'city_select') { 
         what.form.<%$_%>.disabled = false;
         what.form.<%$_%>.style.backgroundColor = '#ffffff';
 %     } 
@@ -60,7 +60,7 @@
       } 
 
 %#sleep/wait until dropdowns are updated?
-%     for (@location_fields) { 
+%     for (@location_fields, 'city_select') { 
         what.form.<%$_%>.disabled = true;
         what.form.<%$_%>.style.backgroundColor = '#dddddd';
 %     } 
@@ -85,6 +85,7 @@
       } else {
         county_el.selectedIndex = 0;
       }
+      county_changed(county_el);
     }
     return fix_county;
   }

--- NEW FILE: city.html ---
<%doc>

Example:

  include( '/elements/city.html',
    #recommended
    country    => $current_country,
    state      => $current_state,
    county     => $current_county,
    city       => $current_city,

    #optional
    prefix        => $optional_unique_prefix,
    onchange      => $javascript,
    disabled      => 0, #bool
#    disable_empty => 1, #defaults to 1, disable the empty option
#    empty_label   => 'all', #label for empty option
    style         => [ 'attribute:value', 'another:value' ],
  );

</%doc>

<% include('/elements/xmlhttp.html',
              'url'  => $p.'misc/cities.cgi',
              'subs' => [ $pre. 'get_cities' ],
           )
%>

<SCRIPT TYPE="text/javascript">

  function opt(what,value,text) {
    var optionName = new Option(text, value, false, false);
    var length = what.length;
    what.options[length] = optionName;
  }

  var saved_<%$pre%>city= '';

  function <% $pre %>county_changed(what, callback) {

    county  = what.options[what.selectedIndex].value;
    state   = what.form.<% $pre %>state.options[what.form.<% $pre %>state.selectedIndex].value;
    country = what.form.<% $pre %>country.options[what.form.<% $pre %>country.selectedIndex].value;

    function <% $pre %>update_cities(cities) {
     
      // blank the current city list
      for ( var i = what.form.<% $pre %>city_select.length; i >= 0; i-- )
          what.form.<% $pre %>city_select.options[i] = null;

      // add the new cities
      var citiesArray = eval('(' + cities + ')' );

      for ( var s = 0; s < citiesArray.length; s++ ) {
          var cityLabel = citiesArray[s];
          if ( cityLabel == "" )
              cityLabel = '(n/a)';
          opt(what.form.<% $pre %>city_select, citiesArray[s], cityLabel);
      }

     if ( citiesArray.length > 1 || citiesArray[0].length ) { 
        // turn off the text city, turn on the select
        saved_<%$pre%>city = what.form.<%$ pre %>city.value;
        what.form.<% $pre %>city.style.display = 'none';
        what.form.<% $pre %>city_select.style.display = '';
      } else {
        // turn on the text city, turn off the select
        what.form.<%$ pre %>city.value = saved_<%$pre%>city;
        what.form.<% $pre %>city.style.display = '';
        what.form.<% $pre %>city_select.style.display = 'none';
      }

      //run the callback
      if ( callback != null )
        callback();
    }

    // go get the new cities
    <% $pre %>get_cities( county, state, country, <% $pre %>update_cities );

  }

  function <%$pre%>city_select_changed(what) {
    what.form.<%$pre%>city.value = what.options[what.selectedIndex].value;
  }

</SCRIPT>

<INPUT TYPE     = "text"
       NAME     = "<%$pre%>city"
       ID       = "<%$pre%>city"
       VALUE    = "<% $opt{'city'} |h %>"
       onChange = "<% $opt{'onchange'} %>"
       <% $opt{'disabled'} %>
       <% $text_style %>
>

<SELECT NAME     = "<%$pre%>city_select"
        ID       = "<%$pre%>city_select"
        onChange = "<%$pre%>city_select_changed(this); <% $opt{'onchange'} %>"
        <% $opt{'disabled'} %>
        <% $select_style %>
>

% foreach my $city ( @cities ) {

    <OPTION VALUE="<% $city |h %>"
            <% $city eq $opt{'city'} ? 'SELECTED' : '' %>
    ><% $city eq $opt{'empty_data_value'} ? $opt{'empty_data_label'} : $city %>

% }

</SELECT>

%#           VALUE    = "<% $curr_value |h %>"
<%init>

my %opt = @_;

my $pre = $opt{'prefix'};

my $text_style   = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];
my $select_style = $opt{'style'} ? [ @{ $opt{'style'} } ] : [];

my @cities = cities( $opt{'county'}, $opt{'state'}, $opt{'country'} );
if ( scalar(@cities) > 1 || $cities[0] ) {
  push @$text_style, 'display:none';
} else {
  push @$select_style, 'display:none';
}

$text_style =
  scalar(@$text_style)
    ? 'STYLE="'. join(';', @$text_style). '"'
    : '';

$select_style =
  scalar(@$select_style)
    ? 'STYLE="'. join(';', @$select_style). '"'
    : '';

</%init>

Index: select-county.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/elements/select-county.html,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- select-county.html	25 May 2009 01:49:34 -0000	1.3
+++ select-county.html	12 Oct 2009 01:45:12 -0000	1.4
@@ -67,8 +67,11 @@
         }
 
         //run the callback
-        if ( callback != null ) 
+        if ( callback != null )  {
           callback();
+        } else {
+          <% $pre %>county_changed(what.form.<% $pre %>county);
+        }
       }
   
       // go get the new counties
@@ -80,7 +83,7 @@
 
   <SELECT NAME    = "<% $pre %>county"
           ID      = "<% $pre %>county"
-          onChange= "<% $opt{'onchange'} %>"
+          onChange= "<% $onchange %>"
           <% $opt{'disabled'} %>
           <% $style %>
   >
@@ -127,11 +130,13 @@
 
 my $pre = $opt{'prefix'};
 
+
+# disable_cityupdate?
+my $onchange =
+  ( $opt{'disable_cityupdate'} ? '' : $pre.'county_changed(this); ' ).
+  $opt{'onchange'};
+
 $opt{'style'} ||= [];
-my $style =
-  scalar(@{$opt{style}})
-    ? 'STYLE="'. join(';', @{$opt{style}}). '"'
-    : '';
 
 my @counties = ();
 if ( $countyflag ) {
@@ -139,17 +144,16 @@
   @counties = map { length($_) ? $_ : $opt{'empty_data_value'} }
                   counties( $opt{'state'}, $opt{'country'} );
 
-  # this is very hacky
-  unless ( scalar(@counties) > 1 ) {
-    if ( $opt{'disabled'} =~ /STYLE=/i ) {
-      $opt{'disabled'} =~ s/STYLE="([^"]+)"/STYLE="$1; display:none"/i;
-    } else {
-      $opt{'disabled'} .= ' STYLE="display:none"';
-    }
-  }
+  push @{ $opt{'style'} }, 'display:none'
+    unless scalar(@counties) > 1;
 
 }
 
+my $style =
+  scalar(@{$opt{style}})
+    ? 'STYLE="'. join(';', @{$opt{style}}). '"'
+    : '';
+
 </%init>
 <%once>
 

Index: location.html
===================================================================
RCS file: /home/cvs/cvsroot/freeside/httemplate/elements/location.html,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- location.html	27 Jul 2009 03:26:46 -0000	1.8
+++ location.html	12 Oct 2009 01:45:12 -0000	1.9
@@ -49,16 +49,7 @@
 
 <TR>
   <TH ALIGN="right"><%$r%>City</TH>
-  <TD WIDTH="1">
-    <INPUT TYPE     = "text"
-           NAME     = "<%$pre%>city"
-           ID       = "<%$pre%>city"
-           VALUE    = "<% $object->get($pre.'city') |h %>"
-           onChange = "<% $onchange %>"
-           <% $disabled %>
-           <% $style %>
-    >
-  </TD>
+  <TD WIDTH="1"><% include('/elements/city.html', %select_hash) %></TD>
   <TH ALIGN="right" ID="<%$pre%>countylabel" <%$county_style%>><%$r%>County</TH>
   <TD><% include('/elements/select-county.html', %select_hash ) %></TD>
   <TH ALIGN="right" WIDTH="1"><%$r%>State</TH>
@@ -123,7 +114,7 @@
          || $object->get($pre.'country') ne $countrydefault;
 
 my @style = ();
-push @style, 'background-color: #dddddd"' if $disabled;
+push @style, 'background-color: #dddddd' if $disabled;
 
 my @address2_label_style = ();
 push @address2_label_style, 'visibility:hidden'
@@ -152,6 +143,7 @@
     : '';
 
 my %select_hash = (
+  'city'     => $object->get($pre.'city'),
   'county'   => $object->get($pre.'county'),
   'state'    => $object->get($pre.'state'),
   'country'  => $object->get($pre.'country'),



More information about the freeside-commits mailing list