forked from eriktufvesson/ngBootbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathngBootbox.js
More file actions
116 lines (115 loc) · 3.75 KB
/
ngBootbox.js
File metadata and controls
116 lines (115 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
angular.module('ngBootbox', function() {
})
.directive('ngBootboxAlert', function($ngBootbox) {
return {
restrict: 'A',
scope: false,
link: function (scope, element, attr) {
var msg = attr.ngBootboxAlert || "Yo!";
element.bind('click', function () {
bootbox.alert(msg);
});
}
};
})
.directive('ngBootboxConfirm', function() {
return {
restrict: 'A',
scope: {
actionOK: '&ngBootboxConfirmAction',
actionCancel: '&ngBootboxConfirmActionCancel'
},
link: function (scope, element, attr) {
var msg = attr.ngBootboxConfirm || "Are you sure?";
element.bind('click', function () {
bootbox.confirm(msg, function (result) {
if (result) {
scope.actionOK();
}
else {
scope.actionCancel();
}
});
});
}
};
})
.directive('ngBootboxPrompt', function() {
return {
restrict: 'A',
scope: {
actionOK: '&ngBootboxPromptAction',
actionCancel: '&ngBootboxPromptActionCancel'
},
link: function (scope, element, attr) {
var msg = attr.ngBootboxPrompt || "Are you sure?";
element.bind('click', function () {
bootbox.prompt(msg, function (result) {
if (result !== null) {
scope.actionOK({result: result});
}
else {
scope.actionCancel();
}
});
});
}
};
})
.directive('ngBootboxCustomDialog', function() {
return {
restrict: 'A',
scope: {
actionSuccess: '&ngBootboxActionSuccess',
actionDanger: '&ngBootboxActionDanger',
actionMain: '&ngBootboxActionMain',
title: '@ngBootboxTitle',
buttons: '=ngBootboxButtons'
},
link: function (scope, element, attr) {
var msg = attr.ngBootboxCustomDialog;
element.bind('click', function () {
bootbox.dialog({
message: msg,
title: scope.title,
buttons: scope.buttons
});
});
}
};
})
.factory('$ngBootbox', function($q) {
return {
alert: function(msg) {
var deferred = $q.defer();
bootbox.alert(msg, function() {
deferred.resolve();
});
return deferred.promise;
},
confirm: function(msg) {
var deferred = $q.defer();
bootbox.confirm(msg, function(result) {
if (result) {
deferred.resolve();
}
else {
deferred.reject();
}
});
return deferred.promise;
},
prompt: function(msg) {
var deferred = $q.defer();
bootbox.prompt(msg, function(result) {
if (result !== null) {
deferred.resolve(result);
}
else {
deferred.reject();
}
});
return deferred.promise;
}
};
});