summaryrefslogtreecommitdiffstats
path: root/testapi/3rd_party/static/testapi-ui/shared/alerts/confirmModalFactory.js
blob: aba205e0ffb3b48252f53794f8cf4825c0ab7914 (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
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
(function () {
    'use strict';

    angular
        .module('testapiApp')
        .factory('confirmModal', confirmModal);

    confirmModal.$inject = ['$uibModal'];

    /**
     * Opens confirm modal dialog with input textbox
     */
    function confirmModal($uibModal) {
        return function(text, successHandler) {
            $uibModal.open({
                templateUrl: '/testapi-ui/shared/alerts/confirmModal.html',
                controller: 'CustomConfirmModalController as confirmModal',
                size: 'md',
                resolve: {
                    data: function () {
                        return {
                            text: text,
                            successHandler: successHandler
                        };
                    }
                }
            });
        };
    }

    angular
        .module('testapiApp')
        .controller('CustomConfirmModalController',
                    CustomConfirmModalController);

    CustomConfirmModalController.$inject = ['$uibModalInstance', 'data'];

    /**
     * This is the controller for the alert pop-up.
     */
    function CustomConfirmModalController($uibModalInstance, data) {
        var ctrl = this;

        ctrl.confirm = confirm;
        ctrl.cancel = cancel;

        ctrl.data = angular.copy(data);

        /**
         * Initiate confirmation and call the success handler with the
         * input text.
         */
        function confirm() {
            $uibModalInstance.close();
            if (angular.isDefined(ctrl.data.successHandler)) {
                ctrl.data.successHandler(ctrl.inputText);
            }
        }

        /**
         * Close the confirm modal without initiating changes.
         */
        function cancel() {
            $uibModalInstance.dismiss('cancel');
        }
    }
})();