﻿/*  This file has generic/customzed logic to create flux widget. 
*
*   for ex: to display only rating widget , we have to use 'ContentAction' widget
*   and customize it to get only rating feature. This file makes your life simple.
*   User has to just call the following function to get rating feature.
*
*   InvokeWidget('Rating','ContentUri'); 
*
********************************************************************/

// Invoke Flux widget with the given options.
InvokeWidget = function (widgetName,customOptions){
    // get widget options by it's name
    var widgetOptions = getOptionsByName(widgetName,customOptions);
    // get actual widget by the user given name. 
    var widgetName = getWidgetNameByName(widgetName);
    // this is the actual call with Flux to create widget

    if(typeof(Flux) != 'undefined'){
    Flux.createWidget(widgetName, widgetOptions);
    }
}
// Retreive widget options by widgetname.
var getOptionsByName = function(name,customOptions){
    var defaultOptions = null;
    var fluxContentUri = "";
    if(typeof(PC) != 'undefined'){
       fluxContentUri = PC.fluxContentUri;
    }
    switch(name){
        case 'QuickMenu' : defaultOptions = {}; return jQuery.extend(defaultOptions, customOptions);break;
        case 'Comments' : 
        //Flux.createWidget('Comments', { contentUri : 'http://localhost/Flux/NewArticle.htm',pageSize: 2 });   
        defaultOptions = {};
        defaultOptions.size = 'small';
        defaultOptions.contentUri = fluxContentUri;
        defaultOptions.pageSize = '8';
        return jQuery.extend(defaultOptions, customOptions);
        break;
        case 'CommentsCount' : 
        //Flux.createWidget('ContentAction', { contentUri: 'http://localhost/Flux/NewArticle.htm', 
        //layout: 'horizontal', size: 'large', items: [{ id: 'commentCount', title: '' }]    }); 
        defaultOptions = {};
        defaultOptions.size = 'small';
        defaultOptions.layout = 'horizontal';
        defaultOptions.contentUri = fluxContentUri;
        defaultOptions.items = [{ id: 'commentCount', title: '' }];
        return jQuery.extend(defaultOptions, customOptions);
        break;
        case 'Rating' :
        //Flux.createWidget('ContentAction', { contentUri: 'http://localhost/Flux/NewArticle.htm', 
        //layout: 'horizontal', size: 'small', 
        //items: [ { id: 'contentRating', title: { thumbsUpTitle: 'Rating', thumbsDownTitle: 'Rating' } },
        //{id: 'rate', title: 'Rate This Article' }] }); 
        defaultOptions = {};
        defaultOptions.size = 'small';
        defaultOptions.layout = 'horizontal';
        defaultOptions.contentUri = fluxContentUri;
        defaultOptions.items = [{ id: 'rate', title: 'Rate This Article' },{ id: 'contentRating', title: { thumbsUpTitle: 'Rating', thumbsDownTitle: 'Rating'}}];
        return jQuery.extend(defaultOptions, customOptions);
        break;
        case 'AddToFavorites' :
        //Flux.createWidget('ContentAction', { 
        //contentUri: 'http://localhost/Flux/NewArticle.htm', layout: 'horizontal',  size: 'small', 
        //items: [ { id: 'addToFavorites', title: 'Add to My Profile' }] }); 
        defaultOptions = {};
        defaultOptions.size = 'small';
        defaultOptions.layout = 'horizontal';
        defaultOptions.contentUri = fluxContentUri;
        defaultOptions.items = [ { id: 'addToFavorites', title: 'Add to My Profile' }];
        return jQuery.extend(defaultOptions, customOptions);
        break;
        case 'ContentAction' : 
        defaultOptions = {};
        defaultOptions.size = 'small';
        defaultOptions.layout = 'horizontal';
        defaultOptions.contentUri = fluxContentUri;
        return jQuery.extend(defaultOptions, customOptions);
        break;
        default : defaultOptions = {}; return defaultOptions; break;
    }
}
// Retreive actual widget to be used based on the widgetname given by user.
getWidgetNameByName = function (widgetName){
    switch(widgetName){
        case 'Rating' :
        case 'Usage' :
        case 'Statistics' :
        case 'Share' :
        case 'CommentsCount' :
        case 'AddToFavorites' :
        return 'ContentAction';
        break;
        default :
        return widgetName;
        break;
    }
}