Skip to content

Commit 7329647

Browse files
js for calc
1 parent eb51cfc commit 7329647

File tree

1 file changed

+130
-0
lines changed

1 file changed

+130
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
2+
3+
var formatMoney = function(n) {
4+
var c = isNaN(c = Math.abs(c)) ? 2 : c,
5+
d = "." ,
6+
t = t == undefined ? "," : t,
7+
s = n < 0 ? "-" : "",
8+
i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
9+
j = (j = i.length) > 3 ? j % 3 : 0;
10+
return '$' + s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
11+
12+
}
13+
14+
var formatCandidates = function(num) {
15+
if (num == 1) {
16+
return num + ' Candidate';
17+
}
18+
return num + " Candidates";
19+
}
20+
21+
var formatMinutes = function(num) {
22+
if (num == 1) {
23+
return num + ' Minute';
24+
}
25+
return num + ' Minutes';
26+
}
27+
28+
var updateScreeningCost = function(num_candidates, per_hour, time_per_candidate) {
29+
var time_to_minutes = time_per_candidate / 60; //convert from minutes to hour
30+
var total_cost = time_to_minutes * per_hour * num_candidates;
31+
$('#total-screening-cost').html(formatMoney(total_cost) + ' / Month!');
32+
}
33+
34+
35+
$(document).ready(function() {
36+
var per_hour = 40;
37+
var time_per_candidate = 45;
38+
var num_candidates = 20;
39+
updateScreeningCost(num_candidates, per_hour, time_per_candidate);
40+
$('#btn-minus_per-hour').click(function(e) {
41+
e.preventDefault();
42+
if( per_hour > 1) {
43+
per_hour--;
44+
}
45+
$('#per-hour-input').val(formatMoney(per_hour));
46+
updateScreeningCost(num_candidates, per_hour, time_per_candidate);
47+
48+
});
49+
$('#btn-plus_per-hour').click(function(e) {
50+
e.preventDefault();
51+
per_hour++;
52+
$('#per-hour-input').val(formatMoney(per_hour));
53+
updateScreeningCost(num_candidates, per_hour, time_per_candidate);
54+
55+
});
56+
57+
$('#per-hour-input').change(function(e){
58+
per_hour = parseFloat($(this).val());
59+
$('#per-hour-input').val(formatMoney(per_hour));
60+
updateScreeningCost(num_candidates, per_hour, time_per_candidate);
61+
});
62+
63+
64+
// number of candidates
65+
$('#btn-minus_num_candidates').click(function(e){
66+
e.preventDefault();
67+
if (num_candidates > 1 ) {
68+
num_candidates--;
69+
}
70+
$('#input_screenings').val(formatCandidates(num_candidates));
71+
updateScreeningCost(num_candidates, per_hour, time_per_candidate);
72+
});
73+
74+
$('#btn-plus_num_candidates').click(function(e){
75+
e.preventDefault();
76+
num_candidates++;
77+
78+
$('#input_screenings').val(formatCandidates(num_candidates));
79+
updateScreeningCost(num_candidates, per_hour, time_per_candidate);
80+
});
81+
82+
$('#input_screenings').change(function() {
83+
num_candidates = parseInt($(this).val());
84+
$('#input_screenings').val(formatCandidates(num_candidates));
85+
updateScreeningCost(num_candidates, per_hour, time_per_candidate);
86+
});
87+
88+
89+
// Time per candidate
90+
$('#btn-minus_time_per_candidate').click(function(e){
91+
e.preventDefault();
92+
if (time_per_candidate > 1 ) {
93+
time_per_candidate--;
94+
}
95+
$('#time-per-screening').val(formatMinutes(time_per_candidate));
96+
updateScreeningCost(num_candidates, per_hour, time_per_candidate);
97+
});
98+
99+
$('#btn-plus_time_per_candidate').click(function(e){
100+
e.preventDefault();
101+
time_per_candidate++;
102+
103+
$('#time-per-screening').val(formatMinutes(time_per_candidate));
104+
updateScreeningCost(num_candidates, per_hour, time_per_candidate);
105+
});
106+
107+
$('#time-per-screening').change(function() {
108+
time_per_candidate = parseInt($(this).val());
109+
$('#time-per-screening').val(formatMinutes(time_per_candidate));
110+
updateScreeningCost(num_candidates, per_hour, time_per_candidate);
111+
});
112+
});
113+
114+
$(document).ready(function(){
115+
$(".input-number").keydown(function (e) {
116+
// Allow: backspace, delete, tab, escape, enter and .
117+
if ($.inArray(e.keyCode, [46, 8, 9, 27, 13, 190]) !== -1 ||
118+
// Allow: Ctrl+A
119+
(e.keyCode == 65 && e.ctrlKey === true) ||
120+
// Allow: home, end, left, right
121+
(e.keyCode >= 35 && e.keyCode <= 39)) {
122+
// let it happen, don't do anything
123+
return;
124+
}
125+
// Ensure that it is a number and stop the keypress
126+
if ((e.shiftKey || (e.keyCode < 48 || e.keyCode > 57)) && (e.keyCode < 96 || e.keyCode > 105)) {
127+
e.preventDefault();
128+
}
129+
});
130+
});

0 commit comments

Comments
 (0)