mirror of
https://github.com/lukevella/rallly.git
synced 2025-06-13 16:11:51 +02:00
Updated editing of event
This commit is contained in:
parent
6b1e9893e9
commit
bc1e25377c
16 changed files with 197 additions and 36 deletions
44
public/js/controllers/editevent.controller.js
Normal file
44
public/js/controllers/editevent.controller.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
angular.module('rallly')
|
||||
.controller('EditEventCtrl', function($scope, $http, $state, $timeout, Event){
|
||||
var id = $state.params.id
|
||||
$scope.event = Event.get({id:id}, function(data){
|
||||
var dates = [];
|
||||
for (var i = 0; i < data.dates.length; i++){
|
||||
dates.push(new Date(data.dates[i]));
|
||||
}
|
||||
$("[data-datepicker]").datepicker('setDates',dates);
|
||||
$scope.master = angular.copy($scope.event);
|
||||
}, function(e){
|
||||
$state.go('notfound');
|
||||
});
|
||||
$scope.didChange = function(){
|
||||
return JSON.stringify($scope.master) != JSON.stringify($scope.event);
|
||||
}
|
||||
$scope.didChangeDates = function(){
|
||||
return JSON.stringify($scope.master.dates) != JSON.stringify($scope.event.dates);
|
||||
}
|
||||
$scope.submit = function(){
|
||||
if ($scope.didChange()){
|
||||
if ($scope.didChangeDates() ){
|
||||
if (confirm("Changing the dates will reset all entries by the participants. Are you sure you want to proceed?")){
|
||||
update();
|
||||
}
|
||||
} else {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
var update = function(){
|
||||
$scope.event.participants = [];
|
||||
Event.update({
|
||||
id : id
|
||||
}, $scope.event,
|
||||
function(){
|
||||
$timeout.cancel($scope.didSave);
|
||||
$scope.master = angular.copy($scope.event);
|
||||
$scope.didSave = $timeout(function(){
|
||||
$scope.didSave = false;
|
||||
}, 2000);
|
||||
});
|
||||
}
|
||||
});
|
|
@ -2,7 +2,13 @@ angular.module('rallly')
|
|||
.controller('EventCtrl', function($scope, $http, $state, Event, Participant){
|
||||
$(".nav-link").removeClass('active');
|
||||
var id = $state.params.id;
|
||||
$scope.event = Event.get({id:id}, function(data){}, function(e){
|
||||
$scope.event = Event.get({id:id}, function(data){
|
||||
$scope.eventUrl = $state.href('event', {
|
||||
id: $scope.event._id
|
||||
}, {
|
||||
absolute : true
|
||||
});
|
||||
}, function(e){
|
||||
$state.go('notfound');
|
||||
});
|
||||
$scope.delete = function(participant){
|
||||
|
@ -14,6 +20,10 @@ angular.module('rallly')
|
|||
}
|
||||
$scope.defaults = [];
|
||||
|
||||
$scope.editEvent = function(){
|
||||
$state.go('editevent', { id : $scope.event._id });
|
||||
}
|
||||
|
||||
$scope.update = function(participant){
|
||||
Participant.update({
|
||||
id : $scope.event._id,
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
angular.module('rallly')
|
||||
.controller('NewEventCtrl', function($scope, $http, $state){
|
||||
.controller('NewEventCtrl', function($scope, $http, $state, Event){
|
||||
$(".nav-link[href='/']").addClass('active');
|
||||
$scope.event = {};
|
||||
$scope.isNewEvent = true;
|
||||
|
||||
$scope.submit = function(){
|
||||
$http.post('/api/event', $scope.event)
|
||||
.success(function(event, status, headers, config){
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue