Guest User

Untitled

a guest
Sep 11th, 2014
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. window.MarketsUI = flight.component ->
  2. @defaultAttrs
  3. table: 'tbody'
  4. filter: '.dropdown-menu a'
  5.  
  6. @refresh = (data) ->
  7. $table = @select('table')
  8. $table.prepend(JST['market'](market)) for market in data.markets
  9. console.log data.markets
  10.  
  11.  
  12. @filter = (event) ->
  13. type = event.target.className
  14. return @list.filter() if type == ''
  15.  
  16. @list.filter (item) ->
  17. item.values().type == "#{gon.i18n[type]}"
  18.  
  19. @initList = ->
  20. options =
  21. valueNames: [ 'market', 'currency', 'vol', 'change',
  22. 'last', 'high', 'low']
  23. @list = new List('marketsX', options)
  24.  
  25. @after 'initialize', ->
  26.  
  27. $.getJSON "/api/v2/tickers", (data) ->
  28.  
  29. markets = []
  30. for own cur of data
  31. ticker = data[cur].ticker
  32. item = {}
  33. [
  34. "change"
  35. "change_trend"
  36. "last"
  37. "high"
  38. "low"
  39. ].forEach (key) ->
  40. item[key] = ticker[key]
  41. return
  42.  
  43. item.volume = ticker.vol
  44. item.market = cur.substring(0, 3) + "/" + cur.substring(3)
  45. item.currency = cur.substring(0, 3)
  46. markets.push item
  47. console.log markets
  48. markets.sort (a, b)->
  49. a.volume - b.volume
  50.  
  51. @.refresh {markets: markets}
  52.  
  53. @.initList()
  54.  
  55. @.on @select('filter'), 'click', @filter
Advertisement
Add Comment
Please, Sign In to add comment