mirror of
https://github.com/lukevella/rallly.git
synced 2025-07-29 22:27:25 +02:00
Added custom confirm modal dialog box
This commit is contained in:
parent
0320185ce5
commit
6ad493a079
31 changed files with 909 additions and 41 deletions
|
@ -1,5 +1,5 @@
|
|||
angular.module('rallly')
|
||||
.controller('EditEventCtrl', function($scope, $http, $state, $timeout, Event){
|
||||
.controller('EditEventCtrl', function($scope, $http, $state, $timeout, Event, ConfirmModal){
|
||||
var id = $state.params.id
|
||||
$scope.event = Event.get({id:id}, function(data){
|
||||
var dates = [];
|
||||
|
@ -20,16 +20,23 @@ angular.module('rallly')
|
|||
$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();
|
||||
}
|
||||
var modal = new ConfirmModal({
|
||||
title : 'Hold up!',
|
||||
message : 'Changing the dates will reset all entries by the participants. Are you sure you want to do that?',
|
||||
confirmText : 'Yes, I\'m sure',
|
||||
isDestructive : true,
|
||||
confirm : function(){
|
||||
update();
|
||||
}
|
||||
});
|
||||
modal.show();
|
||||
|
||||
} else {
|
||||
update();
|
||||
}
|
||||
}
|
||||
}
|
||||
var update = function(){
|
||||
$scope.event.participants = [];
|
||||
Event.update({
|
||||
id : id
|
||||
}, $scope.event,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
angular.module('rallly')
|
||||
.controller('EventCtrl', function($scope, $http, $state, Event, Participant){
|
||||
.controller('EventCtrl', function($scope, $http, $state, Event, Participant, ConfirmModal){
|
||||
$(".nav-link").removeClass('active');
|
||||
var id = $state.params.id;
|
||||
$scope.participant = {};
|
||||
|
@ -13,12 +13,21 @@ angular.module('rallly')
|
|||
$state.go('notfound');
|
||||
});
|
||||
$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;
|
||||
});
|
||||
}
|
||||
var modal = new ConfirmModal({
|
||||
title : 'Delete "'+participant.name+'"?',
|
||||
message : 'Are you sure you want to remove '+participant.name+' from the poll?',
|
||||
confirmText : 'Yes - delete',
|
||||
cancelText : 'No - nevermind',
|
||||
isDestructive : true,
|
||||
confirm : function(){
|
||||
Participant.remove({ id : id , pid : participant._id }, function(event){
|
||||
$scope.event = event;
|
||||
});
|
||||
}
|
||||
});
|
||||
modal.show();
|
||||
}
|
||||
|
||||
$scope.defaults = [];
|
||||
|
||||
$scope.editEvent = function(){
|
||||
|
@ -46,4 +55,6 @@ angular.module('rallly')
|
|||
$scope.participant = {};
|
||||
});
|
||||
}
|
||||
}).controller('DeleteModalCtrl', function(){
|
||||
|
||||
});
|
||||
|
|
|
@ -25,7 +25,7 @@ angular.module('rallly')
|
|||
restrict : 'A',
|
||||
require : 'ngModel',
|
||||
link : function(scope, el, attrs, ngModel){
|
||||
$(el).datepicker({
|
||||
angular.element(el).datepicker({
|
||||
multidate : true,
|
||||
todayHighlight: true,
|
||||
format : 'dd/mm/yyyy'
|
||||
|
@ -40,10 +40,10 @@ angular.module('rallly')
|
|||
});
|
||||
|
||||
scope.clearDates = function(){
|
||||
$(el).datepicker('setDate', null)
|
||||
angular.element(el).datepicker('setDate', null)
|
||||
};
|
||||
scope.unsetDate = function(date){
|
||||
$(el).datepicker('setDates', scope.event.dates.filter(function(el){
|
||||
angular.element(el).datepicker('setDates', scope.event.dates.filter(function(el){
|
||||
return el != date;
|
||||
}));
|
||||
};
|
||||
|
|
28
public/js/filters/elapsed.filter.js
Normal file
28
public/js/filters/elapsed.filter.js
Normal file
|
@ -0,0 +1,28 @@
|
|||
angular.module('rallly')
|
||||
.filter('elapsed', function(){
|
||||
return function(date){
|
||||
if (!date) return;
|
||||
var time = Date.parse(date),
|
||||
timeNow = new Date().getTime(),
|
||||
difference = timeNow - time,
|
||||
seconds = Math.floor(difference / 1000),
|
||||
minutes = Math.floor(seconds / 60),
|
||||
hours = Math.floor(minutes / 60),
|
||||
days = Math.floor(hours / 24);
|
||||
if (days > 1) {
|
||||
return days + " days ago";
|
||||
} else if (days == 1) {
|
||||
return "1 day ago"
|
||||
} else if (hours > 1) {
|
||||
return hours + " hours ago";
|
||||
} else if (hours == 1) {
|
||||
return "an hour ago";
|
||||
} else if (minutes > 1) {
|
||||
return minutes + " minutes ago";
|
||||
} else if (minutes == 1){
|
||||
return "a minute ago";
|
||||
} else {
|
||||
return "a few seconds ago";
|
||||
}
|
||||
}
|
||||
})
|
|
@ -1,4 +1,4 @@
|
|||
angular.module('rallly', ['ui.router','ngResource','ngFx'])
|
||||
angular.module('rallly', ['ui.router','ngResource','ngFx','btford.modal'])
|
||||
.config(function($stateProvider, $urlRouterProvider, $locationProvider){
|
||||
$locationProvider.html5Mode(true);
|
||||
$urlRouterProvider.otherwise("/notfound")
|
||||
|
|
29
public/js/services/modal.service.js
Normal file
29
public/js/services/modal.service.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
angular.module('rallly')
|
||||
.factory('ConfirmModal', function(btfModal){
|
||||
|
||||
return function(config){
|
||||
var modal;
|
||||
modal = btfModal({
|
||||
templateUrl : 'templates/confirmmodal.html',
|
||||
controllerAs : 'modal',
|
||||
controller : function(){
|
||||
this.title = config.title
|
||||
this.message = config.message;
|
||||
this.confirm = function(){
|
||||
if (config.confirm) config.confirm();
|
||||
modal.deactivate();
|
||||
}
|
||||
this.cancel = modal.deactivate;
|
||||
this.confirmText = config.confirmText || 'Confirm';
|
||||
this.cancelText = config.cancelText || 'Cancel';
|
||||
this.isDestructive = config.isDestructive;
|
||||
}
|
||||
});
|
||||
this.show = function(){
|
||||
modal.activate();
|
||||
}
|
||||
this.destroy = function(){
|
||||
modal.deactivate();
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue