1 (function(angular
, $, _
) {
4 angular
.module('crmSearchTasks').component('crmSearchInputVal', {
10 require
: {ngModel
: 'ngModel'},
11 template
: '<div class="form-group" ng-include="$ctrl.getTemplate()"></div>',
12 controller: function($scope
, formatForSelect2
) {
13 var ts
= $scope
.ts
= CRM
.ts('org.civicrm.search_kit'),
16 this.$onInit = function() {
18 ctrl
.dateRanges
= CRM
.crmSearchTasks
.dateRanges
;
19 ctrl
.entity
= ctrl
.field
.fk_entity
|| ctrl
.field
.entity
;
21 this.ngModel
.$render = function() {
22 ctrl
.value
= ctrl
.ngModel
.$viewValue
;
23 if (!rendered
&& ctrl
.field
.input_type
=== 'Date') {
29 $scope
.$watch('$ctrl.value', function() {
30 ctrl
.ngModel
.$setViewValue(ctrl
.value
);
33 function setDateType() {
34 if (_
.findWhere(ctrl
.dateRanges
, {id
: ctrl
.value
})) {
35 ctrl
.dateType
= 'range';
36 } else if (ctrl
.value
=== 'now') {
37 ctrl
.dateType
= 'now';
38 } else if (_
.includes(ctrl
.value
, 'now -')) {
39 ctrl
.dateType
= 'now -';
40 } else if (_
.includes(ctrl
.value
, 'now +')) {
41 ctrl
.dateType
= 'now +';
43 ctrl
.dateType
= 'fixed';
48 this.changeDateType = function() {
49 switch (ctrl
.dateType
) {
55 ctrl
.value
= ctrl
.dateRanges
[0].id
;
63 ctrl
.value
= ctrl
.dateType
+ ' 1 day';
67 this.dateUnits = function(setUnit
) {
68 var vals
= ctrl
.value
.split(' ');
69 if (arguments
.length
) {
71 ctrl
.value
= vals
.join(' ');
77 this.dateNumber = function(setNumber
) {
78 var vals
= ctrl
.value
.split(' ');
79 if (arguments
.length
) {
81 ctrl
.value
= vals
.join(' ');
83 return parseInt(vals
[2], 10);
87 this.getTemplate = function() {
88 var field
= ctrl
.field
|| {};
90 if (field
.input_type
=== 'Date') {
91 return '~/crmSearchTasks/crmSearchInput/date.html';
94 if (field
.data_type
=== 'Boolean') {
95 return '~/crmSearchTasks/crmSearchInput/boolean.html';
99 return '~/crmSearchTasks/crmSearchInput/select.html';
102 if (field
.fk_entity
|| field
.name
=== 'id') {
103 return '~/crmSearchTasks/crmSearchInput/entityRef.html';
106 if (field
.data_type
=== 'Integer') {
107 return '~/crmSearchTasks/crmSearchInput/integer.html';
110 if (field
.data_type
=== 'Float') {
111 return '~/crmSearchTasks/crmSearchInput/float.html';
114 return '~/crmSearchTasks/crmSearchInput/text.html';
117 this.getFieldOptions = function() {
118 var field
= ctrl
.field
|| {};
119 return {results
: formatForSelect2(field
.options
|| [], ctrl
.optionKey
|| 'id', 'label', ['description', 'color', 'icon'])};
125 })(angular
, CRM
.$, CRM
._
);