(function () { 'use strict'; angular .module('messages.admin') .controller('AdminMessageController', AdminMessageController); AdminMessageController.$inject = ['$scope', '$state', '$translate', '$timeout', 'Authentication', '$filter', 'NotifycationService', '$stateParams', 'MessagesService', 'MeanTorrentConfig', 'ModalConfirmService', 'marked', '$rootScope']; function AdminMessageController($scope, $state, $translate, $timeout, Authentication, $filter, NotifycationService, $stateParams, MessagesService, MeanTorrentConfig, ModalConfirmService, marked, $rootScope) { var vm = this; vm.messageConfig = MeanTorrentConfig.meanTorrentConfig.messages; vm.user = Authentication.user; vm.messageType = 'system'; /** * If user is not signed in then redirect back home */ if (!Authentication.user) { $state.go('authentication.signin'); } /** * sendMessage * @param isValid */ vm.sendMessage = function (isValid) { if (!isValid) { $scope.$broadcast('show-errors-check-validity', 'vm.messageForm'); return false; } var msg = new MessagesService(vm.messageFields); msg.type = vm.messageType; msg.$save(function (response) { successCallback(response); }, function (errorResponse) { errorCallback(errorResponse); }); function successCallback(res) { vm.messageFields = {}; $scope.$broadcast('show-errors-reset', 'vm.messageForm'); NotifycationService.showSuccessNotify('MESSAGE_SEND_SUCCESSFULLY'); $state.go('messages.send', {reload: true, to: undefined}); } function errorCallback(res) { NotifycationService.showErrorNotify(res.data.message, 'MESSAGE_SEND_FAILED'); } }; } }());