'use strict';

var HomeController = angular.module('home.controllers.home', [
    'system'
])
    .controller('HomeController', [
        '$scope',
        '$location',
        '$locale',
        '$timeout',
        'Config',
        '$route',
        'System',
        'Global',
        '$routeParams',
        '$route',
        'NavigationService',
        'PageService',
        'PageFactory',
        'ContentService',
        function ($scope, $location, $locale, $timeout, Config, System, Global, $route, $routeParams, NavigationService, PageService, PageFactory, ContentService) {
            $locale.id = "sr";
            $scope.ui = {};
          
            $scope.content = function (page) {
                ContentService.getEditPage(page.ID)
                   .then(function (data) {
                       $scope.content = data;
                       var id = $scope.content.ID;
                       if (id != null)
                       { $location.url('/contents/' + id + '/edit'); }
                       else
                       { $location.url('/contents/' + page.ID + '/create'); }
                   });
            };
               

            $scope.children = function (page, event) {
                if (!page.Children || page.Children.length == 0)
                    PageService.top({ parentId: page.ID })
                        .then(function (data) {
                            page.Children = page.Children || [];
                            page.Children.push(data.pages);
                        });
            };

        }
    ]);