1 (function(angular
, $, _
) {
4 angular
.module('crmSearchActions').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(),
16 this.$onInit = function() {
18 ctrl
.dateRanges
= CRM
.crmSearchActions
.dateRanges
;
20 this.ngModel
.$render = function() {
21 ctrl
.value
= ctrl
.ngModel
.$viewValue
;
22 if (!rendered
&& ctrl
.field
.input_type
=== 'Date') {
28 $scope
.$watch('$ctrl.value', function() {
29 ctrl
.ngModel
.$setViewValue(ctrl
.value
);
32 function setDateType() {
33 if (_
.findWhere(ctrl
.dateRanges
, {id
: ctrl
.value
})) {
34 ctrl
.dateType
= 'range';
35 } else if (ctrl
.value
=== 'now') {
36 ctrl
.dateType
= 'now';
37 } else if (_
.includes(ctrl
.value
, 'now -')) {
38 ctrl
.dateType
= 'now -';
39 } else if (_
.includes(ctrl
.value
, 'now +')) {
40 ctrl
.dateType
= 'now +';
42 ctrl
.dateType
= 'fixed';
47 this.changeDateType = function() {
48 switch (ctrl
.dateType
) {
54 ctrl
.value
= ctrl
.dateRanges
[0].id
;
62 ctrl
.value
= ctrl
.dateType
+ ' 1 day';
66 this.dateUnits = function(setUnit
) {
67 var vals
= ctrl
.value
.split(' ');
68 if (arguments
.length
) {
70 ctrl
.value
= vals
.join(' ');
76 this.dateNumber = function(setNumber
) {
77 var vals
= ctrl
.value
.split(' ');
78 if (arguments
.length
) {
80 ctrl
.value
= vals
.join(' ');
82 return parseInt(vals
[2], 10);
86 this.getTemplate = function() {
88 if (ctrl
.field
.input_type
=== 'Date') {
89 return '~/crmSearchActions/crmSearchInput/date.html';
92 if (ctrl
.field
.data_type
=== 'Boolean') {
93 return '~/crmSearchActions/crmSearchInput/boolean.html';
96 if (ctrl
.field
.options
) {
97 return '~/crmSearchActions/crmSearchInput/select.html';
100 if (ctrl
.field
.fk_entity
) {
101 return '~/crmSearchActions/crmSearchInput/entityRef.html';
104 if (ctrl
.field
.data_type
=== 'Integer') {
105 return '~/crmSearchActions/crmSearchInput/integer.html';
108 return '~/crmSearchActions/crmSearchInput/text.html';
111 this.getFieldOptions = function() {
112 return {results
: formatForSelect2(ctrl
.field
.options
, ctrl
.optionKey
|| 'id', 'label', ['description', 'color', 'icon'])};
118 })(angular
, CRM
.$, CRM
._
);