Created
May 5, 2014 12:46
-
-
Save dwaligora/11535718 to your computer and use it in GitHub Desktop.
RemidnerCtrl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /********************* | |
| * ReminderNewCtrl | |
| *********************/ | |
| angular.module('ReminderApp') | |
| .controller('ReminderNewCtrl', function (_, $rootScope, $scope, $injector, UserRepository, ReminderRepository, flash, $navigate, notification) { | |
| $scope.$emit('LOADING'); | |
| $scope.UserRepository = UserRepository; | |
| $injector.invoke(function ($controller) { | |
| $controller('EditableController', {$scope: $scope, $rootScope: $rootScope, UserRepository: UserRepository}); | |
| }); | |
| $injector.invoke(function ($controller) { | |
| $controller('NewCtrl', {$scope: $scope, repository: ReminderRepository}); | |
| }); | |
| $scope.add = function() { | |
| /*jshint -W106 */ | |
| console.log($scope.object); | |
| /*jshint +W106 */ | |
| /*jshint -W014 */ | |
| var error = ReminderRepository.validate($scope.object); | |
| if (error) { | |
| notification.alert(error, null, 'Oops!', 'Ok', 'error'); | |
| return; | |
| } | |
| /*jshint +W014 */ | |
| $scope.$emit('LOADING'); | |
| ReminderRepository.create(_.clone($scope.object)).then(function(response) { | |
| if (600 === response.status) { | |
| $navigate.go('/calendar/day/' + $rootScope.currentDate, 'modal'); | |
| flash.success = 'Reminder was added successfully!'; | |
| } else if(603 === response.status) { | |
| notification.alert('Please fill out properly the form!', null, 'Oops!', 'Ok', 'error'); | |
| return; | |
| } | |
| $scope.$emit('UNLOADING'); | |
| }, function() { | |
| $scope.$emit('UNLOADING'); | |
| $navigate.go('/calendar/day/' + $rootScope.currentDate, 'modal'); | |
| notification.alert('Something terrible was happened. Please report this situation to your school admin!', null, 'Oops!', 'Ok', 'error'); | |
| return; | |
| }); | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment