src/js/init.js
branchpopcorn-port
changeset 171 158f0193ec54
parent 158 1813e6e4f0d6
child 175 b0cb7132accb
equal deleted inserted replaced
170:5150ae56e0a6 171:158f0193ec54
    40 
    40 
    41   var ret_widgets = [];
    41   var ret_widgets = [];
    42   var index;
    42   var index;
    43   
    43   
    44   for (index = 0; index < guiOptions.widgets.length; index++) {    
    44   for (index = 0; index < guiOptions.widgets.length; index++) {    
    45     var widget = guiOptions.widgets[index];
    45     var widgetConfig = guiOptions.widgets[index];
    46     var container = layoutManager.createDiv();
    46     var widget = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig);
    47         
       
    48     var arr = IriSP.jQuery.extend({}, widget);
       
    49     arr.container = container;
       
    50 
       
    51     var serializer = serialFactory.getSerializer(widget.metadata);    
       
    52 
       
    53     // instantiate the object passed as a string
       
    54     var widget = new IriSP[widget.type](popcornInstance, arr, serializer);
       
    55     
       
    56     serializer.sync(IriSP.wrap(widget, function() { this.draw(); }));
       
    57     ret_widgets.push(widget);
    47     ret_widgets.push(widget);
    58    
    48    
    59   };
    49   };
    60 
    50 
    61   return ret_widgets;
    51   return ret_widgets;
    62 };
    52 };
       
    53 
       
    54 IriSP.instantiateWidget = function(popcornInstance, serialFactory, layoutManager, widgetConfig) {
       
    55     var container = layoutManager.createDiv();        
       
    56     var arr = IriSP.jQuery.extend({}, widget);
       
    57     arr.container = container;
       
    58 
       
    59     var serializer = serialFactory.getSerializer(widgetConfig.metadata);    
       
    60 
       
    61     // instantiate the object passed as a string
       
    62     var widget = new IriSP[widgetConfig.type](popcornInstance, arr, serializer);    
       
    63     
       
    64     if (widgetConfig.hasOwnProperty("requires")) {
       
    65       // also create the widgets this one depends on.
       
    66       // the dependency widget is available in the parent widget context as
       
    67       // this.WidgetName (for instance, this.TipWidget);
       
    68       
       
    69       for(var j in widgetConfig.requires) {
       
    70         var widgetName = widgetConfig.requires[j]["type"];
       
    71         widget[widgetName] = IriSP.instantiateWidget(popcornInstance, serialFactory, layoutManager, widgetConfig.requires[j]);
       
    72       }
       
    73     }
       
    74     
       
    75     serializer.sync(IriSP.wrap(widget, function() { this.draw(); }));
       
    76     return widget;
       
    77 };