From: Steve Sutton Date: Fri, 3 Aug 2018 14:48:15 +0000 (-0400) Subject: Setup city select and add new city for billing. X-Git-Tag: v1.0.10^2~27 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/index.cgi?a=commitdiff_plain;h=0289479579383781bddada0fabb390f29c16fc8f;p=WP-Plugins%2Fglm-member-db-billing.git Setup city select and add new city for billing. This is for the contact edit page. Will add the new city if it is not in the database already. --- diff --git a/classes/billingSupport.php b/classes/billingSupport.php index a0fb635..6321361 100644 --- a/classes/billingSupport.php +++ b/classes/billingSupport.php @@ -1647,6 +1647,24 @@ class GlmBillingSupport '%s', // zip ); } else if ( $use_billing ) { + // Check to make sure the billing city is added to the city table + $city_name = filter_var( $_REQUEST['billing_city'] ); + $city_id = $this->wpdb->get_var( + $this->wpdb->prepare( + "SELECT id + FROM " . GLM_MEMBERS_PLUGIN_DB_PREFIX . "cities + WHERE name = %s", + $city_name + ) + ); + if ( !$city_id ) { + // Add new city + $this->wpdb->insert( + GLM_MEMBERS_PLUGIN_DB_PREFIX . 'cities', + array( 'name' => $city_name ), + array( '%s' ) + ); + } $billing_updated = array( 'email' => filter_var( $_REQUEST['billing_email'] ), 'billing_company' => filter_var( $_REQUEST['billing_company'] ), diff --git a/views/admin/billing/contact.html b/views/admin/billing/contact.html index 3ea9058..466890d 100644 --- a/views/admin/billing/contact.html +++ b/views/admin/billing/contact.html @@ -65,13 +65,33 @@ Billing City - {foreach $cities as $city} {/foreach} + +
Add a new City
+
+ + + + + +
City Name + +
+
+

* Required

+ Cancel + +
+ + + {if $account.fieldFail.billing_city}

{$account.fieldFail.billing_city}

{/if}
+ @@ -249,7 +269,8 @@ jQuery(document).ready(function($){ $('input[name=billing_country]').prop('disabled', true); $('input[name=billing_phone]').prop('disabled', true); $('input[name=billing_fax]').prop('disabled', true); - console.log( 'billing form disabled' ); + // Disable click event for add city + $('#newBillingCityButton').off('click'); } // Enable the billing form function enableBillingForm() @@ -267,6 +288,100 @@ jQuery(document).ready(function($){ $('input[name=billing_country]').prop('disabled', false); $('input[name=billing_phone]').prop('disabled', false); $('input[name=billing_fax]').prop('disabled', false); + // Add a new city button action - pop-up dialog + $('#newBillingCityButton').click( function() { + $("#newBillingCityDialog").dialog("open"); + }); + } + + + /* + * New Billing City Dialog + */ + + // Setup dialog box for adding a new city + $("#newBillingCityDialog").dialog({ + autoOpen: false, + minWidth: 400, + dialogClass: "glm-dialog-no-close" + }); + $('#newBillingCityCancel').click( function() { + // Clear new city name from form + $('#newBillingCityName').val(''); + $('#newBillingCityNameTD').removeClass('glm-form-bad-input'); + $('#newBillingCityNameRequired').text(''); + + $("#newBillingCityDialog").dialog("close"); + }); + + // Submit new city + var newBillingCityAdded = false; + $('#newBillingCitySubmit').click( function() { + + // Get new city name + var newBillingCityName = $('#newBillingCityName').val(); + newBillingCityName = newBillingCityName.replace(/"/g, ''); + + // If no name is supplied, notify used it's required + if (newBillingCityName == '') { + $('#newBillingCityNameTD').addClass('glm-form-bad-input'); + $('#newBillingCityNameRequired').text('A city name is required!'); + return false; + } + + // If the city name is already in the list then don't add it! + var nameFoundInBillingCity = false; + $('#billingCity option').each(function(){ + console.log( 'newBillingCityName', newBillingCityName ); + console.log( 'this.value', this.value ); + console.log( 'matches: ', newBillingCityName == this.value ); + if ( newBillingCityName == this.value ) { + // found the city in list already + // Set the select to that value + $('#billingCity').val(newBillingCityName); + + // Reset add city form and close + $('#newBillingCityName').val(''); + $('#newBillingCityNameTD').addClass('glm-form-bad-input'); + $('#newBillingCityNameRequired').text('Already added'); + nameFoundInBillingCity = true; + return false; + } + }); + + if ( nameFoundInBillingCity ) { + return false; + } + + + // Add new city name to the hidden field that will pass the new name to PHP. + $('#billingCityName').val(newBillingCityName); + + // Add new city name to picklist and for storing - Only one permitted per submission + if (newBillingCityAdded) { + + // New city already added, so just update the name and select that one + $('#billingCity option[value=' + newBillingCityAdded + ']').val(newBillingCityName); + $('#billingCity option:selected').text(newBillingCityName); + + } else { + + // Add the new city name to the city picklist + $('#billingCity').append(''); + $('#billingCity').val(newBillingCityName); + $('#newBillingCityNameTD').append(''); + newBillingCityAdded = newBillingCityName; + + } + + // Clear new city name from form + $('#newBillingCityName').val(''); + $('#newBillingCityNameTD').removeClass('glm-form-bad-input'); + $('#newBillingCityNameRequired').text(''); + + $('#newBillingCityDialog').dialog('close'); + + }); });