Last active
October 15, 2016 00:10
-
-
Save davelowensohn/4adb71d4e879b7d936433f60d7baf40a to your computer and use it in GitHub Desktop.
AJAX dependent update pattern
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 1 | |
updateProviders(next) { | |
var matrix = this.get('allPatientProviderMatrix'); | |
var curledMatrix = {matrix}; // wrap array in {} to JSONify | |
var ember = this; | |
new Promise( function(resolve, reject) { | |
var localEmber = ember; | |
Ember.$.ajax({ | |
type: "POST", | |
url: ENV.fullApiUrl+'/matrix/' + localEmber.get('model.report.id'), | |
data: JSON.stringify(curledMatrix), | |
success: function (data){ | |
resolve(data); // on success, goto .then | |
}, | |
contentType: "application/json", | |
}); | |
}).then(data => { | |
this.set('allPatientProviderMatrix', data); | |
this.send('updateFacilities', next); | |
}); | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example 2 | |
saveAndContinue(routeName) { | |
var newRegObj = this.get('newRegistrationObject'), | |
serializedPayload = JSON.stringify(newRegObj), | |
emberContext = this; | |
new Promise( function(resolve, reject) { | |
var localEmber = emberContext; | |
// console.log('step 1'); | |
$.ajax({ | |
type: "POST", | |
url: ENV.fullApiUrl+'/auth', | |
data: serializedPayload, | |
success: function (data){ | |
// console.log('step 2'); | |
resolve(data); // on success, goto .then | |
}, | |
contentType: "application/json", | |
}); | |
}).then(data => { | |
// console.log('we made it!'); | |
this.transitionToRoute(routeName); | |
}); | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment