I've got an event to delete intern messages in my app : a button in front, with a click event who call a method. Everything works fine.
But before the call of the method, I'd like a confirm box "Are you sure you want to delete this message ?"
With the standard confirm js function, works fine. But the standard js confirmbox... No styling allowed.
So my idea was to use sweetalert : everything go well, the berts notifications as well, but no message is deleted..
Below my event, confirm box version & sweetalert version, and the method.
Thanks!
confirm box version
Template.Users.events({
'click .toggle-admin': function() {
Meteor.call('toggleAdmin', this._id);
},
'click button.delete-message':function() {
if(confirm('Are you sure?')) {
Meteor.call('deleteMessage', this._id, function(error) {
if(error) {
Bert.alert({
title: 'Error',
message: error.reason,
type: 'danger'
});
} else {
Bert.alert({
title: 'Success',
message: 'Message deleted.',
type: 'success'
});
}
});
}
}
});
sweetalert version
Template.Users.events({
'click .toggle-admin': function() {
Meteor.call('toggleAdmin', this._id);
},
'click button.delete-message':function() {
swal({
title: "Are you sure?",
text: "You will not be able to recover this message!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!"
}).then(function (){
Meteor.call('deleteMessage', this._id, function(error) {
if(error) {
Bert.alert({
title: 'Error',
message: error.reason,
type: 'danger'
});
} else {
Bert.alert({
title: 'Success',
message: 'Message deleted.',
type: 'success'
});
}
});
})
}
});
method
Meteor.methods({
insertMessage: function(message) {
ContactMessages.insert(message);
},
deleteMessage: function(messageId) {
ContactMessages.remove({_id: messageId});
}
});