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() {
48 dialogService
.cancel($dialog
.name
);
51 $dialog
.loadButtons = function() {
53 angular
.forEach($dialog
.buttons
, function (crmDialogButton
) {
54 var button
= _
.pick(crmDialogButton
, ['icons', 'text', 'disabled']);
55 button
.click = function() {
56 $scope
.$apply(crmDialogButton
.onClick
);
60 dialogService
.setButtons($dialog
.name
, buttons
);
64 $('.ui-dialog:last input:not([disabled]):not([type="submit"]):first').focus();
68 link: function(scope
, element
, attrs
, controller
) {
69 controller
.name
= attrs
.crmDialog
;
70 scope
[attrs
.crmDialog
] = controller
;
75 // Ex: <crm-dialog-button text="ts('Do it')" icons="{primary: 'fa-foo'}" on-click="doIt()" />
76 angular
.module('crmDialog').component('crmDialogButton', {
84 crmDialog
: '?^^crmDialog'
86 controller: function($scope
) {
88 $ctrl
.$onInit = function() {
89 $ctrl
.crmDialog
.buttons
.push(this);
90 $scope
.$watch('$ctrl.disabled', $ctrl
.crmDialog
.loadButtons
);
91 $scope
.$watch('$ctrl.text', $ctrl
.crmDialog
.loadButtons
);
92 $scope
.$watch('$ctrl.icons', $ctrl
.crmDialog
.loadButtons
);
97 })(angular
, CRM
.$, CRM
._
);