├── .gitignore ├── LICENSE ├── README.md ├── bower.json ├── dist ├── dialogs-default-translations.js ├── dialogs-default-translations.min.js ├── dialogs.css ├── dialogs.js ├── dialogs.min.css └── dialogs.min.js ├── example ├── css │ ├── dialogs.css │ └── dialogs.min.css ├── faChk.html ├── index.html ├── index2.html └── js │ ├── dialogTest.js │ ├── dialogTest2.js │ ├── dialogs-default-translations.js │ ├── dialogs-default-translations.min.js │ ├── dialogs-min.min.js │ ├── dialogs.js │ └── dialogs.min.js ├── gulpfile.js ├── index.js ├── karma.conf.js ├── package.json ├── src ├── dialogs-controllers.js ├── dialogs-default-translations.js ├── dialogs-main.js ├── dialogs-services.js ├── dialogs.css └── translate-substitution.js └── tests ├── dialogs-controllers.tests.js ├── dialogs-main.tests.js └── dialogs-services.tests.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | bower_components 3 | .idea 4 | temp -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Michael E Conroy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Angular Dialog Service 2 | ====================== 3 | 4 | >**Please use one of the release versions rather than the Master Branch**. The Master Branch has untested merges and changes and is a work in progress. I urge you to always use a release version rather than linking directly to the Master Branch, as the Master Branch may change and may not always be backward compatible. 5 | 6 | **v4.x.x + is not backward compatible with versions 1,2,3,3.1 Please refer to the changes section to view what is different in v4.0** 7 | 8 | A complete AngularJS service with controllers and templates for generating application modals and dialogs for use with Angular-UI-Bootstrap, Twitter Bootstrap and Font-Awesome. Supports, i18n, language translations for dialog headers, messages and buttons via angular-translate. 9 | 10 | Installation 11 | ----- 12 | Bower 13 | ```bower install angular-dialog-service --save``` 14 | 15 | Npm 16 | ```npm install angular-dialog-service --save ``` 17 | 18 | Importing to project **( ES6 )** 19 | 20 | ```import 'angular-dialog-service';``` 21 | 22 | 23 | Usage 24 | ----- 25 | 26 | ```javascript 27 | var app = angular.module("MyApp", ['dialogs.main']); 28 | 29 | app.controller("MyCtrl", function(dialogs){ 30 | // open dialogs here 31 | }); 32 | ``` 33 | 34 | 35 | ```dialogs.error('Error','An unknown error occurred preventing the completion of the requested action.');``` 36 | 37 | ```dialogs.wait('Creating User','Please wait while we attempt to create user "Michael Conroy."

This should only take a moment.',50);``` 38 | 39 | ```dialogs.notify('Something Happened','Something happened at this point in the application that I wish to let you know about');``` 40 | 41 | ```dialogs.create('url/to/a/template','ctrlrToUse',{data: topass,anotherVar: 'value'},{},'ctrl');``` 42 | 43 | ### API 44 | 45 | All Dialogs return a object with property `result` which is a promise `OK/Yes` resolves the promise `Close/Reject/No` rejects the promise 46 | 47 | #### dialogs.error, dialogs.notify, dialogs.confirm 48 | 49 | ```dialogs.error(header, msg, opts)``` 50 | 51 | ```dialogs.notify(header, msg, opts)``` 52 | 53 | ```dialogs.confirm(header, msg, opts)``` 54 | 55 | | Name | Type | Description | 56 | |---|---|---| 57 | | header | `string` | Dialog header text. | 58 | | msg | `string` | Dialog body text. | 59 | | opts | `object` | Options for the dialog | 60 | 61 | #### dialogs.wait 62 | 63 | ```dialogs.wait(header, msg, progress, opts)``` 64 | 65 | | Name | Type | Description | 66 | |---|---|---| 67 | | header | `string` | Dialog header text. | 68 | | msg | `string` | Dialog body text. | 69 | | progress | `int` | progress in percentage | 70 | | opts | `object` | Options for the dialog | 71 | 72 | #### dialogs.create 73 | 74 | ```dialogs.create(url, ctrlr, data, opts, ctrlAs)``` 75 | 76 | | Name | Type | Description | 77 | |---|---|---| 78 | | url | `string` | Template Url | 79 | | ctrlr | `string` | Dialog Controller | 80 | | data | `object` | data available as a "data" service in the controller | 81 | | opts | `object` | Options for the dialog with the addition of `copy: false|true` which will copy the data instead of passing reference | 82 | | ctrlAs | `string` | `controllerAs` reference 83 | 84 | #### IDialogOptions Properties 85 | 86 | Note: All properties are optional 87 | 88 | | Name | Type | Description | 89 | | --- | --- | --- | 90 | | animation | `boolean` | Set to false to disable animations on new modal/backdrop. Does not toggle animations for modals/backdrops that are already displayed. | 91 | | backdrop | `boolean|string` | controls the presence of a backdrop Allowed values: - true (default) - false (no backdrop) - 'static' backdrop is present but modal window is not closed when clicking outside of the modal window | 92 | | keyboard | `boolean` | indicates whether the dialog should be closable by hitting the ESC key | 93 | | backdropClass | `string` | additional CSS class(es) to be added to a modal backdrop template | 94 | | windowClass | `string` | additional CSS class(es) to be added to a modal window template | 95 | | size | `string` | Optional suffix of modal window class. The value used is appended to the `modal-` class, i.e. a value of `sm` gives `modal-sm`. | 96 | | btnMessages | `object` | Optional map object redefining the text of a dialog button. This is only passed to built-in dialogs. The key to this object should be the same as the translation key. (ex. `DIALOGS_YES` and `DIALOGS_NO` for the `confirm` dialog) | 97 | 98 | ### Callbacks 99 | 100 | Every dialog method ( confirm, wait,error,create ) return object with **result** property, **result** is Promise. Example usage with confirm: 101 | 102 | ```javascript 103 | dialogs.confirm("Confirmation",'Do you want really do this action?') 104 | .result 105 | .then( function(){ console.log("Yes"); } ) 106 | .then( function(){ console.log("No"); } ); 107 | ``` 108 | 109 | 110 | TODO: Add more usage explanations. 111 | 112 | Demos 113 | ----- 114 | - v4.2 : [Codepen: http://codepen.io/m-e-conroy/pen/rkIqv](http://codepen.io/m-e-conroy/pen/rkIqv) 115 | - v4.2 : [Codepen: with UI-Bootstrap Date Picker directive](http://codepen.io/m-e-conroy/pen/DAxzs) 116 | - v2.0 : [Codepen: http://codepen.io/m-e-conroy/pen/AmBpL](http://codepen.io/m-e-conroy/pen/AmBpL) 117 | - v1.0 : [Codepen: http://codepen.io/m-e-conroy/pen/ALsdF](http://codepen.io/m-e-conroy/pen/ALsdF) 118 | 119 | Release Versions 120 | ---------------- 121 | - v5.2.8 : Patched problem with animations when ngAnimate is available and using Angular-Bootstrap 0.13.0 [(issue #117)](https://github.com/m-e-conroy/angular-dialog-service/issues/117) 122 | - v5.2.5 : Better detection of Font-Awesome if style sheet has been concatentated. Tested against Angular 1.3.0 & Angular-Bootstrap 0.11.2 123 | - v5.2.2 - v5.2.4 : small bugs fixes 124 | - v5.2.1 : supports Font-Awesome 125 | - v5.2.x : Angular-Translate made optional 126 | - v4.2.0 - v5.x.x+ : supports AngularJS 1.2 +, Angular UI Bootstrap 0.11.0, Bootstrap 3.1 + 127 | - v4.0.0 - v4.1.0 : supports AngularJS 1.2 +, Angular UI Bootstrap 0.10.0, Bootstrap 3 + 128 | - v3.0 : supports AngularJS 1.2 +, Angular UI Bootstrap 0.10.0 129 | - v2.0 : supports AngularJS 1.2 + 130 | - v1.0 : supports AngularJS 1.1.5 and below. 131 | 132 | 133 | v5.2.8 134 | ------ 135 | 1. Added support for these options: animation & backdropClass - because there is a problem when using Angular-Bootstrap 0.13.0's modal with ngAnimate (Angular v1.4) animation is turned off by default (https://github.com/angular-ui/bootstrap/issues/3633) 136 | 137 | v5.2.1 138 | ------ 139 | 1. Added support for Font-Awesome. 140 | 2. Added Example/faChk.html to show font-awesome inclusion. 141 | 142 | v5.2.0 143 | ------ 144 | 1. Made Angular-Translate dependency optional. 145 | 2. Added Example/index2.html to show dialog service working without including Angular-Translate. 146 | 147 | v5.1.3 148 | ------ 149 | 1. Bug fixes with regards to v5.1.2 #2 (issue #64) 150 | 151 | v5.1.2 152 | ------ 153 | 1. Bug fix for _setOpts (issue #61). 154 | 2. Changed the way resolved *header* and *msg* data is passed to the controller, so it would be easier to **decorate** each service if one so desires (issue #60). 155 | 156 | v5.1.0 157 | ------ 158 | 1. Fixed Wait dialog template, header should now display a passed parameter header to the wait service. Prior to this it would always display the default header whether or not a passed header parameter was used or not. 159 | 2. Default translations have been removed from the dialogs.main module to their own module, in order to support applications that were already using Angular-Translate and had already defined translation lists for 'en-US.' Previously including dialogs.main would have overwritten those translation lists supplied elsewhere in an application. To use the default translations: 160 | - Include the dialogs-default-translations.min.js file in your HTML file and add 'dialogs.default-translations' to your application's dependency list along with 'dialogs.main' 161 | - OR If you already had a translation list setup elsewhere in your application just copy the $translationProvider translation list in the dialogs-default-translations module to where-ever it is that you have your list configured 162 | 163 | v5.0.0 164 | ------ 165 | Re-introduction of the [opts] parameter to dialogs methods. I had many complaints about removing method level options in favor of wholly using the provider instead. 166 | 167 | 1. dialogs.error(header,msg[,opts]) 168 | 2. dialogs.wait(header,msg,progress[,opts]) 169 | 3. dialogs.notify(header,msg[,opts]) 170 | 4. dialogs.confirm(header,msg[,opts]) 171 | 5. dialogs.create(url,ctrlr,data[,opts]) 172 | 173 | v4.2.0 174 | ------ 175 | Bootstrap 3.1.1 / Angular UI Bootstrap 0.11.0 introduced a size property for dialogs. This can be controlled via the provider or by the optional *sz* parameter to the dialog methods. 176 | 177 | 1. dialogs.error(header,msg[,sz]) 178 | 2. dialogs.wait(header,msg,progress[,sz]) 179 | 3. dialogs.notify(header,msg[,sz]) 180 | 4. dialogs.confirm(header,msg[,sz]) 181 | 5. dialogs.create(url,ctrlr,data[,sz]) 182 | 183 | v4.0.0 - 4.1.0 184 | -------------- 185 | Removed *opts* and *static* parameters from dialog methods in favor of provider settings. The dialogs service is now longer **$dialogs**, the *\$* has be removed as this is reserved for Angular core services. 186 | 187 | 1. dialogs.error(header,msg) 188 | 2. dialogs.wait(header,msg,progress) 189 | 3. dialogs.notify(header,msg) 190 | 4. dialogs.confirm(header,msg) 191 | 5. dialogs.create(url,ctrlr,data) 192 | 193 | v1.0 - v3.1.0 194 | ------------- 195 | Predefined dialogs/modals. 196 | 197 | 1. $dialogs.error(header,msg,[static]) 198 | 2. $dialogs.wait(header,msg,progess,[static]) 199 | 3. $dialogs.notify(header,msg,[static]) 200 | 4. $dialogs.confirm(header,msg,[static]) 201 | 5. $dialogs.create(url,ctrlr,data,opts) 202 | 203 | Dependencies 204 | ------------ 205 | 206 | v5.2.1 + 207 | -------- 208 | 1. [Font-Awesome](http://fortawesome.github.io/Font-Awesome/) is now an optional CSS inclusion. 209 | 210 | v5.2.x + 211 | -------- 212 | 1. [Angular Translate](https://github.com/angular-translate) is now optional. 213 | 214 | v4.2.0 & v5.x.x 215 | --------------- 216 | Same as v4.0.0 with the exception of the following: 217 | 218 | 1. [Angular UI Bootstrap Modal 0.11.0, with templates](http://angular-ui.github.io/bootstrap/#/modal) 219 | 2. [Twitter Bootstrap CSS 3.1.x](http://getbootstrap.com) 220 | 221 | v4.0.0 - v4.1.0 222 | --------------- 223 | 1. AngularJS 1.2 + 224 | 2. [Angular UI Bootstrap Modal 0.10.0, with templates](http://angular-ui.github.io/bootstrap/#/modal) 225 | 3. Twitter Bootstrap CSS 3 + (includes 3.1.1) 226 | 4. Angular ngSanitize 227 | 5. [Angular Translate](https://github.com/angular-translate) 228 | 229 | v3.0 230 | ---- 231 | 1. AngularJS 1.2 + 232 | 2. Angular UI Bootstrap 0.10.0 233 | 3. Twitter Bootstrap CSS 3.0.3 234 | 4. AngularJS ngSanitize 235 | 236 | v2.0 Additional Dependencies 237 | ---------------------------- 238 | 1. All version 1.0 dependencies. 239 | 2. [Angular JS ngSanitize](http://code.angularjs.org/1.2.1/angular-sanitize.min.js) 240 | - [ngSanitize](http://docs.angularjs.org/api/ngSanitize) (needed for ng-bind-html) 241 | 242 | v1.0 243 | ---- 244 | 1. [Angular JS](http://www.angularjs.org) (version 1.1.5 and less) 245 | 2. [Angular UI Bootstrap](http://angular-ui.github.io/bootstrap/#/modal) (version <= 0.6.0, Non-Bootstrap 3 Branch) with embedded templates. 246 | 3. [Twitter Bootstrap CSS](http://getbootstrap.com) (version 2) 247 | 248 | 249 | CSS 250 | --- 251 | Included a css file that has a .modal class fix for Bootstrap and also has some predefined styles for the various modals described in the service. 252 | 253 | **v3.0 css file has the .modal class removed that had been a fix for a Bootstrap 3 display problem. This has since been rectified by Angular UI and Bootstrap.** 254 | 255 | Changes 256 | ------- 257 | 258 | - v5.2.1 259 | 1. If you use Font-Awesome, support is now provided for the icons used in the headers of each predefined dialog. The dialog service will automatically detect whether you have Font-Awesome loaded or not and use FA icons or the Bootstrap's glyphicons accordingly. If for some reason the detection doesn't work correctly you can force the use of FA icons by injecting *dialogsProvider* into your module's config function and calling **dialogsProvider.useFontAwesome()**. 260 | 261 | - v5.2.x 262 | 1. Angular-Translate is now optional, however in order to keep support for Angular-Translate and be able to switch it on and off easily without having to add lines of code to your modules I created a substitute module that is automatically included and used when Angular-Translate is not found. This subsitute (*translate-substitution.js : translate.sub*) is a provider service (*$translateProvider*) with the same *translations* method as the Angular-Translate provider service does. The provider service is also named *$translate* and has its own *instant* method. I did this such that, if in the future you do decide to use Angular-Translate all you will have to do is load the module before the dialog's service is loaded. 263 | 2. The *dialogs-default-translations.js* file is also now an optional dependency. 264 | 265 | - v5.1.0 266 | 1. Separated out the default translations into their own module: **dialogs-default-translations.js** Include this or the "min" version in your application if you are not already using $translationProvider elsewhere, otherwise just copy the translation list within the module to your translation list for 'en-US.' 267 | 268 | - v5.0.0 269 | 1. Optionally pass in options object, possible overrides are as follows 270 | 271 | ``` 272 | opts = { 273 | 'keyboard': true or false 274 | 'backdrop': 'static' or true or false 275 | 'size': 'sm' or 'lg' //small or large modal size 276 | 'windowClass': 'dialogs-default' // additional CSS class(es) to be added to a modal window 277 | 'copy': true or false // used only with create custom dialog 278 | } 279 | ``` 280 | 281 | - v4.2.0 282 | 1. Supports everything described above in v4.0.0 - v4.1.0 and added the following 283 | 284 | 2. dialogsProvider.setSize(['sm','lg']) - This will set modal size application wide, but can be overridden using the *sz* parameter added to each dialog method call. 285 | 286 | - v4.0.0 - v4.1.0 287 | 1. Removed *\$* from the *\$dialogs* service as this is reserved for core AngularJS naming. The service is now just *dialogs.* Include **dialogs.main** in your application module in order to use the the *dialogs* service 288 | 2. Changed *dialogs* service from factory to provider, you can now use **dialogsProvider** to set various options of the modals that were previously passed as parameters to the dialogs' service methods. 289 | - **dialogsProvider.useBackdrop([true,false,'static'])** - True or false to use a backdrop for the modal, 'static' to use a backdrop and disallow closing on mouse click of the backdrop. 290 | - **dialogsProvider.useEscClose([true,false])** - Whether or not to allow the use of the 'ESC' key to close the modal 291 | - **dialogsProvider.useClass([string])** - Sets an additional CSS class to the modal window 292 | - **dialogsProvider.useCopy([true,false])** - Determines whether to use angular.copy or not when passing a data object to the custom dialog service. Setting this to false will allow the modal to retain the two-way binding with the calling controller - thus changing data in the modal will automatically change it in the calling controller's scope. The default is setting is true, so if you want the two-way binding you need to set this to false. 293 | 3. Main module is no longer *dialogs* as this would conflict with the new naming of the service. It is now *dialogs.main,* include that in your application's module definition to use the *dialogs* service. 294 | 4. Added i18n support via [Angular-Translate](https://github.com/angular-translate), use the *$translateProvider* to set language specific defaults. Default language is currently *en-US.* An example is provided in the example folder that will show you how to change the defaults from English to Spanish. Translations can be set on the following: 295 | - DIALOGS_ERROR (modal header) 296 | - DIALOGS_ERROR_MSG 297 | - DIALOGS_CLOSE (modal button) 298 | - DIALOGS_PLEASE_WAIT (modal header) 299 | - DIALOGS_PLEASE_WAIT_ELIPS (modal header) 300 | - DIALOGS_PLEASE_WAIT_MSG 301 | - DIALOGS_PERCENT_COMPLETE (modal message partial) 302 | - DIALOGS_NOTIFICATION (modal header) 303 | - DIALOGS_NOTIFICATION_MSG 304 | - DIALOGS_CONFIRMATION (modal header) 305 | - DIALOGS_CONFIRMATION_MSG 306 | - DIALOGS_OK (modal button) 307 | - DIALOGS_YES (modal button) 308 | - DIALOGS_NO (modal button) 309 | 310 | - v3.0 311 | 1. Added support for Angular UI Bootstrap 0.10.0. 312 | 2. Added the ability to customize the header on the error and wait dialogs. 313 | 3. Added example files. 314 | 315 | Notes 316 | ----- 317 | 318 | - Angular Translate: v4.0 requires [Angular-Translate](https://github.com/angular-translate) be included. 319 | - Bootstrap 3: There's a problem with the actual modal being displayed even though it appears in the HTML code to be present. I found that adding a "display: block" to Bootstrap 3's .modal class solved the problem. *(v3.0 of this service no longer requires this fix)* 320 | - It should not rely on including the Bootstrap JS. 321 | - For version 2.0 + of this service module do not forget to include the *ngSanitize* Angular module. 322 | 323 | Contributing 324 | ------------ 325 | 326 | Install Dependencies 327 | 328 | ``` 329 | npm install --dev 330 | bower install 331 | ``` 332 | 333 | For Browser Testing `gulp watch` 334 | 335 | For Unit Testing `npm test` 336 | 337 | 338 | 339 | > Written with [StackEdit](https://stackedit.io/). 340 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-dialog-service", 3 | "description": "A service to handle common dialog types in a web application. Built on top of Angular-Bootstrap's modal", 4 | "version": "5.3.1", 5 | "keywords": [ 6 | "angular", 7 | "dialog", 8 | "modal", 9 | "service" 10 | ], 11 | "authors": [ 12 | { 13 | "name": "Michael Conroy", 14 | "email": "michael.e.conroy@gmail.com", 15 | "homepage": "http://michaeleconroy.blogspot.com/" 16 | } 17 | ], 18 | "license": "MIT", 19 | "repository": { 20 | "type": "git", 21 | "url": "git://github.com/m-e-conroy/angular-dialog-service" 22 | }, 23 | "ignore": [ 24 | "**/.*", 25 | "node_modules", 26 | "bower_components", 27 | "backup", 28 | "src", 29 | ".gitignore", 30 | "bower.json", 31 | "gulpfile.js", 32 | "package.json", 33 | "README.md" 34 | ], 35 | "dependencies": { 36 | "angular": "^1.5.0", 37 | "angular-sanitize": "^1.5.0", 38 | "angular-bootstrap": "^1.1.2" 39 | }, 40 | "main": [ 41 | "dist/dialogs.css", 42 | "dist/dialogs.js", 43 | "dist/dialogs-default-translations.js" 44 | ], 45 | "licenses": [ 46 | { 47 | "type": "MIT", 48 | "url": "http://www.opensource.org/licenses/MIT" 49 | } 50 | ], 51 | "devDependencies": { 52 | "angular-mocks": "~1.5.0" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /dist/dialogs-default-translations.js: -------------------------------------------------------------------------------- 1 | /** 2 | * angular-dialog-service - A service to handle common dialog types in a web application. Built on top of Angular-Bootstrap's modal 3 | * @version v5.3.1 4 | * @author Michael Conroy, michael.e.conroy@gmail.com 5 | * @license MIT, http://www.opensource.org/licenses/MIT 6 | */ 7 | /** 8 | * Dialog Default Translations. 9 | * 10 | * Include this module if you're not already using angular-translate in your application, and 11 | * add it to your application module's dependency list in order to get default header and 12 | * dialog messages to appear. 13 | * 14 | * Ex: var myApp = angular.module('myApplication',['dialogs.main','dialogs.default-translations']); 15 | * 16 | * It was necessary to separate this out for those already using angular-translate because this would 17 | * automatically reset their translation list for 'en-US' 18 | * 19 | * For those already using angular-translate, just copy the list of DIALOG_[..] translations to your 20 | * translation list where you set 'en-US' using the $translateProvider. 21 | */ 22 | 23 | //== Translations =============================================================// 24 | 25 | angular.module('dialogs.default-translations',['pascalprecht.translate']) 26 | /** 27 | * Default translations in English. 28 | * 29 | * Use angular-translate's $translateProvider to provide translations in an 30 | * alternate language. 31 | * 32 | * $translateProvider.translations('[lang]',{[translations]}); 33 | * To use alternate translations set the preferred language to your desired 34 | * language. 35 | * $translateProvider.preferredLanguage('[lang]'); 36 | */ 37 | .config(['$translateProvider',function($translateProvider){ 38 | $translateProvider.translations('de-DE',{ 39 | DIALOGS_ERROR: "Error", 40 | DIALOGS_ERROR_MSG: "Ein unbekannter Fehler ist aufgetreten.", 41 | DIALOGS_CLOSE: "Schließen", 42 | DIALOGS_PLEASE_WAIT: "Bitte warten", 43 | DIALOGS_PLEASE_WAIT_ELIPS: "Bitte warten...", 44 | DIALOGS_PLEASE_WAIT_MSG: "Warte auf Fertigstellung der Operation.", 45 | DIALOGS_PERCENT_COMPLETE: "% fertig", 46 | DIALOGS_NOTIFICATION: "Benachrichtigung", 47 | DIALOGS_NOTIFICATION_MSG: "Unbekannte Anwendungsbenachrichtigung.", 48 | DIALOGS_CONFIRMATION: "Bestätigung", 49 | DIALOGS_CONFIRMATION_MSG: "Bestätigung erforderlich.", 50 | DIALOGS_OK: "OK", 51 | DIALOGS_YES: "Ja", 52 | DIALOGS_NO: "Nein" 53 | }); 54 | 55 | $translateProvider.translations('en-US',{ 56 | DIALOGS_ERROR: "Error", 57 | DIALOGS_ERROR_MSG: "An unknown error has occurred.", 58 | DIALOGS_CLOSE: "Close", 59 | DIALOGS_PLEASE_WAIT: "Please Wait", 60 | DIALOGS_PLEASE_WAIT_ELIPS: "Please Wait...", 61 | DIALOGS_PLEASE_WAIT_MSG: "Waiting on operation to complete.", 62 | DIALOGS_PERCENT_COMPLETE: "% Complete", 63 | DIALOGS_NOTIFICATION: "Notification", 64 | DIALOGS_NOTIFICATION_MSG: "Unknown application notification.", 65 | DIALOGS_CONFIRMATION: "Confirmation", 66 | DIALOGS_CONFIRMATION_MSG: "Confirmation required.", 67 | DIALOGS_OK: "OK", 68 | DIALOGS_YES: "Yes", 69 | DIALOGS_NO: "No" 70 | }); 71 | 72 | $translateProvider.translations('es-ES',{ 73 | DIALOGS_ERROR: "Error", 74 | DIALOGS_ERROR_MSG: "Se ha producido un error.", 75 | DIALOGS_CLOSE: "Cerrar", 76 | DIALOGS_PLEASE_WAIT: "Espere por favor", 77 | DIALOGS_PLEASE_WAIT_ELIPS: "Espere por favor...", 78 | DIALOGS_PLEASE_WAIT_MSG: "Completando operación.", 79 | DIALOGS_PERCENT_COMPLETE: "% Completado", 80 | DIALOGS_NOTIFICATION: "Notificación", 81 | DIALOGS_NOTIFICATION_MSG: "Notificación de una aplicación desconocida.", 82 | DIALOGS_CONFIRMATION: "Confirmación", 83 | DIALOGS_CONFIRMATION_MSG: "Se requiere confirmacion.", 84 | DIALOGS_OK: "Aceptar", 85 | DIALOGS_YES: "Sí", 86 | DIALOGS_NO: "No" 87 | }); 88 | 89 | $translateProvider.translations("fr-FR", { 90 | DIALOGS_ERROR: "Erreur", 91 | DIALOGS_ERROR_MSG: "Une erreur inconnue s'est produite.", 92 | DIALOGS_CLOSE: "Fermer", 93 | DIALOGS_PLEASE_WAIT: "Patientez svp", 94 | DIALOGS_PLEASE_WAIT_ELIPS: "Patienter svp...", 95 | DIALOGS_PLEASE_WAIT_MSG: "En attente de la fin de l'opération.", 96 | DIALOGS_PERCENT_COMPLETE: "% Terminer", 97 | DIALOGS_NOTIFICATION: "Notification", 98 | DIALOGS_NOTIFICATION_MSG: "Notification de l'application inconnue", 99 | DIALOGS_CONFIRMATION: "Confirmer", 100 | DIALOGS_CONFIRMATION_MSG: "Merci de confirmer", 101 | DIALOGS_OK: "OK", 102 | DIALOGS_YES: "Oui", 103 | DIALOGS_NO: "Non" 104 | }); 105 | 106 | $translateProvider.translations('pt-BR',{ 107 | DIALOGS_ERROR: "Erro", 108 | DIALOGS_ERROR_MSG: "Ocorreu um erro inesperado.", 109 | DIALOGS_CLOSE: "Fechar", 110 | DIALOGS_PLEASE_WAIT: "Por favor aguarde", 111 | DIALOGS_PLEASE_WAIT_ELIPS: "Por favor aguarde...", 112 | DIALOGS_PLEASE_WAIT_MSG: "Aguardando que a operação termine.", 113 | DIALOGS_PERCENT_COMPLETE: "% Completados", 114 | DIALOGS_NOTIFICATION: "Notificação", 115 | DIALOGS_NOTIFICATION_MSG: "Notificação de aplicação desconhecida.", 116 | DIALOGS_CONFIRMATION: "Confirmação", 117 | DIALOGS_CONFIRMATION_MSG: "Confirmação requerida.", 118 | DIALOGS_OK: "OK", 119 | DIALOGS_YES: "Sim", 120 | DIALOGS_NO: "Não" 121 | }); 122 | 123 | $translateProvider.translations('tr-TR',{ 124 | DIALOGS_ERROR: "Hata", 125 | DIALOGS_ERROR_MSG: "Bilinmeyen bir hata oluştu.", 126 | DIALOGS_CLOSE: "Kapat", 127 | DIALOGS_PLEASE_WAIT: "Lütfen Bekleyin", 128 | DIALOGS_PLEASE_WAIT_ELIPS: "Lütfen Bekleyin...", 129 | DIALOGS_PLEASE_WAIT_MSG: "İşlemin tamamlanması bekleniyor.", 130 | DIALOGS_PERCENT_COMPLETE: "% Tamamlandı", 131 | DIALOGS_NOTIFICATION: "Uyarı", 132 | DIALOGS_NOTIFICATION_MSG: "Bilinmeyen uygulama uyarısı.", 133 | DIALOGS_CONFIRMATION: "Konfirmasyon", 134 | DIALOGS_CONFIRMATION_MSG: "Konfirmasyon gereklidir.", 135 | DIALOGS_OK: "Tamam", 136 | DIALOGS_YES: "Evet", 137 | DIALOGS_NO: "Hayır" 138 | }); 139 | 140 | $translateProvider.translations('zh-CN',{ 141 | DIALOGS_ERROR: "错误", 142 | DIALOGS_ERROR_MSG: "出现未知错误。", 143 | DIALOGS_CLOSE: "关闭", 144 | DIALOGS_PLEASE_WAIT: "请稍候", 145 | DIALOGS_PLEASE_WAIT_ELIPS: "请稍候...", 146 | DIALOGS_PLEASE_WAIT_MSG: "请等待操作完成。", 147 | DIALOGS_PERCENT_COMPLETE: "% 已完成", 148 | DIALOGS_NOTIFICATION: "通知", 149 | DIALOGS_NOTIFICATION_MSG: "未知应用程序的通知。", 150 | DIALOGS_CONFIRMATION: "确认", 151 | DIALOGS_CONFIRMATION_MSG: "确认要求。", 152 | DIALOGS_OK: "确定", 153 | DIALOGS_YES: "确认", 154 | DIALOGS_NO: "取消" 155 | }); 156 | 157 | $translateProvider.translations('sv-SE',{ 158 | DIALOGS_ERROR: "Fel", 159 | DIALOGS_ERROR_MSG: "Ett okänt fel har uppstått.", 160 | DIALOGS_CLOSE: "Stäng", 161 | DIALOGS_PLEASE_WAIT: "Vänligen vänta", 162 | DIALOGS_PLEASE_WAIT_ELIPS: "Vänligen vänta...", 163 | DIALOGS_PLEASE_WAIT_MSG: "Väntar på att processen skall slutföras.", 164 | DIALOGS_PERCENT_COMPLETE: "% Färdigt", 165 | DIALOGS_NOTIFICATION: "Meddelande", 166 | DIALOGS_NOTIFICATION_MSG: "Okänt meddelande från applikationen.", 167 | DIALOGS_CONFIRMATION: "Bekräftelse", 168 | DIALOGS_CONFIRMATION_MSG: "Bekräftelse krävs.", 169 | DIALOGS_OK: "OK", 170 | DIALOGS_YES: "Ja", 171 | DIALOGS_NO: "Nej" 172 | }); 173 | 174 | $translateProvider.translations('it-IT',{ 175 | DIALOGS_ERROR: "Errore", 176 | DIALOGS_ERROR_MSG: "Si è verificato un errore sconosciuto.", 177 | DIALOGS_CLOSE: "Chiudi", 178 | DIALOGS_PLEASE_WAIT: "Attendere prego", 179 | DIALOGS_PLEASE_WAIT_ELIPS: "Attendere prego...", 180 | DIALOGS_PLEASE_WAIT_MSG: "Attendo il completamento dell'operazione.", 181 | DIALOGS_PERCENT_COMPLETE: "% Completo", 182 | DIALOGS_NOTIFICATION: "Notifica", 183 | DIALOGS_NOTIFICATION_MSG: "Notifica dell'applicazione sconosciuta.", 184 | DIALOGS_CONFIRMATION: "Conferma", 185 | DIALOGS_CONFIRMATION_MSG: "Conferma richiesta.", 186 | DIALOGS_OK: "OK", 187 | DIALOGS_YES: "Sì", 188 | DIALOGS_NO: "No" 189 | }); 190 | 191 | $translateProvider.preferredLanguage('en-US'); 192 | }]); // end config 193 | -------------------------------------------------------------------------------- /dist/dialogs-default-translations.min.js: -------------------------------------------------------------------------------- 1 | angular.module("dialogs.default-translations",["pascalprecht.translate"]).config(["$translateProvider",function(O){O.translations("de-DE",{DIALOGS_ERROR:"Error",DIALOGS_ERROR_MSG:"Ein unbekannter Fehler ist aufgetreten.",DIALOGS_CLOSE:"Schließen",DIALOGS_PLEASE_WAIT:"Bitte warten",DIALOGS_PLEASE_WAIT_ELIPS:"Bitte warten...",DIALOGS_PLEASE_WAIT_MSG:"Warte auf Fertigstellung der Operation.",DIALOGS_PERCENT_COMPLETE:"% fertig",DIALOGS_NOTIFICATION:"Benachrichtigung",DIALOGS_NOTIFICATION_MSG:"Unbekannte Anwendungsbenachrichtigung.",DIALOGS_CONFIRMATION:"Bestätigung",DIALOGS_CONFIRMATION_MSG:"Bestätigung erforderlich.",DIALOGS_OK:"OK",DIALOGS_YES:"Ja",DIALOGS_NO:"Nein"}),O.translations("en-US",{DIALOGS_ERROR:"Error",DIALOGS_ERROR_MSG:"An unknown error has occurred.",DIALOGS_CLOSE:"Close",DIALOGS_PLEASE_WAIT:"Please Wait",DIALOGS_PLEASE_WAIT_ELIPS:"Please Wait...",DIALOGS_PLEASE_WAIT_MSG:"Waiting on operation to complete.",DIALOGS_PERCENT_COMPLETE:"% Complete",DIALOGS_NOTIFICATION:"Notification",DIALOGS_NOTIFICATION_MSG:"Unknown application notification.",DIALOGS_CONFIRMATION:"Confirmation",DIALOGS_CONFIRMATION_MSG:"Confirmation required.",DIALOGS_OK:"OK",DIALOGS_YES:"Yes",DIALOGS_NO:"No"}),O.translations("es-ES",{DIALOGS_ERROR:"Error",DIALOGS_ERROR_MSG:"Se ha producido un error.",DIALOGS_CLOSE:"Cerrar",DIALOGS_PLEASE_WAIT:"Espere por favor",DIALOGS_PLEASE_WAIT_ELIPS:"Espere por favor...",DIALOGS_PLEASE_WAIT_MSG:"Completando operación.",DIALOGS_PERCENT_COMPLETE:"% Completado",DIALOGS_NOTIFICATION:"Notificación",DIALOGS_NOTIFICATION_MSG:"Notificación de una aplicación desconocida.",DIALOGS_CONFIRMATION:"Confirmación",DIALOGS_CONFIRMATION_MSG:"Se requiere confirmacion.",DIALOGS_OK:"Aceptar",DIALOGS_YES:"Sí",DIALOGS_NO:"No"}),O.translations("fr-FR",{DIALOGS_ERROR:"Erreur",DIALOGS_ERROR_MSG:"Une erreur inconnue s'est produite.",DIALOGS_CLOSE:"Fermer",DIALOGS_PLEASE_WAIT:"Patientez svp",DIALOGS_PLEASE_WAIT_ELIPS:"Patienter svp...",DIALOGS_PLEASE_WAIT_MSG:"En attente de la fin de l'opération.",DIALOGS_PERCENT_COMPLETE:"% Terminer",DIALOGS_NOTIFICATION:"Notification",DIALOGS_NOTIFICATION_MSG:"Notification de l'application inconnue",DIALOGS_CONFIRMATION:"Confirmer",DIALOGS_CONFIRMATION_MSG:"Merci de confirmer",DIALOGS_OK:"OK",DIALOGS_YES:"Oui",DIALOGS_NO:"Non"}),O.translations("pt-BR",{DIALOGS_ERROR:"Erro",DIALOGS_ERROR_MSG:"Ocorreu um erro inesperado.",DIALOGS_CLOSE:"Fechar",DIALOGS_PLEASE_WAIT:"Por favor aguarde",DIALOGS_PLEASE_WAIT_ELIPS:"Por favor aguarde...",DIALOGS_PLEASE_WAIT_MSG:"Aguardando que a operação termine.",DIALOGS_PERCENT_COMPLETE:"% Completados",DIALOGS_NOTIFICATION:"Notificação",DIALOGS_NOTIFICATION_MSG:"Notificação de aplicação desconhecida.",DIALOGS_CONFIRMATION:"Confirmação",DIALOGS_CONFIRMATION_MSG:"Confirmação requerida.",DIALOGS_OK:"OK",DIALOGS_YES:"Sim",DIALOGS_NO:"Não"}),O.translations("tr-TR",{DIALOGS_ERROR:"Hata",DIALOGS_ERROR_MSG:"Bilinmeyen bir hata oluştu.",DIALOGS_CLOSE:"Kapat",DIALOGS_PLEASE_WAIT:"Lütfen Bekleyin",DIALOGS_PLEASE_WAIT_ELIPS:"Lütfen Bekleyin...",DIALOGS_PLEASE_WAIT_MSG:"İşlemin tamamlanması bekleniyor.",DIALOGS_PERCENT_COMPLETE:"% Tamamlandı",DIALOGS_NOTIFICATION:"Uyarı",DIALOGS_NOTIFICATION_MSG:"Bilinmeyen uygulama uyarısı.",DIALOGS_CONFIRMATION:"Konfirmasyon",DIALOGS_CONFIRMATION_MSG:"Konfirmasyon gereklidir.",DIALOGS_OK:"Tamam",DIALOGS_YES:"Evet",DIALOGS_NO:"Hayır"}),O.translations("zh-CN",{DIALOGS_ERROR:"错误",DIALOGS_ERROR_MSG:"出现未知错误。",DIALOGS_CLOSE:"关闭",DIALOGS_PLEASE_WAIT:"请稍候",DIALOGS_PLEASE_WAIT_ELIPS:"请稍候...",DIALOGS_PLEASE_WAIT_MSG:"请等待操作完成。",DIALOGS_PERCENT_COMPLETE:"% 已完成",DIALOGS_NOTIFICATION:"通知",DIALOGS_NOTIFICATION_MSG:"未知应用程序的通知。",DIALOGS_CONFIRMATION:"确认",DIALOGS_CONFIRMATION_MSG:"确认要求。",DIALOGS_OK:"确定",DIALOGS_YES:"确认",DIALOGS_NO:"取消"}),O.translations("sv-SE",{DIALOGS_ERROR:"Fel",DIALOGS_ERROR_MSG:"Ett okänt fel har uppstått.",DIALOGS_CLOSE:"Stäng",DIALOGS_PLEASE_WAIT:"Vänligen vänta",DIALOGS_PLEASE_WAIT_ELIPS:"Vänligen vänta...",DIALOGS_PLEASE_WAIT_MSG:"Väntar på att processen skall slutföras.",DIALOGS_PERCENT_COMPLETE:"% Färdigt",DIALOGS_NOTIFICATION:"Meddelande",DIALOGS_NOTIFICATION_MSG:"Okänt meddelande från applikationen.",DIALOGS_CONFIRMATION:"Bekräftelse",DIALOGS_CONFIRMATION_MSG:"Bekräftelse krävs.",DIALOGS_OK:"OK",DIALOGS_YES:"Ja",DIALOGS_NO:"Nej"}),O.translations("it-IT",{DIALOGS_ERROR:"Errore",DIALOGS_ERROR_MSG:"Si è verificato un errore sconosciuto.",DIALOGS_CLOSE:"Chiudi",DIALOGS_PLEASE_WAIT:"Attendere prego",DIALOGS_PLEASE_WAIT_ELIPS:"Attendere prego...",DIALOGS_PLEASE_WAIT_MSG:"Attendo il completamento dell'operazione.",DIALOGS_PERCENT_COMPLETE:"% Completo",DIALOGS_NOTIFICATION:"Notifica",DIALOGS_NOTIFICATION_MSG:"Notifica dell'applicazione non consentita.",DIALOGS_CONFIRMATION:"Conferma",DIALOGS_CONFIRMATION_MSG:"Conferma richiesta.",DIALOGS_OK:"OK",DIALOGS_YES:"Sì",DIALOGS_NO:"No"}),O.preferredLanguage("en-US")}]); 2 | -------------------------------------------------------------------------------- /dist/dialogs.css: -------------------------------------------------------------------------------- 1 | /* Custom dialog/modal headers */ 2 | 3 | .dialog-header-error { background-color: #d2322d; } 4 | .dialog-header-wait { background-color: #428bca; } 5 | .dialog-header-notify { background-color: #eeeeee; } 6 | .dialog-header-confirm { background-color: #333333; } 7 | .dialog-header-error span, .dialog-header-error h4, 8 | .dialog-header-wait span, .dialog-header-wait h4, 9 | .dialog-header-confirm span, .dialog-header-confirm h4 { color: #ffffff; } 10 | -------------------------------------------------------------------------------- /dist/dialogs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * angular-dialog-service - A service to handle common dialog types in a web application. Built on top of Angular-Bootstrap's modal 3 | * @version v5.3.1 4 | * @author Michael Conroy, michael.e.conroy@gmail.com 5 | * @license MIT, http://www.opensource.org/licenses/MIT 6 | */ 7 | (function(){ 8 | "use strict"; 9 | //== Translate Substitute Module =============================================// 10 | 11 | /** 12 | * For those not using Angular-Translate (pascalprecht.translate), this will sub 13 | * in for it so we don't have to include Angular-Translate if we don't want to. 14 | */ 15 | 16 | var translateSubMod = angular.module('translate.sub',[]); 17 | 18 | /** 19 | * $translate Service 20 | * Sets up a $translateProvider service to use in your module's config 21 | * function. $translate.Provider syntax is the same as Angular-Translate, 22 | * use $translate.Provider.translations(lang,obj) to change the defaults 23 | * for modal button, header and message text. 24 | */ 25 | translateSubMod.provider('$translate',[function(){ 26 | var _translations = []; // object of key/value translation pairs 27 | var _current = 'en-US'; // default language 28 | 29 | /** 30 | * Translations 31 | * Set the internal object of translation key/value pairs. 32 | */ 33 | this.translations = function(lang,obj){ 34 | if(angular.isDefined(lang) && angular.isDefined(obj)){ 35 | _translations[lang] = angular.copy(obj); 36 | _current = lang; 37 | } 38 | }; // end translations 39 | 40 | this.$get = [function(){ 41 | return { 42 | /** 43 | * Instant 44 | * Retrieve the translation for the given key, if key not found 45 | * return the key. 46 | * Example: $translate.instant('DIALOGS_OK'); 47 | */ 48 | instant : function(what){ 49 | if(angular.isDefined(what) && angular.isDefined(_translations[_current][what])) 50 | return _translations[_current][what]; 51 | else 52 | return what; 53 | } // end instant 54 | }; // end return 55 | }]; // end $get 56 | 57 | }]); // end $translate 58 | 59 | /** 60 | * Translate Filter 61 | * For use in an Angular template. 62 | * Example: {{"DIALOGS_CLOSE" | translate}} 63 | */ 64 | translateSubMod.filter('translate',['$translate',function($translate){ 65 | return function(what){ 66 | return $translate.instant(what); 67 | }; 68 | }]); // end translate / translate.sub 69 | //== Controllers =============================================================// 70 | 71 | var ctrlrs; // will be dialogs.controllers module 72 | 73 | // determine if Angular-Translate is available, if not use the substitute 74 | try{ 75 | angular.module('pascalprecht.translate'); // throws error if module not loaded 76 | // console.log('Dialogs (Angular-Translate): OK'); 77 | 78 | // dialogs.controllers: module declaration 79 | ctrlrs = angular.module('dialogs.controllers',['ui.bootstrap.modal','pascalprecht.translate']); 80 | }catch(err){ 81 | // console.log('Dialogs: (Angular-Translate): ' + err.message); 82 | // console.log('Dialogs: Attempting to use translate.sub module.'); 83 | 84 | // dialogs.controllers: module declaration 85 | ctrlrs = angular.module('dialogs.controllers',['ui.bootstrap.modal','translate.sub']); 86 | } // end try/catch 87 | 88 | // angular.module('dialogs.controllers',['ui.bootstrap.modal','pascalprecht.translate']) 89 | 90 | /** 91 | * Error Dialog Controller 92 | */ 93 | ctrlrs.controller('errorDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){ 94 | //-- Variables -----// 95 | 96 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_ERROR'); 97 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_ERROR_MSG'); 98 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-warning' : 'glyphicon glyphicon-warning-sign'; 99 | $scope.btnMessages = data.btnMessages || {}; 100 | 101 | //-- Methods -----// 102 | 103 | $scope.close = function(){ 104 | $uibModalInstance.close(); 105 | $scope.$destroy(); 106 | }; // end close 107 | }]); // end ErrorDialogCtrl 108 | 109 | /** 110 | * Wait Dialog Controller 111 | */ 112 | ctrlrs.controller('waitDialogCtrl',['$scope','$uibModalInstance','$translate','$timeout','data',function($scope,$uibModalInstance,$translate,$timeout,data){ 113 | //-- Variables -----// 114 | 115 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_PLEASE_WAIT_ELIPS'); 116 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_PLEASE_WAIT_MSG'); 117 | $scope.progress = (angular.isDefined(data.progress)) ? data.progress : 100; 118 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-clock-o' : 'glyphicon glyphicon-time'; 119 | $scope.btnMessages = data.btnMessages || {}; 120 | 121 | //-- Listeners -----// 122 | 123 | // Note: used $timeout instead of $scope.$apply() because I was getting a $$nextSibling error 124 | 125 | // close wait dialog 126 | $scope.$on('dialogs.wait.complete',function(){ 127 | $timeout(function(){ $uibModalInstance.close(); $scope.$destroy(); }); 128 | }); // end on(dialogs.wait.complete) 129 | 130 | // update the dialog's message 131 | $scope.$on('dialogs.wait.message',function(evt,args){ 132 | $scope.msg = (angular.isDefined(args.msg)) ? args.msg : $scope.msg; 133 | }); // end on(dialogs.wait.message) 134 | 135 | // update the dialog's progress (bar) and/or message 136 | $scope.$on('dialogs.wait.progress',function(evt,args){ 137 | $scope.msg = (angular.isDefined(args.msg)) ? args.msg : $scope.msg; 138 | $scope.progress = (angular.isDefined(args.progress)) ? args.progress : $scope.progress; 139 | }); // end on(dialogs.wait.progress) 140 | 141 | //-- Methods -----// 142 | 143 | $scope.getProgress = function(){ 144 | return {'width': $scope.progress + '%'}; 145 | }; // end getProgress 146 | 147 | }]); // end WaitDialogCtrl 148 | 149 | /** 150 | * Notify Dialog Controller 151 | */ 152 | ctrlrs.controller('notifyDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){ 153 | //-- Variables -----// 154 | 155 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_NOTIFICATION'); 156 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_NOTIFICATION_MSG'); 157 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-info' : 'glyphicon glyphicon-info-sign'; 158 | $scope.btnMessages = data.btnMessages || {}; 159 | 160 | //-- Methods -----// 161 | 162 | $scope.close = function(){ 163 | $uibModalInstance.close(); 164 | $scope.$destroy(); 165 | }; // end close 166 | }]); // end WaitDialogCtrl 167 | 168 | /** 169 | * Confirm Dialog Controller 170 | */ 171 | ctrlrs.controller('confirmDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){ 172 | //-- Variables -----// 173 | 174 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_CONFIRMATION'); 175 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_CONFIRMATION_MSG'); 176 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-check' : 'glyphicon glyphicon-check'; 177 | $scope.btnMessages = data.btnMessages || {}; 178 | 179 | //-- Methods -----// 180 | 181 | $scope.no = function(){ 182 | $uibModalInstance.dismiss('no'); 183 | }; // end close 184 | 185 | $scope.yes = function(){ 186 | $uibModalInstance.close('yes'); 187 | }; // end yes 188 | }]); // end ConfirmDialogCtrl / dialogs.controllers 189 | //== Services ================================================================// 190 | 191 | angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers']) 192 | 193 | .provider('dialogs',[function(){ 194 | var _b = true; // backdrop 195 | var _k = true; // keyboard 196 | var _w = 'dialogs-default'; // windowClass 197 | var _bdc = 'dialogs-backdrop-default'; // backdropClass 198 | var _copy = true; // controls use of angular.copy 199 | var _wTmpl = null; // window template 200 | var _wSize = 'lg'; // large modal window default 201 | var _animation = false; // true/false to use animation 202 | 203 | var _fa = false; // fontawesome flag 204 | 205 | var _setOpts = function(opts){ 206 | var _opts = {}; 207 | opts = opts || {}; 208 | _opts.kb = (angular.isDefined(opts.keyboard)) ? !!opts.keyboard : _k; // values: true,false 209 | _opts.bd = (angular.isDefined(opts.backdrop)) ? opts.backdrop : _b; // values: 'static',true,false 210 | _opts.bdc = (angular.isDefined(opts.backdropClass)) ? opts.backdropClass : _bdc; // additional CSS class(es) to be added to the modal backdrop 211 | _opts.ws = (angular.isDefined(opts.size) && ((opts.size === 'sm') || (opts.size === 'lg') || (opts.size === 'md'))) ? opts.size : _wSize; // values: 'sm', 'lg', 'md' 212 | _opts.wc = (angular.isDefined(opts.windowClass)) ? opts.windowClass : _w; // additional CSS class(es) to be added to a modal window 213 | _opts.anim = (angular.isDefined(opts.animation)) ? !!opts.animation : _animation; // values: true,false 214 | _opts.btnMessages = (angular.isDefined(opts.btnMessages)) ? opts.btnMessages : {}; // button overrides 215 | return _opts; 216 | }; // end _setOpts 217 | 218 | /** 219 | * Use Backdrop 220 | * 221 | * Sets the use of the modal backdrop. Either to have one or not and 222 | * whether or not it responds to mouse clicks ('static' sets the 223 | * backdrop to true and does not respond to mouse clicks). 224 | * 225 | * @param val mixed (true, false, 'static') 226 | */ 227 | this.useBackdrop = function(val){ // possible values : true, false, 'static' 228 | if(angular.isDefined(val)) 229 | _b = val; 230 | }; // end useStaticBackdrop 231 | 232 | /** 233 | * Use ESC Close 234 | * 235 | * Sets the use of the ESC (escape) key to close modal windows. 236 | * 237 | * @param val boolean 238 | */ 239 | this.useEscClose = function(val){ // possible values : true, false 240 | if(angular.isDefined(val)) 241 | _k = (!angular.equals(val,0) && !angular.equals(val,'false') && !angular.equals(val,'no') && !angular.equals(val,null) && !angular.equals(val,false)) ? true : false; 242 | }; // end useESCClose 243 | 244 | /** 245 | * Use Class 246 | * 247 | * Sets the additional CSS window class of the modal window template. 248 | * 249 | * @param val string 250 | */ 251 | this.useClass = function(val){ 252 | if(angular.isDefined(val)) 253 | _w = val; 254 | }; // end useClass 255 | 256 | /** 257 | * Use Copy 258 | * 259 | * Determines the use of angular.copy when sending data to the modal controller. 260 | * 261 | * @param val boolean 262 | */ 263 | this.useCopy = function(val){ 264 | if(angular.isDefined(val)) 265 | _copy = (!angular.equals(val,0) && !angular.equals(val,'false') && !angular.equals(val,'no') && !angular.equals(val,null) && !angular.equals(val,false)) ? true : false; 266 | }; // end useCopy 267 | 268 | /** 269 | * Set Window Template 270 | * 271 | * Sets a path to a template to use overriding modal's window template. 272 | * 273 | * @param val string 274 | */ 275 | this.setWindowTmpl = function(val){ 276 | if(angular.isDefined(val)) 277 | _wTmpl = val; 278 | }; // end setWindowTmpl 279 | 280 | /** 281 | * Set Size 282 | * 283 | * Sets the modal size to use (sm,lg,md) 284 | * 285 | * @param val string (sm,lg,md) 286 | */ 287 | this.setSize = function(val){ 288 | if(angular.isDefined(val)) 289 | _wSize = (angular.equals(val,'sm') || angular.equals(val,'lg') || angular.equals(val,'md')) ? val : _wSize; 290 | }; // end setSize 291 | 292 | /** 293 | * Use Animations 294 | * 295 | * Sets the use of animations to true 296 | */ 297 | this.useAnimation = function(){ 298 | _animation = true; 299 | }; // end useAnimation 300 | 301 | /** 302 | * Use Font-Awesome. 303 | * 304 | * Sets Font-Awesome flag to true and substitutes font-awesome icons for 305 | * Bootstrap's glyphicons. 306 | */ 307 | this.useFontAwesome = function(){ 308 | _fa = true; 309 | }; // end useFontAwesome 310 | 311 | 312 | this.$get = ['$uibModal',function ($uibModal){ 313 | 314 | return { 315 | /** 316 | * Error Dialog 317 | * 318 | * @param header string 319 | * @param msg string 320 | * @param opts object 321 | */ 322 | error : function(header,msg,opts){ 323 | opts = _setOpts(opts); 324 | 325 | return $uibModal.open({ 326 | templateUrl : '/dialogs/error.html', 327 | controller : 'errorDialogCtrl', 328 | backdrop: opts.bd, 329 | backdropClass: opts.bdc, 330 | keyboard: opts.kb, 331 | windowClass: opts.wc, 332 | size: opts.ws, 333 | animation: opts.anim, 334 | resolve : { 335 | data : function(){ 336 | return { 337 | header : angular.copy(header), 338 | msg : angular.copy(msg), 339 | fa : _fa, 340 | btnMessages: opts.btnMessages 341 | }; 342 | } 343 | } 344 | }); // end modal.open 345 | }, // end error 346 | 347 | /** 348 | * Wait Dialog 349 | * 350 | * @param header string 351 | * @param msg string 352 | * @param progress int 353 | * @param opts object 354 | */ 355 | wait : function(header,msg,progress,opts){ 356 | opts = _setOpts(opts); 357 | 358 | return $uibModal.open({ 359 | templateUrl : '/dialogs/wait.html', 360 | controller : 'waitDialogCtrl', 361 | backdrop: opts.bd, 362 | backdropClass: opts.bdc, 363 | keyboard: opts.kb, 364 | windowClass: opts.wc, 365 | size: opts.ws, 366 | animation: opts.anim, 367 | resolve : { 368 | data : function(){ 369 | return { 370 | header : angular.copy(header), 371 | msg : angular.copy(msg), 372 | progress : angular.copy(progress), 373 | fa : _fa 374 | }; 375 | } 376 | } 377 | }); // end modal.open 378 | }, // end wait 379 | 380 | /** 381 | * Notify Dialog 382 | * 383 | * @param header string 384 | * @param msg string 385 | * @param opts object 386 | */ 387 | notify : function(header,msg,opts){ 388 | opts = _setOpts(opts); 389 | 390 | return $uibModal.open({ 391 | templateUrl : '/dialogs/notify.html', 392 | controller : 'notifyDialogCtrl', 393 | backdrop: opts.bd, 394 | backdropClass: opts.bdc, 395 | keyboard: opts.kb, 396 | windowClass: opts.wc, 397 | size: opts.ws, 398 | animation: opts.anim, 399 | resolve : { 400 | data : function(){ 401 | return { 402 | header : angular.copy(header), 403 | msg : angular.copy(msg), 404 | fa : _fa, 405 | btnMessages: opts.btnMessages 406 | }; 407 | } 408 | } 409 | }); // end modal.open 410 | }, // end notify 411 | 412 | /** 413 | * Confirm Dialog 414 | * 415 | * @param header string 416 | * @param msg string 417 | * @param opts object 418 | */ 419 | confirm : function(header,msg,opts){ 420 | opts = _setOpts(opts); 421 | 422 | return $uibModal.open({ 423 | templateUrl : '/dialogs/confirm.html', 424 | controller : 'confirmDialogCtrl', 425 | backdrop: opts.bd, 426 | backdropClass: opts.bdc, 427 | keyboard: opts.kb, 428 | windowClass: opts.wc, 429 | size: opts.ws, 430 | animation: opts.anim, 431 | resolve : { 432 | data : function(){ 433 | return { 434 | header : angular.copy(header), 435 | msg : angular.copy(msg), 436 | fa : _fa, 437 | btnMessages: opts.btnMessages 438 | }; 439 | } 440 | } 441 | }); // end modal.open 442 | }, // end confirm 443 | 444 | /** 445 | * Create Custom Dialog 446 | * 447 | * @param url string 448 | * @param ctrlr string 449 | * @param data object 450 | * @param opts object 451 | */ 452 | create : function(url,ctrlr,data,opts,ctrlAs){ 453 | var copy = (opts && angular.isDefined(opts.copy)) ? opts.copy : _copy; 454 | opts = _setOpts(opts); 455 | 456 | return $uibModal.open({ 457 | templateUrl : url, 458 | controller : ctrlr, 459 | controllerAs : ctrlAs, 460 | keyboard : opts.kb, 461 | backdrop : opts.bd, 462 | backdropClass: opts.bdc, 463 | windowClass: opts.wc, 464 | size: opts.ws, 465 | animation: opts.anim, 466 | resolve : { 467 | data : function() { 468 | if(copy) 469 | return angular.copy(data); 470 | else 471 | return data; 472 | } 473 | } 474 | }); // end modal.open 475 | } // end create 476 | 477 | }; // end return 478 | 479 | }]; // end $get 480 | }]); // end provider dialogs 481 | //== Dialogs.Main Module =====================================================// 482 | 483 | /** 484 | * Include this module 'dialogs.main' in your module's dependency list where you 485 | * intend to use it. Then inject the 'dialogs' service in your controllers that 486 | * need it. 487 | */ 488 | 489 | angular.module('dialogs.main',['dialogs.services','ngSanitize']) // requires angular-sanitize.min.js (ngSanitize) //code.angularjs.org/1.2.1/angular-sanitize.min.js 490 | 491 | .config(['$translateProvider','dialogsProvider',function($translateProvider,dialogsProvider){ 492 | /** 493 | * if Angular-Translate is not loaded, use the translate substitute 494 | * module and create default translations to use as default modal texts 495 | */ 496 | try{ 497 | angular.module('pascalprecht.translate'); 498 | }catch(err){ 499 | // console.log('Dialogs: Creating default translations for use without Angular-Translate.'); 500 | 501 | // This will set default modal buttons, header and message text 502 | $translateProvider.translations('en-US',{ 503 | DIALOGS_ERROR: "Error", 504 | DIALOGS_ERROR_MSG: "An unknown error has occurred.", 505 | DIALOGS_CLOSE: "Close", 506 | DIALOGS_PLEASE_WAIT: "Please Wait", 507 | DIALOGS_PLEASE_WAIT_ELIPS: "Please Wait...", 508 | DIALOGS_PLEASE_WAIT_MSG: "Waiting on operation to complete.", 509 | DIALOGS_PERCENT_COMPLETE: "% Complete", 510 | DIALOGS_NOTIFICATION: "Notification", 511 | DIALOGS_NOTIFICATION_MSG: "Unknown application notification.", 512 | DIALOGS_CONFIRMATION: "Confirmation", 513 | DIALOGS_CONFIRMATION_MSG: "Confirmation required.", 514 | DIALOGS_OK: "OK", 515 | DIALOGS_YES: "Yes", 516 | DIALOGS_NO: "No" 517 | }); 518 | } // end try/catch 519 | 520 | /** 521 | * Attempt to ascertain if page is using Font Awesome instead of the 522 | * regular Bootstrap Icons. If you are changing the stylesheet name or 523 | * not including it from a CDN or have included Font-Awesome as a 524 | * concatentation of CSS sheets together, then you will have to manually 525 | * set Font-Awesome usage in your Angular Module's config by including 526 | * the $dialogsProvider and calling the method $dialogsProvider.useFontAwesome(). 527 | */ 528 | try{ 529 | var _sheets = document.styleSheets; 530 | 531 | sheetLoop: 532 | for(var i = (_sheets.length - 1);i >= 0;i--){ 533 | var _matches = null; 534 | var _rules = null; 535 | 536 | if(!_sheets[i].disabled){ 537 | // check href of style sheet first 538 | if(_sheets[i].href !== null) 539 | _matches = _sheets[i].href.match(/font\-*awesome/i); 540 | 541 | if(angular.isArray(_matches)){ 542 | dialogsProvider.useFontAwesome(); 543 | break; // done, leave the style sheet for loop 544 | }else{ 545 | // try to find css rule .fa, in case style sheet has been concatenated 546 | _rules = _sheets[i].cssRules; 547 | for(var x = (_rules.length - 1);x >= 0;x--){ 548 | if(typeof(_rules[x].selectorText) === 'string' && _rules[x].selectorText.toLowerCase() === '.fa'){ 549 | dialogsProvider.useFontAwesome(); 550 | break sheetLoop; // done, exit both for loops 551 | } 552 | } 553 | } 554 | } // end if(disabled) 555 | } // end for 556 | }catch(err){ 557 | // console.log('Error Message: ' + err); 558 | } 559 | }]) // end config 560 | 561 | // Add default templates via $templateCache 562 | .run(['$templateCache','$interpolate',function($templateCache,$interpolate){ 563 | 564 | // get interpolation symbol (possible that someone may have changed it in their application instead of using '{{}}') 565 | var startSym = $interpolate.startSymbol(); 566 | var endSym = $interpolate.endSymbol(); 567 | 568 | $templateCache.put('/dialogs/error.html',''); 569 | $templateCache.put('/dialogs/wait.html',''); 570 | $templateCache.put('/dialogs/notify.html',''); 571 | $templateCache.put('/dialogs/confirm.html',''); 572 | }]); // end run / dialogs.main 573 | 574 | })(); -------------------------------------------------------------------------------- /dist/dialogs.min.css: -------------------------------------------------------------------------------- 1 | .dialog-header-error{background-color:#d2322d}.dialog-header-wait{background-color:#428bca}.dialog-header-notify{background-color:#eee}.dialog-header-confirm{background-color:#333}.dialog-header-confirm h4,.dialog-header-confirm span,.dialog-header-error h4,.dialog-header-error span,.dialog-header-wait h4,.dialog-header-wait span{color:#fff} -------------------------------------------------------------------------------- /dist/dialogs.min.js: -------------------------------------------------------------------------------- 1 | !function(){"use strict";var a=angular.module("translate.sub",[]);a.provider("$translate",[function(){var a=[],n="en-US";this.translations=function(s,e){angular.isDefined(s)&&angular.isDefined(e)&&(a[s]=angular.copy(e),n=s)},this.$get=[function(){return{instant:function(s){return angular.isDefined(s)&&angular.isDefined(a[n][s])?a[n][s]:s}}}]}]),a.filter("translate",["$translate",function(a){return function(n){return a.instant(n)}}]);var n;try{angular.module("pascalprecht.translate"),n=angular.module("dialogs.controllers",["ui.bootstrap.modal","pascalprecht.translate"])}catch(s){n=angular.module("dialogs.controllers",["ui.bootstrap.modal","translate.sub"])}n.controller("errorDialogCtrl",["$scope","$uibModalInstance","$translate","data",function(a,n,s,e){a.header=angular.isDefined(e.header)?e.header:s.instant("DIALOGS_ERROR"),a.msg=angular.isDefined(e.msg)?e.msg:s.instant("DIALOGS_ERROR_MSG"),a.icon=angular.isDefined(e.fa)&&angular.equals(e.fa,!0)?"fa fa-warning":"glyphicon glyphicon-warning-sign",a.btnMessages=e.btnMessages||{},a.close=function(){n.close(),a.$destroy()}}]),n.controller("waitDialogCtrl",["$scope","$uibModalInstance","$translate","$timeout","data",function(a,n,s,e,t){a.header=angular.isDefined(t.header)?t.header:s.instant("DIALOGS_PLEASE_WAIT_ELIPS"),a.msg=angular.isDefined(t.msg)?t.msg:s.instant("DIALOGS_PLEASE_WAIT_MSG"),a.progress=angular.isDefined(t.progress)?t.progress:100,a.icon=angular.isDefined(t.fa)&&angular.equals(t.fa,!0)?"fa fa-clock-o":"glyphicon glyphicon-time",a.btnMessages=t.btnMessages||{},a.$on("dialogs.wait.complete",function(){e(function(){n.close(),a.$destroy()})}),a.$on("dialogs.wait.message",function(n,s){a.msg=angular.isDefined(s.msg)?s.msg:a.msg}),a.$on("dialogs.wait.progress",function(n,s){a.msg=angular.isDefined(s.msg)?s.msg:a.msg,a.progress=angular.isDefined(s.progress)?s.progress:a.progress}),a.getProgress=function(){return{width:a.progress+"%"}}}]),n.controller("notifyDialogCtrl",["$scope","$uibModalInstance","$translate","data",function(a,n,s,e){a.header=angular.isDefined(e.header)?e.header:s.instant("DIALOGS_NOTIFICATION"),a.msg=angular.isDefined(e.msg)?e.msg:s.instant("DIALOGS_NOTIFICATION_MSG"),a.icon=angular.isDefined(e.fa)&&angular.equals(e.fa,!0)?"fa fa-info":"glyphicon glyphicon-info-sign",a.btnMessages=e.btnMessages||{},a.close=function(){n.close(),a.$destroy()}}]),n.controller("confirmDialogCtrl",["$scope","$uibModalInstance","$translate","data",function(a,n,s,e){a.header=angular.isDefined(e.header)?e.header:s.instant("DIALOGS_CONFIRMATION"),a.msg=angular.isDefined(e.msg)?e.msg:s.instant("DIALOGS_CONFIRMATION_MSG"),a.icon=angular.isDefined(e.fa)&&angular.equals(e.fa,!0)?"fa fa-check":"glyphicon glyphicon-check",a.btnMessages=e.btnMessages||{},a.no=function(){n.dismiss("no")},a.yes=function(){n.close("yes")}}]),angular.module("dialogs.services",["ui.bootstrap.modal","dialogs.controllers"]).provider("dialogs",[function(){var a=!0,n=!0,s="dialogs-default",e="dialogs-backdrop-default",t=!0,o=null,l="lg",r=!1,i=!1,d=function(t){var o={};return t=t||{},o.kb=angular.isDefined(t.keyboard)?!!t.keyboard:n,o.bd=angular.isDefined(t.backdrop)?t.backdrop:a,o.bdc=angular.isDefined(t.backdropClass)?t.backdropClass:e,o.ws=!angular.isDefined(t.size)||"sm"!==t.size&&"lg"!==t.size&&"md"!==t.size?l:t.size,o.wc=angular.isDefined(t.windowClass)?t.windowClass:s,o.anim=angular.isDefined(t.animation)?!!t.animation:r,o.btnMessages=angular.isDefined(t.btnMessages)?t.btnMessages:{},o};this.useBackdrop=function(n){angular.isDefined(n)&&(a=n)},this.useEscClose=function(a){angular.isDefined(a)&&(n=angular.equals(a,0)||angular.equals(a,"false")||angular.equals(a,"no")||angular.equals(a,null)||angular.equals(a,!1)?!1:!0)},this.useClass=function(a){angular.isDefined(a)&&(s=a)},this.useCopy=function(a){angular.isDefined(a)&&(t=angular.equals(a,0)||angular.equals(a,"false")||angular.equals(a,"no")||angular.equals(a,null)||angular.equals(a,!1)?!1:!0)},this.setWindowTmpl=function(a){angular.isDefined(a)&&(o=a)},this.setSize=function(a){angular.isDefined(a)&&(l=angular.equals(a,"sm")||angular.equals(a,"lg")||angular.equals(a,"md")?a:l)},this.useAnimation=function(){r=!0},this.useFontAwesome=function(){i=!0},this.$get=["$uibModal",function(a){return{error:function(n,s,e){return e=d(e),a.open({templateUrl:"/dialogs/error.html",controller:"errorDialogCtrl",backdrop:e.bd,backdropClass:e.bdc,keyboard:e.kb,windowClass:e.wc,size:e.ws,animation:e.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(s),fa:i,btnMessages:e.btnMessages}}}})},wait:function(n,s,e,t){return t=d(t),a.open({templateUrl:"/dialogs/wait.html",controller:"waitDialogCtrl",backdrop:t.bd,backdropClass:t.bdc,keyboard:t.kb,windowClass:t.wc,size:t.ws,animation:t.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(s),progress:angular.copy(e),fa:i}}}})},notify:function(n,s,e){return e=d(e),a.open({templateUrl:"/dialogs/notify.html",controller:"notifyDialogCtrl",backdrop:e.bd,backdropClass:e.bdc,keyboard:e.kb,windowClass:e.wc,size:e.ws,animation:e.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(s),fa:i,btnMessages:e.btnMessages}}}})},confirm:function(n,s,e){return e=d(e),a.open({templateUrl:"/dialogs/confirm.html",controller:"confirmDialogCtrl",backdrop:e.bd,backdropClass:e.bdc,keyboard:e.kb,windowClass:e.wc,size:e.ws,animation:e.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(s),fa:i,btnMessages:e.btnMessages}}}})},create:function(n,s,e,o,l){var r=o&&angular.isDefined(o.copy)?o.copy:t;return o=d(o),a.open({templateUrl:n,controller:s,controllerAs:l,keyboard:o.kb,backdrop:o.bd,backdropClass:o.bdc,windowClass:o.wc,size:o.ws,animation:o.anim,resolve:{data:function(){return r?angular.copy(e):e}}})}}}]}]),angular.module("dialogs.main",["dialogs.services","ngSanitize"]).config(["$translateProvider","dialogsProvider",function(a,n){try{angular.module("pascalprecht.translate")}catch(s){a.translations("en-US",{DIALOGS_ERROR:"Error",DIALOGS_ERROR_MSG:"An unknown error has occurred.",DIALOGS_CLOSE:"Close",DIALOGS_PLEASE_WAIT:"Please Wait",DIALOGS_PLEASE_WAIT_ELIPS:"Please Wait...",DIALOGS_PLEASE_WAIT_MSG:"Waiting on operation to complete.",DIALOGS_PERCENT_COMPLETE:"% Complete",DIALOGS_NOTIFICATION:"Notification",DIALOGS_NOTIFICATION_MSG:"Unknown application notification.",DIALOGS_CONFIRMATION:"Confirmation",DIALOGS_CONFIRMATION_MSG:"Confirmation required.",DIALOGS_OK:"OK",DIALOGS_YES:"Yes",DIALOGS_NO:"No"})}try{var e=document.styleSheets;a:for(var t=e.length-1;t>=0;t--){var o=null,l=null;if(!e[t].disabled){if(null!==e[t].href&&(o=e[t].href.match(/font\-*awesome/i)),angular.isArray(o)){n.useFontAwesome();break}l=e[t].cssRules;for(var r=l.length-1;r>=0;r--)if("string"==typeof l[r].selectorText&&".fa"===l[r].selectorText.toLowerCase()){n.useFontAwesome();break a}}}}catch(s){}}]).run(["$templateCache","$interpolate",function(a,n){var s=n.startSymbol(),e=n.endSymbol();a.put("/dialogs/error.html",'"),a.put("/dialogs/wait.html",'"),a.put("/dialogs/notify.html",'"),a.put("/dialogs/confirm.html",'")}])}(); -------------------------------------------------------------------------------- /example/css/dialogs.css: -------------------------------------------------------------------------------- 1 | /* Custom dialog/modal headers */ 2 | 3 | .dialog-header-error { background-color: #d2322d; } 4 | .dialog-header-wait { background-color: #428bca; } 5 | .dialog-header-notify { background-color: #eeeeee; } 6 | .dialog-header-confirm { background-color: #333333; } 7 | .dialog-header-error span, .dialog-header-error h4, 8 | .dialog-header-wait span, .dialog-header-wait h4, 9 | .dialog-header-confirm span, .dialog-header-confirm h4 { color: #ffffff; } 10 | -------------------------------------------------------------------------------- /example/css/dialogs.min.css: -------------------------------------------------------------------------------- 1 | .dialog-header-error{background-color:#d2322d}.dialog-header-wait{background-color:#428bca}.dialog-header-notify{background-color:#eee}.dialog-header-confirm{background-color:#333}.dialog-header-confirm h4,.dialog-header-confirm span,.dialog-header-error h4,.dialog-header-error span,.dialog-header-wait h4,.dialog-header-wait span{color:#fff} -------------------------------------------------------------------------------- /example/faChk.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Angular-Dialogs-Service Demo v5.2.1 (Font-Awesome) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 24 | 25 | 26 |
27 |
28 |

Dialog Service Demo (v5.3) Font-Awesome Compatible

29 |

(Using: Bootstrap 3.3.6, AngularJS 1.4.8, Angular UI Bootstrap 0.14.3, Font-Awesome 4.5)

30 |

This Demo of Angular-Dialog-Service is the same as the demo for using the service without Angular-Translate. Except now the service checks to see if Font-Awesome has been loaded and will automatically use Font-Awesome icons instead of the Bootstrap "glyphicons," in the header of the predefined dialogs.

Previously glyphicons were hard wired in, if you didn't include the Bootstrap version with the glyphicons because you were using Font-Awesome instead, then nothing appeared in the dialog headers. Now the service will automatically detect that you're using Font-Awesome and include the equivalent icons for each predefined dialog.
31 |

32 |
33 |
34 |
35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
43 |
44 |
45 |
46 |
47 |

Confirmation: {{confirmed}}

48 |

Name Enter (From Custom): {{name}}

49 |

Custom 2 Value: {{custom.val}}

50 |
51 |
52 | 53 | 54 | -------------------------------------------------------------------------------- /example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 24 | 25 | 26 |
27 |
28 |

Dialog Service Demo (v5.3)

29 |

(Using: Bootstrap 3.3.6, AngularJS 1.5.0, Angular UI Bootstrap 1.1.2, Angular-Translate 2.8,1)

30 |

Demo of Angular dialog service using Bootstrap 3 with Angular and Angular UI Bootstrap's modal service.

31 |

As well as the use of Angular-Translate (https://github.com/angular-translate)


32 |
33 |
34 |
35 |
36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 |
45 |
46 |
47 |
48 |
49 |

Confirmation: {{confirmed}}

50 |

Name Enter (From Custom): {{name}}

51 |

Custom 2 Value: {{custom.val}}

52 |

Current Language: {{language}}

53 |
54 |
55 |
56 |
57 | 58 | 59 |
60 |
61 | 62 | 63 | -------------------------------------------------------------------------------- /example/index2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Angular-Dialogs-Service Demo v5.2.0 (without Angular-Translate option) 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 23 | 24 | 25 |
26 |
27 |

Dialog Service Demo (v5.3) Sans Angular-Translate

28 |

(Using: Bootstrap 3.3.6, AngularJS 1.5.0, Angular UI Bootstrap 1.1.2)

29 |

This Demo of Angular-Dialog-Service features an automatic substitution for Angular-Translate. It will detect whether or not Angular-Translate is loaded; if not it will use the included translate substitute (translate.sub) module. The translate substitution is small and modeled after Angular-Translate so that if in the future you wish to use Angular-Translate all you need to do is load the module (pascalprecht.translate) before this dialogs module.

30 |

The result, Angular-Translate (https://github.com/angular-translate) is now optional, its no longer an absolute dependency. If your application does not need a translation module then there is no need to include Angular-Translate anymore. You can however still set default modal button, header and message text via $translateProvider in your module's config function.


31 |
32 |
33 |
34 |
35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
44 |
45 |
46 |
47 |
48 |

Confirmation: {{confirmed}}

49 |

Name Enter (From Custom): {{name}}

50 |

Custom 2 Value: {{custom.val}}

51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /example/js/dialogTest.js: -------------------------------------------------------------------------------- 1 | angular.module('modalTest',['ui.bootstrap','dialogs.main','pascalprecht.translate','dialogs.default-translations']) 2 | .controller('dialogServiceTest',function($scope,$rootScope,$timeout,$translate,dialogs){ 3 | 4 | //-- Variables --// 5 | 6 | $scope.lang = 'en-US'; 7 | $scope.language = 'English'; 8 | 9 | var _progress = 33; 10 | 11 | $scope.name = ''; 12 | $scope.confirmed = 'No confirmation yet!'; 13 | 14 | $scope.custom = { 15 | val: 'Initial Value' 16 | }; 17 | 18 | //-- Listeners & Watchers --// 19 | 20 | $scope.$watch('lang',function(val,old){ 21 | switch(val){ 22 | case 'en-US': 23 | $scope.language = 'English'; 24 | break; 25 | case 'es': 26 | $scope.language = 'Spanish'; 27 | break; 28 | } 29 | }); 30 | 31 | //-- Methods --// 32 | 33 | $scope.setLanguage = function(lang){ 34 | $scope.lang = lang; 35 | $translate.use(lang); 36 | }; 37 | 38 | $scope.launch = function(which){ 39 | switch(which){ 40 | case 'error': 41 | dialogs.error(); 42 | break; 43 | case 'wait': 44 | var dlg = dialogs.wait(undefined,undefined,_progress); 45 | _fakeWaitProgress(); 46 | break; 47 | case 'customwait': 48 | var dlg = dialogs.wait('Custom Wait Header','Custom Wait Message',_progress); 49 | _fakeWaitProgress(); 50 | break; 51 | case 'notify': 52 | dialogs.notify(); 53 | break; 54 | case 'confirm': 55 | var dlg = dialogs.confirm(); 56 | dlg.result.then(function(btn){ 57 | $scope.confirmed = 'You confirmed "Yes."'; 58 | },function(btn){ 59 | $scope.confirmed = 'You confirmed "No."'; 60 | }); 61 | break; 62 | case 'confirm2': 63 | var dlg = dialogs.confirm(undefined, undefined, { 64 | btnMessages: { 65 | DIALOGS_YES: 'Submit', 66 | DIALOGS_NO: 'Abort' 67 | } 68 | }); 69 | dlg.result.then(function(btn){ 70 | $scope.confirmed = 'You confirmed "Yes."'; 71 | },function(btn){ 72 | $scope.confirmed = 'You confirmed "No."'; 73 | }); 74 | break; 75 | case 'custom': 76 | var dlg = dialogs.create('/dialogs/custom.html','customDialogCtrl',{},{size:'lg',keyboard: true,backdrop: false,windowClass: 'my-class'}); 77 | dlg.result.then(function(name){ 78 | $scope.name = name; 79 | },function(){ 80 | if(angular.equals($scope.name,'')) 81 | $scope.name = 'You did not enter in your name!'; 82 | }); 83 | break; 84 | case 'custom2': 85 | var dlg = dialogs.create('/dialogs/custom2.html','customDialogCtrl2',$scope.custom,{size:'lg'}); 86 | break; 87 | } 88 | }; // end launch 89 | 90 | var _fakeWaitProgress = function(){ 91 | $timeout(function(){ 92 | if(_progress < 100){ 93 | _progress += 33; 94 | $rootScope.$broadcast('dialogs.wait.progress',{'progress' : _progress}); 95 | _fakeWaitProgress(); 96 | }else{ 97 | $rootScope.$broadcast('dialogs.wait.complete'); 98 | _progress = 0; 99 | } 100 | },1000); 101 | }; 102 | }) // end controller(dialogsServiceTest) 103 | 104 | .controller('customDialogCtrl',function($scope,$uibModalInstance,data){ 105 | //-- Variables --// 106 | 107 | $scope.user = {name : ''}; 108 | 109 | //-- Methods --// 110 | 111 | $scope.cancel = function(){ 112 | $uibModalInstance.dismiss('Canceled'); 113 | }; // end cancel 114 | 115 | $scope.save = function(){ 116 | $uibModalInstance.close($scope.user.name); 117 | }; // end save 118 | 119 | $scope.hitEnter = function(evt){ 120 | if(angular.equals(evt.keyCode,13) && !(angular.equals($scope.user.name,null) || angular.equals($scope.user.name,''))) 121 | $scope.save(); 122 | }; 123 | }) // end controller(customDialogCtrl) 124 | 125 | .controller('customDialogCtrl2',function($scope,$uibModalInstance,data){ 126 | 127 | $scope.data = data; 128 | 129 | //-- Methods --// 130 | 131 | $scope.done = function(){ 132 | $uibModalInstance.close($scope.data); 133 | }; // end done 134 | 135 | $scope.hitEnter = function(evt){ 136 | if(angular.equals(evt.keyCode,13) && !(angular.equals($scope.user.name,null) || angular.equals($scope.user.name,''))) 137 | $scope.done(); 138 | }; 139 | }) 140 | 141 | .config(['dialogsProvider','$translateProvider',function(dialogsProvider,$translateProvider){ 142 | dialogsProvider.useBackdrop('static'); 143 | dialogsProvider.useEscClose(false); 144 | dialogsProvider.useCopy(false); 145 | dialogsProvider.setSize('sm'); 146 | 147 | $translateProvider.translations('es',{ 148 | DIALOGS_ERROR: "Error", 149 | DIALOGS_ERROR_MSG: "Se ha producido un error desconocido.", 150 | DIALOGS_CLOSE: "Cerca", 151 | DIALOGS_PLEASE_WAIT: "Espere por favor", 152 | DIALOGS_PLEASE_WAIT_ELIPS: "Espere por favor...", 153 | DIALOGS_PLEASE_WAIT_MSG: "Esperando en la operacion para completar.", 154 | DIALOGS_PERCENT_COMPLETE: "% Completado", 155 | DIALOGS_NOTIFICATION: "Notificacion", 156 | DIALOGS_NOTIFICATION_MSG: "Notificacion de aplicacion Desconocido.", 157 | DIALOGS_CONFIRMATION: "Confirmacion", 158 | DIALOGS_CONFIRMATION_MSG: "Se requiere confirmacion.", 159 | DIALOGS_OK: "Bueno", 160 | DIALOGS_YES: "Si", 161 | DIALOGS_NO: "No" 162 | }); 163 | 164 | $translateProvider.preferredLanguage('en-US'); 165 | }]) 166 | 167 | .run(['$templateCache',function($templateCache){ 168 | $templateCache.put('/dialogs/custom.html',''); 169 | $templateCache.put('/dialogs/custom2.html','') 170 | }]); 171 | -------------------------------------------------------------------------------- /example/js/dialogTest2.js: -------------------------------------------------------------------------------- 1 | angular.module('modalTest',['ui.bootstrap','dialogs.main']) 2 | 3 | .controller('dialogServiceTest',function($scope,$rootScope,$timeout,dialogs){ 4 | 5 | //-- Variables --// 6 | 7 | var _progress = 33; 8 | 9 | $scope.name = ''; 10 | $scope.confirmed = 'No confirmation yet!'; 11 | 12 | $scope.custom = { 13 | val: 'Initial Value' 14 | }; 15 | 16 | //-- Methods --// 17 | 18 | $scope.launch = function(which){ 19 | switch(which){ 20 | case 'error': 21 | dialogs.error(); 22 | break; 23 | case 'wait': 24 | var dlg = dialogs.wait(undefined,undefined,_progress); 25 | _fakeWaitProgress(); 26 | break; 27 | case 'customwait': 28 | var dlg = dialogs.wait('Custom Wait Header','Custom Wait Message',_progress); 29 | _fakeWaitProgress(); 30 | break; 31 | case 'notify': 32 | dialogs.notify(); 33 | break; 34 | case 'confirm': 35 | var dlg = dialogs.confirm(); 36 | dlg.result.then(function(btn){ 37 | $scope.confirmed = 'You confirmed "Yes."'; 38 | },function(btn){ 39 | $scope.confirmed = 'You confirmed "No."'; 40 | }); 41 | break; 42 | case 'confirm2': 43 | var dlg = dialogs.confirm(undefined, undefined, { 44 | btnMessages: { 45 | DIALOGS_YES: 'Submit', 46 | DIALOGS_NO: 'Abort' 47 | } 48 | }); 49 | dlg.result.then(function(btn){ 50 | $scope.confirmed = 'You confirmed "Yes."'; 51 | },function(btn){ 52 | $scope.confirmed = 'You confirmed "No."'; 53 | }); 54 | break; 55 | case 'custom': 56 | var dlg = dialogs.create('/dialogs/custom.html','customDialogCtrl',{},{size:'lg',keyboard: true,backdrop: false,windowClass: 'my-class'}); 57 | dlg.result.then(function(name){ 58 | $scope.name = name; 59 | },function(){ 60 | if(angular.equals($scope.name,'')) 61 | $scope.name = 'You did not enter in your name!'; 62 | }); 63 | break; 64 | case 'custom2': 65 | var dlg = dialogs.create('/dialogs/custom2.html','customDialogCtrl2',$scope.custom,{size:'lg'}); 66 | break; 67 | } 68 | }; // end launch 69 | 70 | var _fakeWaitProgress = function(){ 71 | $timeout(function(){ 72 | if(_progress < 100){ 73 | _progress += 33; 74 | $rootScope.$broadcast('dialogs.wait.progress',{'progress' : _progress}); 75 | _fakeWaitProgress(); 76 | }else{ 77 | $rootScope.$broadcast('dialogs.wait.complete'); 78 | _progress = 33; 79 | } 80 | },1000); 81 | }; // end _fakeWaitProgress 82 | 83 | }) 84 | 85 | .controller('customDialogCtrl',function($scope,$uibModalInstance,data){ 86 | //-- Variables --// 87 | 88 | $scope.user = {name : ''}; 89 | 90 | //-- Methods --// 91 | 92 | $scope.cancel = function(){ 93 | $uibModalInstance.dismiss('Canceled'); 94 | }; // end cancel 95 | 96 | $scope.save = function(){ 97 | $uibModalInstance.close($scope.user.name); 98 | }; // end save 99 | 100 | $scope.hitEnter = function(evt){ 101 | if(angular.equals(evt.keyCode,13) && !(angular.equals($scope.user.name,null) || angular.equals($scope.user.name,''))) 102 | $scope.save(); 103 | }; 104 | }) // end controller(customDialogCtrl) 105 | 106 | .controller('customDialogCtrl2',function($scope,$uibModalInstance,data){ 107 | 108 | $scope.data = data; 109 | 110 | //-- Methods --// 111 | 112 | $scope.done = function(){ 113 | $uibModalInstance.close($scope.data); 114 | }; // end done 115 | 116 | $scope.hitEnter = function(evt){ 117 | if(angular.equals(evt.keyCode,13) && !(angular.equals($scope.user.name,null) || angular.equals($scope.user.name,''))) 118 | $scope.done(); 119 | }; 120 | }) 121 | 122 | .config(function($translateProvider){ 123 | /** 124 | * These are the defaults set by the dialogs.main module when Angular-Translate 125 | * is not loaded. You can reset them in your module's configuration 126 | * function by using $translateProvider. If you want to use these when 127 | * Angular-Translate is used and loaded, then you need to also load 128 | * dialogs-default-translations.js or include them where you are setting 129 | * translations in your module. These were separated out when Angular-Translate 130 | * is loaded so as not to clobber translation set elsewhere in one's 131 | * application. 132 | 133 | $translateProvider.translations('en-US',{ 134 | DIALOGS_ERROR: "Error", 135 | DIALOGS_ERROR_MSG: "An unknown error has occurred.", 136 | DIALOGS_CLOSE: "Close", 137 | DIALOGS_PLEASE_WAIT: "Please Wait", 138 | DIALOGS_PLEASE_WAIT_ELIPS: "Please Wait...", 139 | DIALOGS_PLEASE_WAIT_MSG: "Waiting on operation to complete.", 140 | DIALOGS_PERCENT_COMPLETE: "% Complete", 141 | DIALOGS_NOTIFICATION: "Notification", 142 | DIALOGS_NOTIFICATION_MSG: "Unknown application notification.", 143 | DIALOGS_CONFIRMATION: "Confirmation", 144 | DIALOGS_CONFIRMATION_MSG: "Confirmation required.", 145 | DIALOGS_OK: "OK", 146 | DIALOGS_YES: "Yes", 147 | DIALOGS_NO: "No" 148 | }); 149 | */ 150 | }) 151 | 152 | .run(function($templateCache){ 153 | $templateCache.put('/dialogs/custom.html',''); 154 | $templateCache.put('/dialogs/custom2.html',''); 155 | }); 156 | -------------------------------------------------------------------------------- /example/js/dialogs-default-translations.js: -------------------------------------------------------------------------------- 1 | /** 2 | * angular-dialog-service - A service to handle common dialog types in a web application. Built on top of Angular-Bootstrap's modal 3 | * @version v5.3.1 4 | * @author Michael Conroy, michael.e.conroy@gmail.com 5 | * @license MIT, http://www.opensource.org/licenses/MIT 6 | */ 7 | /** 8 | * Dialog Default Translations. 9 | * 10 | * Include this module if you're not already using angular-translate in your application, and 11 | * add it to your application module's dependency list in order to get default header and 12 | * dialog messages to appear. 13 | * 14 | * Ex: var myApp = angular.module('myApplication',['dialogs.main','dialogs.default-translations']); 15 | * 16 | * It was necessary to separate this out for those already using angular-translate because this would 17 | * automatically reset their translation list for 'en-US' 18 | * 19 | * For those already using angular-translate, just copy the list of DIALOG_[..] translations to your 20 | * translation list where you set 'en-US' using the $translateProvider. 21 | */ 22 | 23 | //== Translations =============================================================// 24 | 25 | angular.module('dialogs.default-translations',['pascalprecht.translate']) 26 | /** 27 | * Default translations in English. 28 | * 29 | * Use angular-translate's $translateProvider to provide translations in an 30 | * alternate language. 31 | * 32 | * $translateProvider.translations('[lang]',{[translations]}); 33 | * To use alternate translations set the preferred language to your desired 34 | * language. 35 | * $translateProvider.preferredLanguage('[lang]'); 36 | */ 37 | .config(['$translateProvider',function($translateProvider){ 38 | $translateProvider.translations('de-DE',{ 39 | DIALOGS_ERROR: "Error", 40 | DIALOGS_ERROR_MSG: "Ein unbekannter Fehler ist aufgetreten.", 41 | DIALOGS_CLOSE: "Schließen", 42 | DIALOGS_PLEASE_WAIT: "Bitte warten", 43 | DIALOGS_PLEASE_WAIT_ELIPS: "Bitte warten...", 44 | DIALOGS_PLEASE_WAIT_MSG: "Warte auf Fertigstellung der Operation.", 45 | DIALOGS_PERCENT_COMPLETE: "% fertig", 46 | DIALOGS_NOTIFICATION: "Benachrichtigung", 47 | DIALOGS_NOTIFICATION_MSG: "Unbekannte Anwendungsbenachrichtigung.", 48 | DIALOGS_CONFIRMATION: "Bestätigung", 49 | DIALOGS_CONFIRMATION_MSG: "Bestätigung erforderlich.", 50 | DIALOGS_OK: "OK", 51 | DIALOGS_YES: "Ja", 52 | DIALOGS_NO: "Nein" 53 | }); 54 | 55 | $translateProvider.translations('en-US',{ 56 | DIALOGS_ERROR: "Error", 57 | DIALOGS_ERROR_MSG: "An unknown error has occurred.", 58 | DIALOGS_CLOSE: "Close", 59 | DIALOGS_PLEASE_WAIT: "Please Wait", 60 | DIALOGS_PLEASE_WAIT_ELIPS: "Please Wait...", 61 | DIALOGS_PLEASE_WAIT_MSG: "Waiting on operation to complete.", 62 | DIALOGS_PERCENT_COMPLETE: "% Complete", 63 | DIALOGS_NOTIFICATION: "Notification", 64 | DIALOGS_NOTIFICATION_MSG: "Unknown application notification.", 65 | DIALOGS_CONFIRMATION: "Confirmation", 66 | DIALOGS_CONFIRMATION_MSG: "Confirmation required.", 67 | DIALOGS_OK: "OK", 68 | DIALOGS_YES: "Yes", 69 | DIALOGS_NO: "No" 70 | }); 71 | 72 | $translateProvider.translations('es-ES',{ 73 | DIALOGS_ERROR: "Error", 74 | DIALOGS_ERROR_MSG: "Se ha producido un error.", 75 | DIALOGS_CLOSE: "Cerrar", 76 | DIALOGS_PLEASE_WAIT: "Espere por favor", 77 | DIALOGS_PLEASE_WAIT_ELIPS: "Espere por favor...", 78 | DIALOGS_PLEASE_WAIT_MSG: "Completando operación.", 79 | DIALOGS_PERCENT_COMPLETE: "% Completado", 80 | DIALOGS_NOTIFICATION: "Notificación", 81 | DIALOGS_NOTIFICATION_MSG: "Notificación de una aplicación desconocida.", 82 | DIALOGS_CONFIRMATION: "Confirmación", 83 | DIALOGS_CONFIRMATION_MSG: "Se requiere confirmacion.", 84 | DIALOGS_OK: "Aceptar", 85 | DIALOGS_YES: "Sí", 86 | DIALOGS_NO: "No" 87 | }); 88 | 89 | $translateProvider.translations("fr-FR", { 90 | DIALOGS_ERROR: "Erreur", 91 | DIALOGS_ERROR_MSG: "Une erreur inconnue s'est produite.", 92 | DIALOGS_CLOSE: "Fermer", 93 | DIALOGS_PLEASE_WAIT: "Patientez svp", 94 | DIALOGS_PLEASE_WAIT_ELIPS: "Patienter svp...", 95 | DIALOGS_PLEASE_WAIT_MSG: "En attente de la fin de l'opération.", 96 | DIALOGS_PERCENT_COMPLETE: "% Terminer", 97 | DIALOGS_NOTIFICATION: "Notification", 98 | DIALOGS_NOTIFICATION_MSG: "Notification de l'application inconnue", 99 | DIALOGS_CONFIRMATION: "Confirmer", 100 | DIALOGS_CONFIRMATION_MSG: "Merci de confirmer", 101 | DIALOGS_OK: "OK", 102 | DIALOGS_YES: "Oui", 103 | DIALOGS_NO: "Non" 104 | }); 105 | 106 | $translateProvider.translations('pt-BR',{ 107 | DIALOGS_ERROR: "Erro", 108 | DIALOGS_ERROR_MSG: "Ocorreu um erro inesperado.", 109 | DIALOGS_CLOSE: "Fechar", 110 | DIALOGS_PLEASE_WAIT: "Por favor aguarde", 111 | DIALOGS_PLEASE_WAIT_ELIPS: "Por favor aguarde...", 112 | DIALOGS_PLEASE_WAIT_MSG: "Aguardando que a operação termine.", 113 | DIALOGS_PERCENT_COMPLETE: "% Completados", 114 | DIALOGS_NOTIFICATION: "Notificação", 115 | DIALOGS_NOTIFICATION_MSG: "Notificação de aplicação desconhecida.", 116 | DIALOGS_CONFIRMATION: "Confirmação", 117 | DIALOGS_CONFIRMATION_MSG: "Confirmação requerida.", 118 | DIALOGS_OK: "OK", 119 | DIALOGS_YES: "Sim", 120 | DIALOGS_NO: "Não" 121 | }); 122 | 123 | $translateProvider.translations('tr-TR',{ 124 | DIALOGS_ERROR: "Hata", 125 | DIALOGS_ERROR_MSG: "Bilinmeyen bir hata oluştu.", 126 | DIALOGS_CLOSE: "Kapat", 127 | DIALOGS_PLEASE_WAIT: "Lütfen Bekleyin", 128 | DIALOGS_PLEASE_WAIT_ELIPS: "Lütfen Bekleyin...", 129 | DIALOGS_PLEASE_WAIT_MSG: "İşlemin tamamlanması bekleniyor.", 130 | DIALOGS_PERCENT_COMPLETE: "% Tamamlandı", 131 | DIALOGS_NOTIFICATION: "Uyarı", 132 | DIALOGS_NOTIFICATION_MSG: "Bilinmeyen uygulama uyarısı.", 133 | DIALOGS_CONFIRMATION: "Konfirmasyon", 134 | DIALOGS_CONFIRMATION_MSG: "Konfirmasyon gereklidir.", 135 | DIALOGS_OK: "Tamam", 136 | DIALOGS_YES: "Evet", 137 | DIALOGS_NO: "Hayır" 138 | }); 139 | 140 | $translateProvider.translations('zh-CN',{ 141 | DIALOGS_ERROR: "错误", 142 | DIALOGS_ERROR_MSG: "出现未知错误。", 143 | DIALOGS_CLOSE: "关闭", 144 | DIALOGS_PLEASE_WAIT: "请稍候", 145 | DIALOGS_PLEASE_WAIT_ELIPS: "请稍候...", 146 | DIALOGS_PLEASE_WAIT_MSG: "请等待操作完成。", 147 | DIALOGS_PERCENT_COMPLETE: "% 已完成", 148 | DIALOGS_NOTIFICATION: "通知", 149 | DIALOGS_NOTIFICATION_MSG: "未知应用程序的通知。", 150 | DIALOGS_CONFIRMATION: "确认", 151 | DIALOGS_CONFIRMATION_MSG: "确认要求。", 152 | DIALOGS_OK: "确定", 153 | DIALOGS_YES: "确认", 154 | DIALOGS_NO: "取消" 155 | }); 156 | 157 | $translateProvider.translations('sv-SE',{ 158 | DIALOGS_ERROR: "Fel", 159 | DIALOGS_ERROR_MSG: "Ett okänt fel har uppstått.", 160 | DIALOGS_CLOSE: "Stäng", 161 | DIALOGS_PLEASE_WAIT: "Vänligen vänta", 162 | DIALOGS_PLEASE_WAIT_ELIPS: "Vänligen vänta...", 163 | DIALOGS_PLEASE_WAIT_MSG: "Väntar på att processen skall slutföras.", 164 | DIALOGS_PERCENT_COMPLETE: "% Färdigt", 165 | DIALOGS_NOTIFICATION: "Meddelande", 166 | DIALOGS_NOTIFICATION_MSG: "Okänt meddelande från applikationen.", 167 | DIALOGS_CONFIRMATION: "Bekräftelse", 168 | DIALOGS_CONFIRMATION_MSG: "Bekräftelse krävs.", 169 | DIALOGS_OK: "OK", 170 | DIALOGS_YES: "Ja", 171 | DIALOGS_NO: "Nej" 172 | }); 173 | 174 | $translateProvider.preferredLanguage('en-US'); 175 | }]); // end config 176 | -------------------------------------------------------------------------------- /example/js/dialogs-default-translations.min.js: -------------------------------------------------------------------------------- 1 | angular.module("dialogs.default-translations",["pascalprecht.translate"]).config(["$translateProvider",function(O){O.translations("en-US",{DIALOGS_ERROR:"Error",DIALOGS_ERROR_MSG:"An unknown error has occurred.",DIALOGS_CLOSE:"Close",DIALOGS_PLEASE_WAIT:"Please Wait",DIALOGS_PLEASE_WAIT_ELIPS:"Please Wait...",DIALOGS_PLEASE_WAIT_MSG:"Waiting on operation to complete.",DIALOGS_PERCENT_COMPLETE:"% Complete",DIALOGS_NOTIFICATION:"Notification",DIALOGS_NOTIFICATION_MSG:"Unknown application notification.",DIALOGS_CONFIRMATION:"Confirmation",DIALOGS_CONFIRMATION_MSG:"Confirmation required.",DIALOGS_OK:"OK",DIALOGS_YES:"Yes",DIALOGS_NO:"No"}),O.translations("zh-CN",{DIALOGS_ERROR:"错误",DIALOGS_ERROR_MSG:"出现未知错误。",DIALOGS_CLOSE:"关闭",DIALOGS_PLEASE_WAIT:"请稍候",DIALOGS_PLEASE_WAIT_ELIPS:"请稍候...",DIALOGS_PLEASE_WAIT_MSG:"请等待操作完成。",DIALOGS_PERCENT_COMPLETE:"% 已完成",DIALOGS_NOTIFICATION:"通知",DIALOGS_NOTIFICATION_MSG:"未知应用程序的通知。",DIALOGS_CONFIRMATION:"确认",DIALOGS_CONFIRMATION_MSG:"确认要求。",DIALOGS_OK:"确定",DIALOGS_YES:"确认",DIALOGS_NO:"取消"}),O.translations("es-ES",{DIALOGS_ERROR:"Error",DIALOGS_ERROR_MSG:"Se ha producido un error.",DIALOGS_CLOSE:"Cerrar",DIALOGS_PLEASE_WAIT:"Espere por favor",DIALOGS_PLEASE_WAIT_ELIPS:"Espere por favor...",DIALOGS_PLEASE_WAIT_MSG:"Completando operación.",DIALOGS_PERCENT_COMPLETE:"% Completado",DIALOGS_NOTIFICATION:"Notificación",DIALOGS_NOTIFICATION_MSG:"Notificación de una aplicación desconocida.",DIALOGS_CONFIRMATION:"Confirmación",DIALOGS_CONFIRMATION_MSG:"Se requiere confirmacion.",DIALOGS_OK:"Aceptar",DIALOGS_YES:"Sí",DIALOGS_NO:"No"}),O.translations("fr-FR",{DIALOGS_ERROR:"Erreur",DIALOGS_ERROR_MSG:"Une erreur inconnue s'est produite.",DIALOGS_CLOSE:"Fermer",DIALOGS_PLEASE_WAIT:"Patientez svp",DIALOGS_PLEASE_WAIT_ELIPS:"Patienter svp...",DIALOGS_PLEASE_WAIT_MSG:"En attente de la fin de l'opération.",DIALOGS_PERCENT_COMPLETE:"% Terminer",DIALOGS_NOTIFICATION:"Notification",DIALOGS_NOTIFICATION_MSG:"Notification de l'application inconnue",DIALOGS_CONFIRMATION:"Confirmer",DIALOGS_CONFIRMATION_MSG:"Merci de confirmer",DIALOGS_OK:"OK",DIALOGS_YES:"Oui",DIALOGS_NO:"Non"}),O.translations("pt-BR",{DIALOGS_ERROR:"Erro",DIALOGS_ERROR_MSG:"Ocorreu um erro inesperado.",DIALOGS_CLOSE:"Fechar",DIALOGS_PLEASE_WAIT:"Por favor aguarde",DIALOGS_PLEASE_WAIT_ELIPS:"Por favor aguarde...",DIALOGS_PLEASE_WAIT_MSG:"Aguardando que a operação termine.",DIALOGS_PERCENT_COMPLETE:"% Completados",DIALOGS_NOTIFICATION:"Notificação",DIALOGS_NOTIFICATION_MSG:"Notificação de aplicação desconhecida.",DIALOGS_CONFIRMATION:"Confirmação",DIALOGS_CONFIRMATION_MSG:"Confirmação requerida.",DIALOGS_OK:"OK",DIALOGS_YES:"Sim",DIALOGS_NO:"Não"}),O.preferredLanguage("en-US")}]); -------------------------------------------------------------------------------- /example/js/dialogs-min.min.js: -------------------------------------------------------------------------------- 1 | !function(){"use strict";var a=angular.module("translate.sub",[]);a.provider("$translate",[function(){var a=[],n="en-US";this.translations=function(e,s){angular.isDefined(e)&&angular.isDefined(s)&&(a[e]=angular.copy(s),n=e)},this.$get=[function(){return{instant:function(e){return angular.isDefined(e)&&angular.isDefined(a[n][e])?a[n][e]:""}}}]}]),a.filter("translate",["$translate",function(a){return function(n){return a.instant(n)}}]);var n;try{angular.module("pascalprecht.translate"),n=angular.module("dialogs.controllers",["ui.bootstrap.modal","pascalprecht.translate"])}catch(e){n=angular.module("dialogs.controllers",["ui.bootstrap.modal","translate.sub"])}n.controller("errorDialogCtrl",["$scope","$uibModalInstance","$translate","data",function(a,n,e,s){a.header=angular.isDefined(s.header)?s.header:e.instant("DIALOGS_ERROR"),a.msg=angular.isDefined(s.msg)?s.msg:e.instant("DIALOGS_ERROR_MSG"),a.icon=angular.isDefined(s.fa)&&angular.equals(s.fa,!0)?"fa fa-warning":"glyphicon glyphicon-warning-sign",a.close=function(){n.close(),a.$destroy()}}]),n.controller("waitDialogCtrl",["$scope","$uibModalInstance","$translate","$timeout","data",function(a,n,e,s,t){a.header=angular.isDefined(t.header)?t.header:e.instant("DIALOGS_PLEASE_WAIT_ELIPS"),a.msg=angular.isDefined(t.msg)?t.msg:e.instant("DIALOGS_PLEASE_WAIT_MSG"),a.progress=angular.isDefined(t.progress)?t.progress:100,a.icon=angular.isDefined(t.fa)&&angular.equals(t.fa,!0)?"fa fa-clock-o":"glyphicon glyphicon-time",a.$on("dialogs.wait.complete",function(){s(function(){n.close(),a.$destroy()})}),a.$on("dialogs.wait.message",function(n,e){a.msg=angular.isDefined(e.msg)?e.msg:a.msg}),a.$on("dialogs.wait.progress",function(n,e){a.msg=angular.isDefined(e.msg)?e.msg:a.msg,a.progress=angular.isDefined(e.progress)?e.progress:a.progress}),a.getProgress=function(){return{width:a.progress+"%"}}}]),n.controller("notifyDialogCtrl",["$scope","$uibModalInstance","$translate","data",function(a,n,e,s){a.header=angular.isDefined(s.header)?s.header:e.instant("DIALOGS_NOTIFICATION"),a.msg=angular.isDefined(s.msg)?s.msg:e.instant("DIALOGS_NOTIFICATION_MSG"),a.icon=angular.isDefined(s.fa)&&angular.equals(s.fa,!0)?"fa fa-info":"glyphicon glyphicon-info-sign",a.close=function(){n.close(),a.$destroy()}}]),n.controller("confirmDialogCtrl",["$scope","$uibModalInstance","$translate","data",function(a,n,e,s){a.header=angular.isDefined(s.header)?s.header:e.instant("DIALOGS_CONFIRMATION"),a.msg=angular.isDefined(s.msg)?s.msg:e.instant("DIALOGS_CONFIRMATION_MSG"),a.icon=angular.isDefined(s.fa)&&angular.equals(s.fa,!0)?"fa fa-check":"glyphicon glyphicon-check",a.no=function(){n.dismiss("no")},a.yes=function(){n.close("yes")}}]),angular.module("dialogs.services",["ui.bootstrap.modal","dialogs.controllers"]).provider("dialogs",[function(){var a=!0,n=!0,e="dialogs-default",s="dialogs-backdrop-default",t=!0,o=null,l="lg",i=!1,r=!1,d=function(t){var o={};return t=t||{},o.kb=angular.isDefined(t.keyboard)?!!t.keyboard:n,o.bd=angular.isDefined(t.backdrop)?t.backdrop:a,o.bdc=angular.isDefined(t.backdropClass)?t.backdropClass:s,o.ws=!angular.isDefined(t.size)||"sm"!==t.size&&"lg"!==t.size&&"md"!==t.size?l:t.size,o.wc=angular.isDefined(t.windowClass)?t.windowClass:e,o.anim=angular.isDefined(t.animation)?!!t.animation:i,o};this.useBackdrop=function(n){angular.isDefined(n)&&(a=n)},this.useEscClose=function(a){angular.isDefined(a)&&(n=angular.equals(a,0)||angular.equals(a,"false")||angular.equals(a,"no")||angular.equals(a,null)||angular.equals(a,!1)?!1:!0)},this.useClass=function(a){angular.isDefined(a)&&(e=a)},this.useCopy=function(a){angular.isDefined(a)&&(t=angular.equals(a,0)||angular.equals(a,"false")||angular.equals(a,"no")||angular.equals(a,null)||angular.equals(a,!1)?!1:!0)},this.setWindowTmpl=function(a){angular.isDefined(a)&&(o=a)},this.setSize=function(a){angular.isDefined(a)&&(l=angular.equals(a,"sm")||angular.equals(a,"lg")||angular.equals(a,"md")?a:l)},this.useAnimation=function(){i=!0},this.useFontAwesome=function(){r=!0},this.$get=["$uibModal",function(a){return{error:function(n,e,s){return s=d(s),a.open({templateUrl:"/dialogs/error.html",controller:"errorDialogCtrl",backdrop:s.bd,backdropClass:s.bdc,keyboard:s.kb,windowClass:s.wc,size:s.ws,animation:s.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(e),fa:r}}}})},wait:function(n,e,s,t){return t=d(t),a.open({templateUrl:"/dialogs/wait.html",controller:"waitDialogCtrl",backdrop:t.bd,backdropClass:t.bdc,keyboard:t.kb,windowClass:t.wc,size:t.ws,animation:t.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(e),progress:angular.copy(s),fa:r}}}})},notify:function(n,e,s){return s=d(s),a.open({templateUrl:"/dialogs/notify.html",controller:"notifyDialogCtrl",backdrop:s.bd,backdropClass:s.bdc,keyboard:s.kb,windowClass:s.wc,size:s.ws,animation:s.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(e),fa:r}}}})},confirm:function(n,e,s){return s=d(s),a.open({templateUrl:"/dialogs/confirm.html",controller:"confirmDialogCtrl",backdrop:s.bd,backdropClass:s.bdc,keyboard:s.kb,windowClass:s.wc,size:s.ws,animation:s.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(e),fa:r}}}})},create:function(n,e,s,o){var l=o&&angular.isDefined(o.copy)?o.copy:t;return o=d(o),a.open({templateUrl:n,controller:e,keyboard:o.kb,backdrop:o.bd,backdropClass:o.bdc,windowClass:o.wc,size:o.ws,animation:o.anim,resolve:{data:function(){return l?angular.copy(s):s}}})}}}]}]),angular.module("dialogs.main",["dialogs.services","ngSanitize"]).config(["$translateProvider","dialogsProvider",function(a,n){try{angular.module("pascalprecht.translate")}catch(e){a.translations("en-US",{DIALOGS_ERROR:"Error",DIALOGS_ERROR_MSG:"An unknown error has occurred.",DIALOGS_CLOSE:"Close",DIALOGS_PLEASE_WAIT:"Please Wait",DIALOGS_PLEASE_WAIT_ELIPS:"Please Wait...",DIALOGS_PLEASE_WAIT_MSG:"Waiting on operation to complete.",DIALOGS_PERCENT_COMPLETE:"% Complete",DIALOGS_NOTIFICATION:"Notification",DIALOGS_NOTIFICATION_MSG:"Unknown application notification.",DIALOGS_CONFIRMATION:"Confirmation",DIALOGS_CONFIRMATION_MSG:"Confirmation required.",DIALOGS_OK:"OK",DIALOGS_YES:"Yes",DIALOGS_NO:"No"})}try{var s=document.styleSheets;a:for(var t=s.length-1;t>=0;t--){var o=null,l=null;if(!s[t].disabled){if(null!==s[t].href&&(o=s[t].href.match(/font\-*awesome/i)),angular.isArray(o)){n.useFontAwesome();break}l=s[t].cssRules;for(var i=l.length-1;i>=0;i--)if(".fa"==l[i].selectorText.toLowerCase()){n.useFontAwesome();break a}}}}catch(e){}}]).run(["$templateCache","$interpolate",function(a,n){var e=n.startSymbol(),s=n.endSymbol();a.put("/dialogs/error.html",'"),a.put("/dialogs/wait.html",'"),a.put("/dialogs/notify.html",'"),a.put("/dialogs/confirm.html",'")}])}(); -------------------------------------------------------------------------------- /example/js/dialogs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * angular-dialog-service - A service to handle common dialog types in a web application. Built on top of Angular-Bootstrap's modal 3 | * @version v5.3.1 4 | * @author Michael Conroy, michael.e.conroy@gmail.com 5 | * @license MIT, http://www.opensource.org/licenses/MIT 6 | */ 7 | (function(){ 8 | "use strict"; 9 | //== Translate Substitute Module =============================================// 10 | 11 | /** 12 | * For those not using Angular-Translate (pascalprecht.translate), this will sub 13 | * in for it so we don't have to include Angular-Translate if we don't want to. 14 | */ 15 | 16 | var translateSubMod = angular.module('translate.sub',[]); 17 | 18 | /** 19 | * $translate Service 20 | * Sets up a $translateProvider service to use in your module's config 21 | * function. $translate.Provider syntax is the same as Angular-Translate, 22 | * use $translate.Provider.translations(lang,obj) to change the defaults 23 | * for modal button, header and message text. 24 | */ 25 | translateSubMod.provider('$translate',[function(){ 26 | var _translations = []; // object of key/value translation pairs 27 | var _current = 'en-US'; // default language 28 | 29 | /** 30 | * Translations 31 | * Set the internal object of translation key/value pairs. 32 | */ 33 | this.translations = function(lang,obj){ 34 | if(angular.isDefined(lang) && angular.isDefined(obj)){ 35 | _translations[lang] = angular.copy(obj); 36 | _current = lang; 37 | } 38 | }; // end translations 39 | 40 | this.$get = [function(){ 41 | return { 42 | /** 43 | * Instant 44 | * Retrieve the translation for the given key, if key not found 45 | * return the key. 46 | * Example: $translate.instant('DIALOGS_OK'); 47 | */ 48 | instant : function(what){ 49 | if(angular.isDefined(what) && angular.isDefined(_translations[_current][what])) 50 | return _translations[_current][what]; 51 | else 52 | return what; 53 | } // end instant 54 | }; // end return 55 | }]; // end $get 56 | 57 | }]); // end $translate 58 | 59 | /** 60 | * Translate Filter 61 | * For use in an Angular template. 62 | * Example: {{"DIALOGS_CLOSE" | translate}} 63 | */ 64 | translateSubMod.filter('translate',['$translate',function($translate){ 65 | return function(what){ 66 | return $translate.instant(what); 67 | }; 68 | }]); // end translate / translate.sub 69 | //== Controllers =============================================================// 70 | 71 | var ctrlrs; // will be dialogs.controllers module 72 | 73 | // determine if Angular-Translate is available, if not use the substitute 74 | try{ 75 | angular.module('pascalprecht.translate'); // throws error if module not loaded 76 | // console.log('Dialogs (Angular-Translate): OK'); 77 | 78 | // dialogs.controllers: module declaration 79 | ctrlrs = angular.module('dialogs.controllers',['ui.bootstrap.modal','pascalprecht.translate']); 80 | }catch(err){ 81 | // console.log('Dialogs: (Angular-Translate): ' + err.message); 82 | // console.log('Dialogs: Attempting to use translate.sub module.'); 83 | 84 | // dialogs.controllers: module declaration 85 | ctrlrs = angular.module('dialogs.controllers',['ui.bootstrap.modal','translate.sub']); 86 | } // end try/catch 87 | 88 | // angular.module('dialogs.controllers',['ui.bootstrap.modal','pascalprecht.translate']) 89 | 90 | /** 91 | * Error Dialog Controller 92 | */ 93 | ctrlrs.controller('errorDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){ 94 | //-- Variables -----// 95 | 96 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_ERROR'); 97 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_ERROR_MSG'); 98 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-warning' : 'glyphicon glyphicon-warning-sign'; 99 | $scope.btnMessages = data.btnMessages || {}; 100 | 101 | //-- Methods -----// 102 | 103 | $scope.close = function(){ 104 | $uibModalInstance.close(); 105 | $scope.$destroy(); 106 | }; // end close 107 | }]); // end ErrorDialogCtrl 108 | 109 | /** 110 | * Wait Dialog Controller 111 | */ 112 | ctrlrs.controller('waitDialogCtrl',['$scope','$uibModalInstance','$translate','$timeout','data',function($scope,$uibModalInstance,$translate,$timeout,data){ 113 | //-- Variables -----// 114 | 115 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_PLEASE_WAIT_ELIPS'); 116 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_PLEASE_WAIT_MSG'); 117 | $scope.progress = (angular.isDefined(data.progress)) ? data.progress : 100; 118 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-clock-o' : 'glyphicon glyphicon-time'; 119 | $scope.btnMessages = data.btnMessages || {}; 120 | 121 | //-- Listeners -----// 122 | 123 | // Note: used $timeout instead of $scope.$apply() because I was getting a $$nextSibling error 124 | 125 | // close wait dialog 126 | $scope.$on('dialogs.wait.complete',function(){ 127 | $timeout(function(){ $uibModalInstance.close(); $scope.$destroy(); }); 128 | }); // end on(dialogs.wait.complete) 129 | 130 | // update the dialog's message 131 | $scope.$on('dialogs.wait.message',function(evt,args){ 132 | $scope.msg = (angular.isDefined(args.msg)) ? args.msg : $scope.msg; 133 | }); // end on(dialogs.wait.message) 134 | 135 | // update the dialog's progress (bar) and/or message 136 | $scope.$on('dialogs.wait.progress',function(evt,args){ 137 | $scope.msg = (angular.isDefined(args.msg)) ? args.msg : $scope.msg; 138 | $scope.progress = (angular.isDefined(args.progress)) ? args.progress : $scope.progress; 139 | }); // end on(dialogs.wait.progress) 140 | 141 | //-- Methods -----// 142 | 143 | $scope.getProgress = function(){ 144 | return {'width': $scope.progress + '%'}; 145 | }; // end getProgress 146 | 147 | }]); // end WaitDialogCtrl 148 | 149 | /** 150 | * Notify Dialog Controller 151 | */ 152 | ctrlrs.controller('notifyDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){ 153 | //-- Variables -----// 154 | 155 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_NOTIFICATION'); 156 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_NOTIFICATION_MSG'); 157 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-info' : 'glyphicon glyphicon-info-sign'; 158 | $scope.btnMessages = data.btnMessages || {}; 159 | 160 | //-- Methods -----// 161 | 162 | $scope.close = function(){ 163 | $uibModalInstance.close(); 164 | $scope.$destroy(); 165 | }; // end close 166 | }]); // end WaitDialogCtrl 167 | 168 | /** 169 | * Confirm Dialog Controller 170 | */ 171 | ctrlrs.controller('confirmDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){ 172 | //-- Variables -----// 173 | 174 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_CONFIRMATION'); 175 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_CONFIRMATION_MSG'); 176 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-check' : 'glyphicon glyphicon-check'; 177 | $scope.btnMessages = data.btnMessages || {}; 178 | 179 | //-- Methods -----// 180 | 181 | $scope.no = function(){ 182 | $uibModalInstance.dismiss('no'); 183 | }; // end close 184 | 185 | $scope.yes = function(){ 186 | $uibModalInstance.close('yes'); 187 | }; // end yes 188 | }]); // end ConfirmDialogCtrl / dialogs.controllers 189 | //== Services ================================================================// 190 | 191 | angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers']) 192 | 193 | .provider('dialogs',[function(){ 194 | var _b = true; // backdrop 195 | var _k = true; // keyboard 196 | var _w = 'dialogs-default'; // windowClass 197 | var _bdc = 'dialogs-backdrop-default'; // backdropClass 198 | var _copy = true; // controls use of angular.copy 199 | var _wTmpl = null; // window template 200 | var _wSize = 'lg'; // large modal window default 201 | var _animation = false; // true/false to use animation 202 | 203 | var _fa = false; // fontawesome flag 204 | 205 | var _setOpts = function(opts){ 206 | var _opts = {}; 207 | opts = opts || {}; 208 | _opts.kb = (angular.isDefined(opts.keyboard)) ? !!opts.keyboard : _k; // values: true,false 209 | _opts.bd = (angular.isDefined(opts.backdrop)) ? opts.backdrop : _b; // values: 'static',true,false 210 | _opts.bdc = (angular.isDefined(opts.backdropClass)) ? opts.backdropClass : _bdc; // additional CSS class(es) to be added to the modal backdrop 211 | _opts.ws = (angular.isDefined(opts.size) && ((opts.size === 'sm') || (opts.size === 'lg') || (opts.size === 'md'))) ? opts.size : _wSize; // values: 'sm', 'lg', 'md' 212 | _opts.wc = (angular.isDefined(opts.windowClass)) ? opts.windowClass : _w; // additional CSS class(es) to be added to a modal window 213 | _opts.anim = (angular.isDefined(opts.animation)) ? !!opts.animation : _animation; // values: true,false 214 | _opts.btnMessages = (angular.isDefined(opts.btnMessages)) ? opts.btnMessages : {}; // button overrides 215 | return _opts; 216 | }; // end _setOpts 217 | 218 | /** 219 | * Use Backdrop 220 | * 221 | * Sets the use of the modal backdrop. Either to have one or not and 222 | * whether or not it responds to mouse clicks ('static' sets the 223 | * backdrop to true and does not respond to mouse clicks). 224 | * 225 | * @param val mixed (true, false, 'static') 226 | */ 227 | this.useBackdrop = function(val){ // possible values : true, false, 'static' 228 | if(angular.isDefined(val)) 229 | _b = val; 230 | }; // end useStaticBackdrop 231 | 232 | /** 233 | * Use ESC Close 234 | * 235 | * Sets the use of the ESC (escape) key to close modal windows. 236 | * 237 | * @param val boolean 238 | */ 239 | this.useEscClose = function(val){ // possible values : true, false 240 | if(angular.isDefined(val)) 241 | _k = (!angular.equals(val,0) && !angular.equals(val,'false') && !angular.equals(val,'no') && !angular.equals(val,null) && !angular.equals(val,false)) ? true : false; 242 | }; // end useESCClose 243 | 244 | /** 245 | * Use Class 246 | * 247 | * Sets the additional CSS window class of the modal window template. 248 | * 249 | * @param val string 250 | */ 251 | this.useClass = function(val){ 252 | if(angular.isDefined(val)) 253 | _w = val; 254 | }; // end useClass 255 | 256 | /** 257 | * Use Copy 258 | * 259 | * Determines the use of angular.copy when sending data to the modal controller. 260 | * 261 | * @param val boolean 262 | */ 263 | this.useCopy = function(val){ 264 | if(angular.isDefined(val)) 265 | _copy = (!angular.equals(val,0) && !angular.equals(val,'false') && !angular.equals(val,'no') && !angular.equals(val,null) && !angular.equals(val,false)) ? true : false; 266 | }; // end useCopy 267 | 268 | /** 269 | * Set Window Template 270 | * 271 | * Sets a path to a template to use overriding modal's window template. 272 | * 273 | * @param val string 274 | */ 275 | this.setWindowTmpl = function(val){ 276 | if(angular.isDefined(val)) 277 | _wTmpl = val; 278 | }; // end setWindowTmpl 279 | 280 | /** 281 | * Set Size 282 | * 283 | * Sets the modal size to use (sm,lg,md) 284 | * 285 | * @param val string (sm,lg,md) 286 | */ 287 | this.setSize = function(val){ 288 | if(angular.isDefined(val)) 289 | _wSize = (angular.equals(val,'sm') || angular.equals(val,'lg') || angular.equals(val,'md')) ? val : _wSize; 290 | }; // end setSize 291 | 292 | /** 293 | * Use Animations 294 | * 295 | * Sets the use of animations to true 296 | */ 297 | this.useAnimation = function(){ 298 | _animation = true; 299 | }; // end useAnimation 300 | 301 | /** 302 | * Use Font-Awesome. 303 | * 304 | * Sets Font-Awesome flag to true and substitutes font-awesome icons for 305 | * Bootstrap's glyphicons. 306 | */ 307 | this.useFontAwesome = function(){ 308 | _fa = true; 309 | }; // end useFontAwesome 310 | 311 | 312 | this.$get = ['$uibModal',function ($uibModal){ 313 | 314 | return { 315 | /** 316 | * Error Dialog 317 | * 318 | * @param header string 319 | * @param msg string 320 | * @param opts object 321 | */ 322 | error : function(header,msg,opts){ 323 | opts = _setOpts(opts); 324 | 325 | return $uibModal.open({ 326 | templateUrl : '/dialogs/error.html', 327 | controller : 'errorDialogCtrl', 328 | backdrop: opts.bd, 329 | backdropClass: opts.bdc, 330 | keyboard: opts.kb, 331 | windowClass: opts.wc, 332 | size: opts.ws, 333 | animation: opts.anim, 334 | resolve : { 335 | data : function(){ 336 | return { 337 | header : angular.copy(header), 338 | msg : angular.copy(msg), 339 | fa : _fa, 340 | btnMessages: opts.btnMessages 341 | }; 342 | } 343 | } 344 | }); // end modal.open 345 | }, // end error 346 | 347 | /** 348 | * Wait Dialog 349 | * 350 | * @param header string 351 | * @param msg string 352 | * @param progress int 353 | * @param opts object 354 | */ 355 | wait : function(header,msg,progress,opts){ 356 | opts = _setOpts(opts); 357 | 358 | return $uibModal.open({ 359 | templateUrl : '/dialogs/wait.html', 360 | controller : 'waitDialogCtrl', 361 | backdrop: opts.bd, 362 | backdropClass: opts.bdc, 363 | keyboard: opts.kb, 364 | windowClass: opts.wc, 365 | size: opts.ws, 366 | animation: opts.anim, 367 | resolve : { 368 | data : function(){ 369 | return { 370 | header : angular.copy(header), 371 | msg : angular.copy(msg), 372 | progress : angular.copy(progress), 373 | fa : _fa 374 | }; 375 | } 376 | } 377 | }); // end modal.open 378 | }, // end wait 379 | 380 | /** 381 | * Notify Dialog 382 | * 383 | * @param header string 384 | * @param msg string 385 | * @param opts object 386 | */ 387 | notify : function(header,msg,opts){ 388 | opts = _setOpts(opts); 389 | 390 | return $uibModal.open({ 391 | templateUrl : '/dialogs/notify.html', 392 | controller : 'notifyDialogCtrl', 393 | backdrop: opts.bd, 394 | backdropClass: opts.bdc, 395 | keyboard: opts.kb, 396 | windowClass: opts.wc, 397 | size: opts.ws, 398 | animation: opts.anim, 399 | resolve : { 400 | data : function(){ 401 | return { 402 | header : angular.copy(header), 403 | msg : angular.copy(msg), 404 | fa : _fa, 405 | btnMessages: opts.btnMessages 406 | }; 407 | } 408 | } 409 | }); // end modal.open 410 | }, // end notify 411 | 412 | /** 413 | * Confirm Dialog 414 | * 415 | * @param header string 416 | * @param msg string 417 | * @param opts object 418 | */ 419 | confirm : function(header,msg,opts){ 420 | opts = _setOpts(opts); 421 | 422 | return $uibModal.open({ 423 | templateUrl : '/dialogs/confirm.html', 424 | controller : 'confirmDialogCtrl', 425 | backdrop: opts.bd, 426 | backdropClass: opts.bdc, 427 | keyboard: opts.kb, 428 | windowClass: opts.wc, 429 | size: opts.ws, 430 | animation: opts.anim, 431 | resolve : { 432 | data : function(){ 433 | return { 434 | header : angular.copy(header), 435 | msg : angular.copy(msg), 436 | fa : _fa, 437 | btnMessages: opts.btnMessages 438 | }; 439 | } 440 | } 441 | }); // end modal.open 442 | }, // end confirm 443 | 444 | /** 445 | * Create Custom Dialog 446 | * 447 | * @param url string 448 | * @param ctrlr string 449 | * @param data object 450 | * @param opts object 451 | */ 452 | create : function(url,ctrlr,data,opts,ctrlAs){ 453 | var copy = (opts && angular.isDefined(opts.copy)) ? opts.copy : _copy; 454 | opts = _setOpts(opts); 455 | 456 | return $uibModal.open({ 457 | templateUrl : url, 458 | controller : ctrlr, 459 | controllerAs : ctrlAs, 460 | keyboard : opts.kb, 461 | backdrop : opts.bd, 462 | backdropClass: opts.bdc, 463 | windowClass: opts.wc, 464 | size: opts.ws, 465 | animation: opts.anim, 466 | resolve : { 467 | data : function() { 468 | if(copy) 469 | return angular.copy(data); 470 | else 471 | return data; 472 | } 473 | } 474 | }); // end modal.open 475 | } // end create 476 | 477 | }; // end return 478 | 479 | }]; // end $get 480 | }]); // end provider dialogs 481 | //== Dialogs.Main Module =====================================================// 482 | 483 | /** 484 | * Include this module 'dialogs.main' in your module's dependency list where you 485 | * intend to use it. Then inject the 'dialogs' service in your controllers that 486 | * need it. 487 | */ 488 | 489 | angular.module('dialogs.main',['dialogs.services','ngSanitize']) // requires angular-sanitize.min.js (ngSanitize) //code.angularjs.org/1.2.1/angular-sanitize.min.js 490 | 491 | .config(['$translateProvider','dialogsProvider',function($translateProvider,dialogsProvider){ 492 | /** 493 | * if Angular-Translate is not loaded, use the translate substitute 494 | * module and create default translations to use as default modal texts 495 | */ 496 | try{ 497 | angular.module('pascalprecht.translate'); 498 | }catch(err){ 499 | // console.log('Dialogs: Creating default translations for use without Angular-Translate.'); 500 | 501 | // This will set default modal buttons, header and message text 502 | $translateProvider.translations('en-US',{ 503 | DIALOGS_ERROR: "Error", 504 | DIALOGS_ERROR_MSG: "An unknown error has occurred.", 505 | DIALOGS_CLOSE: "Close", 506 | DIALOGS_PLEASE_WAIT: "Please Wait", 507 | DIALOGS_PLEASE_WAIT_ELIPS: "Please Wait...", 508 | DIALOGS_PLEASE_WAIT_MSG: "Waiting on operation to complete.", 509 | DIALOGS_PERCENT_COMPLETE: "% Complete", 510 | DIALOGS_NOTIFICATION: "Notification", 511 | DIALOGS_NOTIFICATION_MSG: "Unknown application notification.", 512 | DIALOGS_CONFIRMATION: "Confirmation", 513 | DIALOGS_CONFIRMATION_MSG: "Confirmation required.", 514 | DIALOGS_OK: "OK", 515 | DIALOGS_YES: "Yes", 516 | DIALOGS_NO: "No" 517 | }); 518 | } // end try/catch 519 | 520 | /** 521 | * Attempt to ascertain if page is using Font Awesome instead of the 522 | * regular Bootstrap Icons. If you are changing the stylesheet name or 523 | * not including it from a CDN or have included Font-Awesome as a 524 | * concatentation of CSS sheets together, then you will have to manually 525 | * set Font-Awesome usage in your Angular Module's config by including 526 | * the $dialogsProvider and calling the method $dialogsProvider.useFontAwesome(). 527 | */ 528 | try{ 529 | var _sheets = document.styleSheets; 530 | 531 | sheetLoop: 532 | for(var i = (_sheets.length - 1);i >= 0;i--){ 533 | var _matches = null; 534 | var _rules = null; 535 | 536 | if(!_sheets[i].disabled){ 537 | // check href of style sheet first 538 | if(_sheets[i].href !== null) 539 | _matches = _sheets[i].href.match(/font\-*awesome/i); 540 | 541 | if(angular.isArray(_matches)){ 542 | dialogsProvider.useFontAwesome(); 543 | break; // done, leave the style sheet for loop 544 | }else{ 545 | // try to find css rule .fa, in case style sheet has been concatenated 546 | _rules = _sheets[i].cssRules; 547 | for(var x = (_rules.length - 1);x >= 0;x--){ 548 | if(typeof(_rules[x].selectorText) === 'string' && _rules[x].selectorText.toLowerCase() === '.fa'){ 549 | dialogsProvider.useFontAwesome(); 550 | break sheetLoop; // done, exit both for loops 551 | } 552 | } 553 | } 554 | } // end if(disabled) 555 | } // end for 556 | }catch(err){ 557 | // console.log('Error Message: ' + err); 558 | } 559 | }]) // end config 560 | 561 | // Add default templates via $templateCache 562 | .run(['$templateCache','$interpolate',function($templateCache,$interpolate){ 563 | 564 | // get interpolation symbol (possible that someone may have changed it in their application instead of using '{{}}') 565 | var startSym = $interpolate.startSymbol(); 566 | var endSym = $interpolate.endSymbol(); 567 | 568 | $templateCache.put('/dialogs/error.html',''); 569 | $templateCache.put('/dialogs/wait.html',''); 570 | $templateCache.put('/dialogs/notify.html',''); 571 | $templateCache.put('/dialogs/confirm.html',''); 572 | }]); // end run / dialogs.main 573 | 574 | })(); -------------------------------------------------------------------------------- /example/js/dialogs.min.js: -------------------------------------------------------------------------------- 1 | !function(){"use strict";var a=angular.module("translate.sub",[]);a.provider("$translate",[function(){var a=[],n="en-US";this.translations=function(e,s){angular.isDefined(e)&&angular.isDefined(s)&&(a[e]=angular.copy(s),n=e)},this.$get=[function(){return{instant:function(e){return angular.isDefined(e)&&angular.isDefined(a[n][e])?a[n][e]:""}}}]}]),a.filter("translate",["$translate",function(a){return function(n){return a.instant(n)}}]);var n;try{angular.module("pascalprecht.translate"),n=angular.module("dialogs.controllers",["ui.bootstrap.modal","pascalprecht.translate"])}catch(e){n=angular.module("dialogs.controllers",["ui.bootstrap.modal","translate.sub"])}n.controller("errorDialogCtrl",["$scope","$uibModalInstance","$translate","data",function(a,n,e,s){a.header=angular.isDefined(s.header)?s.header:e.instant("DIALOGS_ERROR"),a.msg=angular.isDefined(s.msg)?s.msg:e.instant("DIALOGS_ERROR_MSG"),a.icon=angular.isDefined(s.fa)&&angular.equals(s.fa,!0)?"fa fa-warning":"glyphicon glyphicon-warning-sign",a.close=function(){n.close(),a.$destroy()}}]),n.controller("waitDialogCtrl",["$scope","$uibModalInstance","$translate","$timeout","data",function(a,n,e,s,o){a.header=angular.isDefined(o.header)?o.header:e.instant("DIALOGS_PLEASE_WAIT_ELIPS"),a.msg=angular.isDefined(o.msg)?o.msg:e.instant("DIALOGS_PLEASE_WAIT_MSG"),a.progress=angular.isDefined(o.progress)?o.progress:100,a.icon=angular.isDefined(o.fa)&&angular.equals(o.fa,!0)?"fa fa-clock-o":"glyphicon glyphicon-time",a.$on("dialogs.wait.complete",function(){s(function(){n.close(),a.$destroy()})}),a.$on("dialogs.wait.message",function(n,e){a.msg=angular.isDefined(e.msg)?e.msg:a.msg}),a.$on("dialogs.wait.progress",function(n,e){a.msg=angular.isDefined(e.msg)?e.msg:a.msg,a.progress=angular.isDefined(e.progress)?e.progress:a.progress}),a.getProgress=function(){return{width:a.progress+"%"}}}]),n.controller("notifyDialogCtrl",["$scope","$uibModalInstance","$translate","data",function(a,n,e,s){a.header=angular.isDefined(s.header)?s.header:e.instant("DIALOGS_NOTIFICATION"),a.msg=angular.isDefined(s.msg)?s.msg:e.instant("DIALOGS_NOTIFICATION_MSG"),a.icon=angular.isDefined(s.fa)&&angular.equals(s.fa,!0)?"fa fa-info":"glyphicon glyphicon-info-sign",a.close=function(){n.close(),a.$destroy()}}]),n.controller("confirmDialogCtrl",["$scope","$uibModalInstance","$translate","data",function(a,n,e,s){a.header=angular.isDefined(s.header)?s.header:e.instant("DIALOGS_CONFIRMATION"),a.msg=angular.isDefined(s.msg)?s.msg:e.instant("DIALOGS_CONFIRMATION_MSG"),a.icon=angular.isDefined(s.fa)&&angular.equals(s.fa,!0)?"fa fa-check":"glyphicon glyphicon-check",a.no=function(){n.dismiss("no")},a.yes=function(){n.close("yes")}}]),angular.module("dialogs.services",["ui.bootstrap.modal","dialogs.controllers"]).provider("dialogs",[function(){var a=!0,n=!0,e="dialogs-default",s="dialogs-backdrop-default",o=!0,t=null,l="lg",r=!1,i=!1,d=function(o){var t={};return o=o||{},t.kb=angular.isDefined(o.keyboard)?!!o.keyboard:n,t.bd=angular.isDefined(o.backdrop)?o.backdrop:a,t.bdc=angular.isDefined(o.backdropClass)?o.backdropClass:s,t.ws=!angular.isDefined(o.size)||"sm"!==o.size&&"lg"!==o.size&&"md"!==o.size?l:o.size,t.wc=angular.isDefined(o.windowClass)?o.windowClass:e,t.anim=angular.isDefined(o.animation)?!!o.animation:r,t};this.useBackdrop=function(n){angular.isDefined(n)&&(a=n)},this.useEscClose=function(a){angular.isDefined(a)&&(n=angular.equals(a,0)||angular.equals(a,"false")||angular.equals(a,"no")||angular.equals(a,null)||angular.equals(a,!1)?!1:!0)},this.useClass=function(a){angular.isDefined(a)&&(e=a)},this.useCopy=function(a){angular.isDefined(a)&&(o=angular.equals(a,0)||angular.equals(a,"false")||angular.equals(a,"no")||angular.equals(a,null)||angular.equals(a,!1)?!1:!0)},this.setWindowTmpl=function(a){angular.isDefined(a)&&(t=a)},this.setSize=function(a){angular.isDefined(a)&&(l=angular.equals(a,"sm")||angular.equals(a,"lg")||angular.equals(a,"md")?a:l)},this.useAnimation=function(){r=!0},this.useFontAwesome=function(){i=!0},this.$get=["$uibModal",function(a){return{error:function(n,e,s){return s=d(s),a.open({templateUrl:"/dialogs/error.html",controller:"errorDialogCtrl",backdrop:s.bd,backdropClass:s.bdc,keyboard:s.kb,windowClass:s.wc,size:s.ws,animation:s.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(e),fa:i}}}})},wait:function(n,e,s,o){return o=d(o),a.open({templateUrl:"/dialogs/wait.html",controller:"waitDialogCtrl",backdrop:o.bd,backdropClass:o.bdc,keyboard:o.kb,windowClass:o.wc,size:o.ws,animation:o.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(e),progress:angular.copy(s),fa:i}}}})},notify:function(n,e,s){return s=d(s),a.open({templateUrl:"/dialogs/notify.html",controller:"notifyDialogCtrl",backdrop:s.bd,backdropClass:s.bdc,keyboard:s.kb,windowClass:s.wc,size:s.ws,animation:s.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(e),fa:i}}}})},confirm:function(n,e,s){return s=d(s),a.open({templateUrl:"/dialogs/confirm.html",controller:"confirmDialogCtrl",backdrop:s.bd,backdropClass:s.bdc,keyboard:s.kb,windowClass:s.wc,size:s.ws,animation:s.anim,resolve:{data:function(){return{header:angular.copy(n),msg:angular.copy(e),fa:i}}}})},create:function(n,e,s,t,l){var r=t&&angular.isDefined(t.copy)?t.copy:o;return t=d(t),a.open({templateUrl:n,controller:e,controllerAs:l,keyboard:t.kb,backdrop:t.bd,backdropClass:t.bdc,windowClass:t.wc,size:t.ws,animation:t.anim,resolve:{data:function(){return r?angular.copy(s):s}}})}}}]}]),angular.module("dialogs.main",["dialogs.services","ngSanitize"]).config(["$translateProvider","dialogsProvider",function(a,n){try{angular.module("pascalprecht.translate")}catch(e){a.translations("en-US",{DIALOGS_ERROR:"Error",DIALOGS_ERROR_MSG:"An unknown error has occurred.",DIALOGS_CLOSE:"Close",DIALOGS_PLEASE_WAIT:"Please Wait",DIALOGS_PLEASE_WAIT_ELIPS:"Please Wait...",DIALOGS_PLEASE_WAIT_MSG:"Waiting on operation to complete.",DIALOGS_PERCENT_COMPLETE:"% Complete",DIALOGS_NOTIFICATION:"Notification",DIALOGS_NOTIFICATION_MSG:"Unknown application notification.",DIALOGS_CONFIRMATION:"Confirmation",DIALOGS_CONFIRMATION_MSG:"Confirmation required.",DIALOGS_OK:"OK",DIALOGS_YES:"Yes",DIALOGS_NO:"No"})}try{var s=document.styleSheets;a:for(var o=s.length-1;o>=0;o--){var t=null,l=null;if(!s[o].disabled){if(null!==s[o].href&&(t=s[o].href.match(/font\-*awesome/i)),angular.isArray(t)){n.useFontAwesome();break}l=s[o].cssRules;for(var r=l.length-1;r>=0;r--)if(".fa"==l[r].selectorText.toLowerCase()){n.useFontAwesome();break a}}}}catch(e){}}]).run(["$templateCache","$interpolate",function(a,n){var e=n.startSymbol(),s=n.endSymbol();a.put("/dialogs/error.html",'"),a.put("/dialogs/wait.html",'"),a.put("/dialogs/notify.html",'"),a.put("/dialogs/confirm.html",'")}])}(); -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | var minify = require('gulp-minify'); 3 | var minifyCSS = require('gulp-minify-css'); 4 | var jshint = require('gulp-jshint'); 5 | var rename = require('gulp-rename'); 6 | var concat = require('gulp-concat'); 7 | var wrap = require('gulp-wrap'); 8 | var header = require('gulp-header'); 9 | var bump = require('gulp-bump'); 10 | var util = require('gulp-util'); 11 | var connect = require('gulp-connect'); 12 | 13 | gulp.task('lint',function(){ 14 | return gulp.src('src/*.js') 15 | .pipe(jshint()) 16 | .pipe(jshint.reporter('default')) 17 | .pipe(jshint.reporter('fail')); 18 | }); // end lint 19 | 20 | gulp.task('concat-js',function(){ 21 | return gulp.src(['src/translate-substitution.js','src/dialogs-controllers.js','src/dialogs-services.js','src/dialogs-main.js']) 22 | .pipe(concat('dialogs.js')) 23 | .pipe(wrap('(function(){\n"use strict";\n<%= contents %>\n})();')) 24 | .pipe(gulp.dest('temp')); 25 | }); // end concat-js 26 | 27 | gulp.task('compress-js',['concat-js'],function(){ 28 | var bower = require('./bower.json'); 29 | var banner = ['/**', 30 | ' * <%= bower.name %> - <%= bower.description %>', 31 | ' * @version v<%= bower.version %>', 32 | ' * @author <%= bower.authors[0].name %>, <%= bower.authors[0].email %>', 33 | ' * @license <%= bower.licenses[0].type %>, <%= bower.licenses[0].url %>', 34 | ' */', 35 | ''].join('\n'); 36 | 37 | gulp.src(['temp/dialogs.js','src/dialogs-default-translations.js']) 38 | .pipe(header(banner, {bower : bower})) 39 | .pipe(gulp.dest('dist')) 40 | .pipe(gulp.dest('example/js')) 41 | .pipe(minify({ ext: '.min.js' })) 42 | .pipe(gulp.dest('dist')); 43 | }); // end comrpess-js 44 | 45 | gulp.task('compress-css',function(){ 46 | gulp.src('src/*.css') 47 | .pipe(concat('dialogs.css')) 48 | .pipe(gulp.dest('dist')) 49 | .pipe(minifyCSS({})) 50 | .pipe(concat('dialogs.css')) 51 | .pipe(rename({suffix: '.min'})) 52 | .pipe(gulp.dest('dist')); 53 | 54 | }); // end compress-css 55 | 56 | gulp.task('connect', function(){ 57 | connect.server({ 58 | root: './example', 59 | port: 8000 60 | }); 61 | }); 62 | 63 | gulp.task('watch_files', function(){ 64 | gulp.watch(['src/*.js'], ['lint', 'compress-js']); 65 | gulp.watch(['src/*.css'], ['compress-css']); 66 | }); 67 | 68 | gulp.task('default',['lint','compress-js','compress-css']); 69 | 70 | gulp.task('watch', ['default', 'connect', 'watch_files']); 71 | 72 | /*********************************************************************************************************************** 73 | * VERSIONING - Bump Versions 74 | **********************************************************************************************************************/ 75 | 76 | /** 77 | * Bumps project version based on given command line type. 78 | */ 79 | gulp.task('bump',function(){ 80 | util.log('Starting bump task.'); 81 | 82 | // gulp bump --type [major|minor|patch] 83 | var type = util.env.type; 84 | if((type === 'major') || (type === 'minor') || (type === 'patch')) { 85 | util.log('Bumping ' + type + ' Version'); 86 | return gulp.src(['./bower.json', './package.json']) 87 | .pipe(bump({ 88 | type: type 89 | })) 90 | .pipe(gulp.dest('./')); 91 | } 92 | 93 | return; 94 | }); // end bump 95 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | require('./dist/dialogs.js'); 2 | require('./dist/dialogs-default-translations.js'); 3 | module.exports = 'dialogs.main'; 4 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration 2 | // Generated on Tue Oct 13 2015 22:18:04 GMT-0400 (EDT) 3 | 4 | module.exports = function(config) { 5 | config.set({ 6 | 7 | // base path that will be used to resolve all patterns (eg. files, exclude) 8 | basePath: '', 9 | 10 | 11 | // frameworks to use 12 | // available frameworks: https://npmjs.org/browse/keyword/karma-adapter 13 | frameworks: ['jasmine'], 14 | 15 | 16 | // list of files / patterns to load in the browser 17 | files: [ 18 | 'bower_components/angular/angular.min.js', 19 | 'bower_components/angular-bootstrap/ui-bootstrap.js', 20 | 'bower_components/angular-mocks/angular-mocks.js', 21 | 'src/*.js', 22 | 'tests/*.tests.js' 23 | ], 24 | 25 | 26 | // list of files to exclude 27 | exclude: [ 28 | ], 29 | 30 | 31 | // preprocess matching files before serving them to the browser 32 | // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor 33 | preprocessors: { 34 | }, 35 | 36 | 37 | // test results reporter to use 38 | // possible values: 'dots', 'progress' 39 | // available reporters: https://npmjs.org/browse/keyword/karma-reporter 40 | reporters: ['progress'], 41 | 42 | 43 | // web server port 44 | port: 9876, 45 | 46 | 47 | // enable / disable colors in the output (reporters and logs) 48 | colors: true, 49 | 50 | 51 | // level of logging 52 | // possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG 53 | logLevel: config.LOG_INFO, 54 | 55 | 56 | // enable / disable watching file and executing tests whenever any file changes 57 | autoWatch: true, 58 | 59 | 60 | // start these browsers 61 | // available browser launchers: https://npmjs.org/browse/keyword/karma-launcher 62 | browsers: ['PhantomJS'], 63 | 64 | 65 | // Continuous Integration mode 66 | // if true, Karma captures browsers, runs the tests and exits 67 | singleRun: false 68 | }) 69 | } 70 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "angular-dialog-service", 3 | "description": "A service to handle common dialog types in a web application. Built on top of Angular-Bootstrap's modal", 4 | "version": "5.3.1", 5 | "keywords": [ 6 | "angular", 7 | "dialog", 8 | "modal", 9 | "service" 10 | ], 11 | "authors": [ 12 | { 13 | "name": "Michael Conroy", 14 | "email": "michael.e.conroy@gmail.com", 15 | "homepage": "http://michaeleconroy.blogspot.com/" 16 | } 17 | ], 18 | "repository": { 19 | "type": "git", 20 | "url": "git://github.com/m-e-conroy/angular-dialog-service" 21 | }, 22 | "main": "index.js", 23 | "devDependencies": { 24 | "gulp": "3.9.1", 25 | "gulp-bump": "1.0.0", 26 | "gulp-concat": "2.6.0", 27 | "gulp-connect": "2.3.1", 28 | "gulp-header": "1.7.1", 29 | "gulp-jshint": "2.0.0", 30 | "gulp-minify": "0.0.5", 31 | "gulp-minify-css": "1.2.4", 32 | "gulp-rename": "1.2.2", 33 | "gulp-util": "3.0.7", 34 | "gulp-wrap": "0.11.0", 35 | "jasmine-core": "2.4.1", 36 | "jshint": "2.9.1", 37 | "karma": "0.13.21", 38 | "karma-jasmine": "0.3.7", 39 | "karma-phantomjs-launcher": "1.0.0", 40 | "phantomjs-prebuilt": "2.1.4" 41 | }, 42 | "scripts": { 43 | "test": "karma start karma.conf.js" 44 | }, 45 | "license": "MIT" 46 | } 47 | -------------------------------------------------------------------------------- /src/dialogs-controllers.js: -------------------------------------------------------------------------------- 1 | //== Controllers =============================================================// 2 | 3 | var ctrlrs; // will be dialogs.controllers module 4 | 5 | // determine if Angular-Translate is available, if not use the substitute 6 | try{ 7 | angular.module('pascalprecht.translate'); // throws error if module not loaded 8 | // console.log('Dialogs (Angular-Translate): OK'); 9 | 10 | // dialogs.controllers: module declaration 11 | ctrlrs = angular.module('dialogs.controllers',['ui.bootstrap.modal','pascalprecht.translate']); 12 | }catch(err){ 13 | // console.log('Dialogs: (Angular-Translate): ' + err.message); 14 | // console.log('Dialogs: Attempting to use translate.sub module.'); 15 | 16 | // dialogs.controllers: module declaration 17 | ctrlrs = angular.module('dialogs.controllers',['ui.bootstrap.modal','translate.sub']); 18 | } // end try/catch 19 | 20 | // angular.module('dialogs.controllers',['ui.bootstrap.modal','pascalprecht.translate']) 21 | 22 | /** 23 | * Error Dialog Controller 24 | */ 25 | ctrlrs.controller('errorDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){ 26 | //-- Variables -----// 27 | 28 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_ERROR'); 29 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_ERROR_MSG'); 30 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-warning' : 'glyphicon glyphicon-warning-sign'; 31 | $scope.btnMessages = data.btnMessages; 32 | 33 | //-- Methods -----// 34 | 35 | $scope.close = function(){ 36 | $uibModalInstance.close(); 37 | $scope.$destroy(); 38 | }; // end close 39 | }]); // end ErrorDialogCtrl 40 | 41 | /** 42 | * Wait Dialog Controller 43 | */ 44 | ctrlrs.controller('waitDialogCtrl',['$scope','$uibModalInstance','$translate','$timeout','data',function($scope,$uibModalInstance,$translate,$timeout,data){ 45 | //-- Variables -----// 46 | 47 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_PLEASE_WAIT_ELIPS'); 48 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_PLEASE_WAIT_MSG'); 49 | $scope.progress = (angular.isDefined(data.progress)) ? data.progress : 100; 50 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-clock-o' : 'glyphicon glyphicon-time'; 51 | $scope.btnMessages = data.btnMessages; 52 | 53 | //-- Listeners -----// 54 | 55 | // Note: used $timeout instead of $scope.$apply() because I was getting a $$nextSibling error 56 | 57 | // close wait dialog 58 | $scope.$on('dialogs.wait.complete',function(){ 59 | $timeout(function(){ $uibModalInstance.close(); $scope.$destroy(); }); 60 | }); // end on(dialogs.wait.complete) 61 | 62 | // update the dialog's message 63 | $scope.$on('dialogs.wait.message',function(evt,args){ 64 | $scope.msg = (angular.isDefined(args.msg)) ? args.msg : $scope.msg; 65 | }); // end on(dialogs.wait.message) 66 | 67 | // update the dialog's progress (bar) and/or message 68 | $scope.$on('dialogs.wait.progress',function(evt,args){ 69 | $scope.msg = (angular.isDefined(args.msg)) ? args.msg : $scope.msg; 70 | $scope.progress = (angular.isDefined(args.progress)) ? args.progress : $scope.progress; 71 | }); // end on(dialogs.wait.progress) 72 | 73 | //-- Methods -----// 74 | 75 | $scope.getProgress = function(){ 76 | return {'width': $scope.progress + '%'}; 77 | }; // end getProgress 78 | 79 | }]); // end WaitDialogCtrl 80 | 81 | /** 82 | * Notify Dialog Controller 83 | */ 84 | ctrlrs.controller('notifyDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){ 85 | //-- Variables -----// 86 | 87 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_NOTIFICATION'); 88 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_NOTIFICATION_MSG'); 89 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-info' : 'glyphicon glyphicon-info-sign'; 90 | $scope.btnMessages = data.btnMessages; 91 | 92 | //-- Methods -----// 93 | 94 | $scope.close = function(){ 95 | $uibModalInstance.close(); 96 | $scope.$destroy(); 97 | }; // end close 98 | }]); // end WaitDialogCtrl 99 | 100 | /** 101 | * Confirm Dialog Controller 102 | */ 103 | ctrlrs.controller('confirmDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){ 104 | //-- Variables -----// 105 | 106 | $scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_CONFIRMATION'); 107 | $scope.msg = (angular.isDefined(data.msg)) ? data.msg : $translate.instant('DIALOGS_CONFIRMATION_MSG'); 108 | $scope.icon = (angular.isDefined(data.fa) && angular.equals(data.fa,true)) ? 'fa fa-check' : 'glyphicon glyphicon-check'; 109 | $scope.btnMessages = data.btnMessages; 110 | 111 | //-- Methods -----// 112 | 113 | $scope.no = function(){ 114 | $uibModalInstance.dismiss('no'); 115 | }; // end close 116 | 117 | $scope.yes = function(){ 118 | $uibModalInstance.close('yes'); 119 | }; // end yes 120 | }]); // end ConfirmDialogCtrl / dialogs.controllers 121 | -------------------------------------------------------------------------------- /src/dialogs-default-translations.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Dialog Default Translations. 3 | * 4 | * Include this module if you're not already using angular-translate in your application, and 5 | * add it to your application module's dependency list in order to get default header and 6 | * dialog messages to appear. 7 | * 8 | * Ex: var myApp = angular.module('myApplication',['dialogs.main','dialogs.default-translations']); 9 | * 10 | * It was necessary to separate this out for those already using angular-translate because this would 11 | * automatically reset their translation list for 'en-US' 12 | * 13 | * For those already using angular-translate, just copy the list of DIALOG_[..] translations to your 14 | * translation list where you set 'en-US' using the $translateProvider. 15 | */ 16 | 17 | //== Translations =============================================================// 18 | 19 | angular.module('dialogs.default-translations',['pascalprecht.translate']) 20 | /** 21 | * Default translations in English. 22 | * 23 | * Use angular-translate's $translateProvider to provide translations in an 24 | * alternate language. 25 | * 26 | * $translateProvider.translations('[lang]',{[translations]}); 27 | * To use alternate translations set the preferred language to your desired 28 | * language. 29 | * $translateProvider.preferredLanguage('[lang]'); 30 | */ 31 | .config(['$translateProvider',function($translateProvider){ 32 | $translateProvider.translations('de-DE',{ 33 | DIALOGS_ERROR: "Error", 34 | DIALOGS_ERROR_MSG: "Ein unbekannter Fehler ist aufgetreten.", 35 | DIALOGS_CLOSE: "Schließen", 36 | DIALOGS_PLEASE_WAIT: "Bitte warten", 37 | DIALOGS_PLEASE_WAIT_ELIPS: "Bitte warten...", 38 | DIALOGS_PLEASE_WAIT_MSG: "Warte auf Fertigstellung der Operation.", 39 | DIALOGS_PERCENT_COMPLETE: "% fertig", 40 | DIALOGS_NOTIFICATION: "Benachrichtigung", 41 | DIALOGS_NOTIFICATION_MSG: "Unbekannte Anwendungsbenachrichtigung.", 42 | DIALOGS_CONFIRMATION: "Bestätigung", 43 | DIALOGS_CONFIRMATION_MSG: "Bestätigung erforderlich.", 44 | DIALOGS_OK: "OK", 45 | DIALOGS_YES: "Ja", 46 | DIALOGS_NO: "Nein" 47 | }); 48 | 49 | $translateProvider.translations('en-US',{ 50 | DIALOGS_ERROR: "Error", 51 | DIALOGS_ERROR_MSG: "An unknown error has occurred.", 52 | DIALOGS_CLOSE: "Close", 53 | DIALOGS_PLEASE_WAIT: "Please Wait", 54 | DIALOGS_PLEASE_WAIT_ELIPS: "Please Wait...", 55 | DIALOGS_PLEASE_WAIT_MSG: "Waiting on operation to complete.", 56 | DIALOGS_PERCENT_COMPLETE: "% Complete", 57 | DIALOGS_NOTIFICATION: "Notification", 58 | DIALOGS_NOTIFICATION_MSG: "Unknown application notification.", 59 | DIALOGS_CONFIRMATION: "Confirmation", 60 | DIALOGS_CONFIRMATION_MSG: "Confirmation required.", 61 | DIALOGS_OK: "OK", 62 | DIALOGS_YES: "Yes", 63 | DIALOGS_NO: "No" 64 | }); 65 | 66 | $translateProvider.translations('es-ES',{ 67 | DIALOGS_ERROR: "Error", 68 | DIALOGS_ERROR_MSG: "Se ha producido un error.", 69 | DIALOGS_CLOSE: "Cerrar", 70 | DIALOGS_PLEASE_WAIT: "Espere por favor", 71 | DIALOGS_PLEASE_WAIT_ELIPS: "Espere por favor...", 72 | DIALOGS_PLEASE_WAIT_MSG: "Completando operación.", 73 | DIALOGS_PERCENT_COMPLETE: "% Completado", 74 | DIALOGS_NOTIFICATION: "Notificación", 75 | DIALOGS_NOTIFICATION_MSG: "Notificación de una aplicación desconocida.", 76 | DIALOGS_CONFIRMATION: "Confirmación", 77 | DIALOGS_CONFIRMATION_MSG: "Se requiere confirmacion.", 78 | DIALOGS_OK: "Aceptar", 79 | DIALOGS_YES: "Sí", 80 | DIALOGS_NO: "No" 81 | }); 82 | 83 | $translateProvider.translations("fr-FR", { 84 | DIALOGS_ERROR: "Erreur", 85 | DIALOGS_ERROR_MSG: "Une erreur inconnue s'est produite.", 86 | DIALOGS_CLOSE: "Fermer", 87 | DIALOGS_PLEASE_WAIT: "Patientez svp", 88 | DIALOGS_PLEASE_WAIT_ELIPS: "Patienter svp...", 89 | DIALOGS_PLEASE_WAIT_MSG: "En attente de la fin de l'opération.", 90 | DIALOGS_PERCENT_COMPLETE: "% Terminer", 91 | DIALOGS_NOTIFICATION: "Notification", 92 | DIALOGS_NOTIFICATION_MSG: "Notification de l'application inconnue", 93 | DIALOGS_CONFIRMATION: "Confirmer", 94 | DIALOGS_CONFIRMATION_MSG: "Merci de confirmer", 95 | DIALOGS_OK: "OK", 96 | DIALOGS_YES: "Oui", 97 | DIALOGS_NO: "Non" 98 | }); 99 | 100 | $translateProvider.translations('pt-BR',{ 101 | DIALOGS_ERROR: "Erro", 102 | DIALOGS_ERROR_MSG: "Ocorreu um erro inesperado.", 103 | DIALOGS_CLOSE: "Fechar", 104 | DIALOGS_PLEASE_WAIT: "Por favor aguarde", 105 | DIALOGS_PLEASE_WAIT_ELIPS: "Por favor aguarde...", 106 | DIALOGS_PLEASE_WAIT_MSG: "Aguardando que a operação termine.", 107 | DIALOGS_PERCENT_COMPLETE: "% Completados", 108 | DIALOGS_NOTIFICATION: "Notificação", 109 | DIALOGS_NOTIFICATION_MSG: "Notificação de aplicação desconhecida.", 110 | DIALOGS_CONFIRMATION: "Confirmação", 111 | DIALOGS_CONFIRMATION_MSG: "Confirmação requerida.", 112 | DIALOGS_OK: "OK", 113 | DIALOGS_YES: "Sim", 114 | DIALOGS_NO: "Não" 115 | }); 116 | 117 | $translateProvider.translations('tr-TR',{ 118 | DIALOGS_ERROR: "Hata", 119 | DIALOGS_ERROR_MSG: "Bilinmeyen bir hata oluştu.", 120 | DIALOGS_CLOSE: "Kapat", 121 | DIALOGS_PLEASE_WAIT: "Lütfen Bekleyin", 122 | DIALOGS_PLEASE_WAIT_ELIPS: "Lütfen Bekleyin...", 123 | DIALOGS_PLEASE_WAIT_MSG: "İşlemin tamamlanması bekleniyor.", 124 | DIALOGS_PERCENT_COMPLETE: "% Tamamlandı", 125 | DIALOGS_NOTIFICATION: "Uyarı", 126 | DIALOGS_NOTIFICATION_MSG: "Bilinmeyen uygulama uyarısı.", 127 | DIALOGS_CONFIRMATION: "Konfirmasyon", 128 | DIALOGS_CONFIRMATION_MSG: "Konfirmasyon gereklidir.", 129 | DIALOGS_OK: "Tamam", 130 | DIALOGS_YES: "Evet", 131 | DIALOGS_NO: "Hayır" 132 | }); 133 | 134 | $translateProvider.translations('zh-CN',{ 135 | DIALOGS_ERROR: "错误", 136 | DIALOGS_ERROR_MSG: "出现未知错误。", 137 | DIALOGS_CLOSE: "关闭", 138 | DIALOGS_PLEASE_WAIT: "请稍候", 139 | DIALOGS_PLEASE_WAIT_ELIPS: "请稍候...", 140 | DIALOGS_PLEASE_WAIT_MSG: "请等待操作完成。", 141 | DIALOGS_PERCENT_COMPLETE: "% 已完成", 142 | DIALOGS_NOTIFICATION: "通知", 143 | DIALOGS_NOTIFICATION_MSG: "未知应用程序的通知。", 144 | DIALOGS_CONFIRMATION: "确认", 145 | DIALOGS_CONFIRMATION_MSG: "确认要求。", 146 | DIALOGS_OK: "确定", 147 | DIALOGS_YES: "确认", 148 | DIALOGS_NO: "取消" 149 | }); 150 | 151 | $translateProvider.translations('sv-SE',{ 152 | DIALOGS_ERROR: "Fel", 153 | DIALOGS_ERROR_MSG: "Ett okänt fel har uppstått.", 154 | DIALOGS_CLOSE: "Stäng", 155 | DIALOGS_PLEASE_WAIT: "Vänligen vänta", 156 | DIALOGS_PLEASE_WAIT_ELIPS: "Vänligen vänta...", 157 | DIALOGS_PLEASE_WAIT_MSG: "Väntar på att processen skall slutföras.", 158 | DIALOGS_PERCENT_COMPLETE: "% Färdigt", 159 | DIALOGS_NOTIFICATION: "Meddelande", 160 | DIALOGS_NOTIFICATION_MSG: "Okänt meddelande från applikationen.", 161 | DIALOGS_CONFIRMATION: "Bekräftelse", 162 | DIALOGS_CONFIRMATION_MSG: "Bekräftelse krävs.", 163 | DIALOGS_OK: "OK", 164 | DIALOGS_YES: "Ja", 165 | DIALOGS_NO: "Nej" 166 | }); 167 | 168 | $translateProvider.preferredLanguage('en-US'); 169 | }]); // end config 170 | -------------------------------------------------------------------------------- /src/dialogs-main.js: -------------------------------------------------------------------------------- 1 | //== Dialogs.Main Module =====================================================// 2 | 3 | /** 4 | * Include this module 'dialogs.main' in your module's dependency list where you 5 | * intend to use it. Then inject the 'dialogs' service in your controllers that 6 | * need it. 7 | */ 8 | 9 | angular.module('dialogs.main',['dialogs.services','ngSanitize']) // requires angular-sanitize.min.js (ngSanitize) //code.angularjs.org/1.2.1/angular-sanitize.min.js 10 | 11 | .config(['$translateProvider','dialogsProvider',function($translateProvider,dialogsProvider){ 12 | /** 13 | * if Angular-Translate is not loaded, use the translate substitute 14 | * module and create default translations to use as default modal texts 15 | */ 16 | try{ 17 | angular.module('pascalprecht.translate'); 18 | }catch(err){ 19 | // console.log('Dialogs: Creating default translations for use without Angular-Translate.'); 20 | 21 | // This will set default modal buttons, header and message text 22 | $translateProvider.translations('en-US',{ 23 | DIALOGS_ERROR: "Error", 24 | DIALOGS_ERROR_MSG: "An unknown error has occurred.", 25 | DIALOGS_CLOSE: "Close", 26 | DIALOGS_PLEASE_WAIT: "Please Wait", 27 | DIALOGS_PLEASE_WAIT_ELIPS: "Please Wait...", 28 | DIALOGS_PLEASE_WAIT_MSG: "Waiting on operation to complete.", 29 | DIALOGS_PERCENT_COMPLETE: "% Complete", 30 | DIALOGS_NOTIFICATION: "Notification", 31 | DIALOGS_NOTIFICATION_MSG: "Unknown application notification.", 32 | DIALOGS_CONFIRMATION: "Confirmation", 33 | DIALOGS_CONFIRMATION_MSG: "Confirmation required.", 34 | DIALOGS_OK: "OK", 35 | DIALOGS_YES: "Yes", 36 | DIALOGS_NO: "No" 37 | }); 38 | } // end try/catch 39 | 40 | /** 41 | * Attempt to ascertain if page is using Font Awesome instead of the 42 | * regular Bootstrap Icons. If you are changing the stylesheet name or 43 | * not including it from a CDN or have included Font-Awesome as a 44 | * concatentation of CSS sheets together, then you will have to manually 45 | * set Font-Awesome usage in your Angular Module's config by including 46 | * the $dialogsProvider and calling the method $dialogsProvider.useFontAwesome(). 47 | */ 48 | try{ 49 | var _sheets = document.styleSheets; 50 | 51 | sheetLoop: 52 | for(var i = (_sheets.length - 1);i >= 0;i--){ 53 | var _matches = null; 54 | var _rules = null; 55 | 56 | if(!_sheets[i].disabled){ 57 | // check href of style sheet first 58 | if(_sheets[i].href !== null) 59 | _matches = _sheets[i].href.match(/font\-*awesome/i); 60 | 61 | if(angular.isArray(_matches)){ 62 | dialogsProvider.useFontAwesome(); 63 | break; // done, leave the style sheet for loop 64 | }else{ 65 | // try to find css rule .fa, in case style sheet has been concatenated 66 | _rules = _sheets[i].cssRules; 67 | for(var x = (_rules.length - 1);x >= 0;x--){ 68 | if(typeof(_rules[x].selectorText) === 'string' && _rules[x].selectorText.toLowerCase() === '.fa'){ 69 | dialogsProvider.useFontAwesome(); 70 | break sheetLoop; // done, exit both for loops 71 | } 72 | } 73 | } 74 | } // end if(disabled) 75 | } // end for 76 | }catch(err){ 77 | // console.log('Error Message: ' + err); 78 | } 79 | }]) // end config 80 | 81 | // Add default templates via $templateCache 82 | .run(['$templateCache','$interpolate',function($templateCache,$interpolate){ 83 | 84 | // get interpolation symbol (possible that someone may have changed it in their application instead of using '{{}}') 85 | var startSym = $interpolate.startSymbol(); 86 | var endSym = $interpolate.endSymbol(); 87 | 88 | $templateCache.put('/dialogs/error.html',''); 89 | $templateCache.put('/dialogs/wait.html',''); 90 | $templateCache.put('/dialogs/notify.html',''); 91 | $templateCache.put('/dialogs/confirm.html',''); 92 | }]); // end run / dialogs.main 93 | -------------------------------------------------------------------------------- /src/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 _bdc = 'dialogs-backdrop-default'; // backdropClass 10 | var _copy = true; // controls use of angular.copy 11 | var _wTmpl = null; // window template 12 | var _wSize = 'lg'; // large modal window default 13 | var _animation = false; // true/false to use animation 14 | 15 | var _fa = false; // fontawesome flag 16 | 17 | var _setOpts = function(opts){ 18 | var _opts = {}; 19 | opts = opts || {}; 20 | _opts.kb = (angular.isDefined(opts.keyboard)) ? !!opts.keyboard : _k; // values: true,false 21 | _opts.bd = (angular.isDefined(opts.backdrop)) ? opts.backdrop : _b; // values: 'static',true,false 22 | _opts.bdc = (angular.isDefined(opts.backdropClass)) ? opts.backdropClass : _bdc; // additional CSS class(es) to be added to the modal backdrop 23 | _opts.ws = (angular.isDefined(opts.size) && ((opts.size === 'sm') || (opts.size === 'lg') || (opts.size === 'md'))) ? opts.size : _wSize; // values: 'sm', 'lg', 'md' 24 | _opts.wc = (angular.isDefined(opts.windowClass)) ? opts.windowClass : _w; // additional CSS class(es) to be added to a modal window 25 | _opts.anim = (angular.isDefined(opts.animation)) ? !!opts.animation : _animation; // values: true,false 26 | _opts.btnMessages = (angular.isDefined(opts.btnMessages)) ? opts.btnMessages : {}; // button overrides 27 | return _opts; 28 | }; // end _setOpts 29 | 30 | /** 31 | * Use Backdrop 32 | * 33 | * Sets the use of the modal backdrop. Either to have one or not and 34 | * whether or not it responds to mouse clicks ('static' sets the 35 | * backdrop to true and does not respond to mouse clicks). 36 | * 37 | * @param val mixed (true, false, 'static') 38 | */ 39 | this.useBackdrop = function(val){ // possible values : true, false, 'static' 40 | if(angular.isDefined(val)) 41 | _b = val; 42 | }; // end useStaticBackdrop 43 | 44 | /** 45 | * Use ESC Close 46 | * 47 | * Sets the use of the ESC (escape) key to close modal windows. 48 | * 49 | * @param val boolean 50 | */ 51 | this.useEscClose = function(val){ // possible values : true, false 52 | if(angular.isDefined(val)) 53 | _k = (!angular.equals(val,0) && !angular.equals(val,'false') && !angular.equals(val,'no') && !angular.equals(val,null) && !angular.equals(val,false)) ? true : false; 54 | }; // end useESCClose 55 | 56 | /** 57 | * Use Class 58 | * 59 | * Sets the additional CSS window class of the modal window template. 60 | * 61 | * @param val string 62 | */ 63 | this.useClass = function(val){ 64 | if(angular.isDefined(val)) 65 | _w = val; 66 | }; // end useClass 67 | 68 | /** 69 | * Use Copy 70 | * 71 | * Determines the use of angular.copy when sending data to the modal controller. 72 | * 73 | * @param val boolean 74 | */ 75 | this.useCopy = function(val){ 76 | if(angular.isDefined(val)) 77 | _copy = (!angular.equals(val,0) && !angular.equals(val,'false') && !angular.equals(val,'no') && !angular.equals(val,null) && !angular.equals(val,false)) ? true : false; 78 | }; // end useCopy 79 | 80 | /** 81 | * Set Window Template 82 | * 83 | * Sets a path to a template to use overriding modal's window template. 84 | * 85 | * @param val string 86 | */ 87 | this.setWindowTmpl = function(val){ 88 | if(angular.isDefined(val)) 89 | _wTmpl = val; 90 | }; // end setWindowTmpl 91 | 92 | /** 93 | * Set Size 94 | * 95 | * Sets the modal size to use (sm,lg,md) 96 | * 97 | * @param val string (sm,lg,md) 98 | */ 99 | this.setSize = function(val){ 100 | if(angular.isDefined(val)) 101 | _wSize = (angular.equals(val,'sm') || angular.equals(val,'lg') || angular.equals(val,'md')) ? val : _wSize; 102 | }; // end setSize 103 | 104 | /** 105 | * Use Animations 106 | * 107 | * Sets the use of animations to true 108 | */ 109 | this.useAnimation = function(){ 110 | _animation = true; 111 | }; // end useAnimation 112 | 113 | /** 114 | * Use Font-Awesome. 115 | * 116 | * Sets Font-Awesome flag to true and substitutes font-awesome icons for 117 | * Bootstrap's glyphicons. 118 | */ 119 | this.useFontAwesome = function(){ 120 | _fa = true; 121 | }; // end useFontAwesome 122 | 123 | 124 | this.$get = ['$uibModal',function ($uibModal){ 125 | 126 | return { 127 | /** 128 | * Error Dialog 129 | * 130 | * @param header string 131 | * @param msg string 132 | * @param opts object 133 | */ 134 | error : function(header,msg,opts){ 135 | opts = _setOpts(opts); 136 | 137 | return $uibModal.open({ 138 | templateUrl : '/dialogs/error.html', 139 | controller : 'errorDialogCtrl', 140 | backdrop: opts.bd, 141 | backdropClass: opts.bdc, 142 | keyboard: opts.kb, 143 | windowClass: opts.wc, 144 | size: opts.ws, 145 | animation: opts.anim, 146 | resolve : { 147 | data : function(){ 148 | return { 149 | header : angular.copy(header), 150 | msg : angular.copy(msg), 151 | fa : _fa, 152 | btnMessages: opts.btnMessages 153 | }; 154 | } 155 | } 156 | }); // end modal.open 157 | }, // end error 158 | 159 | /** 160 | * Wait Dialog 161 | * 162 | * @param header string 163 | * @param msg string 164 | * @param progress int 165 | * @param opts object 166 | */ 167 | wait : function(header,msg,progress,opts){ 168 | opts = _setOpts(opts); 169 | 170 | return $uibModal.open({ 171 | templateUrl : '/dialogs/wait.html', 172 | controller : 'waitDialogCtrl', 173 | backdrop: opts.bd, 174 | backdropClass: opts.bdc, 175 | keyboard: opts.kb, 176 | windowClass: opts.wc, 177 | size: opts.ws, 178 | animation: opts.anim, 179 | resolve : { 180 | data : function(){ 181 | return { 182 | header : angular.copy(header), 183 | msg : angular.copy(msg), 184 | progress : angular.copy(progress), 185 | fa : _fa 186 | }; 187 | } 188 | } 189 | }); // end modal.open 190 | }, // end wait 191 | 192 | /** 193 | * Notify Dialog 194 | * 195 | * @param header string 196 | * @param msg string 197 | * @param opts object 198 | */ 199 | notify : function(header,msg,opts){ 200 | opts = _setOpts(opts); 201 | 202 | return $uibModal.open({ 203 | templateUrl : '/dialogs/notify.html', 204 | controller : 'notifyDialogCtrl', 205 | backdrop: opts.bd, 206 | backdropClass: opts.bdc, 207 | keyboard: opts.kb, 208 | windowClass: opts.wc, 209 | size: opts.ws, 210 | animation: opts.anim, 211 | resolve : { 212 | data : function(){ 213 | return { 214 | header : angular.copy(header), 215 | msg : angular.copy(msg), 216 | fa : _fa, 217 | btnMessages: opts.btnMessages 218 | }; 219 | } 220 | } 221 | }); // end modal.open 222 | }, // end notify 223 | 224 | /** 225 | * Confirm Dialog 226 | * 227 | * @param header string 228 | * @param msg string 229 | * @param opts object 230 | */ 231 | confirm : function(header,msg,opts){ 232 | opts = _setOpts(opts); 233 | 234 | return $uibModal.open({ 235 | templateUrl : '/dialogs/confirm.html', 236 | controller : 'confirmDialogCtrl', 237 | backdrop: opts.bd, 238 | backdropClass: opts.bdc, 239 | keyboard: opts.kb, 240 | windowClass: opts.wc, 241 | size: opts.ws, 242 | animation: opts.anim, 243 | resolve : { 244 | data : function(){ 245 | return { 246 | header : angular.copy(header), 247 | msg : angular.copy(msg), 248 | fa : _fa, 249 | btnMessages: opts.btnMessages 250 | }; 251 | } 252 | } 253 | }); // end modal.open 254 | }, // end confirm 255 | 256 | /** 257 | * Create Custom Dialog specifying a component 258 | * 259 | * @param component string 260 | * @param data object 261 | * @param opts object 262 | */ 263 | createWithComponent: function(component, data, opts) { 264 | var copy = (opts && angular.isDefined(opts.copy)) ? opts.copy : _copy; 265 | opts = _setOpts(opts); 266 | 267 | return $uibModal.open({ 268 | component : component, 269 | keyboard : opts.kb, 270 | backdrop : opts.bd, 271 | backdropClass: opts.bdc, 272 | windowClass: opts.wc, 273 | size: opts.ws, 274 | animation: opts.anim, 275 | resolve : { 276 | data : function() { 277 | if(copy) 278 | return angular.copy(data); 279 | else 280 | return data; 281 | } 282 | } 283 | }); // end modal.open 284 | }, // end createWithComponent 285 | 286 | /** 287 | * Create Custom Dialog 288 | * 289 | * @param url string 290 | * @param ctrlr string 291 | * @param data object 292 | * @param opts object 293 | */ 294 | create : function(url,ctrlr,data,opts,ctrlAs){ 295 | var copy = (opts && angular.isDefined(opts.copy)) ? opts.copy : _copy; 296 | opts = _setOpts(opts); 297 | 298 | return $uibModal.open({ 299 | templateUrl : url, 300 | controller : ctrlr, 301 | controllerAs : ctrlAs, 302 | keyboard : opts.kb, 303 | backdrop : opts.bd, 304 | backdropClass: opts.bdc, 305 | windowClass: opts.wc, 306 | size: opts.ws, 307 | animation: opts.anim, 308 | resolve : { 309 | data : function() { 310 | if(copy) 311 | return angular.copy(data); 312 | else 313 | return data; 314 | } 315 | } 316 | }); // end modal.open 317 | } // end create 318 | 319 | }; // end return 320 | 321 | }]; // end $get 322 | }]); // end provider dialogs 323 | -------------------------------------------------------------------------------- /src/dialogs.css: -------------------------------------------------------------------------------- 1 | /* Custom dialog/modal headers */ 2 | 3 | .dialog-header-error { background-color: #d2322d; } 4 | .dialog-header-wait { background-color: #428bca; } 5 | .dialog-header-notify { background-color: #eeeeee; } 6 | .dialog-header-confirm { background-color: #333333; } 7 | .dialog-header-error span, .dialog-header-error h4, 8 | .dialog-header-wait span, .dialog-header-wait h4, 9 | .dialog-header-confirm span, .dialog-header-confirm h4 { color: #ffffff; } 10 | -------------------------------------------------------------------------------- /src/translate-substitution.js: -------------------------------------------------------------------------------- 1 | //== Translate Substitute Module =============================================// 2 | 3 | /** 4 | * For those not using Angular-Translate (pascalprecht.translate), this will sub 5 | * in for it so we don't have to include Angular-Translate if we don't want to. 6 | */ 7 | 8 | var translateSubMod = angular.module('translate.sub',[]); 9 | 10 | /** 11 | * $translate Service 12 | * Sets up a $translateProvider service to use in your module's config 13 | * function. $translate.Provider syntax is the same as Angular-Translate, 14 | * use $translate.Provider.translations(lang,obj) to change the defaults 15 | * for modal button, header and message text. 16 | */ 17 | translateSubMod.provider('$translate',[function(){ 18 | var _translations = []; // object of key/value translation pairs 19 | var _current = 'en-US'; // default language 20 | 21 | /** 22 | * Translations 23 | * Set the internal object of translation key/value pairs. 24 | */ 25 | this.translations = function(lang,obj){ 26 | if(angular.isDefined(lang) && angular.isDefined(obj)){ 27 | _translations[lang] = angular.copy(obj); 28 | _current = lang; 29 | } 30 | }; // end translations 31 | 32 | this.$get = [function(){ 33 | return { 34 | /** 35 | * Instant 36 | * Retrieve the translation for the given key, if key not found 37 | * return the key. 38 | * Example: $translate.instant('DIALOGS_OK'); 39 | */ 40 | instant : function(what){ 41 | if(angular.isDefined(what) && angular.isDefined(_translations[_current][what])) 42 | return _translations[_current][what]; 43 | else 44 | return what; 45 | } // end instant 46 | }; // end return 47 | }]; // end $get 48 | 49 | }]); // end $translate 50 | 51 | /** 52 | * Translate Filter 53 | * For use in an Angular template. 54 | * Example: {{"DIALOGS_CLOSE" | translate}} 55 | */ 56 | translateSubMod.filter('translate',['$translate',function($translate){ 57 | return function(what){ 58 | return $translate.instant(what); 59 | }; 60 | }]); // end translate / translate.sub -------------------------------------------------------------------------------- /tests/dialogs-controllers.tests.js: -------------------------------------------------------------------------------- 1 | describe('Module dialogs.controllers', function(){ 2 | 3 | var $uibModalInstance; 4 | var $translate; 5 | 6 | beforeEach(function(){ 7 | module('dialogs.controllers'); 8 | 9 | $uibModalInstance = { 10 | close: function(arg){}, 11 | dismiss: function(arg){} 12 | }; 13 | $translate = { 14 | instant: function(arg){} 15 | }; 16 | 17 | spyOn($translate, 'instant').and.callFake(function(key){ 18 | return { 19 | DIALOGS_ERROR: "Error", 20 | DIALOGS_ERROR_MSG: "An unknown error has occurred.", 21 | DIALOGS_CLOSE: "Close", 22 | DIALOGS_PLEASE_WAIT: "Please Wait", 23 | DIALOGS_PLEASE_WAIT_ELIPS: "Please Wait...", 24 | DIALOGS_PLEASE_WAIT_MSG: "Waiting on operation to complete.", 25 | DIALOGS_PERCENT_COMPLETE: "% Complete", 26 | DIALOGS_NOTIFICATION: "Notification", 27 | DIALOGS_NOTIFICATION_MSG: "Unknown application notification.", 28 | DIALOGS_CONFIRMATION: "Confirmation", 29 | DIALOGS_CONFIRMATION_MSG: "Confirmation required.", 30 | DIALOGS_OK: "OK", 31 | DIALOGS_YES: "Yes", 32 | DIALOGS_NO: "No" 33 | }[key]; 34 | }); 35 | 36 | }); 37 | 38 | describe('Controller errorDialogCtrl', function() { 39 | 40 | var data; 41 | var $scope; 42 | var $ctrlr; 43 | var $rootScope; 44 | 45 | beforeEach(function(){ 46 | inject(function($rootScope, $controller, $injector){ 47 | 48 | $ctrlr = $controller; 49 | $scope = $rootScope.$new(); 50 | $rootScope = $rootScope; 51 | 52 | spyOn($uibModalInstance, 'close'); 53 | spyOn($scope, '$destroy'); 54 | 55 | }); 56 | }); 57 | 58 | describe('Using Default Data', function(){ 59 | beforeEach(function(){ 60 | data = {}; 61 | 62 | $ctrlr('errorDialogCtrl', { 63 | $scope: $scope, 64 | $uibModalInstance: $uibModalInstance, 65 | $translate: $translate, 66 | data: data 67 | }); 68 | }); 69 | 70 | it('should close uibModalInstance when close method executed', function(){ 71 | $scope.close(); 72 | expect($uibModalInstance.close).toHaveBeenCalled(); 73 | expect($scope.$destroy).toHaveBeenCalled(); 74 | }); 75 | 76 | it('should have default values for header', function(){ 77 | expect($translate.instant).toHaveBeenCalledWith('DIALOGS_ERROR'); 78 | expect($scope.header).toBe("Error"); 79 | }); 80 | 81 | it('should have default values for msg', function(){ 82 | expect($translate.instant).toHaveBeenCalledWith('DIALOGS_ERROR_MSG'); 83 | expect($scope.msg).toBe("An unknown error has occurred."); 84 | }); 85 | 86 | it('should have default values for icon', function(){ 87 | expect($scope.icon).toBe("glyphicon glyphicon-warning-sign"); 88 | }); 89 | 90 | }); 91 | 92 | describe('Using Provided Data', function(){ 93 | beforeEach(function(){ 94 | data = { 95 | header: "ThisError", 96 | msg: "Some Error Message", 97 | fa: true 98 | }; 99 | 100 | $ctrlr('errorDialogCtrl', { 101 | $scope: $scope, 102 | $uibModalInstance: $uibModalInstance, 103 | $translate: $translate, 104 | data: data 105 | }); 106 | }); 107 | 108 | it('should have ThisError for header', function(){ 109 | expect($scope.header).toBe("ThisError"); 110 | }); 111 | 112 | it('should have default values for msg', function(){ 113 | expect($scope.msg).toBe("Some Error Message"); 114 | }); 115 | 116 | it('should have default values for icon', function(){ 117 | expect($scope.icon).toBe("fa fa-warning"); 118 | }); 119 | 120 | }); 121 | 122 | }); 123 | 124 | describe('Controller notifyDialogCtrl', function() { 125 | 126 | var $scope; 127 | var data; 128 | var $ctrlr; 129 | var $rootScope; 130 | 131 | beforeEach(function(){ 132 | inject(function($rootScope, $controller, $injector){ 133 | 134 | $ctrlr = $controller; 135 | $scope = $rootScope.$new(); 136 | $rootScope = $rootScope; 137 | 138 | spyOn($uibModalInstance, 'close'); 139 | spyOn($scope, '$destroy'); 140 | 141 | }); 142 | }); 143 | 144 | describe('Using Default Data', function(){ 145 | beforeEach(function(){ 146 | data = {}; 147 | 148 | $ctrlr('notifyDialogCtrl', { 149 | $scope: $scope, 150 | $uibModalInstance: $uibModalInstance, 151 | $translate: $translate, 152 | data: data 153 | }); 154 | }); 155 | 156 | it('should close uibModalInstance when close method executed', function(){ 157 | $scope.close(); 158 | expect($uibModalInstance.close).toHaveBeenCalled(); 159 | expect($scope.$destroy).toHaveBeenCalled(); 160 | }); 161 | 162 | it('should have default values for header', function(){ 163 | expect($translate.instant).toHaveBeenCalledWith('DIALOGS_NOTIFICATION'); 164 | expect($scope.header).toBe("Notification"); 165 | }); 166 | 167 | it('should have default values for msg', function(){ 168 | expect($translate.instant).toHaveBeenCalledWith('DIALOGS_NOTIFICATION_MSG'); 169 | expect($scope.msg).toBe("Unknown application notification."); 170 | }); 171 | 172 | it('should have default values for icon', function(){ 173 | expect($scope.icon).toBe("glyphicon glyphicon-info-sign"); 174 | }); 175 | 176 | }); 177 | 178 | describe('Using Provided Data', function(){ 179 | beforeEach(function(){ 180 | data = { 181 | header: "ThisNotify", 182 | msg: "Some Notify Message", 183 | fa: true 184 | }; 185 | 186 | $ctrlr('notifyDialogCtrl', { 187 | $scope: $scope, 188 | $uibModalInstance: $uibModalInstance, 189 | $translate: $translate, 190 | data: data 191 | }); 192 | }); 193 | 194 | it('should have ThisError for header', function(){ 195 | expect($scope.header).toBe("ThisNotify"); 196 | }); 197 | 198 | it('should have Some Notify Message for msg', function(){ 199 | expect($scope.msg).toBe("Some Notify Message"); 200 | }); 201 | 202 | it('should have font-awesome values for icon', function(){ 203 | expect($scope.icon).toBe("fa fa-info"); 204 | }); 205 | 206 | }); 207 | 208 | }); 209 | 210 | describe('Controller confirmDialogCtrl', function() { 211 | 212 | var $scope; 213 | var data; 214 | var $ctrlr; 215 | var $rootScope; 216 | 217 | beforeEach(function(){ 218 | inject(function($rootScope, $controller, $injector){ 219 | 220 | $ctrlr = $controller; 221 | $scope = $rootScope.$new(); 222 | $rootScope = $rootScope; 223 | 224 | spyOn($uibModalInstance, 'close'); 225 | spyOn($scope, '$destroy'); 226 | spyOn($uibModalInstance, 'dismiss'); 227 | 228 | }); 229 | }); 230 | 231 | describe('Using Default Data', function(){ 232 | beforeEach(function(){ 233 | data = {}; 234 | 235 | $ctrlr('confirmDialogCtrl', { 236 | $scope: $scope, 237 | $uibModalInstance: $uibModalInstance, 238 | $translate: $translate, 239 | data: data 240 | }); 241 | }); 242 | 243 | it('should dismiss uibModalInstance when no method executed', function(){ 244 | $scope.no(); 245 | expect($uibModalInstance.dismiss).toHaveBeenCalledWith('no'); 246 | }); 247 | 248 | it('should close uibModalInstance when yes method executed', function(){ 249 | $scope.yes(); 250 | expect($uibModalInstance.close).toHaveBeenCalledWith('yes'); 251 | }); 252 | 253 | it('should have default values for header', function(){ 254 | expect($translate.instant).toHaveBeenCalledWith('DIALOGS_CONFIRMATION'); 255 | expect($scope.header).toBe("Confirmation"); 256 | }); 257 | 258 | it('should have default values for msg', function(){ 259 | expect($translate.instant).toHaveBeenCalledWith('DIALOGS_CONFIRMATION_MSG'); 260 | expect($scope.msg).toBe("Confirmation required."); 261 | }); 262 | 263 | it('should have default values for icon', function(){ 264 | expect($scope.icon).toBe("glyphicon glyphicon-check"); 265 | }); 266 | 267 | }); 268 | 269 | describe('Using Provided Data', function(){ 270 | beforeEach(function(){ 271 | data = { 272 | header: "ThisConfirm", 273 | msg: "Some Confirm Message", 274 | fa: true 275 | }; 276 | 277 | $ctrlr('confirmDialogCtrl', { 278 | $scope: $scope, 279 | $uibModalInstance: $uibModalInstance, 280 | $translate: $translate, 281 | data: data 282 | }); 283 | }); 284 | 285 | it('should have ThisError for header', function(){ 286 | expect($scope.header).toBe("ThisConfirm"); 287 | }); 288 | 289 | it('should have Some Confirm Message for msg', function(){ 290 | expect($scope.msg).toBe("Some Confirm Message"); 291 | }); 292 | 293 | it('should have font-awesome values for icon', function(){ 294 | expect($scope.icon).toBe("fa fa-check"); 295 | }); 296 | 297 | }); 298 | 299 | }); 300 | 301 | describe('Controller waitDialogCtrl', function() { 302 | 303 | var $scope; 304 | var data; 305 | var $ctrlr; 306 | var $rootScope; 307 | 308 | beforeEach(function(){ 309 | inject(function(_$rootScope_, $controller, $injector){ 310 | 311 | $ctrlr = $controller; 312 | $scope = _$rootScope_.$new(); 313 | $rootScope = _$rootScope_; 314 | 315 | spyOn($uibModalInstance, 'close'); 316 | spyOn($scope, '$destroy'); 317 | 318 | }); 319 | }); 320 | 321 | describe('Sending Events to $scope', function(){ 322 | beforeEach(function(){ 323 | $ctrlr('waitDialogCtrl', { 324 | $scope: $scope, 325 | $uibModalInstance: $uibModalInstance, 326 | $translate: $translate, 327 | data: {} 328 | }); 329 | }); 330 | 331 | it('should get css for progress width', function(){ 332 | $scope.progress = 50; 333 | var retval = $scope.getProgress(); 334 | expect(retval).toEqual({'width': '50%'}); 335 | }); 336 | 337 | }); 338 | 339 | describe('Using Default Data', function(){ 340 | beforeEach(function(){ 341 | data = {}; 342 | 343 | $ctrlr('waitDialogCtrl', { 344 | $scope: $scope, 345 | $uibModalInstance: $uibModalInstance, 346 | $translate: $translate, 347 | data: data 348 | }); 349 | }); 350 | 351 | it('should have default values for header', function(){ 352 | expect($translate.instant).toHaveBeenCalledWith('DIALOGS_PLEASE_WAIT_ELIPS'); 353 | expect($scope.header).toBe("Please Wait..."); 354 | }); 355 | 356 | it('should have default values for msg', function(){ 357 | expect($translate.instant).toHaveBeenCalledWith('DIALOGS_PLEASE_WAIT_MSG'); 358 | expect($scope.msg).toBe("Waiting on operation to complete."); 359 | }); 360 | 361 | it('should have default values for icon', function(){ 362 | expect($scope.icon).toBe("glyphicon glyphicon-time"); 363 | }); 364 | 365 | }); 366 | 367 | describe('Using Provided Data', function(){ 368 | beforeEach(function(){ 369 | data = { 370 | header: "ThisConfirm", 371 | msg: "Some Confirm Message", 372 | fa: true 373 | }; 374 | 375 | $ctrlr('waitDialogCtrl', { 376 | $scope: $scope, 377 | $uibModalInstance: $uibModalInstance, 378 | $translate: $translate, 379 | data: data 380 | }); 381 | }); 382 | 383 | it('should have ThisError for header', function(){ 384 | expect($scope.header).toBe("ThisConfirm"); 385 | }); 386 | 387 | it('should have Some Confirm Message for msg', function(){ 388 | expect($scope.msg).toBe("Some Confirm Message"); 389 | }); 390 | 391 | it('should have font-awesome values for icon', function(){ 392 | expect($scope.icon).toBe("fa fa-clock-o"); 393 | }); 394 | 395 | }); 396 | 397 | }); 398 | 399 | 400 | }); 401 | -------------------------------------------------------------------------------- /tests/dialogs-main.tests.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/m-e-conroy/angular-dialog-service/e5425c0fbc82536ebc90c1bf43eb06eab505e1c0/tests/dialogs-main.tests.js -------------------------------------------------------------------------------- /tests/dialogs-services.tests.js: -------------------------------------------------------------------------------- 1 | describe('Module dialogs.services', function(){ 2 | 3 | var modalOptions = { 4 | templateUrl : '', 5 | controller : '', 6 | backdrop: true, 7 | backdropClass: "dialogs-backdrop-default", 8 | keyboard: true, 9 | windowClass: "dialogs-default", 10 | size: 'lg', 11 | animation: false, 12 | resolve : { 13 | data : jasmine.any(Function) 14 | } 15 | }; 16 | 17 | var modalComponentOptions = { 18 | component: 'myComponent', 19 | backdrop: true, 20 | backdropClass: "dialogs-backdrop-default", 21 | keyboard: true, 22 | windowClass: "dialogs-default", 23 | size: 'lg', 24 | animation: false, 25 | resolve : { 26 | data : jasmine.any(Function) 27 | } 28 | } 29 | 30 | describe('Provider: dialogsProvider and Service: dialogs', function(){ 31 | 32 | var provider; 33 | 34 | beforeEach(function(){ 35 | module('dialogs.services', function(dialogsProvider){ 36 | provider = dialogsProvider; 37 | }); 38 | }); 39 | 40 | it('should open modal instance with default error params', inject(function($uibModal){ 41 | spyOn($uibModal, 'open'); 42 | var service = provider.$get[1]($uibModal).error(); 43 | errorModalOptions = modalOptions; 44 | errorModalOptions.templateUrl = '/dialogs/error.html'; 45 | errorModalOptions.controller = 'errorDialogCtrl'; 46 | 47 | expect($uibModal.open).toHaveBeenCalled(); 48 | expect($uibModal.open).toHaveBeenCalledWith(errorModalOptions); 49 | })); 50 | 51 | it('should open modal instance with default wait params', inject(function($uibModal){ 52 | spyOn($uibModal, 'open'); 53 | var service = provider.$get[1]($uibModal).wait(); 54 | waitModalOptions = modalOptions; 55 | waitModalOptions.templateUrl = '/dialogs/wait.html'; 56 | waitModalOptions.controller = 'waitDialogCtrl'; 57 | 58 | expect($uibModal.open).toHaveBeenCalled(); 59 | expect($uibModal.open).toHaveBeenCalledWith(waitModalOptions); 60 | })); 61 | 62 | it('should open modal instance with default notify params', inject(function($uibModal){ 63 | spyOn($uibModal, 'open'); 64 | var service = provider.$get[1]($uibModal).notify(); 65 | notifyModalOptions = modalOptions; 66 | notifyModalOptions.templateUrl = '/dialogs/notify.html'; 67 | notifyModalOptions.controller = 'notifyDialogCtrl'; 68 | 69 | expect($uibModal.open).toHaveBeenCalled(); 70 | expect($uibModal.open).toHaveBeenCalledWith(notifyModalOptions); 71 | })); 72 | 73 | it('should open modal instance with default confirm params', inject(function($uibModal){ 74 | spyOn($uibModal, 'open'); 75 | var service = provider.$get[1]($uibModal).confirm(); 76 | confirmModalOptions = modalOptions; 77 | confirmModalOptions.templateUrl = '/dialogs/confirm.html'; 78 | confirmModalOptions.controller = 'confirmDialogCtrl'; 79 | 80 | expect($uibModal.open).toHaveBeenCalled(); 81 | expect($uibModal.open).toHaveBeenCalledWith(confirmModalOptions); 82 | })); 83 | 84 | it('should open modal instance with specifying component params', inject(function($uibModal){ 85 | spyOn($uibModal, 'open'); 86 | 87 | createModalOptions = modalComponentOptions; 88 | 89 | var service = provider.$get[1]($uibModal).createWithComponent( 90 | createModalOptions.component 91 | ); 92 | 93 | expect($uibModal.open).toHaveBeenCalled(); 94 | expect($uibModal.open).toHaveBeenCalledWith(jasmine.objectContaining(createModalOptions)); 95 | })); 96 | 97 | it('should open modal instance with using params', inject(function($uibModal){ 98 | spyOn($uibModal, 'open'); 99 | 100 | createModalOptions = modalOptions; 101 | createModalOptions.templateUrl = '/dialogs/create.html'; 102 | createModalOptions.controller = 'createDialogCtrl'; 103 | 104 | var service = provider.$get[1]($uibModal).create( 105 | createModalOptions.templateUrl, 106 | createModalOptions.controller 107 | ); 108 | 109 | expect($uibModal.open).toHaveBeenCalled(); 110 | expect($uibModal.open).toHaveBeenCalledWith(jasmine.objectContaining(createModalOptions)); 111 | })); 112 | 113 | it('should open modal with backdrop value from useBackdrop config', inject(function($uibModal){ 114 | provider.useBackdrop(false); 115 | spyOn($uibModal, 'open'); 116 | var service = provider.$get[1]($uibModal).error(); 117 | errorModalOptions = angular.copy(modalOptions); 118 | errorModalOptions.templateUrl = '/dialogs/error.html'; 119 | errorModalOptions.controller = 'errorDialogCtrl'; 120 | errorModalOptions.backdrop = false; 121 | 122 | expect($uibModal.open).toHaveBeenCalled(); 123 | expect($uibModal.open).toHaveBeenCalledWith(errorModalOptions); 124 | })); 125 | 126 | it('should open modal with keyboard value from useEscClose config', inject(function($uibModal){ 127 | provider.useEscClose(false); 128 | spyOn($uibModal, 'open'); 129 | var service = provider.$get[1]($uibModal).error(); 130 | errorModalOptions = angular.copy(modalOptions); 131 | errorModalOptions.templateUrl = '/dialogs/error.html'; 132 | errorModalOptions.controller = 'errorDialogCtrl'; 133 | errorModalOptions.keyboard = false; 134 | 135 | expect($uibModal.open).toHaveBeenCalled(); 136 | expect($uibModal.open).toHaveBeenCalledWith(errorModalOptions); 137 | })); 138 | 139 | it('should open modal with windowClass value from useClass config', inject(function($uibModal){ 140 | provider.useClass("some-class"); 141 | spyOn($uibModal, 'open'); 142 | var service = provider.$get[1]($uibModal).error(); 143 | errorModalOptions = angular.copy(modalOptions); 144 | errorModalOptions.templateUrl = '/dialogs/error.html'; 145 | errorModalOptions.controller = 'errorDialogCtrl'; 146 | errorModalOptions.windowClass = "some-class"; 147 | 148 | expect($uibModal.open).toHaveBeenCalled(); 149 | expect($uibModal.open).toHaveBeenCalledWith(errorModalOptions); 150 | })); 151 | 152 | it('should copy data when opening create dialog when useCopy is true in config', inject(function($uibModal){ 153 | provider.useCopy(true); 154 | spyOn(angular, 'copy'); 155 | 156 | createModalOptions = modalOptions; 157 | createModalOptions.templateUrl = '/dialogs/create.html'; 158 | createModalOptions.controller = 'createDialogCtrl'; 159 | 160 | var service = provider.$get[1]($uibModal).create( 161 | createModalOptions.templateUrl, 162 | createModalOptions.controller 163 | ); 164 | 165 | expect(angular.copy).toHaveBeenCalled(); 166 | })); 167 | 168 | it('should open modal with size value from setSize config', inject(function($uibModal){ 169 | provider.setSize("md"); 170 | spyOn($uibModal, 'open'); 171 | var service = provider.$get[1]($uibModal).error(); 172 | errorModalOptions = angular.copy(modalOptions); 173 | errorModalOptions.templateUrl = '/dialogs/error.html'; 174 | errorModalOptions.controller = 'errorDialogCtrl'; 175 | errorModalOptions.size = "md"; 176 | 177 | expect($uibModal.open).toHaveBeenCalled(); 178 | expect($uibModal.open).toHaveBeenCalledWith(errorModalOptions); 179 | })); 180 | 181 | it('should open modal with animation true when useAnimation config is executed', inject(function($uibModal){ 182 | provider.useAnimation(); 183 | spyOn($uibModal, 'open'); 184 | var service = provider.$get[1]($uibModal).error(); 185 | errorModalOptions = angular.copy(modalOptions); 186 | errorModalOptions.templateUrl = '/dialogs/error.html'; 187 | errorModalOptions.controller = 'errorDialogCtrl'; 188 | errorModalOptions.animation = true; 189 | 190 | expect($uibModal.open).toHaveBeenCalled(); 191 | expect($uibModal.open).toHaveBeenCalledWith(errorModalOptions); 192 | })); 193 | 194 | 195 | }); 196 | 197 | }); 198 | --------------------------------------------------------------------------------