Merge "Add qtip job to pod zte-virtual6"
[releng.git] / utils / test / testapi / 3rd_party / static / testapi-ui / assets / lib / angular-confirm-modal / angular-confirm.js
1 /*
2  * angular-confirm
3  * https://github.com/Schlogen/angular-confirm
4  * @version v1.2.3 - 2016-01-26
5  * @license Apache
6  */
7 (function (root, factory) {
8   'use strict';
9   if (typeof define === 'function' && define.amd) {
10     define(['angular'], factory);
11   } else if (typeof module !== 'undefined' && typeof module.exports === 'object') {
12     module.exports = factory(require('angular'));
13   } else {
14     return factory(root.angular);
15   }
16 }(this, function (angular) {
17 angular.module('angular-confirm', ['ui.bootstrap.modal'])
18   .controller('ConfirmModalController', function ($scope, $uibModalInstance, data) {
19     $scope.data = angular.copy(data);
20
21     $scope.ok = function (closeMessage) {
22       $uibModalInstance.close(closeMessage);
23     };
24
25     $scope.cancel = function (dismissMessage) {
26       if (angular.isUndefined(dismissMessage)) {
27         dismissMessage = 'cancel';
28       }
29       $uibModalInstance.dismiss(dismissMessage);
30     };
31
32   })
33   .value('$confirmModalDefaults', {
34     template: '<div class="modal-header"><h3 class="modal-title">{{data.title}}</h3></div>' +
35     '<div class="modal-body">{{data.text}}</div>' +
36     '<div class="modal-footer">' +
37     '<button class="btn btn-primary" ng-click="ok()">{{data.ok}}</button>' +
38     '<button class="btn btn-default" ng-click="cancel()">{{data.cancel}}</button>' +
39     '</div>',
40     controller: 'ConfirmModalController',
41     defaultLabels: {
42       title: 'Confirm',
43       ok: 'OK',
44       cancel: 'Cancel'
45     }
46   })
47   .factory('$confirm', function ($uibModal, $confirmModalDefaults) {
48     return function (data, settings) {
49       var defaults = angular.copy($confirmModalDefaults);
50       settings = angular.extend(defaults, (settings || {}));
51       
52       data = angular.extend({}, settings.defaultLabels, data || {});
53
54       if ('templateUrl' in settings && 'template' in settings) {
55         delete settings.template;
56       }
57
58       settings.resolve = {
59         data: function () {
60           return data;
61         }
62       };
63
64       return $uibModal.open(settings).result;
65     };
66   })
67   .directive('confirm', function ($confirm) {
68     return {
69       priority: 1,
70       restrict: 'A',
71       scope: {
72         confirmIf: "=",
73         ngClick: '&',
74         confirm: '@',
75         confirmSettings: "=",
76         confirmTitle: '@',
77         confirmOk: '@',
78         confirmCancel: '@'
79       },
80       link: function (scope, element, attrs) {
81
82         element.unbind("click").bind("click", function ($event) {
83
84           $event.preventDefault();
85
86           if (angular.isUndefined(scope.confirmIf) || scope.confirmIf) {
87
88             var data = {text: scope.confirm};
89             if (scope.confirmTitle) {
90               data.title = scope.confirmTitle;
91             }
92             if (scope.confirmOk) {
93               data.ok = scope.confirmOk;
94             }
95             if (scope.confirmCancel) {
96               data.cancel = scope.confirmCancel;
97             }
98             $confirm(data, scope.confirmSettings || {}).then(scope.ngClick);
99           } else {
100
101             scope.$apply(scope.ngClick);
102           }
103         });
104
105       }
106     }
107   });
108 }));