APIs

Show:
  1. /**
  2. ScenesToolbarView Backbone > View
  3. @class ScenesToolbarView
  4. @constructor
  5. @return {Object} instantiated ScenesToolbarView
  6. **/
  7. define(['jquery', 'backbone'], function ($, Backbone) {
  8.  
  9. /**
  10. Indicates the scene canvas was selected
  11. @property BB.CONSTS.SCENE_CANVAS_SELECTED
  12. @static
  13. @final
  14. @type String
  15. */
  16. BB.CONSTS.SCENE_CANVAS_SELECTED = 'SCENE_CANVAS_SELECTED';
  17.  
  18. var ScenesToolbarView = Backbone.View.extend({
  19.  
  20. /**
  21. Constructor
  22. @method initialize
  23. **/
  24. initialize: function () {
  25. var self = this;
  26. BB.comBroker.setService(BB.SERVICES['SCENE_TOOLBAR_VIEW'], self);
  27. self.m_selectedSceneID = undefined;
  28. self._listenSceneSelection();
  29. self._listenGoBackSceneSelection();
  30. self._listenResourceRemoved();
  31. self._listenSceneItemSelection();
  32. self._listenSceneDimensionsChanged();
  33. self._listenAddNewItem();
  34. self._listenSceneRemoved();
  35. self._listenRemoves();
  36. self._listenZoom();
  37. self._listenPushToTop();
  38. self._listenScenePlayPreview();
  39. self._listenPushToBottom();
  40. self._listenSceneBlockList();
  41. self._listenMemento();
  42. },
  43.  
  44. /**
  45. Listen to changes in a new scene selection
  46. @method _listenSceneSelection
  47. **/
  48. _listenSceneSelection: function () {
  49. var self = this;
  50. BB.comBroker.listen(BB.EVENTS.LOAD_SCENE, function (e) {
  51. self.m_selectedSceneID = e.edata;
  52. });
  53. },
  54.  
  55. /**
  56. Listen to changes in the block list within a scene (canvas) and update the dropdown selection dialog
  57. @method _listenSceneBlockList
  58. **/
  59. _listenSceneBlockList: function () {
  60. BB.comBroker.listen(BB.EVENTS.SCENE_BLOCK_LIST_UPDATED, function (e) {
  61. var blocks = e.edata;
  62. $(Elements.SCENE_BLOCK_LIST).empty();
  63. if (blocks != null) {
  64. var snippet = '<li><a data-block_id="' + BB.CONSTS.SCENE_CANVAS_SELECTED + '" href="#">Canvas</a></li>';
  65. $(Elements.SCENE_BLOCK_LIST).append(snippet);
  66. }
  67. _.forEach(blocks, function (i_block) {
  68. var snippet = '<li><a data-block_id="' + i_block.id + '" href="#">' + i_block.name + '</a></li>';
  69. $(Elements.SCENE_BLOCK_LIST).append(snippet);
  70. });
  71. });
  72. },
  73.  
  74. /**
  75. Listen to re-order of screen division, putting selected on top
  76. @method _listenPushToTop
  77. **/
  78. _listenPushToTop: function () {
  79. var self = this;
  80. $(Elements.SCENE_EDITOR_PUSH_TOP, self.$el).on('click', function () {
  81. BB.comBroker.fire(BB.EVENTS.SCENE_PUSH_TOP);
  82. });
  83. },
  84.  
  85. /**
  86. Listen to live preview of scene
  87. @method _listenScenePlayPreview
  88. **/
  89. _listenScenePlayPreview: function () {
  90. var self = this;
  91. $(Elements.SCENE_PLAY_PREVIEW, self.$el).on('click', function () {
  92. var livePreview = BB.comBroker.getService(BB.SERVICES['LIVEPREVIEW']);
  93. if (_.isUndefined(self.m_selectedSceneID))
  94. return;
  95. livePreview.launchScene(self.m_selectedSceneID);
  96. });
  97. },
  98.  
  99. /**
  100. Listen to re-order of screen division, putting selected at bottom
  101. @method _listenPushToBottom
  102. **/
  103. _listenPushToBottom: function () {
  104. var self = this;
  105. $(Elements.SCENE_EDITOR_PUSH_BOTTOM, self.$el).on('click', function () {
  106. BB.comBroker.fire(BB.EVENTS.SCENE_PUSH_BOTTOM);
  107. });
  108. },
  109.  
  110. /**
  111. Listen to all zoom events via wiring the UI
  112. @method _listenZoom
  113. **/
  114. _listenZoom: function () {
  115. var self = this;
  116. $(Elements.SCENE_ZOOM_IN).on('click', function (e) {
  117. BB.comBroker.fire(BB.EVENTS.SCENE_ZOOM_IN);
  118. });
  119. $(Elements.SCENE_ZOOM_OUT).on('click', function (e) {
  120. BB.comBroker.fire(BB.EVENTS.SCENE_ZOOM_OUT);
  121. });
  122. $(Elements.SCENE_ZOOM_RESET).on('click', function (e) {
  123. BB.comBroker.fire(BB.EVENTS.SCENE_ZOOM_RESET);
  124. });
  125. },
  126.  
  127. /**
  128. Listen for undo and redo
  129. @method _listenMemento
  130. **/
  131. _listenMemento: function () {
  132. var self = this;
  133. $(Elements.SCENE_UNDO, self.el).on('click', function (e) {
  134. BB.comBroker.fire(BB.EVENTS.SCENE_UNDO, this, null);
  135. });
  136.  
  137. $(Elements.SCENE_REDO, self.el).on('click', function (e) {
  138. BB.comBroker.fire(BB.EVENTS.SCENE_REDO, this, null);
  139. });
  140. },
  141.  
  142. /**
  143. Listen to user selection a scene block / item
  144. @method _listenSceneItemSelection
  145. **/
  146. _listenSceneItemSelection: function () {
  147. var self = this;
  148. $(Elements.CLASS_SELECT_SCENE_ITEM_DROPDOWN, self.el).on('click', function (e) {
  149. var id = $(e.target).data('block_id');
  150. if (_.isUndefined(id))
  151. return;
  152. BB.comBroker.fire(BB.EVENTS.SCENE_ITEM_SELECTED, this, null, id);
  153. });
  154. },
  155.  
  156. /**
  157. Listen to event of scene dimensions changed
  158. @method _listenSceneDimensionsChanged
  159. @param {event} e
  160. **/
  161. _listenSceneDimensionsChanged: function () {
  162. var self = this;
  163. BB.comBroker.listen(BB.EVENTS['SCENE_BLOCK_DIMENSIONS_CHANGE'], function (e) {
  164. self._loadScene(e.edata)
  165. });
  166. },
  167.  
  168. /**
  169. Listen to removal of scene blocks
  170. @method _listenRemoves
  171. **/
  172. _listenRemoves: function () {
  173. var self = this;
  174. $(Elements.CLASS_SCENE_REMOVES, self.el).on('click', function (e) {
  175. BB.comBroker.fire(BB.EVENTS.SCENE_ITEM_REMOVE);
  176. });
  177. },
  178.  
  179. /**
  180. Listen to user selection of existing scene
  181. @method _listenAddNewItem
  182. **/
  183. _listenAddNewItem: function () {
  184. var self = this;
  185. $(Elements.CLASS_SCENE_ADD_NEW, self.el).on('click', function (e) {
  186. var sceneEditorView = BB.comBroker.getService(BB.SERVICES['SCENE_EDIT_VIEW']);
  187. var selectedSceneId = sceneEditorView.getSelectedSceneID()
  188. if (_.isUndefined(selectedSceneId)) {
  189. bootbox.alert({
  190. message: $(Elements.MSG_BOOTBOX_MUST_SELECT_SCENE).text()
  191. });
  192. return;
  193. }
  194. var sceneMime = BB.Pepper.getSceneMime(selectedSceneId);
  195. var addBlockView = BB.comBroker.getService(BB.SERVICES.ADD_SCENE_BLOCK_VIEW);
  196. addBlockView.setPlacement(BB.CONSTS.PLACEMENT_SCENE);
  197. addBlockView.setSceneMime(sceneMime);
  198. self.options.stackView.slideToPage(Elements.SCENE_ADD_NEW_BLOCK, 'right');
  199. });
  200. },
  201.  
  202. /**
  203. Listen go back to new scene selection
  204. @method _listenGoBackSceneSelection
  205. **/
  206. _listenGoBackSceneSelection: function () {
  207. var self = this;
  208. $(Elements.BACK_SCENE_SELECTION).on('click', function () {
  209. self._goBackToSceneSelection();
  210. });
  211. },
  212.  
  213. /**
  214. Listen to when a resource is removed
  215. @method _listenResourceRemoved
  216. **/
  217. _listenResourceRemoved: function () {
  218. var self = this;
  219. BB.comBroker.listen(BB.EVENTS.REMOVED_RESOURCE, function(e){
  220. self._goBackToSceneSelection();
  221. });
  222. },
  223.  
  224. /**
  225. Go back to the main scene selection screen
  226. @method _goBackToSceneSelection
  227. **/
  228. _goBackToSceneSelection: function(){
  229. var self = this;
  230. var sceneEditorView = BB.comBroker.getService(BB.SERVICES['SCENE_EDIT_VIEW']);
  231. sceneEditorView.disposeScene();
  232. self.options.stackView.slideToPage(Elements.SCENE_SELECTOR, 'left');
  233. },
  234.  
  235. /**
  236. Listen to scene removed
  237. @method _listenSceneRemoved
  238. **/
  239. _listenSceneRemoved: function(){
  240. var self = this;
  241. BB.comBroker.listen(BB.EVENTS['REMOVED_SCENE'], function (e) {
  242. self.m_selectedSceneID = undefined;
  243. });
  244. },
  245.  
  246. /**
  247. Load a selected Scene
  248. @method _loadScene
  249. @param {String} i_name
  250. @param {String} i_id
  251. **/
  252. _loadScene: function (i_id) {
  253. self.m_selectedSceneID = i_id;
  254. BB.comBroker.fire(BB.EVENTS.LOAD_SCENE, this, null, self.m_selectedSceneID);
  255. }
  256. });
  257.  
  258. return ScenesToolbarView;
  259. });
  260.  
  261.