src/js/init.js
branchpopcorn-port
changeset 811 b9dd62e35e30
parent 810 85a278e12495
child 816 e97e22801146
equal deleted inserted replaced
810:85a278e12495 811:b9dd62e35e30
   148   
   148   
   149   var ret_widgets = [];
   149   var ret_widgets = [];
   150   var index;
   150   var index;
   151   
   151   
   152   for (index = 0; index < guiOptions.widgets.length; index++) {    
   152   for (index = 0; index < guiOptions.widgets.length; index++) {    
   153     var widgetConfig = IriSP.underscore.defaults(guiOptions.widgets[index], default_options);
   153     var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, guiOptions.widgets[index], default_options);
   154     var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig);
       
   155    
   154    
   156     ret_widgets.push(widget);   
   155     ret_widgets.push(widget);   
   157   };
   156   };
   158 
   157 
   159   return ret_widgets;
   158   return ret_widgets;
   183     dependencies.
   182     dependencies.
   184     @param popcornInstance popcorn instance the widget will user
   183     @param popcornInstance popcorn instance the widget will user
   185     @param serialFactory serializer factory to instantiate the widget with
   184     @param serialFactory serializer factory to instantiate the widget with
   186     @param layoutManager layout manager
   185     @param layoutManager layout manager
   187     @param widgetConfig configuration options for the widget
   186     @param widgetConfig configuration options for the widget
       
   187     @param defaultOptions a dictionnary with some options defined for every widget.
   188  */
   188  */
   189 IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) {
   189 IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig, defaultOptions) {
       
   190 
       
   191     if (IriSP.null_or_undefined(defaultOptions))
       
   192       defaultOptions = {};
       
   193     
       
   194     widgetConfig = IriSP.underscore.defaults(widgetConfig, defaultOptions);
   190 
   195 
   191     var arr = IriSP.jQuery.extend({}, widgetConfig);
   196     var arr = IriSP.jQuery.extend({}, widgetConfig);
   192     
   197     
   193     /* create a div for those widgets who didn't already specify a container; */
   198     /* create a div for those widgets who didn't already specify a container; */
   194     if (!arr.hasOwnProperty("container")) {
   199     if (!arr.hasOwnProperty("container")) {
   214       // this.WidgetName (for instance, this.TipWidget);
   219       // this.WidgetName (for instance, this.TipWidget);
   215       
   220       
   216       var i = 0;
   221       var i = 0;
   217       for(i = 0; i < widgetConfig.requires.length; i++) {
   222       for(i = 0; i < widgetConfig.requires.length; i++) {
   218         var widgetName = widgetConfig.requires[i]["type"];
   223         var widgetName = widgetConfig.requires[i]["type"];
   219         widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[i]);
   224         widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[i], defaultOptions);
   220       }
   225       }
   221     }       
   226     }       
   222      
   227      
   223     serializer.sync(IriSP.wrap(widget, function() { this.draw(); }));
   228     serializer.sync(IriSP.wrap(widget, function() { this.draw(); }));
   224     return widget;
   229     return widget;