-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathapp.html
More file actions
496 lines (439 loc) · 16.3 KB
/
Copy pathapp.html
File metadata and controls
496 lines (439 loc) · 16.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
<!DOCTYPE HTML>
<!--
Epilogue by TEMPLATED
templated.co @templatedco
Released for free under the Creative Commons Attribution 3.0 license (templated.co/license)
-->
<html>
<head>
<title>Banking with Friends</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" href="assets/css/main.css" />
<style>
div.friend {
background-color: white;
padding: 1em;
width: 30em;
text-align: center;
}
div.pending {
background-color: pink;
}
div.imageholder {
width: 75px;
height: 75px;
display: inline-flex;
align-content: center;
background-color: green;
align-items: center;
justify-content: center;
}
div.imageholder.green {
background-color: green;
}
div.imageholder.yellow {
background-color: yellow;
}
div.imageholder.red {
background-color: red;
}
p.balance {
display: none;
}
input.transaction_amount {
display: none;
}
p.chatter {
font-size: 1.5em;
}
input[type="button"] {
min-width: 3em;
padding: 0 0.5em;
}
div.imageholder img {
max-width: 50px;
}
input.transaction_amount {
margin: 1em 0;
}
#listemhere {
display: flex;
flex: 1 1 auto;
flex-wrap: wrap;
justify-content: center;
}
</style>
</head>
<body>
<!-- Nav -->
<nav id="nav">
<ul class="links">
<li><a href="index.html">Home</a></li>
<li><a href="newcustomers.html">New Customers</a></li>
<li><a href="listcustomers.html">List of Customers</a></li>
<li><a href="contact.html">Contact Us</a></li>
</ul>
</nav>
<!-- Header -->
<header id="header" class="alt">
<a href="#nav" style="position:absolute;right:10px;top:10px;">Menu</a>
<div class="inner">
<h1>The Unnamed Website</h1>
<p>Banking with friends?</p>
</div>
</header>
<!-- Wrapper -->
<div id="wrapper">
<!-- Banner -->
<section id="intro" class="main">
<h2>Create a new customer</h2>
<form>
<input id="custFName" type="text" placeholder="First Name" />
<input id="custLName" type="text" placeholder="Last Name" />
<input id="custStreetName" type="text" placeholder="Street Name" />
<input id="custStreetNumber" type="text" placeholder="Street Number" />
<input id="custCity" type="text" placeholder="City" />
<input id="custState" type="text" placeholder="State" />
<input id="custZip" type="text" placeholder="Zip" />
</form>
<input id="custSubmit" type="button" value="Submit"/>
</section>
<!-- Items -->
<section class="main items">
<article class="item">
<header>
<a href="#"><img src="images/pic01.jpg" alt="" /></a>
<h3>What is the Unnamed website?</h3>
</header>
<p>This webpage uses CapitalOne's API to allow the user to manage his bank accounts, budget and let his friends know of how much he has spent from his current budget.</p>
<ul class="actions">
<li><a href="#" class="button">More</a></li>
</ul>
</article>
<article class="item">
<header>
<a href="#"><img src="images/pic02.jpg" alt="" /></a>
<h3>Who is it for?</h3>
</header>
<p>Our target market is mainly students. We wanted a platform where budgeting can also be more sociable. This page allows the user to also interact with their friend's budgets too.</p>
<ul class="actions">
<li><a href="#" class="button">More</a></li>
</ul>
</article>
<article class="item">
<header>
<a href="#"><img src="images/pic03.jpg" alt="" /></a>
<h3>How do you use it?</h3>
</header>
<p>Each user will simply have a budget, which will reset once a month (on a day of their choosing) and they will have 'indicators' which will let their friends know how much of their budget they have spent for the month.</p>
<ul class="actions">
<li><a href="#" class="button">More</a></li>
</ul>
</article>
<article class="item">
<header>
<a href="#"><img src="images/pic04.jpg" alt="" /></a>
<h3>Item 4</h3>
</header>
<p>Too sleepy to come up with something else...</p>
<ul class="actions">
<li><a href="#" class="button">More</a></li>
</ul>
</article>
</section>
<section class="main">
<div id="listemhere"></div>
</section>
<!-- CTA -->
<section id="cta" class="main special">
<h2>Try it out!</h2>
<p>Click below to get started? ...</p>
<ul class="actions">
<li><a href="#" class="button big">Get Started</a></li>
</ul>
</section>
<!-- Main -->
<!--
<section id="main" class="main">
<header>
<h2>Lorem ipsum dolor</h2>
</header>
<p>Fusce malesuada efficitur venenatis. Pellentesque tempor leo sed massa hendrerit hendrerit. In sed feugiat est, eu congue elit. Ut porta magna vel felis sodales vulputate. Donec faucibus dapibus lacus non ornare. Etiam eget neque id metus gravida tristique ac quis erat. Aenean quis aliquet sem. Ut ut elementum sem. Suspendisse eleifend ut est non dapibus. Nulla porta, neque quis pretium sagittis, tortor lacus elementum metus, in imperdiet ante lorem vitae ipsum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Etiam eget neque id metus gravida tristique ac quis erat. Aenean quis aliquet sem. Ut ut elementum sem. Suspendisse eleifend ut est non dapibus. Nulla porta, neque quis pretium sagittis, tortor lacus elementum metus, in imperdiet ante lorem vitae ipsum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.</p>
</section>
-->
<!-- Footer -->
<footer id="footer">
<ul class="icons">
<li><a href="#" class="icon fa-twitter"><span class="label">Twitter</span></a></li>
<li><a href="#" class="icon fa-facebook"><span class="label">Facebook</span></a></li>
<li><a href="#" class="icon fa-instagram"><span class="label">Instagram</span></a></li>
<li><a href="#" class="icon fa-linkedin"><span class="label">LinkedIn</span></a></li>
<li><a href="#" class="icon fa-envelope"><span class="label">Email</span></a></li>
</ul>
<p class="copyright">© Untitled. Design: <a href="https://templated.co">TEMPLATED</a>. Images: <a href="https://unsplash.com">Unsplash</a>.</p>
</footer>
</div>
<!-- Scripts -->
<!--<script src="assets/js/jquery.min.js"></script>-->
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="assets/js/skel.min.js"></script>
<script src="assets/js/util.js"></script>
<script src="assets/js/main.js"></script>
<script>
{
let povertyLevel = 300;
let yellowLevel = 500;
// Bind the buttons
$('#custSubmit').on('click', () => submitCust());
//$('#listSubmit').on('click', () => listCusts());
// Using the HTML Inputs, create a new customer
function submitCust(){
api('customers', 'POST',
{
'first_name': $('#custFName').val(),
'last_name': $('#custLName').val(),
'address': {
'street_number': $('#custStreetNumber').val(),
'street_name': $('#custStreetName').val(),
'city': $('#custCity').val(),
'state': $('#custState').val(),
'zip': $('#custZip').val()
}
},
(resp) => {
// They'll need a checing account
createAccount(resp.objectCreated._id);
let storedFriendos = JSON.parse(localStorage.getItem('frands'));
if(typeof storedFriendos == 'object'){
storedFriendos.push({name: $('#custFName').val() + ' ' + $('#custLName').val(), pic: 'images/facebook-default-no-profile-pic.jpg'});
localStorage.setItem('frands', JSON.stringify(storedFriendos));
}
// Refresh the listing to show the new account.
listCusts();
}
);
}
// We only have a name? No problem
function quickSubmitCustomer(fname, lname, callback){
// Fudge the address, and simply do not display that stuff later
api('customers','POST',{
'first_name':fname,
'last_name':lname,
'address': {
'street_number':'1234',
'street_name':'Fake St',
'city':'Fakeville',
'state':'OH',
'zip':'83530'
}
},
(resp) => {
// Make them a checking account
createAccount(resp.objectCreated._id, (response)=>{
// pass the customer ID (not the account ID) back out
callback(resp.objectCreated._id);
});
});
}
// Have we scraped Facebook for friends? Has this been stored?
function listCusts(){
if(localStorage.getItem('frands')){
listFriends();
} else {
listGenerics();
}
}
// Display friends from the local storage
// These were scraped from Facebook during the login process
function listFriends(){
let friendos = JSON.parse(localStorage.getItem('frands'));
// we only want some
//friendos = friendos.slice(10);
$('#listemhere').html('');
for(let friend of friendos){
//render the html
$('#listemhere').append
(`<div class="friend">
<p>${friend.name}</p>
<div class="imageholder">
<img class="friend_photo" src="${friend.pic}" />
</div>
</div>`);
// This Facebook friend might not have a customer ID yet
// Save a reference to this DOM element if we need to give it an ID later
let lastP = $('#listemhere div.friend:last-child');
// However, the friend may have already been assigned a customer ID
// If it has been, we can just give that DOM the id right now
if(friend.hasOwnProperty('cust_id')){
lastP.attr('id',friend.cust_id);
} else {
// Hit the API to make a new customer entry
// we're just splitting the name by the space in the middle
// This is a BAD BAD thing to do, very hostile toward people with
// non-anglo naming schemes, but quick and dirty
quickSubmitCustomer(friend.name.split(' ')[0], friend.name.split(' ')[1],
(response)=>{
let id = response;
lastP.attr('id', id);
friend.cust_id = id;
// yeah, I rewrite localstorage up to 10 times per pageload
// much easier than figuring out when the last
localStorage.setItem('frands', JSON.stringify(friendos));
});
}
waitForReady(()=>{
listCustBalances(friend.cust_id);
});
}
}
function waitForReady(cb){
if($('div.friend:not([id])').length>0){
setTimeout(()=>waitForReady(cb),1000);
} else {
cb();
}
}
//pull randos from the API that we've created
function listGenerics(){
api('customers', 'GET', '', (response) => {
$('#listemhere').html('');
for(let customer of response.slice(10)){
$('#listemhere').append('<p id="'+customer._id+'">'+customer.first_name+' '+customer.last_name +
'<p/><p>'+customer.address.street_number+' '+customer.address.street_name +
' '+customer.address.city+', '+customer.address.state+' '+customer.address.zip
+'</p>');
listCustBalances(customer._id);
}
});
}
function listCustBalances(id){
api('customers/'+id+'/accounts','GET','',function(response){
for(let account of response){
$(`#${id}`).append(
`<p class="balance">${account.balance}</p>
<input type="text" class="transaction_amount" placeholder="transaction" />
<input type="button" value="+" class="transaction_add" />
<p class="chatter"></p>`
);
if(localStorage.getItem('transact-flags')){
let transactFlags = JSON.parse(localStorage.getItem('transact-flags'));
if(transactFlags[id] != account.balance){
transactFlags[id] = undefined;
localStorage.setItem('transact-flags',JSON.stringify(transactFlags));
} else {
$(`#${id}`).addClass('pending');
registerForAjaxPending(id);
for(let input of $(`#${id} input`))
$(input).attr('disabled','');
}
}
$('#'+id).find('.transaction_add').one('click', (evt)=> {
//transact($(evt.target).parent().find('.transaction_amount').val(), account._id, id);
$('#'+id).find('.transaction_amount').css('display','block');
$(evt.target).attr('value','Send');
$('#'+id).find('.transaction_add').on('click', (evt)=> {
transact($(evt.target).parent().find('.transaction_amount').val(), account._id, id);
});
});
//$('#'+id).find('.transaction_remove').on('click', (evt)=> {
//transact(-parseInt($(evt.target).parent().find('.transaction_amount').val()), account._id, id);
//});
colorBoxes(id, account.balance);
}
});
}
function colorBoxes(id, money){
$(`#${id} p.chatter`).text('');
$(`#${id} div.imageholder`).attr('class','imageholder');
if(money>yellowLevel ){
$(`#${id} div.imageholder`).addClass('green');
} else if (money>povertyLevel){
$(`#${id} div.imageholder`).addClass('yellow');
} else {
$(`#${id} div.imageholder`).addClass('red');
$(`#${id} p.chatter`).text(generateChatter(money));
}
}
function generateChatter(dollaz){
if(Math.round(Math.random())) return '';
let amountNeeded = yellowLevel - dollaz;
let days = ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'];
let times = ['Morning','Afternoon','Evening','Night','Noon','Midnight'];
let day = days[Math.floor(Math.random()*7)];
let time = times[Math.floor(Math.random()*6)];
let openers = [
`I'm going to need all my mates to give me £${amountNeeded} if i'm going out on ${day} ${time}.`,
`Listen, I'd love to join you on ${day} ${time} but I just can't do it without... Say... £${amountNeeded}?`,
`Heyyyy! Let's get faced on ${day} ${time}! Thing is, though, I could really use £${amountNeeded}...`,
`Can't drink if I can't eat. Hook me up with £${amountNeeded}?`
];
return openers[Math.floor(Math.random()*openers.length)];
}
function createAccount(id, callback=(response)=>{console.log(response)}){
api('customers/'+id+'/accounts','POST', {
"type":"Checking",
"rewards":0,
"nickname":"auto-created",
"balance": Math.floor(Math.random()*750)
}, (response) => {
callback(response);
});
}
function transact(amount, id, custid) {
api('accounts/'+id+'/'+((amount>0)?'deposits':'withdrawals'), 'POST', {
"medium": "balance",
"transaction_date": "2016-11-20",
"amount": parseFloat(Math.abs(amount)),
"description": "Hand-built transaction"
}, (response) => {
makePending(custid);
});
}
function registerForAjaxPending(id){
api('customers/'+id+'/accounts', 'GET', {}, (response)=> {
if(localStorage.getItem('transact-flags')){
var transactFlags = JSON.parse(localStorage.getItem('transact-flags'));
} else {
var transactFlags = {}
}
if(response[0].balance != transactFlags[id]){
$(`#${id}`).removeClass('pending');
$(`#${id} p.balance`).text(response[0].balance);
colorBoxes(id, response[0].balance);
for(let input of $(`#${id} input`))
$(input).removeAttr('disabled');
} else {
setTimeout(()=>registerForAjaxPending(id), 5000);
}
});
}
function makePending(id){
// detecting whether a transaction is pending
if(localStorage.getItem('transact-flags')){
var transactFlags = JSON.parse(localStorage.getItem('transact-flags'));
} else {
var transactFlags = {}
}
transactFlags[id] = $(`#${id} p.balance`).text();
console.log(`#${id} input`);
for(let input of $(`#${id} input`))
$(input).attr('disabled','');
localStorage.setItem('transact-flags', JSON.stringify(transactFlags));
$(`#${id}`).addClass('pending');
registerForAjaxPending(id);
}
function api(endpoint, method, data, response){
$.ajax({
url: 'http://api.reimaginebanking.com/'+endpoint+'?key=6021ab09d195f722f7c5619957e8679d',
method: method,
contentType: 'application/json',
data: JSON.stringify(data),
success: (text)=>response(text)
});
}
listCusts();
}
</script>
</body>
</html>