Created
April 25, 2015 19:35
-
-
Save joshwcomeau/41c4043767574fe99b7e to your computer and use it in GitHub Desktop.
Application Controller
This file contains 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
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