summaryrefslogtreecommitdiffstats
path: root/app/common/directives/confirm.js
blob: b537905bfa6a04fd06c06a14d75a32e52dfce1d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
window.angular && (function(angular) {
  'use strict';

  angular.module('app.common.directives').directive('confirm', [
    '$timeout',
    function($timeout) {
      return {
        'restrict': 'E',
        'template': require('./confirm.html'),
        'scope':
            {'title': '@', 'message': '@', 'confirm': '=', 'callback': '='},
        'controller': [
          '$scope',
          function($scope) {
            $scope.cancel = function() {
              $scope.confirm = false;
              $scope.$parent.confirm = false;
            };
            $scope.accept = function() {
              $scope.callback();
              $scope.cancel();
            };
          }
        ],
        link: function(scope, e) {
          scope.$watch('confirm', function() {
            if (scope.confirm) {
              $timeout(function() {
                angular.element(e[0].parentNode).css({
                  'min-height':
                      e[0].querySelector('.inline__confirm').offsetHeight + 'px'
                });
              }, 0);
            } else {
              angular.element(e[0].parentNode).css({'min-height': 0 + 'px'});
            }
          });
        }
      };
    }
  ]);
})(window.angular);
OpenPOWER on IntegriCloud