Skip to content

Instantly share code, notes, and snippets.

@vcollado
Forked from mwagena/ng-really.js
Last active November 22, 2017 16:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcollado/2f0e46bf4eef3f7b6318eb033e6b88f0 to your computer and use it in GitHub Desktop.
Save vcollado/2f0e46bf4eef3f7b6318eb033e6b88f0 to your computer and use it in GitHub Desktop.
Updated using es6 and angularUI
/**
* 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">&times;</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