-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.js
86 lines (72 loc) · 2.76 KB
/
calculator.js
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
var App = Ember.Application.create({
LOG_TRANSITIONS: true
});
//Set the model adapters to use local memory
App.ApplicationAdapter = DS.FixtureAdapter.extend();
//if we to link through other object we use this
//App.Router.map(function(){
// this.route('about');
// this.resource('products');
// //our route object can use path -- select specific title product
// this.resource('product' ,{path:'/products/:title'})
//});
App.IndexController = Ember.Controller.extend({
needs: ['Display'],
actions: {
setDisplay: function(value, type) {
this.get('controllers.Display').send('setDisplay', value, type);
}
},
productCount: 6,
// we need to tell this is a property and call it so we use .property for the function
time: function() {
return (new Date()).toDateString();
}.property()
});
//Router - Translates path to Route - used to define routes our appln accepts.
//---------this.resource('products');
//Route -Responsible for getting data from external resources
//----------App.ProductsRoute = Ember.Route.extend({ });
//Controller - Decorates the model, provides property values
//-----------App.ProductsController = Ember.Controller.extend({ });
// get the data from the ext resource -- this wil be used for data template name Products
//add a resource route using this.resoure('products');
//create route to provide model-- App.ProductsData
App.ProductsRoute = Ember.Route.extend({
model: function() {
return App.ProductsData;
}
})
//so select product from products with title specific
App.ProductRoute = Ember.Route.extend({
model: function(params) {
console.log(params);
return App.ProductsData.findBy('title', params.title);
}
})
// get data for data template index
App.IndexRoute = Ember.Route.extend({
model: function() {
return {
//findall of model name
displayInput: this.store.findAll('display'),
operatorBtn: this.store.findAll('operatorBtns'),
numberBtn: this.store.findAll('numberBtns')
}
},
actions: {
onNumberClick: function(val, type) {
this.get('controller').send('setDisplay', val, type);
},
onOperatorClick: function(val, type) {
this.get('controller').send('setDisplay', val, type);
}
},
setupController: function(controller, model) {
controller.set('model', model);
//controller name --- model corresponding to it.
this.controllerFor('NumberBtns').set('model', model.numberBtn);
this.controllerFor('OperatorBtns').set('model', model.operatorBtn);
this.controllerFor('Display').set('model', model.displayInput);
}
})