Canceling Changes

This commit is contained in:
Luke Vella 2015-01-12 14:53:43 +01:00
parent aff8ee6124
commit 10c035e359
10 changed files with 47 additions and 16 deletions

View file

@ -19,6 +19,7 @@ exports.show = function(req, res, next){
}
exports.update = function(req, res){
req.body.updated = Date.now();
Event.update({ '_id' : req.params.id }, req.body, function(){
return res.status(204).end();
});
@ -29,6 +30,7 @@ exports.createParticipant = function(req, res, next){
var participant = req.body;
Event.findById(eventId, function(err, event){
if (err) return handleError(res, err);
event.updated = Date.now();
event.participants.push(participant);
event.save(function(err, event){
if (err) return next(err);
@ -42,6 +44,7 @@ exports.deleteParticipant = function(req, res, next){
var participantId = req.params.pid;
Event.findById(eventId, function(err, event){
if (err) return handleError(res, err);
event.updated = Date.now();
event.participants.pull({ '_id' : participantId });
event.save(function(err, event){
res.json(event);

View file

@ -10,6 +10,14 @@ var EventSchema = new Schema({
name : String,
email : String
},
created : {
type : Date,
default : Date.now
},
updated : {
type : Date,
default : Date.now
},
title : String,
dates : [Date],
emails : [String],

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -2,20 +2,25 @@ angular.module('rallly')
.controller('EventCtrl', function($scope, $http, $state, Event, Participant){
var id = $state.params.id;
$scope.event = Event.get({id:id});
$scope.deleteParticipant = function(participant){
$scope.delete = function(participant){
if (confirm("Are you sure you want to remove "+participant.name+"?")){
Participant.remove({ id : id , pid : participant._id }, function(event){
$scope.event = event;
});
}
}
$scope.edit = function(index){
}
$scope.defaults = [];
$scope.update = function(participant){
Event.update({'_id':$scope.event.id}, $scope.event);
}
$scope.edit = function(participant){
$scope.defaults[$scope.event.participants.indexOf(participant)] = angular.copy(participant);
}
$scope.cancel = function(index){
$scope.event.participants[index] = $scope.defaults[index];
}
$scope.save = function(participant){
var participant = new Participant(participant);

View file

@ -95,10 +95,10 @@
}
&.active {
background:white;
color: $red-clr;
color: $primary-clr;
&:after {
opacity:1;
background: rgba($red-clr,0.1);
background: rgba($primary-clr,0.1);
}
}
&:active {

View file

@ -22,10 +22,14 @@
padding: em(10px);
border-bottom:1px solid #ddd;
}
.event-poll-name {
padding: em(6px) em(11px);
display:inline-block;
}
.event-poll-user {
text-align:left;
font-size: em(14px);
padding: em(15px) em(10px);
padding: em(12px) em(10px);
img {
margin-right: 5px;
}
@ -39,6 +43,9 @@
}
}
}
.event-poll-input {
padding:0;
}
.event-poll-participants {
text-align:left;
padding:0 em(10px);

View file

@ -5,6 +5,7 @@
.form-success-url {
font-size: em(36px);
text-align:center;
padding: em(10px);
border-radius: 3px;
border: 1px solid #eee;
color: $text-clr;

View file

@ -5,6 +5,12 @@
<li class="event-created-by">
Created by <a href="{{event.creator.email}}">{{event.creator.name}}</a>
</li>
<li>
Created on {{event.created | date : 'short'}}
</li>
<li>
Last updated {{event.updated | date : 'short'}}
</li>
<li ng-show="event.location" class="event-location">
{{event.location}}
</li>
@ -37,7 +43,7 @@
</div>
</div>
</th>
<th>
<th width="160">
</th>
</tr>
@ -47,7 +53,7 @@
<td class="event-poll-user">
<img src="/images/user_gray@2x.png" width="11" />
<input type="text" class="form-control" ng-model="participant.name" ng-show="editMode" value="participant.name"/>
<span ng-hide="editMode">{{participant.name}}</span>
<span ng-hide="editMode" class="event-poll-name">{{participant.name}}</span>
</td>
<td class="center" ng-repeat="date in event.dates">
<img src="/images/tick@2x.png" width="16" ng-hide="editMode" ng-if="participant.dates[$index]" />
@ -55,9 +61,10 @@
<input ng-model="participant.dates[$index]" ng-show="editMode" ng-false-value="false" type="checkbox" />
</td>
<td>
<a ng-hide="editMode" href="javascript:" ng-click="editMode = true; edit($index)" class="btn btn-primary">Edit</a>
<a ng-show="editMode" href="javascript:" ng-click="editMode = false; update(participant)" class="btn btn-primary">Save</a>
<a ng-hide="editMode" href="javascript:" ng-click="editMode = true; edit(participant)" class="btn-primary">Edit</a>
<a ng-hide="editMode" href="javascript:" ng-click="delete(participant)" class="btn-primary">Delete</a>
<a ng-show="editMode" href="javascript:" ng-click="editMode = false; update(participant)" class="btn-primary">Save</a>
<a ng-show="editMode" href="javascript:" ng-click="editMode = false; cancel($index)" class="btn-primary">Cancel</a>
</td>
</tr>
<tr class="event-poll-input">