'use strict';

/** 
 * @controller ContentCreateController
 * @property scope 
 * @property route
 * @property location
 * @property System
 * @property ContentService
 */

var ContentCreateController = angular.module('contents.controllers.create', [
    'system'
])
    .controller('ContentCreateController', [
        '$scope',
        '$location',
        '$route',
        'System',
        'ContentService',
        function ($scope, $location, $route, System, ContentService) {
            $scope.content = {};
            var pageid = $route.current.params["pageID"] || {};
            $(".tooltip").tooltip();


            $scope.create = function () {
                $scope.content.PageID = pageid;
                ContentService.create($scope.content).then(function (response) {
                    if (response.Errors) {
                        $scope.errors = response.Errors;
                        System.Message.error($scope.$resource("contents.created_error"));
                    } else {
                        $location.url('/pages');
                        System.Message.success($scope.$resource("contents.created_successfully"));
                    }
                });
            };

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