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

Commit e9788f8

Browse files
author
James Kleeh
committed
Added ability to pass settings from directive
1 parent 3ff07c9 commit e9788f8

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

angular-confirm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ angular.module('angular-confirm', ['ui.bootstrap'])
5454
confirmIf: "=",
5555
ngClick: '&',
5656
confirm: '@',
57+
confirmSettings: "=",
5758
confirmTitle: '@',
5859
confirmOk: '@',
5960
confirmCancel: '@'
@@ -78,7 +79,7 @@ angular.module('angular-confirm', ['ui.bootstrap'])
7879
if (scope.confirmCancel) {
7980
data.cancel = scope.confirmCancel;
8081
}
81-
$confirm(data).then(scope.ngClick);
82+
$confirm(data, scope.confirmSettings || {}).then(scope.ngClick);
8283
}
8384

8485
if (attrs.confirmIf && attrs.confirmIf != "") {

test/unit/confirmSpec.js

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,40 +163,71 @@ describe('angular-confirm', function() {
163163

164164
describe('with confirmTitle option', function() {
165165
beforeEach(angular.mock.inject(function($compile) {
166-
element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-title="Hello!">Delete</button>');
166+
$scope.name = 'Joe';
167+
element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-title="Hello, {{name}}!">Delete</button>');
167168
$compile(element)($scope);
168169
$scope.$digest();
169170
}));
170171

171172
it("should resolve the confirmTitle to the title property", function() {
172173
element.triggerHandler('click');
173-
expect(data.title).toEqual('Hello!');
174+
expect(data.title).toEqual('Hello, Joe!');
174175
});
176+
175177
});
176178

177179
describe('with confirmOk option', function() {
178180
beforeEach(angular.mock.inject(function($compile) {
179-
element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-ok="Okie Dokie!">Delete</button>');
181+
$scope.name = 'Joe';
182+
element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-ok="Okie Dokie, {{name}}!">Delete</button>');
180183
$compile(element)($scope);
181184
$scope.$digest();
182185
}));
183186

184187
it("should resolve the confirmTitle to the title property", function() {
185188
element.triggerHandler('click');
186-
expect(data.ok).toEqual('Okie Dokie!');
189+
expect(data.ok).toEqual('Okie Dokie, Joe!');
187190
});
188191
});
189192

190193
describe('with confirmCancel option', function() {
191194
beforeEach(angular.mock.inject(function($compile) {
192-
element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-cancel="No Way!">Delete</button>');
195+
$scope.name = 'Joe';
196+
element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-cancel="No Way, {{name}}!">Delete</button>');
193197
$compile(element)($scope);
194198
$scope.$digest();
195199
}));
196200

197201
it("should resolve the confirmTitle to the title property", function() {
198202
element.triggerHandler('click');
199-
expect(data.cancel).toEqual('No Way!');
203+
expect(data.cancel).toEqual('No Way, Joe!');
204+
});
205+
});
206+
207+
describe('with confirmSettings option', function() {
208+
beforeEach(angular.mock.inject(function($compile) {
209+
$scope.settings = {name: 'Joe'};
210+
element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-settings="settings">Delete</button>');
211+
$compile(element)($scope);
212+
$scope.$digest();
213+
}));
214+
215+
it("should pass the settings to $confirm", function() {
216+
element.triggerHandler('click');
217+
expect($confirm).toHaveBeenCalledWith({text: "Are you sure?"}, $scope.settings)
218+
});
219+
});
220+
221+
describe('with confirmSettings option direct entry', function() {
222+
beforeEach(angular.mock.inject(function($compile) {
223+
element = angular.element('<button type="button" ng-click="click()" confirm="Are you sure?" confirm-settings="{name: \'Joe\'}">Delete</button>');
224+
$compile(element)($scope);
225+
$scope.$digest();
226+
}));
227+
228+
it("should pass the settings to $confirm", function() {
229+
element.triggerHandler('click');
230+
expect($confirm).toHaveBeenCalledWith({text: "Are you sure?"}, {name: "Joe"})
200231
});
201232
});
202233

0 commit comments

Comments
 (0)