1 (function(angular
, $, _
) {
4 angular
.module('crmSearchActions').component('crmSearchInput', {
11 require
: {ngModel
: 'ngModel'},
12 templateUrl
: '~/crmSearchActions/crmSearchInput/crmSearchInput.html',
13 controller: function($scope
) {
14 var ts
= $scope
.ts
= CRM
.ts(),
17 this.isMulti = function() {
18 // If there's a search operator, return `true` if the operator takes multiple values, else `false`
20 return ctrl
.op
=== 'IN' || ctrl
.op
=== 'NOT IN';
22 // If no search operator this is an input for e.g. the bulk update action
23 // Return `true` if the field is multi-valued, else `null`
24 return ctrl
.field
.serialize
|| ctrl
.field
.data_type
=== 'Array' ? true : null;
27 this.$onInit = function() {
29 $scope
.$watch('$ctrl.value', function() {
30 ctrl
.ngModel
.$setViewValue(ctrl
.value
);
33 // For the ON clause, string values must be quoted
34 ctrl
.ngModel
.$parsers
.push(function(viewValue
) {
35 return ctrl
.format
=== 'json' && _
.isString(viewValue
) && viewValue
.length
? JSON
.stringify(viewValue
) : viewValue
;
38 // For the ON clause, unquote string values
39 ctrl
.ngModel
.$formatters
.push(function(value
) {
40 return ctrl
.format
=== 'json' && _
.isString(value
) && value
.length
? JSON
.parse(value
) : value
;
43 this.ngModel
.$render = function() {
44 ctrl
.value
= ctrl
.ngModel
.$viewValue
;
51 })(angular
, CRM
.$, CRM
._
);