<div class="glm-row">
<div class="glm-columns glm-small-12 glm-large-3 glm-required">
- Member Account
+ Billing Account
</div>
<div class="glm-columns glm-small-12 glm-large-9">
<select id="member-account" name="account" required>
<option value="{$account.id}" data-anniversary="{$account.next_anniversary_date}">{$account.ref_name}</option>
{/foreach}
</select>
+ <a id="newAccountButton" href="#">New Account</a>
</div>
</div>
<div class="glm-row">
Due Date
</div>
<div class="glm-columns glm-small-12 glm-large-9">
- <input id="invoice_due_date" type="text" name="due_date" required>
+ <input class="datepicker" id="invoice_due_date" type="text" name="due_date" required>
</div>
</div>
<div class="glm-row">
</div>
</form>
</div>
+<div id="newAccountDialog" class="glm-dialog-box" title="New Account">
+ <p class="validateAccountTips">* required.</p>
+ <form id="addAccountForm">
+ <input type="hidden" name="glm_action" value="invoices">
+ <input type="hidden" name="option" value="addAccount">
+ <table>
+ <tr>
+ <th class="glm-required">Member</th>
+ <td>
+ <select name="ref_dest" style="width: 300px;">
+ <option value="">Select Member</option>
+ {foreach $nonAccountMembers as $m}
+ <option value="{$m.id}">{$m.name}</option>
+ {/foreach}
+ </select>
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Anniversary Date</th>
+ <td>
+ <input class="datepicker" type="text" name="anniversary_date" value="">
+ </td>
+ </tr>
+ <tr>
+ <th>Renewal Date</th>
+ <td>
+ <input class="datepicker" type="text" name="renewal_date" value="">
+ </td>
+ </tr>
+ <tr>
+ <th class="glm-required">Billing Email</th>
+ <td>
+ <input type="text" name="email" value="">
+ </td>
+ </tr>
+ <tr>
+ <th>Billing Address 1</th>
+ <td>
+ <input type="text" name="billing_addr1" value="">
+ </td>
+ </tr>
+ <tr>
+ <th>Billing Address 2</th>
+ <td>
+ <input type="text" name="billing_addr2" value="">
+ </td>
+ </tr>
+ <tr>
+ <th>Billing City</th>
+ <td>
+ <input type="text" name="billing_city" value="">
+ </td>
+ </tr>
+ <tr>
+ <th>Billing State</th>
+ <td>
+ <input type="text" name="billing_state" value="">
+ </td>
+ </tr>
+ <tr>
+ <th>Billing Zip</th>
+ <td>
+ <input type="text" name="billing_zip" value="">
+ </td>
+ </tr>
+ <tr>
+ <th>Billing Phone</th>
+ <td>
+ <input type="text" name="billing_phone" value="">
+ </td>
+ </tr>
+ </table>
+ </form>
+</div>
<div id="newLineItemDialog" class="glm-dialog-box" title="Enter a Line Item">
+ <p class="validateTips">* Required!</p>
<form id="addLineItemForm">
<input type="hidden" name="glm_action" value="invoices">
<input type="hidden" name="option" value="addLineItem">
jQuery(document).ready(function($){
// Initialize variables for this page.
var dialog, // Dialog for the add line_item form
+ newAccountDialog, // Dialog for the add new account
form, // The add line_item form
- line_item_type = $( 'select[name="line_item_type"]' ), // Line item type in the add line_item form
- line_items = [], // Array holding line_items json objects
- allFields = $( [] ).add( line_item_type ), // Array holding the form fields - add line_item form
- invoiceTypeJSON = $.parseJSON( '{$invoiceTypeJSON}' ); // Json object with all of the invoices types
+ newAccountForm, // New Account Form
+ line_item_type = $( 'select[name="line_item_type"]' ), // Line item type in the add line_item form
+ line_items = [], // Array holding line_items json objects
+ allFields = $( [] ).add( line_item_type ), // Array holding the form fields - add line_item form
+ ref_dest = $( 'select[name="ref_dest"' ),
+ anniversary_date = $( 'input[name="anniversary_date"' ),
+ renewal_date = $( 'input[name="renewal_date"' ),
+ email = $( 'input[name="email"' ),
+ billing_addr1 = $( 'input[name="billing_addr1"' ),
+ billing_addr2 = $( 'input[name="billing_addr2"' ),
+ billing_city = $( 'input[name="billing_city"' ),
+ billing_state = $( 'input[name="billing_state"' ),
+ billing_zip = $( 'input[name="billing_zip"' ),
+ billing_phone = $( 'input[name="billing_phone"' ),
+ lineTips = $('.validateTips'),
+ accountTips = $('.validateAccountTips'),
+ allAccountFields = $( [] ).add( ref_dest ) .add( anniversary_date ) .add( renewal_date )
+ .add( email ) .add( billing_addr1 ) .add( billing_addr2 ) .add( billing_city )
+ .add( billing_state ) .add( billing_zip )
+ .add( billing_phone ) , // Array holding the form fields - add line_item form
+ invoiceTypeJSON = $.parseJSON( '{$invoiceTypeJSON}' ); // Json object with all of the invoices types
/**
* totalInvoice
var valid = true;
allFields.removeClass( 'ui-state-error' );
- valid = valid && checkRequired( line_item_type );
+ valid = valid && checkRequired( line_item_type, lineTips, 'Invoice Type is required!' );
if ( valid ) {
var selectedLineItem = invoiceTypeJSON[line_item_type.val()];
return valid;
}
+ /**
+ * addNewAccount
+ *
+ * Callback function to add a new account.
+ */
+ function addNewAccount(){
+ var valid = true;
+ allAccountFields.removeClass( 'ui-state-error' );
+
+ valid = valid && checkRequired( ref_dest, accountTips, 'Member is required!' );
+ valid = valid && checkRequired( anniversary_date, accountTips, 'Anniversary Date is required!' );
+ valid = valid && checkRequired( email, accountTips, 'Email is required!' );
+
+ if ( valid ) {
+
+ } else {
+ }
+
+ return valid;
+ }
+
/**
* checkRequired
*
* @access public
* @return void
*/
- function checkRequired( fieldName ) {
+ function checkRequired( fieldName, tips, message ) {
if ( fieldName.val() ) {
return true;
} else {
+ fieldName.addClass( 'ui-state-error' );
+ updateTips( tips, message );
return false;
}
}
+
+ function updateTips( tips, t ) {
+ tips
+ .text( t )
+ .addClass( 'ui-state-highlight' );
+ setTimeout(function(){
+ tips.removeClass( 'ui-state-highlight', 1500 );
+ }, 500);
+ }
+
/**
* dialog
*
},
},
close: function() {
- form[0 ].reset();
+ form[0].reset();
allFields.removeClass( 'ui-state-error' );
+ updateTips( lineTips, '* required!' );
},
});
return false;
});
+ /**
+ * dialog for the New Account Form
+ */
+ newAccountDialog = $('#newAccountDialog').dialog({
+ autoOpen: false,
+ minWidth: 500,
+ dialogClass: 'glm-dialog-no-close',
+ modal: true,
+ buttons: {
+ "Add New Account": addNewAccount,
+ Cancel: function(){
+ newAccountDialog.dialog( 'close' );
+ },
+ },
+ close: function() {
+ newAccountForm[0].reset();
+ allAccountFields.removeClass( 'ui-state-error' );
+ updateTips( accountTips, '* required!' );
+ },
+ });
+
+ /**
+ * Add Account Form
+ *
+ * form with id of #addAccountForm
+ */
+ newAccountForm = newAccountDialog.find( '#addAccountForm' ).on( 'submit', function(){
+ event.preventDefault();
+ console.log('Adding new Account');
+ });
+
+ /**
+ * Click event for the id of #newLineItemButton.
+ *
+ * Activates the dialog for adding line items.
+ */
+ $('#newAccountButton').click( function() {
+ $("#newAccountDialog").dialog("open");
+ return false;
+ });
+
/**
* Onchange event for the qty fields.
* So the line_items array gets updated with the qty number.
});
// Setup the date picker for the input field with the name due_date
- $('input[name="due_date"]').datepicker();
+ $('.datepicker').datepicker();
/**
* Change event listener for member account select.