-
-
Save vcollado/2f0e46bf4eef3f7b6318eb033e6b88f0 to your computer and use it in GitHub Desktop.
Updated using es6 and angularUI
This file contains hidden or 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 | |
*/ | |
export default function ngReallyClick($uibModal, $timeout) { | |
return { | |
restrict: 'A', | |
link: function (scope, element, attrs) { | |
return element.bind('click', function () { | |
var message, title; | |
message = attrs.ngReallyMessage; | |
title = attrs.ngReallyTitle || 'Confirmación'; | |
return $uibModal.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()">Cancelar</button> | |
<button class="btn btn-primary" ng-click="confirm()">Confirmar</button> | |
</div> | |
`, | |
size: 'sm', | |
controller: function ($scope, $uibModalInstance) { | |
$scope.cancel = function () { | |
return $uibModalInstance.dismiss('cancel'); | |
}; | |
return $scope.confirm = function () { | |
return $timeout(function () { | |
scope.$apply(attrs.ngReallyClick); | |
return $uibModalInstance.dismiss(); | |
}, 0); | |
}; | |
} | |
}); | |
}); | |
} | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment