Advertisement
Guest User

Untitled

a guest
Dec 14th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // app/controllers/index.js
  2. import Ember from 'ember';
  3.  
  4. export default Ember.Controller.extend({
  5.  
  6.   emailAddress: '',
  7.   consoleInformation: 'Nothing to see here yet!',
  8.  
  9.   isValid: Ember.computed.match('emailAddress', /^.+@.+\..+$/),
  10.   // isDisabled: Ember.computed.not('isValid'),
  11.   isDisabled: Ember.computed('emailAddress', function() {
  12.     return (this.get('emailAddress').length > 4);
  13.   }),
  14.  
  15.  
  16.   actions: {
  17.  
  18.     createRequest() {
  19.       this.set('consoleInformation', "Request Created! Awaiting Response...");
  20.       var consoleBuffer = "";
  21.       consoleBuffer = this.get('consoleInformation');
  22.       // Assign handlers immediately after making the request,
  23.       // and remember the jqxhr object for this request
  24.       var scope = this;
  25.       var jqxhr = Ember.$.get("http://localhost:3000", function() {
  26.           consoleBuffer += "\n" + "success";
  27.           setConsole(consoleBuffer, scope);
  28.         })
  29.         .done(function(response) {
  30.           // consoleBuffer += "\n" + "second success";
  31.           consoleBuffer += "\n" + response.data;
  32.           setConsole(consoleBuffer, scope);
  33.         })
  34.         .fail(function(response) {
  35.           // consoleBuffer += "\n" + "error";
  36.           consoleBuffer += "\n" + JSON.stringify(response, null, 4);
  37.           setConsole(consoleBuffer, scope);
  38.         })
  39.         .always(function() {
  40.           consoleBuffer += "\n" + "finished";
  41.           setConsole(consoleBuffer, scope);
  42.         });
  43.  
  44.         function setConsole (printMe, scope){
  45.           scope.set("consoleInformation", printMe);
  46.         }
  47.  
  48.  
  49.  
  50.       // Perform other work here ...
  51.  
  52.       // Set another completion function for the request above
  53.       jqxhr.always(function() {
  54.         // alert("second finished");
  55.       });
  56.     }, //End of create request
  57.  
  58.     clearConsole() {
  59.       this.set('consoleInformation', "Console Cleared!");
  60.     }
  61.   }
  62.  
  63. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement