-
-
Save mwagena/dd30c7803a65f6ae23ec to your computer and use it in GitHub Desktop.
Updatet script to use Bootstrap Modals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A generic confirmation for risky actions. | |
* Usage: Add attributes: ng-really-message="Are you sure"? ng-really-click="takeAction()" ng-really-title="Delete this?" function | |
*/ | |
angular.module('app').directive('ngReallyClick', ["$modal", "$timeout", function($modal, $timeout) { | |
return { | |
restrict: 'A', | |
link: function(scope, element, attrs) { | |
return element.bind('click', function() { | |
var message, title; | |
message = attrs.ngReallyMessage; | |
title = attrs.ngReallyTitle || 'Are you sure?'; | |
return $modal.open({ | |
template: '<div class="modal-header">' + | |
'<button type="button" class="close" ng-click="cancel()" aria-label="Close"><span aria-hidden="true">×</span></button>' + | |
'<h4 class="modal-title">' + title + '</h4>' + | |
'</div>' + | |
'<div class="modal-body">' + message + '</div>' + | |
'<div class="modal-footer">' + | |
'<button class="btn btn-default" ng-click="cancel()">Cancel</button>' + | |
'<button class="btn btn-primary" ng-click="confirm()">Confirm</button>' + | |
'</div>', | |
size: 'sm', | |
controller: ["$scope", "$modalInstance", function($scope, $modalInstance) { | |
$scope.cancel = function() { | |
return $modalInstance.dismiss('cancel'); | |
}; | |
return $scope.confirm = function() { | |
return $timeout(function() { | |
scope.$apply(attrs.ngReallyClick); | |
return $modalInstance.dismiss(); | |
}, 0); | |
}; | |
}] | |
}); | |
}); | |
} | |
}; | |
}]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment