APIs

Show:
  1. /**
  2. * BlockClock block resides inside a scene or timeline
  3. * @class BlockClock
  4. * @extends Block
  5. * @constructor
  6. * @param {string} i_placement location where objects resides which can be scene or timeline
  7. * @param {string} i_campaign_timeline_chanel_player_id required and set as block id when block is inserted onto timeline_channel
  8. * @return {Object} Block instance
  9. */
  10. define(['jquery', 'backbone', 'Block'], function ($, Backbone, Block) {
  11.  
  12. var BlockClock = Block.extend({
  13.  
  14. /**
  15. Constructor
  16. @method initialize
  17. **/
  18. constructor: function (options) {
  19. var self = this;
  20. self.m_blockType = 3320;
  21. _.extend(options, {blockType: self.m_blockType})
  22. Block.prototype.constructor.call(this, options);
  23. self._initSubPanel(Elements.BLOCK_CLOCK_COMMON_PROPERTIES);
  24. self.m_clockFontSelector = self.m_blockProperty.getClockFontSelector();
  25. self._listenFontSelectionChange();
  26. self._listenClockMaskChange();
  27. },
  28.  
  29. /**
  30. Load up property values in the common panel
  31. @method _populate
  32. @return none
  33. **/
  34. _populate: function () {
  35. var self = this;
  36. var domPlayerData = self._getBlockPlayerData();
  37. var xSnippet = $(domPlayerData).find('Clock');
  38. var mask = $(xSnippet).attr('clockMask');
  39. var xSnippetFont = $(xSnippet).find('Font');
  40.  
  41. $('input[type="radio"]',self.$el).filter(function(i){
  42. var radioValue = $(this).attr('value');
  43. var currMask = BB.PepperHelper.getBlockBoilerplate(self.m_blockType).getDateTimeMask(radioValue);
  44. if (mask == currMask){
  45. $(this).prop('checked',true);
  46. return false;
  47. }
  48. });
  49.  
  50. self.m_clockFontSelector.setConfig({
  51. bold: xSnippetFont.attr('fontWeight') == 'bold' ? true : false,
  52. italic: xSnippetFont.attr('fontStyle') == 'italic' ? true : false,
  53. underline: xSnippetFont.attr('textDecoration') == 'underline' ? true : false,
  54. alignment: xSnippetFont.attr('textAlign'),
  55. font: xSnippetFont.attr('fontFamily'),
  56. color: BB.lib.colorToHex(BB.lib.decimalToHex(xSnippetFont.attr('fontColor'))),
  57. size: xSnippetFont.attr('fontSize')
  58. });
  59. },
  60.  
  61. /**
  62. Listen to new selection in clock mask radio button change
  63. @method _listenClockMaskChange
  64. **/
  65. _listenClockMaskChange: function(){
  66. var self = this;
  67. self.m_clockMaskHandler = function(e){
  68. if (!self.m_selected)
  69. return;
  70. var radioValue = $(e.target).attr('value');
  71. var mask = BB.PepperHelper.getBlockBoilerplate(self.m_blockType).getDateTimeMask(radioValue);
  72. var domPlayerData = self._getBlockPlayerData();
  73. var xSnippet = $(domPlayerData).find('Clock');
  74. xSnippet.attr('clockMask',mask);
  75. self._setBlockPlayerData(domPlayerData, BB.CONSTS.NO_NOTIFICATION);
  76.  
  77. }
  78. $('input[type="radio"]',self.$el).on('change',self.m_clockMaskHandler);
  79. },
  80.  
  81. /**
  82. Listen to changes in font UI selection from Block property and take action on changes
  83. @method _listenFontSelectionChange
  84. **/
  85. _listenFontSelectionChange: function () {
  86. var self = this;
  87. BB.comBroker.listenWithNamespace(BB.EVENTS.FONT_SELECTION_CHANGED, self, function (e) {
  88. if (!self.m_selected || e.caller !== self.m_clockFontSelector)
  89. return;
  90. var config = e.edata;
  91. var domPlayerData = self._getBlockPlayerData();
  92. var xSnippet = $(domPlayerData).find('Clock');
  93. var xSnippetFont = $(xSnippet).find('Font');
  94.  
  95. config.bold == true ? xSnippetFont.attr('fontWeight', 'bold') : xSnippetFont.attr('fontWeight', 'normal');
  96. config.italic == true ? xSnippetFont.attr('fontStyle', 'italic') : xSnippetFont.attr('fontStyle', 'normal');
  97. config.underline == true ? xSnippetFont.attr('textDecoration', 'underline') : xSnippetFont.attr('textDecoration', 'none');
  98. xSnippetFont.attr('fontColor', BB.lib.colorToDecimal(config.color));
  99. xSnippetFont.attr('fontSize', config.size);
  100. xSnippetFont.attr('fontFamily', config.font);
  101. xSnippetFont.attr('textAlign', config.alignment);
  102. self._setBlockPlayerData(domPlayerData, BB.CONSTS.NO_NOTIFICATION);
  103. });
  104. },
  105.  
  106. /**
  107. Populate the common block properties panel, called from base class if exists
  108. @method _loadBlockSpecificProps
  109. @return none
  110. **/
  111. _loadBlockSpecificProps: function () {
  112. var self = this;
  113. self._populate();
  114. this._viewSubPanel(Elements.BLOCK_CLOCK_COMMON_PROPERTIES);
  115. },
  116.  
  117. /**
  118. Delete this block
  119. @method deleteBlock
  120. @params {Boolean} i_memoryOnly if true only remove from existance but not from msdb
  121. **/
  122. deleteBlock: function (i_memoryOnly) {
  123. var self = this;
  124. $('input[type="radio"]',self.$el).off('change',self.m_clockMaskHandler);
  125. BB.comBroker.stopListenWithNamespace(BB.EVENTS.FONT_SELECTION_CHANGED, self);
  126. self._deleteBlock(i_memoryOnly);
  127. }
  128. });
  129.  
  130. return BlockClock;
  131. });