'use strict';

var NewsletterAddController = angular.module('newsletters.controllers.newsletteradd', [
    'system'
])
    .controller('NewsletterAddController', [
        '$scope',
        '$location',
        '$route',
        'System',
        'NewslettersService',
        function ($scope, $location, $route, System, NewslettersService) {
            PageTitle.setTitle("Registracija");
 
            $scope.Newsletter = {};

            $scope.SaveAndPublish = function () {  
                $scope.newsletter.status = 5;
                NewslettersService.create($scope.newsletter).then(function (response) {
                    if (response.Errors) {
                        $scope.errors = response.Errors;
                        System.Message.error($scope.$resource('newsletters.NewsletterCreatedError'));
                    } else {
                        $location.url('/newsletters');
                        System.Message.success($scope.$resource('newsletters.NewsletterCreated'));
                    }
                });
            };

            $scope.back = function () {
                $location.url('/newsletters');
            };

            $scope.Save = function () {
            };
        }
    ]);