Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
issue #104 - generate and fill logic for payoffs settings form
- Loading branch information
Showing
3 changed files
with
181 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
The latest version of this package is available at: | ||
<http://github.com/jantman/biweeklybudget> | ||
################################################################################ | ||
Copyright 2016 Jason Antman <jason@jasonantman.com> <http://www.jasonantman.com> | ||
This file is part of biweeklybudget, also known as biweeklybudget. | ||
biweeklybudget is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU Affero General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
biweeklybudget is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU Affero General Public License for more details. | ||
You should have received a copy of the GNU Affero General Public License | ||
along with biweeklybudget. If not, see <http://www.gnu.org/licenses/>. | ||
The Copyright and Authors attributions contained herein may not be removed or | ||
otherwise altered, except to add the Author attribution of a contributor to | ||
this work. (Additional Terms pursuant to Section 7b of the AGPL v3) | ||
################################################################################ | ||
While not legally required, I sincerely request that anyone who finds | ||
bugs please submit them at <https://github.com/jantman/biweeklybudget> or | ||
to me via email, and that you send any contributions or improvements | ||
either as a pull request on GitHub, or to me via email. | ||
################################################################################ | ||
AUTHORS: | ||
Jason Antman <jason@jasonantman.com> <http://www.jasonantman.com> | ||
################################################################################ | ||
*/ | ||
|
||
/** | ||
* Link handler to add another "starting on, increase payments by" form to | ||
* the credit payoff page. | ||
*/ | ||
function addIncrease(settings) { | ||
idx = nextIndex("payoff_increase_frm_"); | ||
var s = '<form id="payoff_increase_frm_' + idx + '" class="form-inline">'; | ||
s = s + '<div class="form-group">'; | ||
s = s + '<label for="payoff_increase_frm_' + idx + '_enable" class="control-label sr-only">Enable Payment Increase ' + idx + '</label>'; | ||
s = s + '<input type="checkbox" id="payoff_increase_frm_' + idx + '_enable" name="payoff_increase_frm_' + idx + '_enable" onchange="setChanged()">'; | ||
s = s + ' Starting on '; | ||
s = s + '<label for="payoff_increase_frm_' + idx + '_date" class="control-label sr-only">Payment Increase ' + idx + ' Date</label>'; | ||
s = s + '<div class="input-group date" id="payoff_increase_frm_' + idx + '_date_input_group">'; | ||
s = s + '<span class="input-group-addon"><i class="fa fa-calendar fa-fw"></i></span><input class="form-control" id="payoff_increase_frm_' + idx + '_date" name="payoff_increase_frm_' + idx + '_date" type="text" size="12" maxlength="10" style="width: auto;" onchange="setChanged()">'; | ||
s = s + '</div>'; | ||
s = s + ' , increase sum of monthly payments by '; | ||
s = s + '<label for="payoff_increase_frm_' + idx + '_amt" class="control-label sr-only">Payment Increase ' + idx + ' Amount</label>'; | ||
s = s + '<div class="input-group">'; | ||
s = s + '<span class="input-group-addon">$</span><input class="form-control" id="payoff_increase_frm_' + idx + '_amt" name="payoff_increase_frm_' + idx + '_amt" type="text" size="8" style="width: auto;" onchange="setChanged()">'; | ||
s = s + '</div> .</div></form>'; | ||
s = s + '<!-- /#payoff_increase_frm_' + idx + ' -->'; | ||
$('#payoff_increase_forms').append(s); | ||
if ( settings !== undefined ) { | ||
$('#payoff_increase_frm_' + idx + '_enable').prop('checked', settings['enabled']); | ||
$('#payoff_increase_frm_' + idx + '_date').val(settings['date']['str']); | ||
$('#payoff_increase_frm_' + idx + '_date').datepicker({ | ||
todayBtn: "linked", | ||
autoclose: true, | ||
todayHighlight: true, | ||
format: 'yyyy-mm-dd' | ||
}); | ||
$('#payoff_increase_frm_' + idx + '_amt').val(settings['amount']); | ||
} | ||
} | ||
|
||
/** | ||
* Return the next index for the form with an ID beginning with a given string. | ||
* | ||
* @param {string} prefix - The prefix of the form IDs. | ||
* @return {int} next form index | ||
*/ | ||
function nextIndex(prefix) { | ||
return $('form[id^="' + prefix + '"]').length + 1; | ||
} | ||
|
||
/** | ||
* Link handler to add another one time payment form to the credit payoff page. | ||
*/ | ||
function addOnetime(settings) { | ||
idx = nextIndex("payoff_onetime_frm_"); | ||
var s = '<form id="payoff_onetime_frm_' + idx + '" class="form-inline">'; | ||
s = s + '<div class="form-group">'; | ||
s = s + '<label for="payoff_onetime_frm_' + idx + '_enable" class="control-label sr-only">Enable Onetime Payment ' + idx + '</label>'; | ||
s = s + '<input type="checkbox" id="payoff_onetime_frm_' + idx + '_enable" name="payoff_onetime_frm_' + idx + '_enable" onchange="setChanged()">'; | ||
s = s + ' On the first payment date on or after '; | ||
s = s + '<label for="payoff_onetime_frm_' + idx + '_date" class="control-label sr-only">Onetime Payment ' + idx + ' Date</label>'; | ||
s = s + '<div class="input-group date" id="payoff_onetime_frm_' + idx + '_date_input_group">'; | ||
s = s + '<span class="input-group-addon"><i class="fa fa-calendar fa-fw"></i></span><input class="form-control" id="payoff_onetime_frm_' + idx + '_date" name="payoff_onetime_frm_' + idx + '_date" type="text" size="12" maxlength="10" style="width: auto;" onchange="setChanged()">'; | ||
s = s + '</div>'; | ||
s = s + ' , add '; | ||
s = s + '<label for="payoff_onetime_frm_' + idx + '_amt" class="control-label sr-only">Onetime Payment ' + idx + ' Amount</label>'; | ||
s = s + '<div class="input-group">'; | ||
s = s + '<span class="input-group-addon">$</span><input class="form-control" id="payoff_onetime_frm_' + idx + '_amt" name="payoff_onetime_frm_' + idx + '_amt" type="text" size="8" style="width: auto;" onchange="setChanged()">'; | ||
s = s + '</div> to the payment amount.</div></form>'; | ||
s = s + '<!-- /#payoff_onetime_frm_' + idx + ' -->'; | ||
$('#payoff_onetime_forms').append(s); | ||
if ( settings !== undefined ) { | ||
$('#payoff_onetime_frm_' + idx + '_enable').prop('checked', settings['enabled']); | ||
$('#payoff_onetime_frm_' + idx + '_date').val(settings['date']['str']); | ||
$('#payoff_onetime_frm_' + idx + '_date').datepicker({ | ||
todayBtn: "linked", | ||
autoclose: true, | ||
todayHighlight: true, | ||
format: 'yyyy-mm-dd' | ||
}); | ||
$('#payoff_onetime_frm_' + idx + '_amt').val(settings['amount']); | ||
} | ||
} | ||
|
||
/** | ||
* Buttom handler to serialize and submit the forms, to save user input and | ||
* recalculate the payoff amounts. | ||
*/ | ||
function recalcPayoffs() { | ||
console.log("recalcPayoffs() called"); | ||
} | ||
|
||
/** | ||
* Event handler to activate the "Save & Recalculate" button when user input | ||
* fields have changed. | ||
*/ | ||
function setChanged() { | ||
$('#btn_recalc_payoffs').removeClass('disabled btn-default').addClass('btn-primary'); | ||
} | ||
|
||
/** | ||
* Load settings from embedded JSON. Called on page load. | ||
*/ | ||
function loadSettings() { | ||
var settings = JSON.parse($('#pymt_settings_json').html()); | ||
for (var s in settings["increases"]) { addIncrease(settings["increases"][s]); } | ||
if ( settings["increases"].length == 0 ) { addIncrease(); } | ||
for (var s in settings["onetimes"]) { addOnetime(settings["onetimes"][s]); } | ||
if ( settings["onetimes"].length == 0 ) { addOnetime(); } | ||
} | ||
|
||
$(document).ready(function() { | ||
loadSettings(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters