Merge "Fix the docker push"
[clamp.git] / src / main / resources / META-INF / resources / designer / lib / dialogs-services.js
1 //== Services ================================================================//
2
3 angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])
4
5         .provider('dialogs',[function(){
6                 var _b = true; // backdrop
7                 var _k = true; // keyboard
8                 var _w = 'dialogs-default'; // windowClass
9                 var _copy = true; // controls use of angular.copy
10                 var _wTmpl = null; // window template
11                 var _wSize = 'lg'; // large modal window default
12
13                 var _fa = false; // fontawesome flag
14
15                 var _setOpts = function(opts){
16                         var _opts = {};
17                         opts = opts || {};
18                         _opts.kb = (angular.isDefined(opts.keyboard)) ? opts.keyboard : _k; // values: true,false
19                         _opts.bd = (angular.isDefined(opts.backdrop)) ? opts.backdrop : _b; // values: 'static',true,false
20                         _opts.ws = (angular.isDefined(opts.size) && (angular.equals(opts.size,'sm') || angular.equals(opts.size,'lg') || angular.equals(opts.size,'md'))) ? opts.size : _wSize; // values: 'sm', 'lg', 'md'
21                         _opts.wc = (angular.isDefined(opts.windowClass)) ? opts.windowClass : _w; // additional CSS class(es) to be added to a modal window
22
23                         return _opts;
24                 }; // end _setOpts
25
26                 /**
27                  * Use Backdrop
28                  * 
29                  * Sets the use of the modal backdrop.  Either to have one or not and
30                  * whether or not it responds to mouse clicks ('static' sets the 
31                  * backdrop to true and does not respond to mouse clicks).
32                  *
33                  * @param       val     mixed   (true, false, 'static')
34                  */
35                 this.useBackdrop = function(val){ // possible values : true, false, 'static'
36                         if(angular.isDefined(val))
37                                 _b = val;
38                 }; // end useStaticBackdrop
39
40                 /**
41                  * Use ESC Close
42                  * 
43                  * Sets the use of the ESC (escape) key to close modal windows.
44                  *
45                  * @param       val     boolean
46                  */
47                 this.useEscClose = function(val){ // possible values : true, false
48                         if(angular.isDefined(val))
49                                 _k = (!angular.equals(val,0) && !angular.equals(val,'false') && !angular.equals(val,'no') && !angular.equals(val,null) && !angular.equals(val,false)) ? true : false;
50                 }; // end useESCClose
51
52                 /**
53                  * Use Class
54                  *
55                  * Sets the additional CSS window class of the modal window template.
56                  *
57                  * @param       val     string
58                  */
59                 this.useClass = function(val){
60                         if(angular.isDefined(val))
61                                 _w = val;
62                 }; // end useClass
63
64                 /**
65                  * Use Copy
66                  * 
67                  * Determines the use of angular.copy when sending data to the modal controller.
68                  *
69                  * @param       val     boolean
70                  */
71                 this.useCopy = function(val){
72                         if(angular.isDefined(val))
73                                 _copy = (!angular.equals(val,0) && !angular.equals(val,'false') && !angular.equals(val,'no') && !angular.equals(val,null) && !angular.equals(val,false)) ? true : false;
74                 }; // end useCopy
75
76                 /**
77                  * Set Window Template
78                  *
79                  * Sets a path to a template to use overriding modal's window template.
80                  *
81                  * @param       val     string
82                  */
83                 this.setWindowTmpl = function(val){
84                         if(angular.isDefined(val))
85                                 _wTmpl = val;
86                 }; // end setWindowTmpl
87
88                 /**
89                  * Set Size
90                  *
91                  * Sets the modal size to use (sm,lg,md), requires Angular-ui-Bootstrap 0.11.0 and Bootstrap 3.1.0 + 
92                  *
93                  * @param       val     string (sm,lg,md)
94                  */
95                 this.setSize = function(val){
96                         if(angular.isDefined(val))
97                                 _wSize = (angular.equals(val,'sm') || angular.equals(val,'lg') || angular.equals(val,'md')) ? val : _wSize;
98                 }; // end setSize
99
100                 /**
101                  * Use Font-Awesome.
102                  *
103                  * Sets Font-Awesome flag to true and substitutes font-awesome icons for
104                  * Bootstrap's glyphicons.
105                  */
106                 this.useFontAwesome = function(){
107                         _fa = true;
108                 }; // end useFontAwesome
109
110
111                 this.$get = ['$modal',function ($modal){
112                         
113                         return {
114                                 /**
115                                  * Error Dialog
116                                  *
117                                  * @param       header  string
118                                  * @param       msg     string
119                                  * @param       opts    object
120                                  */
121                                 error : function(header,msg,opts){
122                                         opts = _setOpts(opts);
123
124                                         return $modal.open({
125                                                 templateUrl : '/dialogs/error.html',
126                                                 controller : 'errorDialogCtrl',
127                                                 backdrop: opts.bd,
128                                                 keyboard: opts.kb,
129                                                 windowClass: opts.wc,
130                                                 size: opts.ws,
131                                                 resolve : {
132                                                         data : function(){
133                                                                 return {
134                                                                         header : angular.copy(header),
135                                                                         msg : angular.copy(msg),
136                                                                         fa : _fa
137                                                                 };
138                                                         }
139                                                 }
140                                         }); // end modal.open
141                                 }, // end error
142                                 
143                                 /**
144                                  * Wait Dialog
145                                  *
146                                  * @param       header          string
147                                  * @param       msg             string
148                                  * @param       progress        int
149                                  * @param       opts    object
150                                  */
151                                 wait : function(header,msg,progress,opts){
152                                         opts = _setOpts(opts);
153
154                                         return $modal.open({
155                                                 templateUrl : '/dialogs/wait.html',
156                                                 controller : 'waitDialogCtrl',
157                                                 backdrop: opts.bd,
158                                                 keyboard: opts.kb,
159                                                 windowClass: opts.wc,
160                                                 size: opts.ws,
161                                                 resolve : {
162                                                         data : function(){
163                                                                 return {
164                                                                         header : angular.copy(header),
165                                                                         msg : angular.copy(msg),
166                                                                         progress : angular.copy(progress),
167                                                                         fa : _fa
168                                                                 };
169                                                         }
170                                                 }
171                                         }); // end modal.open
172                                 }, // end wait
173                                 
174                                 /**
175                                  * Notify Dialog
176                                  *
177                                  * @param       header          string
178                                  * @param       msg             string
179                                  * @param       opts    object
180                                  */
181                                 notify : function(header,msg,opts){
182                                         opts = _setOpts(opts);
183
184                                         return $modal.open({
185                                                 templateUrl : '/dialogs/notify.html',
186                                                 controller : 'notifyDialogCtrl',
187                                                 backdrop: opts.bd,
188                                                 keyboard: opts.kb,
189                                                 windowClass: opts.wc,
190                                                 size: opts.ws,
191                                                 resolve : {
192                                                         data : function(){
193                                                                 return {
194                                                                         header : angular.copy(header),
195                                                                         msg : angular.copy(msg),
196                                                                         fa : _fa
197                                                                 };
198                                                         }
199                                                 }
200                                         }); // end modal.open
201                                 }, // end notify
202                                 
203                                 /**
204                                  * Confirm Dialog
205                                  *
206                                  * @param       header  string
207                                  * @param       msg     string
208                                  * @param       opts    object
209                                  */
210                                 confirm : function(header,msg,opts){
211                                         opts = _setOpts(opts);
212
213                                         return $modal.open({
214                                                 templateUrl : '/dialogs/confirm.html',
215                                                 controller : 'confirmDialogCtrl',
216                                                 backdrop: opts.bd,
217                                                 keyboard: opts.kb,
218                                                 windowClass: opts.wc,
219                                                 size: opts.ws,
220                                                 resolve : {
221                                                         data : function(){
222                                                                 return {
223                                                                         header : angular.copy(header),
224                                                                         msg : angular.copy(msg),
225                                                                         fa : _fa
226                                                                 };
227                                                         }
228                                                 }
229                                         }); // end modal.open
230                                 }, // end confirm
231                                 
232                                 /**
233                                  * Create Custom Dialog
234                                  *
235                                  * @param       url     string
236                                  * @param       ctrlr   string
237                                  * @param       data    object
238                                  * @param       opts    object
239                                  */
240                                 create : function(url,ctrlr,data,opts){
241                                         var copy = (opts && angular.isDefined(opts.copy)) ? opts.copy : _copy;
242                                         opts = _setOpts(opts);
243
244                                         return $modal.open({
245                                                 templateUrl : url,
246                                                 controller : ctrlr,
247                                                 keyboard : opts.kb,
248                                                 backdrop : opts.bd,
249                                                 windowClass: opts.wc,
250                                                 size: opts.ws,
251                                                 resolve : {
252                                                         data : function() { 
253                                                                 if(copy)
254                                                                         return angular.copy(data);
255                                                                 else
256                                                                         return data;
257                                                         }
258                                                 }
259                                         }); // end modal.open
260                                 } // end create
261
262                         }; // end return
263
264                 }]; // end $get
265         }]); // end provider dialogs