1 //== Services ================================================================//
3 angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])
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
13 var _fa = false; // fontawesome flag
15 var _setOpts = function(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
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).
33 * @param val mixed (true, false, 'static')
35 this.useBackdrop = function(val){ // possible values : true, false, 'static'
36 if(angular.isDefined(val))
38 }; // end useStaticBackdrop
43 * Sets the use of the ESC (escape) key to close modal windows.
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;
55 * Sets the additional CSS window class of the modal window template.
59 this.useClass = function(val){
60 if(angular.isDefined(val))
67 * Determines the use of angular.copy when sending data to the modal controller.
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;
79 * Sets a path to a template to use overriding modal's window template.
83 this.setWindowTmpl = function(val){
84 if(angular.isDefined(val))
86 }; // end setWindowTmpl
91 * Sets the modal size to use (sm,lg,md), requires Angular-ui-Bootstrap 0.11.0 and Bootstrap 3.1.0 +
93 * @param val string (sm,lg,md)
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;
103 * Sets Font-Awesome flag to true and substitutes font-awesome icons for
104 * Bootstrap's glyphicons.
106 this.useFontAwesome = function(){
108 }; // end useFontAwesome
111 this.$get = ['$modal',function ($modal){
117 * @param header string
121 error : function(header,msg,opts){
122 opts = _setOpts(opts);
125 templateUrl : '/dialogs/error.html',
126 controller : 'errorDialogCtrl',
129 windowClass: opts.wc,
134 header : angular.copy(header),
135 msg : angular.copy(msg),
140 }); // end modal.open
146 * @param header string
148 * @param progress int
151 wait : function(header,msg,progress,opts){
152 opts = _setOpts(opts);
155 templateUrl : '/dialogs/wait.html',
156 controller : 'waitDialogCtrl',
159 windowClass: opts.wc,
164 header : angular.copy(header),
165 msg : angular.copy(msg),
166 progress : angular.copy(progress),
171 }); // end modal.open
177 * @param header string
181 notify : function(header,msg,opts){
182 opts = _setOpts(opts);
185 templateUrl : '/dialogs/notify.html',
186 controller : 'notifyDialogCtrl',
189 windowClass: opts.wc,
194 header : angular.copy(header),
195 msg : angular.copy(msg),
200 }); // end modal.open
206 * @param header string
210 confirm : function(header,msg,opts){
211 opts = _setOpts(opts);
214 templateUrl : '/dialogs/confirm.html',
215 controller : 'confirmDialogCtrl',
218 windowClass: opts.wc,
223 header : angular.copy(header),
224 msg : angular.copy(msg),
229 }); // end modal.open
233 * Create Custom Dialog
236 * @param ctrlr string
240 create : function(url,ctrlr,data,opts){
241 var copy = (opts && angular.isDefined(opts.copy)) ? opts.copy : _copy;
242 opts = _setOpts(opts);
249 windowClass: opts.wc,
254 return angular.copy(data);
259 }); // end modal.open
265 }]); // end provider dialogs