/
shared.dialog.directive.js
80 lines (68 loc) · 2.81 KB
/
shared.dialog.directive.js
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
(function () {
'use strict';
function WavesDialogController($scope, dialogService) {
var defaults = {
isError: false,
cancelButtonVisible: true,
closeable: true,
showButtons: true,
okButtonCaption: 'OK',
okButtonEnabled: true,
cancelButtonCaption: 'CANCEL'
};
_.defaults($scope, defaults);
var imageSuffix = $scope.isError ? '-danger' : '';
$scope.image = 'modal-header' + imageSuffix;
if (!$scope.closeable)
$scope.image = 'modal-header-round';
$scope.image += '.svg';
$scope.onOk = function () {
var shouldClose;
if ($scope.dialogOk)
shouldClose = $scope.dialogOk();
if (angular.isUndefined(shouldClose) || shouldClose !== false)
dialogService.close();
};
$scope.onCancel = function () {
if ($scope.dialogCancel)
$scope.dialogCancel();
dialogService.close();
};
}
function WavesDialogLink(scope, element, attrs, controller) {
element.addClass('wavesPop');
}
angular
.module('app.shared')
.directive('wavesDialog', function WavesDialogDirective() {
return {
restrict: 'A',
controller: ['$scope', 'dialogService', WavesDialogController],
transclude: true,
scope: {
closeable: '=?',
cancelButtonVisible: '=?',
showButtons: '=?',
tooltip: '=?',
dialogOk: '&onDialogOk',
dialogCancel: '&onDialogCancel',
okButtonCaption: '@',
okButtonEnabled: '=?',
cancelButtonCaption: '@',
isError: '=?'
},
link: WavesDialogLink,
template: '<img class="wPop-header" ng-src="img/{{image}}" />' +
'<div class="wavesPop-content" ng-transclude></div>' +
'<div class="wPop-content-buttons" ng-show="showButtons">' +
'<button class="wButton fade tooltip-1" ng-class="[{wButtonDanger: isError}]" ' +
'title="{{::tooltip}}" ng-click="onOk()" ng-disabled="!okButtonEnabled">' +
'{{::okButtonCaption}}</button>' +
'<span class="divider-2" ng-if="cancelButtonVisible"></span>' +
'<button ng-if="cancelButtonVisible" class="wButton fade" ' +
'ng-class="[{wButtonDanger: isError}]" ng-click="onCancel()">{{::cancelButtonCaption}}' +
'</button>' +
'</div>'
};
});
})();