Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gulp #15

Open
wants to merge 4 commits into
base: gulp
Choose a base branch
from
Open

Gulp #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ module.exports.initialize = function(app) {
app.get('/api/contacts/:id', contacts.getById);
app.post('/api/contacts', contacts.add);
app.put('/api/contacts', contacts.update);
app.delete('/api/contacts/:id', contacts.delete);
};
16 changes: 15 additions & 1 deletion client/src/views/contact_details.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,25 @@ var Marionette = require('backbone.marionette');
module.exports = ContactDetailsView = Marionette.ItemView.extend({
template: require('../../templates/contact_details.hbs'),
events: {
'click a': 'goBack'
'click a.back': 'goBack',
'click a.delete': 'deleteContact'
},

goBack: function(e) {
e.preventDefault();
window.App.controller.home();
},
deleteContact: function(e) {
e.preventDefault();
console.log('Deleting contact');

// this will actually send a DELETE to the server:
this.model.destroy({
success: function(model, response) {
window.App.data.contacts.remove(this.model);
}
});

window.App.controller.home();
}
});
2 changes: 1 addition & 1 deletion client/templates/contact_details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@

</div>

<a href="#"><< Back</a>
<a href="#" class="back"><< Back</a> | <a href="#" class="delete">Delete Contact</a>
11 changes: 11 additions & 0 deletions controllers/contacts.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,16 @@ module.exports = {
update: function(req, res) {
console.log(req.body);
res.json(req.body);
},
delete: function(req, res) {
models.Contact.findOne({ _id: req.params.id }, function(err, contact) {
if (err) {
res.json({error: 'Contact not found.'});
} else {
contact.remove(function(err, contact){
res.json(200, {status: 'Success'});
})
}
});
}
};