1 (function(angular
, $, _
) {
4 angular
.module('crmSearchAdmin').component('crmSearchClause', {
14 templateUrl
: '~/crmSearchAdmin/crmSearchClause.html',
15 controller: function ($scope
, $element
, $timeout
, searchMeta
) {
16 var ts
= $scope
.ts
= CRM
.ts(),
19 this.conjunctions
= {AND
: ts('And'), OR
: ts('Or'), NOT
: ts('Not')};
20 this.operators
= CRM
.crmSearchAdmin
.operators
;
23 connectWith
: '.api4-clause-group-sortable',
24 containment
: $element
.closest('.api4-clause-fieldset'),
30 this.$onInit = function() {
31 ctrl
.hasParent
= !!$element
.attr('delete-group');
34 this.getField = function(expr
) {
36 meta
[expr
] = searchMeta
.parseExpr(expr
);
38 return meta
[expr
].field
;
41 this.getOptionKey = function(expr
) {
43 meta
[expr
] = searchMeta
.parseExpr(expr
);
45 return meta
[expr
].suffix
? meta
[expr
].suffix
.slice(1) : 'id';
48 this.addGroup = function(op
) {
49 ctrl
.clauses
.push([op
, []]);
52 function onSort(event
, ui
) {
53 $($element
).closest('.api4-clause-fieldset').toggleClass('api4-sorting', event
.type
=== 'sortstart');
54 $('.api4-input.form-inline').css('margin-left', '');
57 // Indent clause while dragging between nested groups
58 function onSortOver(event
, ui
) {
61 offset
= $(ui
.placeholder
).offset().left
- $(ui
.sender
).offset().left
;
63 $('.api4-input.form-inline.ui-sortable-helper').css('margin-left', '' + offset
+ 'px');
66 this.addClause = function() {
69 ctrl
.clauses
.push([ctrl
.newClause
, '=', '']);
70 ctrl
.newClause
= null;
75 this.deleteRow = function(index
) {
76 ctrl
.clauses
.splice(index
, 1);
79 // Remove empty values
80 this.changeClauseField = function(clause
, index
) {
81 if (clause
[0] === '') {
82 ctrl
.deleteRow(index
);
86 // Add/remove value if operator allows for one
87 this.changeClauseOperator = function(clause
) {
88 if (_
.contains(clause
[1], 'NULL')) {
90 } else if (clause
.length
=== 2) {
98 })(angular
, CRM
.$, CRM
._
);