1 (function(angular
, $, _
) {
4 angular
.module('crmSearchActions').component('crmSearchActions', {
10 templateUrl
: '~/crmSearchActions/crmSearchActions.html',
11 controller: function($scope
, crmApi4
, dialogService
) {
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() {
27 entityInfo
: ['Entity', 'get', {select
: ['name', 'title', 'title_plural'], where
: [['name', '=', ctrl
.entity
]]}, 0],
28 allowed
: [ctrl
.entity
, 'getActions', {where
: [['name', 'IN', ['update', 'delete']]]}, ['name']]
29 }).then(function(result
) {
30 ctrl
.entityInfo
= result
.entityInfo
;
31 _
.each(result
.allowed
, function(action
) {
32 CRM
.crmSearchActions
.tasks
[action
].entities
.push(ctrl
.entity
);
34 var actions
= _
.transform(_
.cloneDeep(CRM
.crmSearchActions
.tasks
), function(actions
, action
) {
35 if (_
.includes(action
.entities
, ctrl
.entity
)) {
36 action
.title
= action
.title
.replace('%1', ctrl
.entityInfo
.title_plural
);
40 ctrl
.actions
= _
.sortBy(actions
, 'title');
44 this.isActionAllowed = function(action
) {
45 return !action
.number
|| $scope
.eval('' + $ctrl
.ids
.length
+ action
.number
);
48 this.doAction = function(action
) {
49 if (!ctrl
.isActionAllowed(action
) || !ctrl
.ids
.length
) {
55 entityInfo
: ctrl
.entityInfo
57 // If action uses a crmPopup form
58 if (action
.crmPopup
) {
59 var path
= $scope
.$eval(action
.crmPopup
.path
, data
),
60 query
= action
.crmPopup
.query
&& $scope
.$eval(action
.crmPopup
.query
, data
);
61 CRM
.loadForm(CRM
.url(path
, query
))
62 .on('crmFormSuccess', ctrl
.refresh
);
64 // If action uses dialogService
65 else if (action
.uiDialog
) {
66 var options
= CRM
.utils
.adjustDialogDefaults({
70 dialogService
.open('crmSearchAction', action
.uiDialog
.templateUrl
, data
, options
)
77 })(angular
, CRM
.$, CRM
._
);