Skip to content

Commit 29070e3

Browse files
committed
working secured calculator
1 parent 491f502 commit 29070e3

25 files changed

+462
-408
lines changed

app/assets/javascripts/currency.js

+217
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
/*
2+
* jQuery Currency v0.5
3+
* Simple, unobtrusive currency converting and formatting
4+
* http://dev7studios.com/demo/jquery-currency/
5+
*
6+
* Copyright 2011, Gilbert Pellegrom
7+
* Free to use and abuse under the MIT license.
8+
* http://www.opensource.org/licenses/mit-license.php
9+
*
10+
* http://dev7studios.com
11+
*/
12+
13+
(function($) {
14+
15+
$.fn.currency = function(method) {
16+
17+
var methods = {
18+
19+
init : function(options) {
20+
var settings = $.extend({}, this.currency.defaults, options);
21+
return this.each(function() {
22+
var $element = $(this),
23+
element = this;
24+
var value = 0;
25+
26+
if($element.is(':input')){
27+
value = $element.val();
28+
} else {
29+
value = $element.text();
30+
}
31+
32+
if(helpers.isNumber(value)){
33+
34+
if(settings.convertFrom != ''){
35+
if($element.is(':input')){
36+
$element.val(value +' '+ settings.convertLoading);
37+
} else {
38+
$element.html(value +' '+ settings.convertLoading);
39+
}
40+
$.post(settings.convertLocation, { amount: value, from: settings.convertFrom, to: settings.region }, function(data){
41+
value = data;
42+
if($element.is(':input')){
43+
$element.val(helpers.format_currency(value, settings));
44+
} else {
45+
$element.html(helpers.format_currency(value, settings));
46+
}
47+
});
48+
} else {
49+
if($element.is(':input')){
50+
$element.val(helpers.format_currency(value, settings));
51+
} else {
52+
$element.html(helpers.format_currency(value, settings));
53+
}
54+
}
55+
56+
}
57+
58+
});
59+
60+
},
61+
62+
}
63+
64+
var helpers = {
65+
66+
format_currency: function(amount, settings) {
67+
var bc = settings.region;
68+
var currency_before = '';
69+
var currency_after = '';
70+
71+
if(bc == 'ALL') currency_before = 'Lek';
72+
if(bc == 'ARS') currency_before = '$';
73+
if(bc == 'AWG') currency_before = 'f';
74+
if(bc == 'AUD') currency_before = '$';
75+
if(bc == 'BSD') currency_before = '$';
76+
if(bc == 'BBD') currency_before = '$';
77+
if(bc == 'BYR') currency_before = 'p.';
78+
if(bc == 'BZD') currency_before = 'BZ$';
79+
if(bc == 'BMD') currency_before = '$';
80+
if(bc == 'BOB') currency_before = '$b';
81+
if(bc == 'BAM') currency_before = 'KM';
82+
if(bc == 'BWP') currency_before = 'P';
83+
if(bc == 'BRL') currency_before = 'R$';
84+
if(bc == 'BND') currency_before = '$';
85+
if(bc == 'CAD') currency_before = '$';
86+
if(bc == 'KYD') currency_before = '$';
87+
if(bc == 'CLP') currency_before = '$';
88+
if(bc == 'CNY') currency_before = '¥';
89+
if(bc == 'COP') currency_before = '$';
90+
if(bc == 'CRC') currency_before = 'c';
91+
if(bc == 'HRK') currency_before = 'kn';
92+
if(bc == 'CZK') currency_before = 'Kc';
93+
if(bc == 'DKK') currency_before = 'kr';
94+
if(bc == 'DOP') currency_before = 'RD$';
95+
if(bc == 'XCD') currency_before = '$';
96+
if(bc == 'EGP') currency_before = '£';
97+
if(bc == 'SVC') currency_before = '$';
98+
if(bc == 'EEK') currency_before = 'kr';
99+
if(bc == 'EUR') currency_before = '€';
100+
if(bc == 'FKP') currency_before = '£';
101+
if(bc == 'FJD') currency_before = '$';
102+
if(bc == 'GBP') currency_before = '£';
103+
if(bc == 'GHC') currency_before = 'c';
104+
if(bc == 'GIP') currency_before = '£';
105+
if(bc == 'GTQ') currency_before = 'Q';
106+
if(bc == 'GGP') currency_before = '£';
107+
if(bc == 'GYD') currency_before = '$';
108+
if(bc == 'HNL') currency_before = 'L';
109+
if(bc == 'HKD') currency_before = '$';
110+
if(bc == 'HUF') currency_before = 'Ft';
111+
if(bc == 'ISK') currency_before = 'kr';
112+
if(bc == 'IDR') currency_before = 'Rp';
113+
if(bc == 'IMP') currency_before = '£';
114+
if(bc == 'JMD') currency_before = 'J$';
115+
if(bc == 'JPY') currency_before = '¥';
116+
if(bc == 'JEP') currency_before = '£';
117+
if(bc == 'LVL') currency_before = 'Ls';
118+
if(bc == 'LBP') currency_before = '£';
119+
if(bc == 'LRD') currency_before = '$';
120+
if(bc == 'LTL') currency_before = 'Lt';
121+
if(bc == 'MYR') currency_before = 'RM';
122+
if(bc == 'MXN') currency_before = '$';
123+
if(bc == 'MZN') currency_before = 'MT';
124+
if(bc == 'NAD') currency_before = '$';
125+
if(bc == 'ANG') currency_before = 'f';
126+
if(bc == 'NZD') currency_before = '$';
127+
if(bc == 'NIO') currency_before = 'C$';
128+
if(bc == 'NOK') currency_before = 'kr';
129+
if(bc == 'PAB') currency_before = 'B/.';
130+
if(bc == 'PYG') currency_before = 'Gs';
131+
if(bc == 'PEN') currency_before = 'S/.';
132+
if(bc == 'PLN') currency_before = 'zl';
133+
if(bc == 'RON') currency_before = 'lei';
134+
if(bc == 'SHP') currency_before = '£';
135+
if(bc == 'SGD') currency_before = '$';
136+
if(bc == 'SBD') currency_before = '$';
137+
if(bc == 'SOS') currency_before = 'S';
138+
if(bc == 'ZAR') currency_before = 'R';
139+
if(bc == 'SEK') currency_before = 'kr';
140+
if(bc == 'CHF') currency_before = 'CHF';
141+
if(bc == 'SRD') currency_before = '$';
142+
if(bc == 'SYP') currency_before = '£';
143+
if(bc == 'TWD') currency_before = 'NT$';
144+
if(bc == 'TTD') currency_before = 'TT$';
145+
if(bc == 'TRY') currency_before = 'TL';
146+
if(bc == 'TRL') currency_before = '£';
147+
if(bc == 'TVD') currency_before = '$';
148+
if(bc == 'GBP') currency_before = '£';
149+
if(bc == 'USD') currency_before = '$';
150+
if(bc == 'UYU') currency_before = '$U';
151+
if(bc == 'VEF') currency_before = 'Bs';
152+
if(bc == 'ZWD') currency_before = 'Z$';
153+
154+
if( currency_before == '' && currency_after == '' ) currency_before = '$';
155+
156+
var output = '';
157+
if(!settings.hidePrefix) output += currency_before;
158+
output += helpers.number_format( amount, settings.decimals, settings.decimal, settings.thousands );
159+
if(!settings.hidePostfix) output += currency_after;
160+
return output;
161+
},
162+
163+
// Kindly borrowed from http://phpjs.org/functions/number_format
164+
number_format: function(number, decimals, dec_point, thousands_sep) {
165+
number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
166+
var n = !isFinite(+number) ? 0 : +number,
167+
prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
168+
sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
169+
dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
170+
s = '',
171+
toFixedFix = function (n, prec) {
172+
var k = Math.pow(10, prec);
173+
return '' + Math.round(n * k) / k;
174+
};
175+
// Fix for IE parseFloat(0.55).toFixed(0) = 0;
176+
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
177+
if (s[0].length > 3) {
178+
s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
179+
}
180+
if ((s[1] || '').length < prec) {
181+
s[1] = s[1] || '';
182+
s[1] += new Array(prec - s[1].length + 1).join('0');
183+
}
184+
return s.join(dec);
185+
},
186+
187+
isNumber: function(n) {
188+
return !isNaN(parseFloat(n)) && isFinite(n);
189+
}
190+
191+
}
192+
193+
if (methods[method]) {
194+
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
195+
} else if (typeof method === 'object' || !method) {
196+
return methods.init.apply(this, arguments);
197+
} else {
198+
$.error( 'Method "' + method + '" does not exist in currency plugin!');
199+
}
200+
201+
}
202+
203+
$.fn.currency.defaults = {
204+
region: 'USD', // The 3 digit ISO code you want to display your currency in
205+
thousands: ',', // Thousands separator
206+
decimal: '.', // Decimal separator
207+
decimals: 2, // How many decimals to show
208+
hidePrefix: false, // Hide any prefix
209+
hidePostfix: false, // Hide any postfix
210+
convertFrom: '', // If converting, the 3 digit ISO code you want to convert from,
211+
convertLoading: '(Converting...)', // Loading message appended to values while converting
212+
convertLocation: 'convert.php' // Location of convert.php file
213+
}
214+
215+
$.fn.currency.settings = {}
216+
217+
})(jQuery);

app/assets/javascripts/homes.js.coffee

-3
This file was deleted.

app/assets/javascripts/infos.js.coffee

-3
This file was deleted.

app/assets/javascripts/lenders.js.coffee

-3
This file was deleted.

app/assets/javascripts/partners.js.coffee

-3
This file was deleted.

app/assets/javascripts/public.js

+45-52
Original file line numberDiff line numberDiff line change
@@ -212,79 +212,82 @@ startchrome:function(){
212212

213213
}
214214

215-
216215
// sort secured card table //
217-
var sortcell = 1 //td element to sort by in secured card table
216+
var sortcell = 0 //td element to sort by in secured card table, first cell is 0
218217

219218
$(document).ready(function()
220219
{
221220
$("#securedCardTable").tablesorter({
222-
sortList: [[sortcell,1]]
221+
sortList: [[sortcell,0]]
223222
});
224223
}
225224
);
226225

227226
// ***************** sliders for secured card ************//
227+
228+
229+
228230
$(document).ready(function () {
229231
var purBal = parseFloat($("#purBal").html());
230232
var cashBal = parseFloat($("#cashBal").html());
231233
var duration = parseFloat($("#duration").html());
232-
var durationYears = parseFloat($("#durationYears").html());
233-
var yearsPercent = parseFloat($("#yearsPercent").html());
234234
var cards = parseFloat($("#securedCards").html());
235235

236-
/* console.log('purBal is', purBal, 'and is of type ', typeof(purBal));
237-
console.log('cashBal is', cashBal, 'and is of type ', typeof(cashBal));
238-
console.log('duration is', duration, 'and is of type ', typeof(duration));
239-
console.log('cards is', cards, 'and is of type ', typeof(cards));
240-
console.log('yearsPercent is', yearsPercent, 'and is of type ', typeof(yearsPercent));
241-
console.log('durationYears is', durationYears, 'and is of type ', typeof(durationYears));
242-
*/
236+
// console.log('purBal is', purBal, 'and is of type ', typeof(purBal));
237+
// console.log('cashBal is', cashBal, 'and is of type ', typeof(cashBal));
238+
// console.log('duration is', duration, 'and is of type ', typeof(duration));
239+
// console.log('cards is', cards, 'and is of type ', typeof(cards));
240+
241+
function update (){
242+
for ( var i = 0 ; i<cards ; i++){
243+
var annualFee = parseFloat($('#annualFee'+i+'').html());
244+
var monthlyFee = parseFloat($('#monthlyFee'+i+'').html());
245+
var purAPR = parseFloat($('#purAPR'+i+'').html());
246+
var cashAPR = parseFloat($('#cashAPR'+i+'').html());
247+
var totalFee = duration * monthlyFee + Math.ceil(duration/12) * annualFee;
248+
var totalInt = ((duration/12)*365)*(purBal * purAPR/100/365 + cashBal * cashAPR/100/365);
249+
// console.log('annualFee is', annualFee, 'and is of type ', typeof(annualFee));
250+
// console.log('monthlyFee is', monthlyFee, 'and is of type ', typeof(monthlFee));
251+
// console.log('purAPR is', purAPR, 'and is of type ', typeof(purAPR));
252+
// console.log('cashAPR is', cashAPR, 'and is of type ', typeof(cashAPR));
253+
// console.log('totalFee is', totalFee, 'and is of type ', typeof(totalFee));
254+
// console.log('totalInt is', totalInt, 'and is of type ', typeof(totalInt));
255+
$('#cardCost'+i+'').html("$" + (totalInt+totalFee).toFixed(0));
256+
};
257+
}
258+
259+
243260
$("#sliderPurBal").slider({
244261
value: 300,
245262
min: 0,
246-
max: 5000,
263+
max: 3000,
247264
step: 100,
248-
slide: function (event, ui) {
249-
$("#calcPurBal").html(ui.value);
250-
purBal = ui.value;
251-
for ( var i = 0 ; i<cards ; i++){
252-
annualFee = parseFloat($('#annFee'+i+'').html());
253-
monthlyFee = parseFloat($('#mthFee'+i+'').html());
254-
purAPR = parseFloat($('#purAPR'+i+'').html());
255-
cashAPR = parseFloat($('#cashAPR'+i+'').html());
256-
var totalFee = duration * monthlyFee + durationYears * annualFee;
257-
var totalInt = yearsPercent * (purBal * purAPR + cashBal + cashAPR);
258-
$('#cardCost'+i+'').html("$" + Math.round(totalInt+totalFee));
259-
};
265+
slide: function (event, ui){
266+
$("#calcPurBal").html(ui.value).currency({decimals:0});
267+
purBal = ui.value;
268+
update(event, ui);
260269
},
261270
stop: function (event, ui) {$("#securedCardTable").tablesorter({
262-
sortList: [[sortcell,1]]
271+
sortList: [[sortcell,0]]
263272
});
264273
}
265274
});
266275

267276
$("#sliderCashBal").slider({
268277
value: 300,
269278
min: 0,
270-
max: 5000,
279+
max: 3000,
271280
step: 100,
272281
slide: function (event, ui) {
273-
$("#calcCashBal").html(ui.value);
282+
$("#calcCashBal").html(ui.value).currency({decimals:0});
274283
cashBal = ui.value;
275-
for ( var i = 0 ; i<cards ; i++){
276-
annualFee = parseFloat($('#annFee'+i+'').html());
277-
monthlyFee = parseFloat($('#mthFee'+i+'').html());
278-
purAPR = parseFloat($('#purAPR'+i+'').html());
279-
cashAPR = parseFloat($('#cashAPR'+i+'').html());
280-
var totalFee = duration * monthlyFee + durationYears * annualFee;
281-
var totalInt = yearsPercent * (purBal * purAPR + cashBal + cashAPR);
282-
$('#cardCost'+i+'').html("$" + Math.round(totalInt+totalFee));
283-
};
284+
update();
284285
},
285-
stop: function (event, ui) {$("#securedCardTable").tablesorter({
286-
sortList: [[sortcell,1]]
287-
});
286+
stop: function (event, ui) {
287+
console.log('this thing stopped');
288+
$("#securedCardTable").tablesorter({
289+
sortList: [[sortcell,0]]
290+
});
288291
}
289292
});
290293

@@ -296,20 +299,10 @@ $(document).ready(function () {
296299
slide: function (event, ui) {
297300
$("#calcDuration").html(ui.value);
298301
duration = ui.value;
299-
durationYears = Math.ceil(duration/12);
300-
yearsPercent = duration*365/12/100/365;
301-
for ( var i = 0 ; i<cards ; i++){
302-
annualFee = parseFloat($('#annFee'+i+'').html());
303-
monthlyFee = parseFloat($('#mthFee'+i+'').html());
304-
purAPR = parseFloat($('#purAPR'+i+'').html());
305-
cashAPR = parseFloat($('#cashAPR'+i+'').html());
306-
var totalFee = duration * monthlyFee + durationYears * annualFee;
307-
var totalInt = yearsPercent * (purBal * purAPR + cashBal + cashAPR);
308-
$('#cardCost'+i+'').html("$" + Math.round(totalInt+totalFee));
309-
};
302+
update();
310303
},
311304
stop: function (event, ui) {$("#securedCardTable").tablesorter({
312-
sortList: [[sortcell,1]]
305+
sortList: [[sortcell,0]]
313306
});
314307
}
315308
});

app/assets/javascripts/secureds.js.coffee

-3
This file was deleted.

0 commit comments

Comments
 (0)