Can I bubble-up an event from Ajax.response?

I've been struggling with this for a day. I can't figure out how to bubble an event up from the ajax.response() (or ajax.error() handlers coming from the fetch() of my enyo/Source...

I could really use some help on understanding how to bubble-up an event to be handled by a parent kind - I am currently calling mftLbUserLoginModel.fetch(); from a parent's Button ontap event, and the Ajax is working fine, I just can't figure out how to handle UI changes based on success or failure. Here is the enyo/Source and enyo/Model I'm working with:
<br />var kind = require('enyo/kind'),<br />  EnyoSource = require('enyo/Source'),<br />  Ajax = require('enyo/Ajax'),<br />  Model = require('enyo/Model');<br /><br />// MUST CHANGE FOR PRODUCTION: lbApiUrl<br />  var mftLbApiUrl = '';<br />  var mftLbLoginEndpoint = 'mftUsers/login';<br />  var mftGetUserWithIdEndpoint = 'mftUsers/';<br /><br />var MftLbLoginSource = kind({<br />  name: 'mftLbLoginSource',<br />  kind: EnyoSource,<br />  fetch: function (rec, opts) {<br />    // implement code to fetch records<br />    var ajax = new Ajax({<br />      url: mftLbApiUrl + mftLbLoginEndpoint,<br />      method: 'POST',<br />      cacheBust: false,<br />      postBody: {username: rec.get('username'), password: rec.get('password')}<br />    });<br />    <br />    ajax.go();<br /><br />    ajax.response(this, function (inSender, inResponse) {<br />      opts.success(inResponse); // call success callback to return data<br />      // ** How to bubble a loginSuccess event from here **<br />      // get username from API with get /mftUsers/{id}<br />      mftLbUserModel.fetch();<br />    });<br />    <br />    ajax.error(this, function (inError, err) {// WIP: Needs Work...<br />      opts.error(inError);<br />      mftLbUserLoginModel.clearError();<br />      mftLbUserModel.set('username', undefined); // TEMP - Looks ugly, shoudln't this send an event to be handled<br />    });<br />  }<br />});<br />var mftLbLoginSource = new MftLbLoginSource({name: 'mftLbLoginSource'});<br /><br />var MftLbUserLoginModel = kind({<br />  name: "mftUserLoginModel",<br />  kind: Model,<br />  source: 'mftLbLoginSource',<br />  url: mftLbApiUrl + mftLbLoginEndpoint,<br />  options: {parse: true},<br />  parse: function (data) {<br />    data.access_token =; // Loopback access_token is returned as 'id'<br />    return data;<br />  }<br />});<br /><br />var mftLbUserLoginModel = new MftLbUserLoginModel({name: "mftLbUserLoginModel"});
-Thanks in advance for any help!
Sign In or Register to comment.