Billing Account
</div>
<div class="glm-columns glm-small-12 glm-large-9">
- <input type="hidden" name="account" />
- <select id="member-account" name="account" required>
- <option value="">Select an Account</option>
- {foreach $accounts as $account}
- {if $account.id}
- <option value="{$account.id}">{$account.ref_name}</option>
- {/if}
- {/foreach}
- </select>
+ <input id="glm_member_accounts_hidden" type="hidden" name="account" />
+ <input id="glm_member_accounts" name="account_input" required />
<a id="newAccountButton" href="#">New Account</a>
</div>
</div>
<script>
jQuery(document).ready(function($){
+
// List of Billing Accounts.
var availableAccounts = [
{foreach $accounts as $m}
{ label: "{$m.name|unescape:'html'|replace:'"':''}", value: "{$m.name|unescape:'html'|replace:'"':''}", id: '{$m.id}' },
{/foreach}
];
- $('#member_account_name').autocomplete({
- source: availableAccounts
+ // Setup autocomplete for the member account input.
+ $('#glm_member_accounts').autocomplete({
+ source: availableAccounts,
+ select: function( event, ui ){
+ $('#glm_member_accounts_hidden').val( ui.item.id );
+ },
+ change: function( event, ui ) {
+ // If not in select option then empty the field
+ $(this).val((ui.item ? ui.item.label : ""));
+ },
});
+ // Setup autocomplete for the non member input.
+ // This is on the add new account form.
$('#glm_member_name').autocomplete({
source: availableNonAccountMembers,
appendTo: '#newAccountDialog',
select: function( event, ui ){
$('#non-member-account').val( ui.item.id );
},
+ change: function( event, ui ) {
+ // If not in select option then empty the field
+ $(this).val((ui.item ? ui.item.label : ""));
+ },
});
// Initialize variables for this page.
var dialog, // Dialog for the add line_item form
}).done(function( msg ){
if ( msg.status === true ) {
// Reload the account select
- updateBillingAccountSelect( msg.account.fieldData.id );
+ updateBillingAccountList( msg.account.fieldData.id );
updateNonAccountMemberList();
// Close the dialog
newAccountDialog.dialog( 'close' );
* Ajax call to get the list of billing accounts and update the select
* for the Billing account drop down.
*/
- function updateBillingAccountSelect(selected_id = null) {
+ // function updateBillingAccountSelect(selected_id = null) {
+ // $.ajax({
+ // url: '{$ajaxUrl}',
+ // cache: false,
+ // type: 'GET',
+ // data: 'action=glm_members_admin_ajax&glm_action=account&option=list',
+ // encode: true,
+ // dataType: 'json'
+ // }).done(function(msg){
+ // // console.log( msg.length );
+ // var memberAccount = document.getElementById('member-account');
+ // memberAccount.options.length = 0;
+ // memberAccount.options[memberAccount.options.length] = new Option( 'Select an Account', '' );
+ // for ( index in msg ) {
+ // var obj = msg[index];
+ // memberAccount.options[memberAccount.options.length] = new Option( obj.ref_name, obj.id );
+ // }
+ // memberAccount.value = selected_id;
+ // });
+ // }
+
+ /**
+ * Ajax call to get the list of members with accounts.
+ * Updating the account list used for the autocomplete.
+ */
+ function updateBillingAccountList( selected_id = null )
+ {
+
$.ajax({
url: '{$ajaxUrl}',
cache: false,
encode: true,
dataType: 'json'
}).done(function(msg){
- // console.log( msg.length );
- var memberAccount = document.getElementById('member-account');
- memberAccount.options.length = 0;
- memberAccount.options[memberAccount.options.length] = new Option( 'Select an Account', '' );
+ availableAccountMembers = [];
for ( index in msg ) {
var obj = msg[index];
- memberAccount.options[memberAccount.options.length] = new Option( obj.ref_name, obj.id );
+ availableAccountMembers.push( { label: obj.name, value: obj.name, id: obj.id } );
}
- memberAccount.value = selected_id;
+ // also need to update the source for the autocomplete
+ $('#glm_member_accounts').autocomplete(
+ 'option',
+ { source: availableAccountMembers }
+ );
});
}
/**
* Change event listener for member account select.
+ * When the member account is selected it should set the
+ * invoice due_date to the current year based on the anniversary date.
+ * Todo: Update this for the changes for adding in the autocomplete.
*/
$('#member-account').change(function(){
$('#invoice_due_date').val( $(this).find('option:selected').data('anniversary') );