(function(angular, $, _) {
"use strict";
- angular.module('search').component('crmSearchActions', {
+ angular.module('searchActions').component('crmSearchActions', {
bindings: {
entity: '<',
refresh: '&',
ids: '<'
},
- templateUrl: '~/search/crmSearchActions.html',
+ templateUrl: '~/searchActions/crmSearchActions.html',
controller: function($scope, crmApi4, dialogService, searchMeta) {
var ts = $scope.ts = CRM.ts(),
- ctrl = this;
+ ctrl = this,
+ initialized = false,
+ unwatchIDs = $scope.$watch('$ctrl.ids.length', watchIDs);
- this.$onInit = function() {
+ function watchIDs() {
+ if (ctrl.ids && ctrl.ids.length && !initialized) {
+ unwatchIDs();
+ initialized = true;
+ initialize();
+ }
+ }
+
+ function initialize() {
var entityTitle = searchMeta.getEntity(ctrl.entity).titlePlural;
- if (!ctrl.actions) {
- var actions = _.transform(_.cloneDeep(CRM.vars.search.actions), function (actions, action) {
+ crmApi4(ctrl.entity, 'getActions', {
+ where: [['name', 'IN', ['update', 'delete']]],
+ }, ['name']).then(function(allowed) {
+ _.each(allowed, function(action) {
+ CRM.searchActions.tasks[action].entities.push(ctrl.entity);
+ });
+ var actions = _.transform(_.cloneDeep(CRM.searchActions.tasks), function(actions, action) {
if (_.includes(action.entities, ctrl.entity)) {
action.title = action.title.replace('%1', entityTitle);
actions.push(action);
}
}, []);
ctrl.actions = _.sortBy(actions, 'title');
- }
- };
+ });
+ }
this.isActionAllowed = function(action) {
return !action.number || $scope.eval('' + $ctrl.ids.length + action.number);