1 /**
  2  * @ignore
  3  */
  4 var Ozone = Ozone ? Ozone : {};
  5 
  6 /**
  7  * @ignore
  8  * @namespace
  9  */
 10 Ozone.state = Ozone.state ? Ozone.state : {};
 11 
 12 /**
 13  *  @deprecated Since OWF 3.7.0  You should use <a href="#.getInstance">Ozone.state.WidgetStateHandler.getInstance</a>
 14  *  @constructor  WidgetStateHandler - Handles eventing from OWF widget to OWF container
 15  *  @param  {Ozone.eventing.Widget} widgetEventingController - widget eventing object which handles eventing for the widget
 16  *  @description This object is used handle widget requests.  To do so it requires a widgetEventingController
 17  *
 18  */
 19 Ozone.state.WidgetStateHandler = function(widgetEventingController) {
 20   if (Ozone.state.WidgetStateHandler.instance == null) {
 21     this.stateChannelName = "_WIDGET_STATE_CHANNEL_";
 22     this.widgetEventingController = widgetEventingController || Ozone.eventing.Widget.instance;
 23     this.widgetIdJSON = Ozone.util.parseJson(this.widgetEventingController.getWidgetId());
 24     this.version = Ozone.version.owfversion + Ozone.version.widgetStateHandler
 25 
 26     Ozone.state.WidgetStateHandler.instance = this;
 27   }
 28 
 29   return Ozone.state.WidgetStateHandler.instance;
 30 };
 31 
 32 Ozone.state.WidgetStateHandler.prototype = {
 33 
 34   /**
 35    * @description handles a widget state request based on the config
 36    * @param {Object} config object see example for structure
 37    * @param {Function} callback a function to be called once after the stateWidget is executed
 38    *
 39    * @example
 40    *
 41    * //Example for closing a widget
 42    * var widgetEventingController = new Ozone.eventing.Widget(Ozone.util.contextPath() + '/js/eventing/rpc_relay.uncompressed.html');
 43    * var widgetStateHandler = new Ozone.state.WidgetStateHandler(this.widgetEventingController);
 44    * widgetStateHandler.handleStateRequest({
 45    *     fn: 'closeWidget',
 46    *     params: {
 47    *     	guid: <widgetGuid>
 48    *     }
 49    * });
 50    *
 51    */
 52 	handleWidgetRequest: function(config, callback) {
 53 
 54 		//send state request to a widget
 55 		var stateChannel = this.stateChannelName + this.widgetIdJSON.id;
 56 	    gadgets.rpc.call('..', stateChannel, callback, this.widgetIdJSON, config);	
 57 	}
 58 };
 59 
 60 /**
 61  *  @description Retrieves Ozone.eventing.Widget Singleton instance.
 62  *    This object is used handle widget requests.  To do so it requires a widgetEventingController
 63  *  @param  {Ozone.eventing.Widget} widgetEventingController - widget eventing object which handles eventing for the widget
 64  *  @example
 65  *  this.widgetStateHandler = Ozone.state.WidgetStateHandler.getInstance(this.widgetEventingController);
 66  */
 67 Ozone.state.WidgetStateHandler.getInstance = function(widgetEventingController) {
 68   if (Ozone.state.WidgetStateHandler.instance == null) {
 69     Ozone.state.WidgetStateHandler.instance = new Ozone.state.WidgetStateHandler(widgetEventingController);
 70   }
 71   return Ozone.state.WidgetStateHandler.instance;
 72 };
 73