Source: widgets/detail/detailslist.js

  1. define('application/widgets/detail/detailslist', [
  2. 'rofl/widgets/verticallist',
  3. 'rofl/widgets/horizontallist',
  4. 'rofl/widgets/label',
  5. 'rofl/widgets/container',
  6. 'rofl/lib/l10n',
  7. 'application/widgets/button',
  8. 'application/utils',
  9. 'application/widgets/detail/iconbutton',
  10. 'application/widgets/detail/episodeitem',
  11. 'rofl/lib/utils',
  12. 'antie/runtimecontext',
  13. 'application/managers/feature'
  14. ], function (
  15. VerticalList,
  16. HorizontalList,
  17. Label,
  18. Container,
  19. L10N,
  20. KPNButton,
  21. AppUtils,
  22. IconButton,
  23. EpisodeItem,
  24. Utils,
  25. RuntimeContext,
  26. FeatureManager
  27. ) {
  28. 'use strict';
  29. var l10n = L10N.getInstance(),
  30. application = RuntimeContext.getCurrentApplication(),
  31. featureManager = FeatureManager.getInstance();
  32. return VerticalList.extend({
  33. /**
  34. * Initialises the widget.
  35. *
  36. * @param {Object} data - The detail data.
  37. */
  38. init: function init (data) {
  39. init.base.call(this);
  40. this.addClass('details-page-list');
  41. this._build(data);
  42. },
  43. /**
  44. * Builds elements.
  45. *
  46. * @param {Object} data - The detail data.
  47. */
  48. _build: function (data) {
  49. this._buildEpisodesList(data);
  50. // TODO: Renable once data is available.
  51. // this._buildCastLabel(data.getCastLabel() || '');
  52. // this._buildCastNames(data.getCast() || []);
  53. // this._buildSeasonsList(data, buttons);
  54. },
  55. /**
  56. * Builds presenter label element.
  57. *
  58. * @param {string} text - Cast label.
  59. */
  60. _buildCastLabel: function (text) {
  61. var castlabel = this._castlabel = new Label({ text: text, classNames: ['cast-label'] });
  62. this.appendChildWidget(castlabel);
  63. },
  64. /**
  65. * Builds presenter name element.
  66. *
  67. * @param {string} names - Presenter name.
  68. */
  69. _buildCastNames: function (names) {
  70. var text = names.join(', '),
  71. castnames = new Label({ text: text, classNames: ['cast-names'] });
  72. this.appendChildWidget(castnames);
  73. },
  74. /**
  75. * Builds element.
  76. *
  77. * @param {Array} episodes - The episodes to append.
  78. */
  79. _buildEpisodesList: function (episodes) {
  80. var now = application.getDate(),
  81. episodesList = this._episodeslist = new VerticalList(''),
  82. replayEnabled = featureManager.isReplayEnabled(),
  83. restricted,
  84. listelement,
  85. start,
  86. end,
  87. isLive,
  88. isCatchup,
  89. inactive;
  90. episodesList.addClass('episodes-list');
  91. Utils.each(episodes, function (data) {
  92. start = new Date(data.getStartTime() * 1000);
  93. end = new Date(data.getEndTime() * 1000);
  94. restricted = false;
  95. inactive = true;
  96. isCatchup = false;
  97. isLive = false;
  98. if (start > now) {
  99. isCatchup = false;
  100. } else {
  101. inactive = false;
  102. if (replayEnabled) {
  103. if (data.canCatchup() && data.canPlay()) {
  104. isCatchup = true;
  105. } else {
  106. restricted = true;
  107. }
  108. }
  109. }
  110. if (start <= now && now <= end) {
  111. isLive = true;
  112. isCatchup = false;
  113. }
  114. listelement = new EpisodeItem('', {
  115. restricted: restricted,
  116. live: isLive,
  117. catchup: isCatchup,
  118. data: data
  119. });
  120. if (inactive) {
  121. listelement.addClass('unactive');
  122. }
  123. episodesList.appendChildWidget(listelement);
  124. this.appendChildWidget(episodesList);
  125. }, this);
  126. },
  127. /**
  128. * Builds element.
  129. *
  130. * @param {Object} mockdata - Mocked data.
  131. */
  132. _buildSeasonsList: function (mockdata) {
  133. var seasonsList = this._seasonslist = new HorizontalList(),
  134. seasons = mockdata.seasons,
  135. seasonNumber = 0,
  136. seasonitem;
  137. seasonsList.addClass('seasons-list');
  138. Utils.each(seasons, function (seasonsData) {
  139. seasonNumber += 1;
  140. // build season item
  141. seasonitem = new KPNButton(l10n.get('details.season') + ' ' + seasonNumber, 'season' + seasonNumber);
  142. seasonitem.addClass('season-title');
  143. seasonsList.appendChildWidget(seasonitem);
  144. // get episodes list
  145. this._episodes = seasonsData.episodes;
  146. }, this);
  147. this.appendChildWidget(seasonsList);
  148. },
  149. /**
  150. * Returns episodes.
  151. *
  152. * @returns {Object} Episodes.
  153. */
  154. getEpisodeList: function () {
  155. return this._episodeslist;
  156. },
  157. /**
  158. * Dispose the widgets.
  159. */
  160. dispose: function () {
  161. Utils.each(this._episodeslist.getChildWidgets(), function (widget) {
  162. widget.dispose();
  163. });
  164. }
  165. });
  166. });