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
;
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() {
89 if (ctrl
.field
.input_type
=== 'Date') {
90 return '~/crmSearchActions/crmSearchInput/date.html';
93 if (ctrl
.field
.data_type
=== 'Boolean') {
94 return '~/crmSearchActions/crmSearchInput/boolean.html';
97 if (ctrl
.field
.options
) {
98 return '~/crmSearchActions/crmSearchInput/select.html';
101 if (ctrl
.field
.fk_entity
|| ctrl
.field
.name
=== 'id') {
102 return '~/crmSearchActions/crmSearchInput/entityRef.html';
105 if (ctrl
.field
.data_type
=== 'Integer') {
106 return '~/crmSearchActions/crmSearchInput/integer.html';
109 return '~/crmSearchActions/crmSearchInput/text.html';
112 this.getFieldOptions = function() {
113 return {results
: formatForSelect2(ctrl
.field
.options
, ctrl
.optionKey
|| 'id', 'label', ['description', 'color', 'icon'])};
119 })(angular
, CRM
.$, CRM
._
);