define(['jquery', 'underscore', 'backbone',
    'text!modules/statistics/statisticsViewTemplate.html',
    'text!modules/statistics/pieTabTemplate.html',
    'modules/base/baseView', 'controls/window/window', 'jqx'],
        function ($, _, Backbone, statisticsViewTemplate, pieTabTemplate, BaseView, Window) {

            var StatisticsView = BaseView.extend({
                dataAdapter: undefined,
                //initialize template
                template: _.template(statisticsViewTemplate),
                editorRicetta: null,
                initialize: function () {
                    StatisticsView.__super__.initialize.call(this);
                    //this.header.title = "pippo";
                },
                //render the content into div of view
                render: function () {
                    //this.header.title = "pippo";
                    StatisticsView.__super__.render.call(this);
                    var self = this;
                    var chartSettings = {
//                        source: new $.jqx.dataAdapter({
//                            datatype: "jsonp",
//                            datafields: [
//                                {name: 'CountSerie', type: 'int'},
//                                {name: 'Serie', type: 'string'}
//                            ],
//                            url: myManifest.Settings.DefaultURL + "/backend/statistics/gender"
//                        }),
                        title: '',
                        //description: "Genere",
                        enableAnimations: false,
                        showLegend: true,
                        showBorderLine: true,
                        padding: {left: 5, top: 5, right: 5, bottom: 5},
                        titlePadding: {left: 0, top: 0, right: 0, bottom: 10},
                        colorScheme: 'scheme03',
                        seriesGroups: [
                            {
                                type: 'pie',
                                showLegend: true,
                                enableSeriesToggle: true,
                                series:
                                        [
                                            {
                                                dataField: 'CountSerie',
                                                displayText: 'Serie',
                                                showLabels: true,
                                                labelRadius: 160,
                                                labelLinesEnabled: true,
                                                labelLinesAngles: true,
                                                labelsAutoRotate: false,
                                                initialAngle: 0,
                                                radius: 125,
                                                minAngle: 0,
                                                maxAngle: 180,
                                                centerOffset: 0,
                                                offsetY: 170
                                            }
                                        ]
                            }
                        ]
                    };
                    var window = new Window({
                        title: "Statistiche",
                        width: "850px",
                        resizable: true,
                        height: "510px",
                        maxHeight: 1000,
                        maxWidth: 1000,
                        content: _.template(pieTabTemplate),
                        initContentFn: function () {
                            chartSettings.source = new $.jqx.dataAdapter({
                                datatype: "jsonp",
                                datafields: [
                                    {name: 'CountSerie', type: 'int'},
                                    {name: 'Serie', type: 'string'}
                                ],
                                url: myManifest.Settings.DefaultURL + "/backend/statistics/gender"
                            });
                            chartSettings.title = "Genere";
                            $("#chartContainer1").jqxChart(chartSettings);
                            
                            chartSettings.source = new $.jqx.dataAdapter({
                                datatype: "jsonp",
                                datafields: [
                                    {name: 'CountSerie', type: 'int'},
                                    {name: 'Serie', type: 'string'}
                                ],
                                url: myManifest.Settings.DefaultURL + "/backend/statistics/typeAccess"
                            });
                            chartSettings.title = "Tipo Accessi";
                            $("#chartContainer2").jqxChart(chartSettings);
                            
                            chartSettings.source = new $.jqx.dataAdapter({
                                datatype: "jsonp",
                                datafields: [
                                    {name: 'CountSerie', type: 'int'},
                                    {name: 'Serie', type: 'string'}
                                ],
                                url: myManifest.Settings.DefaultURL + "/backend/statistics/themesUsage"
                            });
                            chartSettings.title = "Temi Usati";
                            $("#chartContainer3").jqxChart(chartSettings);
                        }
                    });
                    window.id = "statistics";

                    this.$el.append(this.template());
                    this.$el.find("#content").append(window.$el);
                    window.render();
                    return this;
                }
            });
            return StatisticsView;
        });