Book Image

Node.js Blueprints

By : Krasimir Stefanov Tsonev
Book Image

Node.js Blueprints

By: Krasimir Stefanov Tsonev

Overview of this book

Table of Contents (19 chapters)
Node.js Blueprints
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Handling the user input and moving to the second screen


We need to define a controller for the social-feed/index template. It will transfer the user to the second screen if the button on the screen is clicked. Along with that, we will get the Twitter handle that is entered in the input element. We define a controller as follows:

App.SocialFeedIndexController = Ember.Controller.extend({
  handle: '',
  actions: {
    getTweets: function() {
      if(this.get('handle') !== '') {
        window.location.href = "#/tweets/" + this.get('handle');
        this.set('handle', '');
      } else {
        alert("Please type a Twitter handle.");
      }
    }
  }
});

Note that we are clearing the value of the handle property—this.set('handle', ''). We are doing this because the user will later return to that view and will want to enter a new username. As an addition, we can extend the view that is responsible for that template, and we can bring the browser's focus to the field once the template is added...