PageRenderTime 50ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/app/assets/javascripts/collections/track_search_results.js

https://bitbucket.org/olivernn/scpl
JavaScript | 27 lines | 17 code | 3 blank | 7 comment | 0 complexity | 1fd78ab71e57783873d6a22418de9230 MD5 | raw file
  1. define(['backbone', 'soundcloud', 'models/track'], function (backbone, sc, Track) {
  2. // TrackSearchResults
  3. // @collection
  4. //
  5. // Manages track searches afainst the SoundCloud api.
  6. // will hold a colleciton of tracks representing the search results from the soundcloud api.
  7. return backbone.Collection.extend({
  8. model: Track,
  9. // makes a query to the soundcloud api and then adds instances of tracks.
  10. // Once the search completes it triggers an event to let everyone know.
  11. query: function (query) {
  12. var renameId = function (track) {
  13. track.sc_id = track.id
  14. delete track.id
  15. return track
  16. }
  17. var resultsLoaded = function (tracks) {
  18. this.add(tracks.map(renameId))
  19. this.trigger('searchComplete')
  20. }
  21. sc.get('/tracks', {q: query}, resultsLoaded.bind(this))
  22. }
  23. })
  24. })