angular .module('EssayApp.controllers') .controller('ContactsController', ['$scope', '$window', 'checkAuthService', 'dataService', 'ngProgress', 'contactService', ($scope, $window, checkAuthService, dataService, ngProgress, contactService) -> # Load data from server $scope.auth = checkAuthService $scope.dataService = dataService $scope.user = $scope.auth.user() $scope.contactService = contactService $scope.data = STATE: DEFAULT: 'default' PENDING: 'pending' SUCCESS: 'success' feedback_reasons: [] show_agreement_popup: false reason: null $scope.data.state = $scope.data.STATE.DEFAULT dataService.get_feedback_reasons() .then (responce)-> $scope.data.feedback_reasons = responce.data , (_err)-> $scope.data.feedback_reasons = [] $scope.customer = {} # DEV window.cuc = $scope $scope.ifState = (state) -> state && state == $scope.data.state $scope.setState = (state) -> $scope.data.state = state if state $scope.$watch 'auth.current_user', (user) -> if user $scope.user = user $scope.resetForm = -> $scope.customer = {} $scope.setState($scope.data.STATE.DEFAULT) $scope.submit = (e, form) -> e?.preventDefault() window.fff = form form.$setSubmitted() if form.$valid ngProgress.start() $scope.customer.reason_id = $scope.data.reason?.id # DEV contactService.send_feedback($scope.customer).then( ((success) -> console.log 'success', success form.$submitted = false setTimeout -> $scope.setState($scope.data.STATE.SUCCESS) ngProgress.complete() ), ((fail) -> console.log 'fail', fail ) ) # accountService.registration({ customer: data }) # .success (data) -> # ngProgress.complete() # if data && data.customer # $window.location.replace(data.customer.url) # .error (data) -> # $scope.errors = data?.errors # # form.$setSubmitted() # ngProgress.complete() return false return $scope ])