Created
July 22, 2014 10:45
-
-
Save aregee/54840bbf1ffdc9c3f276 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('ngApp') | |
.service('modalService', ['$modal', | |
function ($modal) { | |
// Default options for Modal window Options | |
var modalOptions = { | |
closeButtonText: 'Close', | |
actionButtonText: 'OK', | |
headerText: 'Proceed?', | |
bodyText: 'Perform this action?', | |
value: {}, | |
}; | |
// Default parameters required for the Modal Window | |
var modalDefaults = { | |
backdrop: true, | |
keyboard: true, | |
modalFade: true, | |
templateUrl: 'views/modal_template.html', | |
controller: null, | |
}; | |
this.showModal = function (customModalDefaults, customModalOptions) { | |
if(!customModalDefaults) { | |
customModalDefaults = {}; | |
} | |
customModalDefaults.backdrop = 'static'; | |
return this.show(customModalDefaults, customModalOptions); | |
}; | |
this.show = function (customModalDefaults, customModalOptions) { | |
//Create temp objects to work with since we're in a singleton service | |
var tempModalDefaults = {}; | |
var tempModalOptions = {}; | |
//Map angular-ui modal custom defaults to modal defaults defined in service | |
angular.extend(tempModalDefaults, modalDefaults, customModalDefaults); | |
//Map modal.html $scope custom properties to defaults defined in service | |
angular.extend(tempModalOptions, modalOptions, customModalOptions); | |
if(!tempModalDefaults.controller) { | |
tempModalDefaults.controller = function ($scope, $modalInstance) { | |
$scope.modalOptions = tempModalOptions; | |
$scope.modalOptions.ok = function () { | |
$modalInstance.close('ok'); | |
}; | |
$scope.modalOptions.close = function () { | |
$modalInstance.dismiss('cancel'); | |
}; | |
}; | |
} | |
return $modal.open(tempModalDefaults).result; | |
}; | |
} | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment