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

Statements: 86.79% (46 / 53)      Branches: 59.38% (19 / 32)      Functions: 100% (20 / 20)      Lines: 86.79% (46 / 53)      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 132 133 134 135 136 137 138 139 140 1411                                       32 32   32 16         16     16     16     16     16     16     16     16     16         16   2     14         32 32 32       32 77 77 16 61 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;
      var modalInstance;
 
      ctrl.open = function () {
        modalInstance = $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;
            }
          }
        });
 
        modalInstance.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) {
        Eif (changesObj.showModal) {
          if (changesObj.showModal.currentValue === true) {
            ctrl.open();
          } else if (changesObj.showModal.currentValue === false && modalInstance) {
            modalInstance.dismiss('showModal set to false');
          }
        }
      };
    }
  });
 
 
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") {
          if (actionFn() !== false) {
            ctrl.close({$value: label});
          }
        } else {
          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();
          }
        }
      });
    };
  }
});