1 (function(angular
, $, _
) {
4 angular
.module('search').controller('crmSearchActionUpdate', function ($scope
, $timeout
, crmApi4
, dialogService
, searchMeta
) {
5 var ts
= $scope
.ts
= CRM
.ts(),
7 ctrl
= $scope
.$ctrl
= this;
9 this.entity
= searchMeta
.getEntity(model
.entity
);
13 function fieldInUse(fieldName
) {
14 return _
.includes(_
.collect(ctrl
.values
, 0), fieldName
);
17 this.updateField = function(index
) {
18 // Debounce the onchange event using timeout
20 if (!ctrl
.values
[index
][0]) {
21 ctrl
.values
.splice(index
, 1);
26 this.addField = function() {
27 // Debounce the onchange event using timeout
30 ctrl
.values
.push([ctrl
.add
, '']);
36 this.availableFields = function() {
37 var results
= _
.transform(ctrl
.entity
.fields
, function(result
, item
) {
38 var formatted
= {id
: item
.name
, text
: item
.title
, description
: item
.description
};
39 if (fieldInUse(item
.name
)) {
40 formatted
.disabled
= true;
42 if (item
.name
!== 'id') {
43 result
.push(formatted
);
46 return {results
: results
};
49 this.cancel = function() {
50 dialogService
.cancel('crmSearchAction');
53 this.save = function() {
54 crmApi4(model
.entity
, 'Update', {
55 where
: [['id', 'IN', model
.ids
]],
56 values
: _
.zipObject(ctrl
.values
)
58 dialogService
.close('crmSearchAction');
63 })(angular
, CRM
.$, CRM
._
);