Merge "re-enable testapi auto update"
[releng.git] / utils / test / testapi / 3rd_party / static / testapi-ui / shared / alerts / confirmModalFactory.js
1 (function () {
2     'use strict';
3
4     angular
5         .module('testapiApp')
6         .factory('confirmModal', confirmModal);
7
8     confirmModal.$inject = ['$uibModal'];
9
10     /**
11      * Opens confirm modal dialog with input textbox
12      */
13     function confirmModal($uibModal) {
14         return function(text, successHandler) {
15             $uibModal.open({
16                 templateUrl: '/shared/alerts/confirmModal.html',
17                 controller: 'CustomConfirmModalController as confirmModal',
18                 size: 'md',
19                 resolve: {
20                     data: function () {
21                         return {
22                             text: text,
23                             successHandler: successHandler
24                         };
25                     }
26                 }
27             });
28         };
29     }
30
31     angular
32         .module('testapiApp')
33         .controller('CustomConfirmModalController',
34                     CustomConfirmModalController);
35
36     CustomConfirmModalController.$inject = ['$uibModalInstance', 'data'];
37
38     /**
39      * This is the controller for the alert pop-up.
40      */
41     function CustomConfirmModalController($uibModalInstance, data) {
42         var ctrl = this;
43
44         ctrl.confirm = confirm;
45         ctrl.cancel = cancel;
46
47         ctrl.data = angular.copy(data);
48
49         /**
50          * Initiate confirmation and call the success handler with the
51          * input text.
52          */
53         function confirm() {
54             $uibModalInstance.close();
55             if (angular.isDefined(ctrl.data.successHandler)) {
56                 ctrl.data.successHandler(ctrl.inputText);
57             }
58         }
59
60         /**
61          * Close the confirm modal without initiating changes.
62          */
63         function cancel() {
64             $uibModalInstance.dismiss('cancel');
65         }
66     }
67 })();