1 (function(angular
, $, _
) {
4 angular
.module('searchActions').component('crmSearchActions', {
10 templateUrl
: '~/searchActions/crmSearchActions.html',
11 controller: function($scope
, crmApi4
, dialogService
, searchMeta
) {
12 var ts
= $scope
.ts
= CRM
.ts(),
15 unwatchIDs
= $scope
.$watch('$ctrl.ids.length', watchIDs
);
18 if (ctrl
.ids
&& ctrl
.ids
.length
&& !initialized
) {
25 function initialize() {
26 var entityTitle
= searchMeta
.getEntity(ctrl
.entity
).title_plural
;
27 crmApi4(ctrl
.entity
, 'getActions', {
28 where
: [['name', 'IN', ['update', 'delete']]],
29 }, ['name']).then(function(allowed
) {
30 _
.each(allowed
, function(action
) {
31 CRM
.searchActions
.tasks
[action
].entities
.push(ctrl
.entity
);
33 var actions
= _
.transform(_
.cloneDeep(CRM
.searchActions
.tasks
), function(actions
, action
) {
34 if (_
.includes(action
.entities
, ctrl
.entity
)) {
35 action
.title
= action
.title
.replace('%1', entityTitle
);
39 ctrl
.actions
= _
.sortBy(actions
, 'title');
43 this.isActionAllowed = function(action
) {
44 return !action
.number
|| $scope
.eval('' + $ctrl
.ids
.length
+ action
.number
);
47 this.doAction = function(action
) {
48 if (!ctrl
.isActionAllowed(action
) || !ctrl
.ids
.length
) {
55 // If action uses a crmPopup form
56 if (action
.crmPopup
) {
57 var path
= $scope
.$eval(action
.crmPopup
.path
, data
),
58 query
= action
.crmPopup
.query
&& $scope
.$eval(action
.crmPopup
.query
, data
);
59 CRM
.loadForm(CRM
.url(path
, query
))
60 .on('crmFormSuccess', ctrl
.refresh
);
62 // If action uses dialogService
63 else if (action
.uiDialog
) {
64 var options
= CRM
.utils
.adjustDialogDefaults({
68 dialogService
.open('crmSearchAction', action
.uiDialog
.templateUrl
, data
, options
)
75 })(angular
, CRM
.$, CRM
._
);