Skip to content

Commit

Permalink
First 6 Chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivo-Balbaert committed Jun 13, 2014
1 parent b7964e1 commit 484405e
Show file tree
Hide file tree
Showing 2,181 changed files with 960,181 additions and 0 deletions.
35 changes: 35 additions & 0 deletions Chapter 1/bank_terminal/build/web/bank_terminal_s5.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
body {
background-color: #F8F8F8;
font-family: 'Open Sans', sans-serif;
font-size: 14px;
font-weight: normal;
line-height: 1.2em;
margin: 15px;
padding: 20px;
}

form {
background: #9cbc2c;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
padding: 20px;
width: 400px;
}

h1, p {
color: #333;
}

.auto-style1 {
width: 25%;
border: 1px solid #0000FF;
}

.auto-style2 {
width: 107px;
}

.btns {
width: 127px;
}
100 changes: 100 additions & 0 deletions Chapter 1/bank_terminal/build/web/bank_terminal_s5.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import 'dart:html';
import 'package:bank_terminal_s5/bank_terminal.dart';

LabelElement owner, balance, error;
InputElement number, amount;
ButtonElement btn_other, btn_deposit, btn_withdrawal, btn_interest;
BankAccount bac;

void main() {
bind_elements();
attach_event_handlers();
disable_transactions(true);
}

bind_elements() {
owner = querySelector('#owner');
balance = querySelector('#balance');
number = querySelector('#number');
btn_other = querySelector('#btn_other');
amount = querySelector('#amount');
btn_deposit = querySelector('#btn_deposit');
btn_interest = querySelector('#btn_interest');
error = querySelector('#error');
}

attach_event_handlers() {
number.onInput.listen(readData);
amount.onChange.listen(nonNegative);
amount.onBlur.listen(nonNegative);
btn_other.onClick.listen(clearData);
btn_deposit.onClick.listen(changeBalance);
btn_interest.onClick.listen(interest);
}

readData(Event e) {
// show data:
var key = 'Bankaccount:${number.value}';
if (!window.localStorage.containsKey(key)) {
error.innerHtml = "Unknown bank account!";
number.focus();
return;
}
error.innerHtml = "";
// read data from local storage:
String acc_json = window.localStorage[key];
bac = new BankAccount.fromJsonString(acc_json);
// show owner and balance:
owner.innerHtml = "<b>${bac.owner.name}</b>";
balance.innerHtml = "<b>${bac.balance.toStringAsFixed(2)}</b>";
// enable transactions part:
disable_transactions(false);
}

clearData(Event e) => clear();

clear() {
number.value = "";
owner.innerHtml = "----------";
balance.innerHtml = "0.0";
number.focus();
disable_transactions(true);
}

disable_transactions(bool off) {
amount.disabled = off;
btn_deposit.disabled = off;
btn_interest.disabled = off;
}

nonNegative(Event e) {
num input;
try {
input = double.parse(amount.value);
} on FormatException catch(e) {
window.alert("This is not a valid amount!");
amount.focus();
}
}

changeBalance(Event e) {
// read amount:
double money_amount = double.parse(amount.value);
// call deposit on BankAccount object:
if (money_amount >= 0) bac.deposit(money_amount);
else bac.withdraw(money_amount);
window.localStorage["Bankaccount:${bac.number}"] = bac.toJson();
// show new amount:
balance.innerHtml = "<b>${bac.balance.toStringAsFixed(2)}</b>";
// disable refresh screen:
e.preventDefault();
e.stopPropagation();
}

interest(Event e) {
bac.interest();
window.localStorage["Bankaccount:${bac.number}"] = bac.toJson();
balance.innerHtml = "<b>${bac.balance.toStringAsFixed(2)}</b>";
e.preventDefault();
e.stopPropagation();
}
Loading

0 comments on commit 484405e

Please sign in to comment.