1 (function(angular
, $, _
) {
4 angular
.module('crmSearchAdmin').component('crmSearchFunction', {
9 templateUrl
: '~/crmSearchAdmin/crmSearchFunction.html',
10 controller: function($scope
, formatForSelect2
, searchMeta
) {
11 var ts
= $scope
.ts
= CRM
.ts(),
14 this.$onInit = function() {
15 ctrl
.functions
= formatForSelect2(_
.where(CRM
.crmSearchAdmin
.functions
, {category
: ctrl
.cat
}), 'name', 'title');
16 var fieldInfo
= searchMeta
.parseExpr(ctrl
.expr
);
17 ctrl
.path
= fieldInfo
.path
+ fieldInfo
.suffix
;
18 ctrl
.field
= fieldInfo
.field
;
19 ctrl
.fn
= !fieldInfo
.fn
? '' : fieldInfo
.fn
.name
;
20 ctrl
.modifier
= fieldInfo
.modifier
|| null;
24 function initFunction() {
25 ctrl
.fnInfo
= _
.find(CRM
.crmSearchAdmin
.functions
, {name
: ctrl
.fn
});
26 if (ctrl
.fnInfo
&& _
.includes(ctrl
.fnInfo
.params
[0].prefix
, 'DISTINCT')) {
27 ctrl
.modifierAllowed
= true;
30 ctrl
.modifierAllowed
= false;
35 this.selectFunction = function() {
40 this.writeExpr = function() {
41 ctrl
.expr
= ctrl
.fn
? (ctrl
.fn
+ '(' + (ctrl
.modifier
? ctrl
.modifier
+ ' ' : '') + ctrl
.path
+ ')') : ctrl
.path
;
46 })(angular
, CRM
.$, CRM
._
);