Skip to content

Instantly share code, notes, and snippets.

@joshwcomeau
Created April 25, 2015 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshwcomeau/41c4043767574fe99b7e to your computer and use it in GitHub Desktop.
Save joshwcomeau/41c4043767574fe99b7e to your computer and use it in GitHub Desktop.
Application Controller
window.reqKitControllers.application = {
// Fetch an array of 'Emotion' objects from the server.
// Returns a promise.
fetchEmotions: function() {
return $.ajax(window.reqKitConstants.ApiEmotionIndex, {
method: 'GET',
contentType: "application/json",
headers: {
'Authorization': window.reqKitConstants.ApiKey
}
});
},
// Update a specified DOM node with input Options
populateEmotionsSelect: function(destination, defaultText, showBlankOption) {
var options = showBlankOption ? "<option val=''>"+defaultText+"</option>" : "";
this.fetchEmotions()
.then(function(emotions) {
options += emotions._items.map(function(emo) {
return "<option val='"+ emo.name +"'>"+ emo.name +"</option>";
});
$(destination).html(options);
});
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment