Skip to content

Commit

Permalink
Enyo Tutorial: Part 2a
Browse files Browse the repository at this point in the history
  • Loading branch information
robertkowalski committed Sep 3, 2012
1 parent 4f6eb9e commit 8f931b8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
18 changes: 12 additions & 6 deletions source/App.js
Expand Up @@ -10,19 +10,25 @@ enyo.kind({
{kind: "onyx.InputDecorator", components: [
{kind: "onyx.Input", name: "percentControl", placeholder: "Enter percent"}
]},
{kind: "onyx.Button", content: "Calculate tip", ontap: "calculate"},
{tag: "div", name: "tipAmount"}
{kind: "onyx.Button", content: "Calculate tip", ontap: "calculateWithComponent"},
{tag: "div", name: "tipAmount"},
{kind: "PercentCalculator", name: "percentCalculator", onCalculated: "updateControls"}
],
create: function() {
this.inherited(arguments);
},
calculate: function(inSource, inEvent) {
updateControls: function(inSource, inEvent) {
this.$.tipAmount.setContent(inEvent.percentValue);

return true; // stop bubbling
},
calculateWithComponent: function(inSource, inEvent) {
var sum = this.$.sumControl.hasNode().value;
var percent = this.$.percentControl.hasNode().value;

var result = (sum * percent) / 100;
this.$.tipAmount.setContent(result);
this.$.percentCalculator.setSum(sum);
this.$.percentCalculator.setPercent(percent);

return true; // stop bubbling
this.$.percentCalculator.calculate();
}
});
21 changes: 21 additions & 0 deletions source/calc.percent.js
@@ -0,0 +1,21 @@
enyo.kind({
name: 'PercentCalculator',
kind: enyo.Component,
published: {
sum: 0, //optional default values
percent: 0
},
events: {
onCalculated: ''
},
create: function() {
this.inherited(arguments);
},
calculate: function() {
var result;

result = (this.sum * this.percent) / 100;

this.doCalculated({percentValue: result});
}
});
5 changes: 3 additions & 2 deletions source/package.js
Expand Up @@ -2,5 +2,6 @@ enyo.depends(
"$lib/layout",
"$lib/onyx",
"App.css",
"App.js"
);
"App.js",
"calc.percent.js"
);

0 comments on commit 8f931b8

Please sign in to comment.