all files / app/components/modalConfirm/ modalConfirm.js

100% Statements 23/23
50% Branches 2/4
100% Functions 7/7
100% Lines 23/23
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                                                    257×                                                             13× 13×   13×         11× 11× 11× 11×                        
/**
 * @ngdoc service
 * @name app.components.modalConfirm
 * @description
 * Display a confirmation dialog box
 *
 */
 
(function () {
  'use strict';
  
  angular
    .module('app.components')
    .factory('modalConfirm', factory);
 
  var modalSettings = {
    templateUrl: 'app/components/modalConfirm/modalConfirm.html',
    controller: Controller,
    controllerAs: 'vm'
  };
 
  var defaultLabels = {
    message: 'Are you sure?',
    title: 'Confirm',
    ok: 'Yes',
    cancel: 'Cancel'
  };
 
  /** @ngInject */
  function factory($uibModal) {
 
    return {
      confirm: confirm,
      open: open
    };
 
    /**
     * @ngdoc function
     * @name confirm
     * @methodOf app.components.modalConfirm
     * @description
     * Show a confirmation dialog box and let the caller wait for a response from the user
     *
     * @param {Object} customLabels
     * Overrides for HTML content (ok button, cancel button, message, title)
     * @returns {Object} Promise
     * * Resolved when user chooses OK
     * * Rejected when user chooses Cancel
     */
    function confirm(customLabels) {
      return open(customLabels).result; // promise
    }
 
    /**
     * @ngdoc function
     * @name open
     * @methodOf app.components.modalConfirm
     * @description
     * Create a confirmation dialog box
     *
     * @param {Object} customLabels
     * Overrides 
     * @returns {Object} modal
     */
    function open(customLabels) {
      var settings = angular.copy(modalSettings);
      settings.resolve = {labels: angular.extend({}, defaultLabels, customLabels || {})};
 
      return $uibModal.open(settings);
    }
  }
 
  /** @ngInject */
  function Controller($uibModalInstance, labels) {
    var vm = this;
    vm.labels = labels;
    vm.ok = ok;
    vm.cancel = cancel;
 
    function ok(closeMessage) {
      $uibModalInstance.close(closeMessage);
    }
 
    function cancel(dismissMessage) {
      Eif (angular.isUndefined(dismissMessage)) {
        dismissMessage = 'cancel';
      }
      $uibModalInstance.dismiss(dismissMessage);
    }
  }
 
 
 
})();