1 (function(angular
, $, _
) {
4 angular
.module('searchActions').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
);
10 this.entityTitle
= model
.ids
.length
=== 1 ? this.entity
.title
: this.entity
.titlePlural
;
14 function fieldInUse(fieldName
) {
15 return _
.includes(_
.collect(ctrl
.values
, 0), fieldName
);
18 this.updateField = function(index
) {
19 // Debounce the onchange event using timeout
21 if (!ctrl
.values
[index
][0]) {
22 ctrl
.values
.splice(index
, 1);
27 this.addField = function() {
28 // Debounce the onchange event using timeout
31 ctrl
.values
.push([ctrl
.add
, '']);
37 this.availableFields = function() {
38 var results
= _
.transform(ctrl
.entity
.fields
, function(result
, item
) {
39 var formatted
= {id
: item
.name
, text
: item
.label
, description
: item
.description
};
40 if (fieldInUse(item
.name
)) {
41 formatted
.disabled
= true;
43 if (item
.name
!== 'id') {
44 result
.push(formatted
);
47 return {results
: results
};
50 this.cancel = function() {
51 dialogService
.cancel('crmSearchAction');
54 this.save = function() {
55 crmApi4(model
.entity
, 'Update', {
56 where
: [['id', 'IN', model
.ids
]],
57 values
: _
.zipObject(ctrl
.values
)
59 dialogService
.close('crmSearchAction');
64 })(angular
, CRM
.$, CRM
._
);