1 /**
  2  * @namespace
  3  */
  4 var Ozone = Ozone ? Ozone : {};
  5 
  6 /**
  7  * @ignore
  8  * @namespace
  9  */
 10 Ozone.launcher = Ozone.launcher ? Ozone.launcher : {};
 11 
 12 (function() {
 13 
 14     var launchChannelName = "_WIDGET_LAUNCHER_CHANNEL";
 15 
 16     /**
 17      *  @deprecated Since OWF 3.7.0  You should use <a href="#.getInstance">Ozone.launcher.WidgetLauncher.getInstance</a>
 18      *  @constructor  widgetEventingController - Ozone.eventing.Widget object
 19      *  @param  {Ozone.eventing.Widget} [widgetEventingController] - widget eventing object which handles eventing for the widget
 20      *  @description This object is used launch other widgets.  To do so it requires a widgetEventingController
 21      *
 22      */
 23     Ozone.launcher.WidgetLauncher = function() {
 24         if (Ozone.launcher.WidgetLauncher.instance == null) {
 25             this.version = Ozone.version.owfversion + Ozone.version.widgetLauncher
 26 
 27             Ozone.launcher.WidgetLauncher.instance = this;
 28         }
 29 
 30         return Ozone.launcher.WidgetLauncher.instance;
 31     };
 32 
 33     Ozone.launcher.WidgetLauncher.prototype = {
 34 
 35       /**
 36        * @description launches a Widget based on the config
 37        * @param {Object} config object see example for structure
 38        * @param {Function} callback a function to be called once after the launchWidget is executed
 39        *
 40        * @example
 41        *
 42        * //Example for launching a widget
 43        * var widgetEventingController = Ozone.eventing.Widget.getInstance();
 44        * var widgetLauncher = Ozone.launcher.WidgetLauncher.getInstance(this.widgetEventingController);
 45        * var data = {
 46        *   channel: channel,
 47        *   message: message
 48        * };
 49        * var dataString = Ozone.util.toString(data);
 50        * widgetLauncher.launchWidget({
 51        *     universalName: 'universal name of widget to launch',  //universalName or guid maybe identify the widget to be launched
 52        *     guid: 'guid of widget to launch',
 53        *     title: 'title to replace the widgets title' the title will only be changed if the widget is opened.
 54        *     titleRegex: optional regex used to replace the previous title with the new value of title
 55        *     launchOnlyIfClosed: true, //if true will only launch the widget if it is not already opened.
 56        *                               //if it is opened then the widget will be restored
 57        *     data: dataString  //initial launch config data to be passed to a widget only if the widget is opened.  this must be a string
 58        * });
 59        *
 60        */
 61         launchWidget: function(config,callback) {
 62             //send message to launch a widget
 63 
 64             if (config.titleRegex != null && config.titleRegex instanceof RegExp) {
 65                 config.titleRegex = config.titleRegex.toString();
 66             }
 67 
 68             var jsonString = gadgets.json.stringify(config);
 69             gadgets.rpc.call('..', launchChannelName, callback, OWF.getIframeId(), jsonString);
 70         }
 71     };
 72 
 73     /**
 74      *  @constructor none
 75      *  @description Utility functions for a widget that has been launched
 76      *
 77      */
 78     Ozone.launcher.WidgetLauncherUtils = {
 79       /**
 80        * @description gets initial launch config data for this widget if it was just launched
 81        * @returns {Object} data object which contains initial information for the widget 
 82        * @example
 83        *
 84        * var launchConfig = Ozone.launcher.WidgetLauncherUtils.getLaunchConfigData();
 85        * if (launchConfig != null) {
 86        *   var data = Ozone.util.parseJson(launchConfig);  //in this example the data object has two fields: channel and message
 87        *   if (data != null) {
 88        *       //do something with the data
 89        *       scope.subscribeToChannel(data.channel);
 90        *       scope.addToGrid(null,data.message,data.channel);
 91        *   }
 92        * }
 93        *
 94        */
 95         getLaunchConfigData: function() {
 96             var launchConfig = null;
 97 
 98             //check for data in window.name
 99             var configParams = Ozone.util.parseWindowNameData();
100             if (configParams != null) {
101 
102                 //get launchConfig
103                 launchConfig = configParams.data;
104             }
105 
106             return launchConfig;
107         }
108     };
109 
110     /**
111      *  @description Retrieves Ozone.eventing.Widget Singleton instance. This object is used launch other widgets.
112      *  @example
113      *  this.widgetLauncher = Ozone.launcher.WidgetLauncher.getInstance(this.widgetEventingController);
114      */
115     Ozone.launcher.WidgetLauncher.getInstance = function() {
116         if (Ozone.launcher.WidgetLauncher.instance == null) {
117             Ozone.launcher.WidgetLauncher.instance = new Ozone.launcher.WidgetLauncher();
118         }
119         return Ozone.launcher.WidgetLauncher.instance;
120     };
121 
122 }());
123