rallly/public/js/controllers/newevent.controller.js
2015-01-10 15:43:05 +01:00

65 lines
1.9 KiB
JavaScript

angular.module('rallly')
.controller('NewEventCtrl', function($scope, $http, $state){
$scope.event = {};
$scope.templates = {
modal : 'templates/modal.html'
};
$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;
console.log(data.errors);
})
}
$scope.clearDates = null
})
.directive('datepicker', function(){
return {
restrict : 'A',
require : 'ngModel',
link : function(scope, el, attrs, ngModel){
$(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;
});
ngModel.$setViewValue(dates, e);
});
scope.clearDates = function(){
$(el).datepicker('setDate', null)
};
scope.unsetDate = function(date){
$(el).datepicker('setDates', scope.event.dates.filter(function(el){
return el != date;
}));
};
}
}
})
.directive('rallly-error', function(){
return {
restrict : 'A',
scope: {
'message': '='
},
controller : function($scope){
console.log($scope.message);
}
}
});