Skip to content

Commit da9743a

Browse files
author
Chris Noble
committed
Treatments
1 parent 4c266a7 commit da9743a

File tree

4 files changed

+46
-4
lines changed

4 files changed

+46
-4
lines changed

www/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
</div>
2727
</nav>
2828

29+
2930
<div class="appContainer">
3031
<div class="container">
3132
<div class="questionContainer"></div>
@@ -143,9 +144,9 @@
143144
$(function() {
144145
var questionCollection = new QuestionsCollection(questions);
145146
var pastTreatments = new PastTreatmentCollection();
146-
// pastTreatments.loadFromLocal();
147+
pastTreatments.loadFromLocal();
147148
var currentTreatments = new CurrentTreatmentCollection();
148-
// currentTreatments.loadFromLocal();
149+
currentTreatments.loadFromLocal();
149150
app = new AppView({'questionCollection':questionCollection, 'currentTreatments': currentTreatments, 'pastTreatments':pastTreatments, el:$('.app')});
150151
app.getNextQuestion();
151152
});

www/js/collections/current-treatment-collection.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,23 @@
88

99
CurrentTreatmentCollection = Backbone.Collection.extend({
1010
model: Treatment,
11-
key: 'currentTreatments'
11+
key: 'currentTreatments',
12+
13+
/**
14+
* loadFromLocal
15+
* Loads the value to local storage
16+
*/
17+
loadFromLocal:function() {
18+
var data = localStorage.getItem(this.key);
19+
if (data !== null){
20+
data = JSON.parse(data);
21+
}else{
22+
data = [];
23+
}
24+
var that = this;
25+
_.each(data, function(treatmentJSON){
26+
var treatment = new Treatment(treatmentJSON);
27+
that.add(treatment);
28+
});
29+
}
1230
});

www/js/collections/past-treatment-collection.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,24 @@
88

99
PastTreatmentCollection = Backbone.Collection.extend({
1010
model: Treatment,
11-
key: 'pastTreatments'
11+
key: 'pastTreatments',
12+
13+
/**
14+
* loadFromLocal
15+
* Loads the value to local storage
16+
*/
17+
loadFromLocal:function() {
18+
var data = localStorage.getItem(this.key);
19+
if (data !== null){
20+
data = JSON.parse(data);
21+
}else{
22+
data = [];
23+
}
24+
var that = this;
25+
_.each(data, function(treatmentJSON){
26+
var treatment = new Treatment(treatmentJSON);
27+
that.add(treatment);
28+
});
29+
}
1230

1331
});

www/js/views/app-view.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ var AppView = Backbone.View.extend({
1111

1212

1313
questionCollection: null,
14+
currentTreatments: null,
15+
currentTreatments: null,
16+
pastTreatments: null,
1417
questionContainer: '.questionContainer',
1518
allDoneTemplate: '#doneTemplate',
1619
appContainer: '.appContainer',
@@ -32,6 +35,8 @@ var AppView = Backbone.View.extend({
3235

3336
var that = this;
3437
this.questionCollection = options.questionCollection;
38+
this.pastTreatments = options.pastTreatments;
39+
this.currentTreatments = options.currentTreatments;
3540
this.timestamp = new Date().getTime();
3641

3742
},

0 commit comments

Comments
 (0)