/src/js/apps/movie/show/show_controller.js.coffee

https://github.com/xbmc/chorus2 · CoffeeScript · 137 lines · 119 code · 14 blank · 4 comment · 7 complexity · f8c64ef5afad8324339329da77187b45 MD5 · raw file

  1. @Kodi.module "MovieApp.Show", (Show, App, Backbone, Marionette, $, _) ->
  2. API =
  3. bindTriggers: (view) ->
  4. App.listenTo view, 'movie:play', (viewItem) ->
  5. App.execute 'movie:action', 'play', viewItem
  6. App.listenTo view, 'movie:add', (viewItem) ->
  7. App.execute 'movie:action', 'add', viewItem
  8. App.listenTo view, 'movie:localplay', (viewItem) ->
  9. App.execute 'movie:action', 'localplay', viewItem
  10. App.listenTo view, 'movie:download', (viewItem) ->
  11. App.execute 'movie:action', 'download', viewItem
  12. App.listenTo view, 'toggle:watched', (viewItem) ->
  13. App.execute 'movie:action:watched', viewItem.view, viewItem.view
  14. App.listenTo view, 'movie:refresh', (viewItem) ->
  15. App.execute 'movie:action', 'refresh', viewItem
  16. App.listenTo view, 'movie:edit', (viewItem) ->
  17. App.execute 'movie:edit', viewItem.model
  18. moreContent: [
  19. {
  20. title: 'More from %1$s'
  21. filter: 'set'
  22. key: 'set'
  23. type: 'string'
  24. pluck: false
  25. }
  26. {
  27. title: 'More %1$s movies'
  28. filter: 'genre'
  29. key: 'genre'
  30. type: 'array'
  31. pluck: false
  32. }
  33. {
  34. title: 'More movies staring %1$s'
  35. filter: 'actor'
  36. key: 'cast'
  37. type: 'array'
  38. pluck: 'name'
  39. }
  40. {
  41. title: 'Other movies released in %1$s'
  42. filter: 'year'
  43. key: 'year'
  44. type: 'string'
  45. pluck: false
  46. }
  47. ]
  48. class Show.Controller extends App.Controllers.Base
  49. ## The Movie page.
  50. initialize: (options) ->
  51. id = parseInt options.id
  52. movie = App.request "movie:entity", id
  53. ## Fetch the movie
  54. App.execute "when:entity:fetched", movie, =>
  55. ## Get the layout.
  56. @layout = @getLayoutView movie
  57. ## Listen to the show of our layout.
  58. @listenTo @layout, "show", =>
  59. @getDetailsLayoutView movie
  60. @getContentView movie
  61. ## Add the layout to content.
  62. App.regionContent.show @layout
  63. ## Get the base layout
  64. getLayoutView: (movie) ->
  65. new Show.PageLayout
  66. model: movie
  67. getContentView: (movie) ->
  68. @contentLayout = new Show.Content model: movie
  69. @listenTo @contentLayout, "movie:youtube", (view) ->
  70. trailer = movie.get('mediaTrailer')
  71. App.execute "ui:modal:youtube", movie.escape('title') + ' Trailer', trailer.id
  72. @listenTo @contentLayout, 'show', =>
  73. if movie.get('cast').length > 0
  74. @contentLayout.regionCast.show @getCast(movie)
  75. @getMoreContent movie
  76. @layout.regionContent.show @contentLayout
  77. getCast: (movie) ->
  78. App.request 'cast:list:view', movie.get('cast'), 'movies'
  79. ## Build the details layout.
  80. getDetailsLayoutView: (movie) ->
  81. headerLayout = new Show.HeaderLayout model: movie
  82. @listenTo headerLayout, "show", =>
  83. teaser = new Show.MovieTeaser model: movie
  84. API.bindTriggers teaser
  85. detail = new Show.Details model: movie
  86. API.bindTriggers detail
  87. headerLayout.regionSide.show teaser
  88. headerLayout.regionMeta.show detail
  89. @layout.regionHeader.show headerLayout
  90. getMoreContent: (movie) ->
  91. idx = 0
  92. for i, more of API.moreContent
  93. # Get the correct value to filter by
  94. filterVal = false
  95. if more.type is 'array'
  96. filterVals = if more.pluck then _.pluck(movie.get(more.key), more.pluck) else movie.get(more.key)
  97. filterVals = _.shuffle filterVals.slice(0, 4)
  98. filterVal = _.first filterVals
  99. else
  100. filterVal = movie.get(more.key)
  101. # Built req options
  102. if filterVal and filterVal isnt ''
  103. idx++
  104. opts =
  105. limit: {start: 0, end: 6}
  106. cache: false
  107. sort: {method: 'random', order: 'ascending'}
  108. filter: {}
  109. title: t.sprintf(tr(more.title), '<a href="#movies?' + more.key + '=' + _.escape(filterVal) + '">' + _.escape(filterVal) + '</a>')
  110. idx: idx
  111. opts.filter[more.filter] = filterVal
  112. # On get results
  113. opts.success = (collection) =>
  114. collection.remove(movie);
  115. if collection.length > 0
  116. view = new Show.Set
  117. set: collection.options.title
  118. App.listenTo view, "show", =>
  119. listview = App.request "movie:list:view", collection
  120. view.regionCollection.show listview
  121. @contentLayout["regionMore#{collection.options.idx}"].show view
  122. # Fetch
  123. App.request "movie:entities", opts