Skip to content

Instantly share code, notes, and snippets.

@dwaligora
Created May 5, 2014 12:46
Show Gist options
  • Select an option

  • Save dwaligora/11535718 to your computer and use it in GitHub Desktop.

Select an option

Save dwaligora/11535718 to your computer and use it in GitHub Desktop.
RemidnerCtrl
/*********************
* 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