Initial OpenECOMP policy/engine commit
[policy/engine.git] / ecomp-sdk-app / src / main / webapp / app / fusion / scripts / modalService.js
1 angular.module("modalServices",[]).service('modalService', ['$modal', function ($modal) {
2         
3                                                                                                                 
4                 this.showSuccess = function(heading, messageBody){
5                         var modalInstance = $modal.open({
6                         templateUrl: 'modal_informative.html',
7                         controller: 'modalpopupController',
8                         resolve: {
9                            message: function () {
10                                         $(".overlayed").css("display","none");
11                                         $(".loadingId").css("display","none");
12                                    var message = {
13                                                    title:    heading,
14                                         text:     messageBody
15                                 };
16                                   return message;
17                                         }
18                         }
19                       }); 
20                 };
21                 this.showFailure = function(heading, messageBody){
22                 var modalInstance = $modal.open({
23                         templateUrl: 'modal_warning.html',
24                         controller: 'modalpopupController',
25                         resolve: {
26                            message: function () {
27                                   var message = {
28                                  title:    heading,
29                                  text:     messageBody
30                                 };
31                                   return message;
32                                         }
33                         }
34                       }); 
35                 };
36                 
37                 this.showMessage = function(heading, messageBody){
38                 var modalInstance = $modal.open({
39                         templateUrl: 'modal_message.html',
40                         controller: 'modalpopupController',
41                         resolve: {
42                            message: function () {
43                                   var message = {
44                                          title:    heading,
45                                          text:     messageBody
46                                         };
47                                           return message;
48                                                 }
49                         }
50                       }); 
51                 };
52                 
53                 this.showWarning = function(heading, messageBody){
54                 var modalInstance = $modal.open({
55                         templateUrl: 'modal_warning_message.html',
56                         controller: 'modalpopupController',
57                         resolve: {
58                            message: function () {
59                                   var message = {
60                                          title:    heading,
61                                          text:     messageBody
62                                         };
63                                           return message;
64                                                 }
65                         }
66                       }); 
67                 };
68                 
69                 this.popupConfirmWin = function(title, msgBody, callback){
70                          var modalInstance = $modal.open({
71                         templateUrl: 'confirmation_informative.html',
72                         controller: 'modalpopupController',
73                         resolve: {
74                            message: function () {
75                                    var message = {
76                                                    title:    title,
77                                         text:    msgBody
78                                 };
79                                           return message;
80                                         }
81                         }
82                       }); 
83                          var args = Array.prototype.slice.call( arguments, 0 );
84                      args.splice( 0, 3); 
85                         modalInstance.result.then(function(){
86                                         callback.apply(null, args);
87                                 }, function() {
88                           })['finally'](function(){
89                            modalInstance = undefined;
90                           });
91                         
92                 };
93                 this.popupConfirmWinWithCancel = function(title, msgBody, callback,dismissCallback){
94                          var modalInstance = $modal.open({
95                         templateUrl: 'confirmation_informative.html',
96                         controller: 'modalpopupController',
97                         resolve: {
98                            message: function () {
99                                    var message = {
100                                                    title:    title,
101                                         text:    msgBody
102                                 };
103                                           return message;
104                                         }
105                         }
106                       }); 
107                          var args = Array.prototype.slice.call( arguments, 0 );
108                      args.splice( 0, 3); 
109                         modalInstance.result.then(function(){
110                                         callback.apply(null, args);
111                                 }, function() {
112                                   dismissCallback();
113                           })['finally'](function(){
114                            modalInstance = undefined;
115                           });
116                         
117                 };
118         this.popupDeleteConfirmWin = function(title, msgBody, callback, argForCallBack){
119                          var modalInstance = $modal.open({
120                         templateUrl: 'confirmation_for_delete.html',
121                         controller: 'modalpopupController',
122                         resolve: {
123                            message: function () {
124                                    var message = {
125                                                    title:    title,
126                                         text:    msgBody
127                                 };
128                                           return message;
129                                         }
130                         }
131                       }); 
132                          
133                         modalInstance.result.then(function(){
134                                         callback(argForCallBack);
135                                 }, function() {
136                           })['finally'](function(){
137                            modalInstance = undefined;
138                           });
139                         
140                 };              
141                 
142          this.popupSuccessRedirectWin = function(title, msgBody, redirectUrl){
143                 var modalInstance = $modal.open({
144                 templateUrl: 'modal_informative.html',
145                 controller: 'modalpopupController',
146                 resolve: {
147                    message: function () {
148                            var message = {
149                                            title:    title,
150                                text:    msgBody
151                         };
152                                   return message;
153                                 }
154                 }
155               }); 
156                 modalInstance.result.then(function() {
157                   }, function() {
158                           window.location.href=redirectUrl;
159                   })['finally'](function(){
160                    modalInstance = undefined;
161                   });   
162         };      
163         
164         this.popupWarningRedirectWin = function(title, msgBody, redirectUrl){
165                 var modalInstance = $modal.open({
166                         templateUrl: 'modal_warning_message.html',
167                 controller: 'modalpopupController',
168                 resolve: {
169                    message: function () {
170                            var message = {
171                                            title:    title,
172                                text:    msgBody
173                         };
174                                   return message;
175                                 }
176                 }
177               }); 
178                 modalInstance.result.then(function() {
179                   }, function() {
180                           window.location.href=redirectUrl;
181                   })['finally'](function(){
182                    modalInstance = undefined;
183                   });   
184         };      
185  }]);