'use strict'

app.controller('mainController', ['$scope', '$location', 'activitiesFactory', 'kendoSchedulerFactory',

    function ($scope, $location, activitiesFactory, kendoSchedulerFactory) {
        activitiesFactory.getSchoolName().
            success(function (data, status) {
                $scope.NomeEscola = data.SchoolName;
            })

        $scope.ShowActivityIndicator = false;

        var loadHorario = function () {
            $scope.ShowActivityIndicator = true;
            activitiesFactory.getAtividades()
                .success(function (data, status, headers) {

                    var tt = headers("date");

                    var options = kendoSchedulerFactory.getGUIOptions(data);

                    //options.views = [{ type: "day", selected: false }, { type: "week", selected: true }, { type: "month", selected: false }];

                    $("#horarioScheduler").kendoScheduler(options);
                    //$("#horarioScheduler .k-scheduler-toolbar").hide();

                    $scope.ShowActivityIndicator = false;
                })
            .error(function (data, status) {
                $scope.ShowActivityIndicator = false;
            });
        };

        loadHorario();

        $("#horarioScheduler").on("click", ".k-event", function (e) {
            var scheduler = $("#horarioScheduler").data("kendoScheduler");

            var event = scheduler.dataSource.getByUid($(e.currentTarget).attr("data-uid"));

            scheduler.view("day");
            scheduler.date(event.start);
        });
    }]);