APIs

Show:
  1. /**
  2. Property manager is a singleton class that manages all of the StackView element properties.
  3. If you select a block such as the Clock component, the property manager is responsible
  4. for loading the proper view stack for the selected element. Note that it is the job of the caller
  5. to populate the view stack with the appropriate data.
  6. The property manager is also capable of managing common properties which are used for blocks.
  7. For example, all blocks (QR, RSS etc) have a border color, the property value for the border will appear
  8. in the sub-panel via the BlockProperties (m_subViewStack) which co-resides inside the PropertiesView module.
  9. @class PropertiesView
  10. @constructor
  11. @param {string} i_elementID is the the main property HTML ID (div element).
  12. @return {object} CompProperty instance.
  13. **/
  14. define(['jquery', 'backbone', 'StackView'], function ($, Backbone, StackView) {
  15.  
  16. /**
  17. Even is fired when Side properties panel changed in size
  18. @event SIDE_PANEL_SIZED
  19. @param {This} caller
  20. @param {Self} context caller
  21. @param {Event}
  22. @static
  23. @final
  24. **/
  25. BB.EVENTS.SIDE_PANEL_SIZED = 'SIDE_PANEL_SIZED';
  26.  
  27. BB.SERVICES.PROPERTIES_VIEW = 'PropertiesView';
  28.  
  29. var PropertiesView = BB.StackView.Fader.extend({
  30.  
  31. /**
  32. Constructor
  33. @method initialize
  34. **/
  35. initialize: function () {
  36. var self = this;
  37.  
  38. BB.StackView.ViewPort.prototype.initialize.call(this);
  39. BB.comBroker.listen(BB.EVENTS.APP_SIZED, self._reconfigPropPanelLocation);
  40. BB.comBroker.listen(BB.EVENTS.APP_SIZED, self._reConfigPropPanelIcon);
  41.  
  42. this.m_subViewStack = new StackView.Fader({el: Elements.BLOCK_SUBPROPERTIES}); // Block specific properties
  43. this.m_blockCommonSettingsViewStack = new StackView.Fader({el: Elements.BLOCK_COMMON_SETTINGS}); // Block specific settings, like used in JSON components
  44. this.m_selectedPanelID = undefined;
  45. this.m_selectedSubPanelID = undefined;
  46. this.m_selectedCommonSettingsPanelID = undefined;
  47.  
  48. this._listenClickSlidingPanel();
  49. this._listenGlobalOpenProps();
  50. },
  51.  
  52. /**
  53. Change the icon of the open properties panel button so it reflects full screen vs
  54. right side panel properties inspection
  55. @method _reConfigPropPanelIcon
  56. **/
  57. _reConfigPropPanelIcon: function () {
  58. var self = this;
  59. var layoutRouter = BB.comBroker.getService(BB.SERVICES.LAYOUT_ROUTER);
  60.  
  61. if (layoutRouter.getAppWidth() < 768) {
  62. $(Elements.TOGGLE_PANEL + ' > span').removeClass('glyphicon-resize-horizontal');
  63. $(Elements.TOGGLE_PANEL + ' > span').addClass('glyphicon-cog');
  64. $(Elements.TOGGLE_PANEL).addClass('headerPropIcon');
  65. } else {
  66. $(Elements.TOGGLE_PANEL + ' > span').removeClass('glyphicon-cog');
  67. $(Elements.TOGGLE_PANEL + ' > span').addClass('glyphicon-resize-horizontal');
  68. $(Elements.TOGGLE_PANEL).removeClass('headerPropIcon');
  69. }
  70. },
  71.  
  72. /**
  73. Listen for open/close actions on properties panel that can slide in and out
  74. @method _listenClickSlidingPanel
  75. **/
  76. _listenClickSlidingPanel: function () {
  77. var self = this;
  78. $(Elements.TOGGLE_PANEL).on('click', function () {
  79. self._announcePanelSized();
  80. self._reConfigPropPanelIcon();
  81. if ($(Elements.TOGGLE_PANEL).hasClass('propPanelIsOpen')) {
  82. $(Elements.TOGGLE_PANEL).toggleClass('propPanelIsOpen');
  83. // $(Elements.PROP_PANEL_WRAP).fadeOut(function () {
  84. $(Elements.PROP_PANEL_WRAP).addClass('hidden-sm hidden-md');
  85. $(Elements.MAIN_PANEL_WRAP).removeClass('col-sm-9 col-md-9');
  86. $(Elements.MAIN_PANEL_WRAP).addClass('col-md-12');
  87. // });
  88. } else {
  89. $(Elements.TOGGLE_PANEL).toggleClass('propPanelIsOpen');
  90. $(Elements.MAIN_PANEL_WRAP).addClass('col-sm-9 col-md-9');
  91. setTimeout(function () {
  92. $(Elements.PROP_PANEL_WRAP).hide();
  93. $(Elements.MAIN_PANEL_WRAP).removeClass('col-md-12');
  94. $(Elements.PROP_PANEL_WRAP).removeClass('hidden-sm hidden-md');
  95. $(Elements.PROP_PANEL_WRAP).fadeIn('fast');
  96. // $(Elements.PROP_PANEL_WRAP).children().fadeIn();
  97. }, 500)
  98. }
  99. });
  100. },
  101.  
  102. /**
  103. Announce that the side properties panel has changed in size
  104. @method _announcePanelSized
  105. **/
  106. _announcePanelSized: function(){
  107. var self = this;
  108. setTimeout(function(){
  109. BB.comBroker.fire(BB.EVENTS.SIDE_PANEL_SIZED,self,self);
  110. },400);
  111.  
  112. },
  113.  
  114. /**
  115. Move properties panel between side panel or full screen popup panel depending on the screen size
  116. @method _reconfigPropPanelLocation
  117. **/
  118. _reconfigPropPanelLocation: function () {
  119. var self = this;
  120. var layoutRouter = BB.comBroker.getService(BB.SERVICES.LAYOUT_ROUTER);
  121. if (layoutRouter.getAppWidth() > 768) {
  122. $(Elements.PROP_PANEL_WRAP).append($(Elements.PROP_PANEL));
  123. } else {
  124. $(Elements.POPUP_PROPERTIES).append($(Elements.PROP_PANEL));
  125. }
  126. },
  127.  
  128. /**
  129. Open global properties button hook via popup
  130. @method _listenGlobalOpenProps
  131. **/
  132. _listenGlobalOpenProps: function () {
  133. var self = this;
  134. $(Elements.TOGGLE_PANEL).on('click', function () {
  135. var layoutRouter = BB.comBroker.getService(BB.SERVICES.LAYOUT_ROUTER);
  136. if (layoutRouter.getAppWidth() < 768) {
  137. self.openPropertiesPanel();
  138. }
  139. });
  140. },
  141.  
  142. /**
  143. Load the requested panel into the current viewstack (i.e.: hide all other panels).
  144. @method viewPanel
  145. @param {String} i_panelID html element id of panel to load into current viewstack.
  146. **/
  147. viewPanel: function (i_panelID) {
  148. var self = this;
  149. self.m_selectedPanelID = i_panelID;
  150. self.selectView(i_panelID);
  151. },
  152.  
  153. /**
  154. Load the requested sub panel into the current viewstack (i.e.: hide all other panels).
  155. @method viewSubPanel
  156. @param {String} i_panelID html element id of sub panel to load into current view stack.
  157. **/
  158. viewSubPanel: function (i_panelID) {
  159. var self = this;
  160. // var index = self.m_subPanels[i_panelID];
  161. self.m_subViewStack.selectView(i_panelID);
  162. self.m_selectedSubPanelID = i_panelID;
  163. },
  164.  
  165. /**
  166. Load the requested sub panel for the block settings (used mostly for JSON shared components)
  167. @method viewSettingsPanel
  168. @param {String} i_panelID html element id of sub panel to load into current view stack.
  169. **/
  170. viewSettingsPanel: function (i_panelID) {
  171. var self = this;
  172. self.m_blockCommonSettingsViewStack.selectView(i_panelID);
  173. self.m_selectedCommonSettingsPanelID = i_panelID;
  174. },
  175.  
  176. /**
  177. Init the properties panel and add it to the viewstack.
  178. @method initPanel
  179. @param {String} i_panelID the html element id to be inserted into properties panel
  180. @return {Boolean} returns true if panel created, or false if it already existed so nothing was done.
  181. **/
  182. initPanel: function (i_panelID) {
  183. var self = this;
  184. if (self.getViewByID(i_panelID) != undefined)
  185. return false;
  186. var view = new BB.View({el: i_panelID});
  187. self.addView(view);
  188. return true;
  189. },
  190.  
  191. /**
  192. Init the properties sub-panel and add it to the view stack.
  193. @method initSubPanel
  194. @param {String} i_panelID the html element id to be inserted into sub properties panel
  195. @return {Boolean} returns true if panel created, or false if it already existed so nothing was done
  196. **/
  197. initSubPanel: function (i_panelID) {
  198. var self = this;
  199. if (self.m_subViewStack.getViewByID(i_panelID) != undefined)
  200. return false;
  201. var view = new BB.View({el: i_panelID});
  202. self.m_subViewStack.addView(view);
  203. return true;
  204. },
  205.  
  206. /**
  207. Init the properties sub-panel for block settings view stack.
  208. @method initSettingsPanel
  209. @param {String} i_panelID the html element id to be inserted into sub properties panel
  210. @return {Boolean} returns true if panel created, or false if it already existed so nothing was done
  211. **/
  212. initSettingsPanel: function (i_panelID) {
  213. var self = this;
  214. if (self.m_blockCommonSettingsViewStack.getViewByID(i_panelID) != undefined)
  215. return false;
  216. var view = new BB.View({el: i_panelID});
  217. self.m_blockCommonSettingsViewStack.addView(view);
  218. return true;
  219. },
  220.  
  221. /**
  222. Open the properties panel (side or popup per screen size)
  223. @method openPropertiesPanel
  224. **/
  225. openPropertiesPanel: function () {
  226. var self = this;
  227. self._reconfigPropPanelLocation();
  228. self._reConfigPropPanelIcon();
  229. var layoutRouter = BB.comBroker.getService(BB.SERVICES.LAYOUT_ROUTER);
  230. if (layoutRouter.getAppWidth() > 768) {
  231. if ($(Elements.TOGGLE_PANEL).hasClass('propPanelIsOpen') == false) {
  232. $(Elements.TOGGLE_PANEL).trigger('click');
  233. }
  234. } else {
  235. var popModalView = BB.comBroker.getService(BB.SERVICES.POP_MODAL_VIEW);
  236. popModalView.selectView(Elements.POPUP_PROPERTIES);
  237. }
  238. },
  239.  
  240. /**
  241. Select the default properties view which is the Dashboard
  242. @method resetPropertiesView
  243. **/
  244. resetPropertiesView: function(){
  245. var self = this;
  246. this.selectView(Elements.DASHBOARD_PROPERTIES);
  247. return self;
  248. },
  249.  
  250. /**
  251. Get the property div total width which may vary, especially when in full popup mode vs left slide mode
  252. @method getPropWidth
  253. @return {Number} current width
  254. **/
  255. getPropWidth: function(){
  256. var layoutRouter = BB.comBroker.getService(BB.SERVICES.LAYOUT_ROUTER);
  257. if (layoutRouter.getAppWidth() > 768) {
  258. return $(Elements.PROP_PANEL_WRAP).outerWidth();
  259. } else {
  260. return layoutRouter.getAppWidth();
  261. }
  262. }
  263. });
  264.  
  265. return PropertiesView;
  266.  
  267. });
  268.  
  269.  
  270.  
  271.