Code coverage report for src/modals/modal-overlay/modal-overlay.component.js

Statements: 87.23% (41 / 47)      Branches: 61.54% (16 / 26)      Functions: 100% (20 / 20)      Lines: 87.23% (41 / 47)      Ignored: none     

All files » src/modals/modal-overlay/ » modal-overlay.component.js
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 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 1321                                       32   32 16         16     16     16     16     16     16     16     16     16           2     1         32 32 32       32 77 16             1                 16   16 16 16 16 16 16 16 16 16 16   16 2     2     16 1     1     16 16                          
angular.module('patternfly.modals')
  .component('pfModalOverlay', {
    bindings: {
      showModal: '<',
      close: "&onClose",
      modalId: '=',
      modalTitle: "=",
      titleId: "=?",
      hideCloseIcon: "<?",
      backgroundClose: "<?",
      onBackgroundClick: "=?",
      isForm: "<?",
      modalBodyTemplate: "=",
      modalBodyScope: "=?",
      actionButtons: "<"
    },
    templateUrl: 'modals/modal-overlay/modal-overlay.html',
    controller: function ( $uibModal ) {
      'use strict';
 
      var ctrl = this;
 
      ctrl.open = function () {
        $uibModal.open({
          component: 'pfModalOverlayContent',
          backdrop: ctrl.backgroundClose ? true : 'static',
          resolve: {
            modalId: function () {
              return ctrl.modalId;
            },
            titleId: function () {
              return ctrl.titleId || "modalTitle";
            },
            modalTitle: function () {
              return ctrl.modalTitle;
            },
            hideCloseIcon: function () {
              return ctrl.hideCloseIcon;
            },
            onBackgroundClick: function() {
              return ctrl.onBackgroundClick;
            },
            isForm: function() {
              return ctrl.isForm;
            },
            modalBodyTemplate: function() {
              return ctrl.modalBodyTemplate;
            },
            modalBodyScope: function() {
              return ctrl.modalBodyScope;
            },
            actionButtons: function () {
              return ctrl.actionButtons;
            }
          }
        })
          .result.then(
          function (dismissCause) {
            ctrl.close({'dismissCause': dismissCause}); // closed
          },
          function (dismissCause) {
            ctrl.close({'dismissCause': dismissCause}); // dismissed
          }
        );
      };
 
      ctrl.$onInit = function () {
        Eif (ctrl.showModal === undefined) {
          ctrl.showModal = false;
        }
      };
 
      ctrl.$onChanges = function (changesObj) {
        if (changesObj.showModal && changesObj.showModal.currentValue === true) {
          ctrl.open();
        }
      };
    }
  });
 
 
angular.module('patternfly.modals').component('pfModalOverlayContent', {
  templateUrl: 'modal-overlay-template.html',
  bindings: {
    resolve: '<',
    close: '&',
    dismiss: '&'
  },
  controller: function ($scope) {
    'use strict';
    var ctrl = this;
 
    ctrl.$onInit = function () {
      ctrl.modalId = ctrl.resolve.modalId;
      ctrl.titleId = ctrl.resolve.titleId || "modalTitle";
      ctrl.modalTitle = ctrl.resolve.modalTitle;
      ctrl.hideCloseIcon = ctrl.resolve.hideCloseIcon || false;
      ctrl.modalBodyTemplate = ctrl.resolve.modalBodyTemplate;
      ctrl.modalBodyScope = ctrl.resolve.modalBodyScope;
      ctrl.actionButtons = ctrl.resolve.actionButtons;
      ctrl.isForm = ctrl.resolve.isForm;
      ctrl.onBackgroundClick = ctrl.resolve.onBackgroundClick;
 
      ctrl.ok = function (label, actionFn) {
        Iif (typeof actionFn === "function") {
          actionFn();
        }
        ctrl.close({$value: label});
      };
 
      ctrl.cancel = function (actionFn) {
        Iif (typeof actionFn === "function") {
          actionFn();
        }
        ctrl.dismiss({$value: 'cancel'});
      };
 
      $scope.$on('modal.closing', function(event, reason, closed) {
        Iif (reason === "backdrop click" || reason === "escape key press") {
          event.preventDefault();
          if ( typeof ctrl.onBackgroundClick === "function" && ctrl.onBackgroundClick()) {
            ctrl.dismiss({$value: 'backdropClick'});
          } else {
            // onBackgroundClick' returned false, may have changed ctrl vars; execute $digest to refresh view
            $scope.$digest();
          }
        }
      });
    };
  }
});