'use strict';
/** 
 * @controller DocumentController
 * @property scope 
 * @property route
 * @property location
 * @property System
 * @property DocumentService
 */
angular.module('documents.controllers.document', [
    'system'
])
    .controller('DocumentController', [
        '$scope',
        '$route',
        '$location',
        'DocumentService',
        function ($scope, $route, $location, DocumentService) {
            
            $(".tooltip").tooltip();

            var id = $route.current.params["id"];

            /*Get document*/
            $scope.get = function() {
                DocumentService.download(id)
                    .then(function (data) {
                        $scope.document = data;
                        DocumentService.query({ libraryId: data.LibraryID }).then(function(response) {
                            $scope.documents = response.documents;
                        });
                       
                    });
            };

            /**
            *@action changeDocument
            *@description Open another document from current playlist.
            */
            $scope.changeDocument = function (documentId) {
                $location.url('/document/' + documentId);
            };
            
            /**
            *@action back
            *@description Back to document library.
            */
            $scope.back = function() {
                $location.url('/documents/' + $scope.document.LibraryID);
            };

            $scope.get();

        }
    ]);