APIs

Show:
  1. /**
  2. * Image block resides inside a scene or timeline
  3. * @class BlockImage
  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 BlockImage = Block.extend({
  13.  
  14. /**
  15. Constructor
  16. @method initialize
  17. **/
  18. constructor: function (options) {
  19. var self = this;
  20. self.m_blockType = 3130;
  21. _.extend(options, {blockType: self.m_blockType})
  22. Block.prototype.constructor.call(this, options);
  23. self._initSubPanel(Elements.BLOCK_IMAGE_COMMON_PROPERTIES);
  24. self._listenInputChange();
  25. self._initResourcesData();
  26. },
  27.  
  28. /**
  29. Set the instance resource data from msdb which includes resource_id (handle of a resource)
  30. as well as the description of the resource and icon.
  31. @method _initResourcesData
  32. **/
  33. _initResourcesData: function () {
  34. var self = this;
  35. var domPlayerData = self._getBlockPlayerData();
  36. var xSnippet = $(domPlayerData).find('Resource');
  37. self.m_resourceID = $(xSnippet).attr('hResource');
  38. self.m_nativeID = pepper.getResourceNativeID(self.m_resourceID);
  39. if (_.isNull(self.m_nativeID)) {
  40. self._selfDestruct();
  41. return;
  42. }
  43. self.m_blockName = pepper.getResourceRecord(self.m_resourceID).resource_name;
  44. self.m_blockDescription = pepper.getResourceName(self.m_resourceID);
  45. self.m_fileFormat = pepper.getResourceType(self.m_resourceID);
  46. self.m_blockFontAwesome = BB.PepperHelper.getFontAwesome(self.m_fileFormat);
  47. },
  48.  
  49. /**
  50. Populate the common block properties panel, called from base class if exists
  51. @method _loadBlockSpecificProps
  52. @return none
  53. **/
  54. _loadBlockSpecificProps: function () {
  55. var self = this;
  56. self._populate();
  57. this._viewSubPanel(Elements.BLOCK_IMAGE_COMMON_PROPERTIES);
  58. },
  59.  
  60. /**
  61. Update common property title element
  62. @method _updateTitle override
  63. @return none
  64. **/
  65. _updateTitle: function () {
  66. var self = this;
  67. $(Elements.SELECTED_CHANNEL_RESOURCE_NAME).text(self.m_blockDescription);
  68. },
  69.  
  70. /**
  71. When user changes a URL link for the feed, update the msdb
  72. @method _listenInputChange
  73. @return none
  74. **/
  75. _listenInputChange: function () {
  76. var self = this;
  77. self.m_inputChangeHandler = function () {
  78. if (!self.m_selected)
  79. return;
  80. var aspectRatio = $(Elements.IMAGE_ASPECT_RATIO + ' option:selected').val() == "on" ? 1 : 0;
  81. var domPlayerData = self._getBlockPlayerData();
  82. var xSnippet = $(domPlayerData).find('AspectRatio');
  83. $(xSnippet).attr('maintain', aspectRatio);
  84. self._setBlockPlayerData(domPlayerData, BB.CONSTS.NO_NOTIFICATION);
  85. };
  86. $(Elements.IMAGE_ASPECT_RATIO).on('change', self.m_inputChangeHandler);
  87. },
  88.  
  89. /**
  90. Load up property values in the common panel
  91. @method _populate
  92. @return none
  93. **/
  94. _populate: function () {
  95. var self = this;
  96. var domPlayerData = self._getBlockPlayerData();
  97. var xSnippet = $(domPlayerData).find('AspectRatio');
  98. var aspectRatio = xSnippet.attr('maintain') == '1' ? 'on' : 'off';
  99. $(Elements.IMAGE_ASPECT_RATIO + ' option[value="' + aspectRatio + '"]').prop("selected", "selected");
  100. },
  101.  
  102. /**
  103. Convert the block into a fabric js compatible object
  104. @Override
  105. @method fabricateBlock
  106. **/
  107. fabricateBlock: function (i_canvasScale, i_callback) {
  108. var self = this;
  109.  
  110. var domPlayerData = self._getBlockPlayerData();
  111. var layout = $(domPlayerData).find('Layout');
  112. var businessID = pepper.getUserData().businessID;
  113. var elemID = _.uniqueId('imgElemrand')
  114. var imgPath;
  115.  
  116. if (self.m_fileFormat == 'swf') {
  117. imgPath = './_assets/flash.png';
  118. } else {
  119. /*
  120. if (platform.name == 'Chrome') {
  121. // CDN
  122. imgPath = window.g_protocol + 's3.signage.me/business' + pepper.getUserData().businessID + '/resources/';
  123. imgPath = 'https://s3.signage.me/business' + pepper.getUserData().businessID + '/resources/';
  124. imgPath += +self.m_nativeID + '.' + self.m_fileFormat;
  125. } else {
  126. // Legacy
  127. imgPath = window.g_protocol + pepper.getUserData().domain + '/Resources/business' + pepper.getUserData().businessID + '/resources/' + self.m_nativeID + '.' + self.m_fileFormat;
  128. }
  129. */
  130. imgPath = window.g_protocol + pepper.getUserData().domain + '/Resources/business' + pepper.getUserData().businessID + '/resources/' + self.m_nativeID + '.' + self.m_fileFormat;
  131. // log('loading img from ' + imgPath);
  132. }
  133.  
  134. var initImage = function (i_image, i_passed) {
  135. if (!i_passed){
  136. i_callback();
  137. return;
  138. }
  139. $(i_image).width(1000).height(800).appendTo('body');
  140. var options = self._fabricateOptions(parseInt(layout.attr('y')), parseInt(layout.attr('x')), parseInt(layout.attr('width')), parseInt(layout.attr('height')), parseInt(layout.attr('rotation')));
  141. var img = new fabric.Image(i_image, options);
  142. _.extend(self, img);
  143. self._fabricAlpha(domPlayerData);
  144. self._fabricLock();
  145. self['canvasScale'] = i_canvasScale;
  146. i_callback();
  147. };
  148.  
  149. // manage errors of resources which don't load
  150. $('<img src="' + imgPath + '" style="display: none" >').load(function () {
  151. initImage(this, true);
  152. }).error(function () {
  153. initImage(this, false);
  154. })
  155. },
  156.  
  157. /**
  158. Get the resource id of the embedded resource
  159. @method getResourceID
  160. @return {Number} resource_id;
  161. **/
  162. getResourceID: function () {
  163. var self = this;
  164. return self.m_resourceID;
  165. },
  166.  
  167. /**
  168. Delete this block
  169. @method deleteBlock
  170. @params {Boolean} i_memoryOnly if true only remove from existance but not from msdb
  171. **/
  172. deleteBlock: function (i_memoryOnly) {
  173. var self = this;
  174. $(Elements.IMAGE_ASPECT_RATIO).off('change', self.m_inputChangeHandler);
  175. self._deleteBlock(i_memoryOnly);
  176. }
  177. });
  178.  
  179. return BlockImage;
  180. });