Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // app/controllers/index.js
- import Ember from 'ember';
- export default Ember.Controller.extend({
- emailAddress: '',
- consoleInformation: 'Nothing to see here yet!',
- isValid: Ember.computed.match('emailAddress', /^.+@.+\..+$/),
- // isDisabled: Ember.computed.not('isValid'),
- isDisabled: Ember.computed('emailAddress', function() {
- return (this.get('emailAddress').length > 4);
- }),
- actions: {
- createRequest() {
- this.set('consoleInformation', "Request Created! Awaiting Response...");
- var consoleBuffer = "";
- consoleBuffer = this.get('consoleInformation');
- // Assign handlers immediately after making the request,
- // and remember the jqxhr object for this request
- var scope = this;
- var jqxhr = Ember.$.get("http://localhost:3000", function() {
- consoleBuffer += "\n" + "success";
- setConsole(consoleBuffer, scope);
- })
- .done(function(response) {
- // consoleBuffer += "\n" + "second success";
- consoleBuffer += "\n" + response.data;
- setConsole(consoleBuffer, scope);
- })
- .fail(function(response) {
- // consoleBuffer += "\n" + "error";
- consoleBuffer += "\n" + JSON.stringify(response, null, 4);
- setConsole(consoleBuffer, scope);
- })
- .always(function() {
- consoleBuffer += "\n" + "finished";
- setConsole(consoleBuffer, scope);
- });
- function setConsole (printMe, scope){
- scope.set("consoleInformation", printMe);
- }
- // Perform other work here ...
- // Set another completion function for the request above
- jqxhr.always(function() {
- // alert("second finished");
- });
- }, //End of create request
- clearConsole() {
- this.set('consoleInformation', "Console Cleared!");
- }
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement