1 (function(angular
, $, _
) {
4 angular
.module('crmSearchActions').controller('crmSearchActionUpdate', function ($scope
, $timeout
, crmApi4
, dialogService
) {
5 var ts
= $scope
.ts
= CRM
.ts(),
7 ctrl
= $scope
.$ctrl
= this;
9 this.entityTitle
= model
.ids
.length
=== 1 ? model
.entityInfo
.title
: model
.entityInfo
.title_plural
;
14 crmApi4(model
.entity
, 'getFields', {action
: 'update', loadOptions
: ['id', 'name', 'label', 'description', 'color', 'icon']})
15 .then(function(fields
) {
19 this.updateField = function(index
) {
20 // Debounce the onchange event using timeout
22 if (!ctrl
.values
[index
][0]) {
23 ctrl
.values
.splice(index
, 1);
28 this.addField = function() {
29 // Debounce the onchange event using timeout
32 ctrl
.values
.push([ctrl
.add
, '']);
38 this.getField = function(fieldName
) {
39 return _
.where(ctrl
.fields
, {name
: fieldName
})[0];
42 function fieldInUse(fieldName
) {
43 return _
.includes(_
.collect(ctrl
.values
, 0), fieldName
);
46 this.availableFields = function() {
47 var results
= _
.transform(ctrl
.fields
, function(result
, item
) {
48 var formatted
= {id
: item
.name
, text
: item
.label
, description
: item
.description
};
49 if (fieldInUse(item
.name
)) {
50 formatted
.disabled
= true;
52 if (item
.name
!== 'id') {
53 result
.push(formatted
);
56 return {results
: results
};
59 this.cancel = function() {
60 dialogService
.cancel('crmSearchAction');
63 this.save = function() {
64 crmApi4(model
.entity
, 'Update', {
65 where
: [['id', 'IN', model
.ids
]],
66 values
: _
.zipObject(ctrl
.values
)
68 dialogService
.close('crmSearchAction');
73 })(angular
, CRM
.$, CRM
._
);