1 (function(angular
, $, _
) {
4 angular
.module('crmDialog', CRM
.angRequires('crmDialog'));
6 // Convenience binding to automatically launch a dialog when clicking an element
7 // Ex: <button type="button" crm-dialog-popup="myDialogName" popup-tpl="~/myExt/MyDialogTpl.html" popup-data="{foo: bar}"
8 angular
.module('crmDialog').directive('crmDialogPopup', function(dialogService
) {
13 popupName
: '@crmDialogPopup',
16 controller: function($scope
, $element
) {
18 $element
.on('click', function() {
19 var options
= CRM
.utils
.adjustDialogDefaults({
21 title
: _
.trim($element
.attr('title') || $element
.text())
23 dialogService
.open(ctrl
.popupName
, ctrl
.popupTpl
, ctrl
.popupData
|| {}, options
)
24 .then(function(success
) {
25 $element
.trigger('crmPopupFormSuccess');
32 // Ex: <div crm-dialog="myDialogName"> ... <button ng-click="$dialog.cancel()">Cancel</button> ... </div>
33 // Ex: <div crm-dialog="myDialogName"> ... <button ng-click="$dialog.close(outputData)">Close</button> ... </div>
34 // Ex: <div crm-dialog="myDialogName"> ... <crm-dialog-button text="'Close'" on-click="$dialog.close()" /> ... </div>
35 angular
.module('crmDialog').directive('crmDialog', function(dialogService
) {
38 controllerAs
: '$dialog',
39 controller: function($scope
, $parse
, $timeout
) {
43 $dialog
.close = function (result
) {
44 dialogService
.close($dialog
.name
, result
);
47 $dialog
.cancel = function (result
) {
48 dialogService
.cancel($dialog
.name
);
51 $dialog
.loadButtons = function() {
53 angular
.forEach($dialog
.buttons
, function (crmDialogButton
) {
54 var button
= _
.pick(crmDialogButton
, ['id', 'icons', 'text']);
55 button
.click = function () {
56 crmDialogButton
.onClick();
60 dialogService
.setButtons($dialog
.name
, buttons
);
61 $dialog
.toggleButtons();
64 $dialog
.toggleButtons = function() {
65 angular
.forEach($dialog
.buttons
, function (crmDialogButton
) {
66 $('#' + crmDialogButton
.id
).prop('disabled', crmDialogButton
.disabled
);
71 $dialog
.loadButtons();
72 $('.ui-dialog:last input:not([disabled]):not([type="submit"]):first').focus();
76 link: function(scope
, element
, attrs
, controller
) {
77 controller
.name
= attrs
.crmDialog
;
78 scope
[attrs
.crmDialog
] = controller
;
85 // Ex: <crm-dialog-button text="ts('Do it')" icons="{primary: 'fa-foo'}" on-click="doIt()" />
86 angular
.module('crmDialog').component('crmDialogButton', {
94 crmDialog
: '?^^crmDialog'
96 controller: function($scope
) {
98 $ctrl
.$onInit = function() {
99 $ctrl
.crmDialog
.buttons
.push(this);
101 $ctrl
.id
= 'crmDialogButton_' + (idNum
++);
103 $scope
.$watch('$ctrl.disabled', function() {
104 $ctrl
.crmDialog
.toggleButtons();
109 })(angular
, CRM
.$, CRM
._
);