1 (function(angular
, $, _
) {
4 angular
.module('crmDialog', CRM
.angRequires('crmDialog'));
6 // Ex: <div crm-dialog="myDialogName"> ... <button ng-click="$dialog.cancel()">Cancel</button> ... </div>
7 // Ex: <div crm-dialog="myDialogName"> ... <button ng-click="$dialog.close(outputData)">Close</button> ... </div>
8 // Ex: <div crm-dialog="myDialogName"> ... <crm-dialog-button text="'Close'" on-click="$dialog.close()" /> ... </div>
9 angular
.module('crmDialog').directive('crmDialog', function(dialogService
) {
12 controllerAs
: '$dialog',
13 controller: function($scope
, $parse
, $timeout
) {
17 $dialog
.close = function (result
) {
18 dialogService
.close($dialog
.name
, result
);
21 $dialog
.cancel = function (result
) {
22 dialogService
.cancel($dialog
.name
);
25 $dialog
.loadButtons = function() {
27 angular
.forEach($dialog
.buttons
, function (crmDialogButton
) {
28 var button
= _
.pick(crmDialogButton
, ['id', 'icons', 'text']);
29 button
.click = function () {
30 crmDialogButton
.onClick();
34 dialogService
.setButtons($dialog
.name
, buttons
);
35 $dialog
.toggleButtons();
38 $dialog
.toggleButtons = function() {
39 angular
.forEach($dialog
.buttons
, function (crmDialogButton
) {
40 $('#' + crmDialogButton
.id
).prop('disabled', crmDialogButton
.disabled
);
45 $dialog
.loadButtons();
46 $('.ui-dialog:last input:not([disabled]):not([type="submit"]):first').focus();
50 link: function(scope
, element
, attrs
, controller
) {
51 controller
.name
= attrs
.crmDialog
;
52 scope
[attrs
.crmDialog
] = controller
;
59 // Ex: <crm-dialog-button text="ts('Do it')" icons="{primary: 'fa-foo'}" on-click="doIt()" />
60 angular
.module('crmDialog').component('crmDialogButton', {
68 crmDialog
: '?^^crmDialog'
70 controller: function($scope
, $element
, dialogService
, $timeout
) {
71 var ts
= $scope
.ts
= CRM
.ts('crmDialog'), $ctrl
= this;
72 $ctrl
.$onInit = function() {
73 $ctrl
.crmDialog
.buttons
.push(this);
75 $ctrl
.id
= 'crmDialogButton_' + (idNum
++);
77 $scope
.$watch('$ctrl.disabled', function(){
78 $ctrl
.crmDialog
.toggleButtons();
83 })(angular
, CRM
.$, CRM
._
);