+/**
+ * angular-dialog-service - A service to handle common dialog types in a web application. Built on top of Angular-Bootstrap's modal
+ * @version v5.3.0
+ * @author Michael Conroy, michael.e.conroy@gmail.com
+ * @license MIT, http://www.opensource.org/licenses/MIT
+ */
(function(){
"use strict";
//== Translate Substitute Module =============================================//
/**
* Error Dialog Controller
*/
-ctrlrs.controller('errorDialogCtrl',['$scope','$modalInstance','$translate','data',function($scope,$modalInstance,$translate,data){
+ctrlrs.controller('errorDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){
//-- Variables -----//
$scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_ERROR');
//-- Methods -----//
$scope.close = function(){
- $modalInstance.close();
+ $uibModalInstance.close();
$scope.$destroy();
}; // end close
}]); // end ErrorDialogCtrl
/**
* Wait Dialog Controller
*/
-ctrlrs.controller('waitDialogCtrl',['$scope','$modalInstance','$translate','$timeout','data',function($scope,$modalInstance,$translate,$timeout,data){
+ctrlrs.controller('waitDialogCtrl',['$scope','$uibModalInstance','$translate','$timeout','data',function($scope,$uibModalInstance,$translate,$timeout,data){
//-- Variables -----//
$scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_PLEASE_WAIT_ELIPS');
// close wait dialog
$scope.$on('dialogs.wait.complete',function(){
- $timeout(function(){ $modalInstance.close(); $scope.$destroy(); });
+ $timeout(function(){ $uibModalInstance.close(); $scope.$destroy(); });
}); // end on(dialogs.wait.complete)
// update the dialog's message
/**
* Notify Dialog Controller
*/
-ctrlrs.controller('notifyDialogCtrl',['$scope','$modalInstance','$translate','data',function($scope,$modalInstance,$translate,data){
+ctrlrs.controller('notifyDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){
//-- Variables -----//
$scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_NOTIFICATION');
//-- Methods -----//
$scope.close = function(){
- $modalInstance.close();
+ $uibModalInstance.close();
$scope.$destroy();
}; // end close
}]); // end WaitDialogCtrl
/**
* Confirm Dialog Controller
*/
-ctrlrs.controller('confirmDialogCtrl',['$scope','$modalInstance','$translate','data',function($scope,$modalInstance,$translate,data){
+ctrlrs.controller('confirmDialogCtrl',['$scope','$uibModalInstance','$translate','data',function($scope,$uibModalInstance,$translate,data){
//-- Variables -----//
$scope.header = (angular.isDefined(data.header)) ? data.header : $translate.instant('DIALOGS_CONFIRMATION');
//-- Methods -----//
$scope.no = function(){
- $modalInstance.dismiss('no');
+ $uibModalInstance.dismiss('no');
}; // end close
$scope.yes = function(){
- $modalInstance.close('yes');
+ $uibModalInstance.close('yes');
}; // end yes
}]); // end ConfirmDialogCtrl / dialogs.controllers
//== Services ================================================================//
var _b = true; // backdrop
var _k = true; // keyboard
var _w = 'dialogs-default'; // windowClass
+ var _bdc = 'dialogs-backdrop-default'; // backdropClass
var _copy = true; // controls use of angular.copy
var _wTmpl = null; // window template
var _wSize = 'lg'; // large modal window default
+ var _animation = false; // true/false to use animation
var _fa = false; // fontawesome flag
var _setOpts = function(opts){
var _opts = {};
opts = opts || {};
- _opts.kb = (angular.isDefined(opts.keyboard)) ? opts.keyboard : _k; // values: true,false
+ _opts.kb = (angular.isDefined(opts.keyboard)) ? !!opts.keyboard : _k; // values: true,false
_opts.bd = (angular.isDefined(opts.backdrop)) ? opts.backdrop : _b; // values: 'static',true,false
- _opts.ws = (angular.isDefined(opts.size) && (angular.equals(opts.size,'sm') || angular.equals(opts.size,'lg') || angular.equals(opts.size,'md'))) ? opts.size : _wSize; // values: 'sm', 'lg', 'md'
+ _opts.bdc = (angular.isDefined(opts.backdropClass)) ? opts.backdropClass : _bdc; // additional CSS class(es) to be added to the modal backdrop
+ _opts.ws = (angular.isDefined(opts.size) && ((opts.size === 'sm') || (opts.size === 'lg') || (opts.size === 'md'))) ? opts.size : _wSize; // values: 'sm', 'lg', 'md'
_opts.wc = (angular.isDefined(opts.windowClass)) ? opts.windowClass : _w; // additional CSS class(es) to be added to a modal window
-
+ _opts.anim = (angular.isDefined(opts.animation)) ? !!opts.animation : _animation; // values: true,false
return _opts;
}; // end _setOpts
/**
* Use Backdrop
- *
+ *
* Sets the use of the modal backdrop. Either to have one or not and
- * whether or not it responds to mouse clicks ('static' sets the
+ * whether or not it responds to mouse clicks ('static' sets the
* backdrop to true and does not respond to mouse clicks).
*
* @param val mixed (true, false, 'static')
/**
* Use ESC Close
- *
+ *
* Sets the use of the ESC (escape) key to close modal windows.
*
* @param val boolean
/**
* Use Copy
- *
+ *
* Determines the use of angular.copy when sending data to the modal controller.
*
* @param val boolean
/**
* Set Size
*
- * Sets the modal size to use (sm,lg,md), requires Angular-ui-Bootstrap 0.11.0 and Bootstrap 3.1.0 +
+ * Sets the modal size to use (sm,lg,md)
*
* @param val string (sm,lg,md)
*/
_wSize = (angular.equals(val,'sm') || angular.equals(val,'lg') || angular.equals(val,'md')) ? val : _wSize;
}; // end setSize
+ /**
+ * Use Animations
+ *
+ * Sets the use of animations to true
+ */
+ this.useAnimation = function(){
+ _animation = true;
+ }; // end useAnimation
+
/**
* Use Font-Awesome.
*
}; // end useFontAwesome
- this.$get = ['$modal',function ($modal){
-
+ this.$get = ['$uibModal',function ($uibModal){
+
return {
/**
* Error Dialog
error : function(header,msg,opts){
opts = _setOpts(opts);
- return $modal.open({
+ return $uibModal.open({
templateUrl : '/dialogs/error.html',
controller : 'errorDialogCtrl',
backdrop: opts.bd,
+ backdropClass: opts.bdc,
keyboard: opts.kb,
windowClass: opts.wc,
size: opts.ws,
+ animation: opts.anim,
resolve : {
data : function(){
return {
}
}); // end modal.open
}, // end error
-
+
/**
* Wait Dialog
*
wait : function(header,msg,progress,opts){
opts = _setOpts(opts);
- return $modal.open({
+ return $uibModal.open({
templateUrl : '/dialogs/wait.html',
controller : 'waitDialogCtrl',
backdrop: opts.bd,
+ backdropClass: opts.bdc,
keyboard: opts.kb,
windowClass: opts.wc,
size: opts.ws,
+ animation: opts.anim,
resolve : {
data : function(){
return {
}
}); // end modal.open
}, // end wait
-
+
/**
* Notify Dialog
*
notify : function(header,msg,opts){
opts = _setOpts(opts);
- return $modal.open({
+ return $uibModal.open({
templateUrl : '/dialogs/notify.html',
controller : 'notifyDialogCtrl',
backdrop: opts.bd,
+ backdropClass: opts.bdc,
keyboard: opts.kb,
windowClass: opts.wc,
size: opts.ws,
+ animation: opts.anim,
resolve : {
data : function(){
return {
}
}); // end modal.open
}, // end notify
-
+
/**
* Confirm Dialog
*
confirm : function(header,msg,opts){
opts = _setOpts(opts);
- return $modal.open({
+ return $uibModal.open({
templateUrl : '/dialogs/confirm.html',
controller : 'confirmDialogCtrl',
backdrop: opts.bd,
+ backdropClass: opts.bdc,
keyboard: opts.kb,
windowClass: opts.wc,
size: opts.ws,
+ animation: opts.anim,
resolve : {
data : function(){
return {
}
}); // end modal.open
}, // end confirm
-
+
/**
* Create Custom Dialog
*
* @param data object
* @param opts object
*/
- create : function(url,ctrlr,data,opts){
+ create : function(url,ctrlr,data,opts,ctrlAs){
var copy = (opts && angular.isDefined(opts.copy)) ? opts.copy : _copy;
opts = _setOpts(opts);
- return $modal.open({
+ return $uibModal.open({
templateUrl : url,
controller : ctrlr,
+ controllerAs : ctrlAs,
keyboard : opts.kb,
backdrop : opts.bd,
+ backdropClass: opts.bdc,
windowClass: opts.wc,
size: opts.ws,
+ animation: opts.anim,
resolve : {
- data : function() {
+ data : function() {
if(copy)
return angular.copy(data);
else
if(!_sheets[i].disabled){
// check href of style sheet first
if(_sheets[i].href !== null)
- _matches = _sheets[i].match(/font\-*awesome/i);
+ _matches = _sheets[i].href.match(/font\-*awesome/i);
if(angular.isArray(_matches)){
dialogsProvider.useFontAwesome();
// try to find css rule .fa, in case style sheet has been concatenated
_rules = _sheets[i].cssRules;
for(var x = (_rules.length - 1);x >= 0;x--){
- if(_rules[x].selectorText.toLowerCase() == '.fa'){
+ if(typeof(_rules[x].selectorText) === 'string' && _rules[x].selectorText.toLowerCase() === '.fa'){
dialogsProvider.useFontAwesome();
break sheetLoop; // done, exit both for loops
}
}
} // end if(disabled)
} // end for
-
- /* Removed in favor of above, will delete this permanently after more testing
- angular.forEach(_sheets,function(_sheet,key){
- var _matches = null;
- if(!angular.equals(_sheet.href,null))
- _matches = _sheet.href.match(/font\-*awesome/);
-
- if(!_sheet.disabled && angular.isArray(_matches)){
- // console.log('Dialogs: Using Font-Awesome Icons');
- dialogsProvider.useFontAwesome();
- }
- });
- */
}catch(err){
// console.log('Error Message: ' + err);
}
$templateCache.put('/dialogs/notify.html','<div class="modal-header dialog-header-notify"><button type="button" class="close" ng-click="close()" class="pull-right">×</button><h4 class="modal-title text-info"><span class="'+startSym+'icon'+endSym+'"></span> '+startSym+'header'+endSym+'</h4></div><div class="modal-body text-info" ng-bind-html="msg"></div><div class="modal-footer"><button type="button" class="btn btn-primary" ng-click="close()">'+startSym+'"DIALOGS_OK" | translate'+endSym+'</button></div>');
$templateCache.put('/dialogs/confirm.html','<div class="modal-header dialog-header-confirm"><button type="button" class="close" ng-click="no()">×</button><h4 class="modal-title"><span class="'+startSym+'icon'+endSym+'"></span> '+startSym+'header'+endSym+'</h4></div><div class="modal-body" ng-bind-html="msg"></div><div class="modal-footer"><button type="button" class="btn btn-default" ng-click="yes()">'+startSym+'"DIALOGS_YES" | translate'+endSym+'</button><button type="button" class="btn btn-primary" ng-click="no()">'+startSym+'"DIALOGS_NO" | translate'+endSym+'</button></div>');
}]); // end run / dialogs.main
+
})();
\ No newline at end of file