Advertisement
Guest User

Untitled

a guest
Jun 13th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.directive('ngConfirmClick', function (Modals,$parse) {
  2.         return {
  3.             priority: -1,
  4.             restrict: 'A',
  5.             scope: {
  6.                 ngConfirmClick: '='
  7.             },
  8.             link: function (scope, element, attrs) {
  9.                 element.bind('click', function (e) {
  10.                     //cancel original
  11.                     e.stopImmediatePropagation();
  12.                     e.preventDefault();
  13.                     Modals.confirm(scope.ngConfirmClick).result.then(function () {
  14.                         //run original on parent scope
  15.                         scope.$parent.$eval(attrs.ngClick);
  16.                     }, function () {
  17.                         if (attrs.ngConfirmCancel) {
  18.                             scope.$parent.$eval(attrs.ngConfirmCancel);
  19.                         }
  20.                     });
  21.                 });
  22.             }
  23.         }
  24.     }
  25. );
  26.  
  27. 'use strict';
  28. app.factory('Modals', function ($modal, $filter, $fileUploader, KB) {
  29.     var generalConfig = {
  30.         backdrop: true
  31.     };
  32.  
  33.     return {
  34.         confirm: function (config) {
  35.             var defaultConfig = {
  36.                 title: 'Warning',
  37.                 message: 'Are you sure?',
  38.                 okButtonLabel: $filter('lc')('content.ok'),
  39.                 cancelButtonLabel: $filter('lc')('content.cancel')
  40.             };
  41.             config = angular.extend({}, defaultConfig, config);
  42.  
  43.             return $modal.open(
  44.                 {
  45.                     backdrop: generalConfig.backdrop,
  46.                     template: '<div class="modal-header"><h3>{{config.title}}</h3></div>' +
  47.                         '<div class="modal-body"><h4>{{config.message}}</h4></div>' +
  48.                         '<div class="modal-footer">' +
  49.                         '<button class="btn btn-warning" ng-click="close()">{{config.cancelButtonLabel}}</button>' +
  50.                         '<button class="btn btn-primary" ng-click="ok()">{{config.okButtonLabel}}</button>' +
  51.                         '</div>',
  52.                     controller: function ($scope, $modalInstance) {
  53.                         $scope.config = config;
  54.                         $scope.close = function () {
  55.                             $modalInstance.dismiss();
  56.                         };
  57.                         $scope.ok = function () {
  58.                             $modalInstance.close('');
  59.                         }
  60.                     }
  61.                 }
  62.             );
  63.         },
  64. .....
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement