Updates to Event Form

This commit is contained in:
Luke Vella 2015-01-19 13:18:27 +01:00
parent f776756798
commit e61ef151f6
43 changed files with 736 additions and 484 deletions

View file

@ -1,52 +1,35 @@
angular.module('rallly')
.controller('NewEventCtrl', function($scope, $http, $state, Event){
$(".nav-link").removeClass('active');
$(".nav-link[href='/']").addClass('active');
.controller('NewEventCtrl', function($scope, $http, $state, Event, ConfirmModal){
$scope.title = "Schedule a New Event";
$scope.description = "Fill in the form below to create your event and share it with your friends and colleagues.";
var showModal = function(title, message){
var modal = new ConfirmModal({
title : title || 'Not so fast!',
message : message || 'Make sure you fill in all the required fields and try again.',
cancelText : 'OK'
});
}
$scope.submit = function(){
$http.post('/api/event', $scope.event)
.success(function(event, status, headers, config){
$scope.event = event;
$scope.eventUrl = $state.href('event', {
id: $scope.event._id
}, {
absolute : true
});
// $state.go('event',{id : data.event._id});
})
.error(function(data, status, headers, config){
$scope.errors = data.errors;
})
}
$scope.clearDates = null
})
.directive('datepicker', function(){
return {
restrict : 'A',
require : 'ngModel',
link : function(scope, el, attrs, ngModel){
angular.element(el).datepicker({
multidate : true,
todayHighlight: true,
format : 'dd/mm/yyyy'
})
.on('changeDate', function(e){
var dates = e.dates;
dates.sort(function(a, b){
if (a.getTime() > b.getTime()) return true;
return false;
if ($scope.form.$valid){
$http.post('/api/event', $scope.event)
.success(function(event, status, headers, config){
$scope.event = event;
$scope.eventUrl = $state.href('event', {
id: $scope.event._id
}, {
absolute : true
});
ngModel.$setViewValue(dates, e);
})
.error(function(){
showModal('Uh oh!', 'There was an error creating your event. Please try again later.');
});
scope.clearDates = function(){
angular.element(el).datepicker('setDate', null)
};
scope.unsetDate = function(date){
angular.element(el).datepicker('setDates', scope.event.dates.filter(function(el){
return el != date;
}));
};
} else {
showModal();
}
}
$scope.clearDates = null
});