'use strict';

var PageDetailsController = angular.module('pages.controllers.details', [
    'system'
])
    .controller('PageDetailsController', [
        '$scope',
        '$route',
        '$location',
        'System',
        'PageService',
        'ContentService',
        '$sce',
        function ($scope, $route, $location, System, PageService, ContentService,$sce) {
            var pageId = $route.current.params["id"];

            $scope.refresh = function() {
                ContentService.get(pageId)
                   .then(function (data) {
                       $scope.content = data;
                       System.Page.title($scope.content.Title);
                   });
            };

            $scope.renderHtml = function(html_code)
            {
                return $sce.trustAsHtml(html_code);
            };

            $scope.selectLibrary = function (tip) {
                if (tip != null)
                    $location.url('/documentst/' + tip);
                else
                    $location.url('/documentst');
            };

            $scope.selectLibraryJ = function (tip) {
                $location.url('/javnenabavke/' + tip);
            };

            $scope.selectLibraryG = function (tip) {
                $location.url('/sluzbeniglasnici/' + tip);
            };

            $scope.selectLibraryPristup = function (id) {
                $location.url('/documents?LibraryID=' + id);
            };

            $scope.selectLibraryZasjedanja = function (tip) {
                if (tip != null)
                    $location.url('/skupstinska/' + tip);
                else
                    $location.url('/documentst/');
            };

            $scope.refresh();
        }
    ]);