'use strict';

/** 
 * @controller PageDetailsController
 * @property scope 
 * @property route
 * @property location
 * @property System
 * @property PageService
 * @property Resource
 */

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

            /**
            * @method update
            * @param page
            * @description PageService updates Page data after successful edit
            */
            $scope.update = function() {
                PageService.update($scope.page)
                    .then(function(data) {
                        $scope.page = data;
                    });
            };

            /**
            * @method refresh
            * @description Gets initial data
            */
            $scope.refresh = function() {
                PageService.get(id)
                    .then(function(data) {
                        $scope.page = data;
                    });
            };

            /**
             * @action back returns to location /pages
             */
            $scope.back = function() {
                $location.url('/pages');
            };

            $scope.refresh();

        }
    ]);