Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- app.directive('ngConfirmClick', function (Modals,$parse) {
- return {
- priority: -1,
- restrict: 'A',
- scope: {
- ngConfirmClick: '='
- },
- link: function (scope, element, attrs) {
- element.bind('click', function (e) {
- //cancel original
- e.stopImmediatePropagation();
- e.preventDefault();
- Modals.confirm(scope.ngConfirmClick).result.then(function () {
- //run original on parent scope
- scope.$parent.$eval(attrs.ngClick);
- }, function () {
- if (attrs.ngConfirmCancel) {
- scope.$parent.$eval(attrs.ngConfirmCancel);
- }
- });
- });
- }
- }
- }
- );
- 'use strict';
- app.factory('Modals', function ($modal, $filter, $fileUploader, KB) {
- var generalConfig = {
- backdrop: true
- };
- return {
- confirm: function (config) {
- var defaultConfig = {
- title: 'Warning',
- message: 'Are you sure?',
- okButtonLabel: $filter('lc')('content.ok'),
- cancelButtonLabel: $filter('lc')('content.cancel')
- };
- config = angular.extend({}, defaultConfig, config);
- return $modal.open(
- {
- backdrop: generalConfig.backdrop,
- template: '<div class="modal-header"><h3>{{config.title}}</h3></div>' +
- '<div class="modal-body"><h4>{{config.message}}</h4></div>' +
- '<div class="modal-footer">' +
- '<button class="btn btn-warning" ng-click="close()">{{config.cancelButtonLabel}}</button>' +
- '<button class="btn btn-primary" ng-click="ok()">{{config.okButtonLabel}}</button>' +
- '</div>',
- controller: function ($scope, $modalInstance) {
- $scope.config = config;
- $scope.close = function () {
- $modalInstance.dismiss();
- };
- $scope.ok = function () {
- $modalInstance.close('');
- }
- }
- }
- );
- },
- .....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement