Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Div
classtutorial-linear-nav
Span
classtutorial-nav-left

Prev: Model

Span
classtutorial-nav-centre

Up to overview

Span
classtutorial-nav-right

Next: View Components

Div
classfloatRight
Panel
borderColor#ccc
bgColor#fff
titleOn This Page
borderStylesolid
Table of Contents
minLevel2
maxLevel5

...

Code Block
javascript
javascript
fluid.defaults("tutorials.currencyConverter", {
    gradeNames: ["fluid.modelComponent", "fluid.eventedComponent", "autoInit"],
    model: {
        rates: {
            euro: 0.712,
            yen: 81.841,
            yuan: 6.609,
            usd: 1.02,
            rupee: 45.789
        },
        currentSelection: "euro",
        amount: 0,
        convertedAmount: 0
    },
    events: {
        conversionUpdated: null
    },
    finalInitFunction: "tutorials.currencyConverter.finalInit"
});

tutorials.currencyConverter.finalInit = function (that) {

    // Add methods to the component object
    that.updateCurrency = function (newCurrency) {
        that.applier.requestChange("currentSelection", newCurrency);
    };

    that.updateRate = function (currency, newRate) {
        that.applier.requestChange("rates." + currency, newRate);
    };

    that.convert = function (amount) {
        var convertedAmount = amount * that.model.rates[that.model.currentSelection];
        that.applier.requestChange("convertedAmount", convertedAmount);
        return amount;
    };

    that.applier.modelChanged.addListener("convertedAmount", function (model, oldModel, changeRequest) {
        that.events.conversionUpdated.fire(model.convertedAmount);
    });
};
Div
classtutorial-linear-nav
Span
classtutorial-nav-left

Prev: Model

Span
classtutorial-nav-centre

Up to overview

Span
classtutorial-nav-right

Next: View Components