Skip to content
This repository was archived by the owner on Apr 20, 2023. It is now read-only.

Commit 78eedd8

Browse files
authored
Merge pull request #68 from ClearPoint-Strategy/master
Add support for custom bootstrap button classes
2 parents 0d356d7 + 021e3b9 commit 78eedd8

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

angular-confirm.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ angular.module('angular-confirm', ['ui.bootstrap.modal'])
4242
title: 'Confirm',
4343
ok: 'OK',
4444
cancel: 'Cancel'
45-
}
45+
},
46+
additionalTemplates: {}
4647
})
4748
.factory('$confirm', ["$uibModal", "$confirmModalDefaults", function ($uibModal, $confirmModalDefaults) {
4849
return function (data, settings) {
@@ -51,6 +52,14 @@ angular.module('angular-confirm', ['ui.bootstrap.modal'])
5152

5253
data = angular.extend({}, settings.defaultLabels, data || {});
5354

55+
if(data.templateName){
56+
var customTemplateDefinition = settings.additionalTemplates[data.templateName];
57+
if(customTemplateDefinition != undefined) {
58+
settings.template = customTemplateDefinition.template;
59+
settings.templateUrl = customTemplateDefinition.templateUrl;
60+
}
61+
}
62+
5463
if ('templateUrl' in settings && 'template' in settings) {
5564
delete settings.template;
5665
}
@@ -73,6 +82,7 @@ angular.module('angular-confirm', ['ui.bootstrap.modal'])
7382
ngClick: '&',
7483
confirm: '@',
7584
confirmSettings: "=",
85+
confirmTemplateName: "@",
7686
confirmTitle: '@',
7787
confirmOk: '@',
7888
confirmCancel: '@'
@@ -110,6 +120,9 @@ angular.module('angular-confirm', ['ui.bootstrap.modal'])
110120
if (scope.confirmCancel) {
111121
data.cancel = scope.confirmCancel;
112122
}
123+
if (scope.confirmTemplateName){
124+
data.templateName = scope.confirmTemplateName;
125+
}
113126
$confirm(data, scope.confirmSettings || {}).then(onSuccess);
114127
} else {
115128
scope.$apply(onSuccess);

angular-confirm.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/unit/confirmSpec.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,31 @@ describe('angular-confirm', function() {
9696
expect(settings.template).not.toBeDefined();
9797
});
9898

99+
it("should use default template", function(){
100+
var settings = $confirm({}, {});
101+
expect(settings.templateUrl).toEqual($confirmModalDefaults.templateUrl)
102+
});
103+
104+
it("should use override template", function(){
105+
var settings = $confirm({}, {templateUrl: 'something'});
106+
expect(settings.templateUrl).not.toEqual($confirmModalDefaults.templateUrl)
107+
expect(settings.templateUrl).toEqual('something');
108+
});
109+
110+
it("should use custom template if found", function(){
111+
$confirmModalDefaults.additionalTemplates.danger = {templateUrl: "something"}
112+
var settings = $confirm({templateName: 'random'}, {});
113+
expect(settings.templateUrl).toEqual($confirmModalDefaults.templateUrl);
114+
115+
settings = $confirm({templateName: 'danger'}, {});
116+
expect(settings.templateUrl).not.toEqual($confirmModalDefaults.templateUrl);
117+
expect(settings.templateUrl).toEqual('something');
118+
119+
settings = $confirm({templateName: 'danger'}, {templateUrl: 'thiswillbeignored'});
120+
expect(settings.templateUrl).not.toEqual($confirmModalDefaults.templateUrl);
121+
expect(settings.templateUrl).toEqual('something');
122+
})
123+
99124
});
100125

101126
describe('confirm directive', function() {
@@ -249,6 +274,20 @@ describe('angular-confirm', function() {
249274
});
250275
});
251276

277+
describe('with confirmTemplateName option', function() {
278+
beforeEach(angular.mock.inject(function($compile) {
279+
element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-template-name="danger">Delete</button>');
280+
$compile(element)($scope);
281+
$scope.$digest();
282+
}));
283+
284+
it("should use custom template", function() {
285+
element.triggerHandler('click');
286+
$timeout.flush();
287+
expect($confirm).toHaveBeenCalledWith({text: "Are you sure?", templateName: "danger"}, {})
288+
});
289+
});
290+
252291

253292
describe('with checkbox', function() {
254293

0 commit comments

Comments
 (0)