1 (function(angular
, $, _
) {
4 angular
.module('searchAdmin').component('crmSearchClause', {
14 templateUrl
: '~/searchAdmin/crmSearchClause.html',
15 controller: function ($scope
, $element
, $timeout
) {
16 var ts
= $scope
.ts
= CRM
.ts(),
18 this.conjunctions
= {AND
: ts('And'), OR
: ts('Or'), NOT
: ts('Not')};
19 this.operators
= CRM
.vars
.search
.operators
;
22 connectWith
: '.api4-clause-group-sortable',
23 containment
: $element
.closest('.api4-clause-fieldset'),
29 this.$onInit = function() {
30 ctrl
.hasParent
= !!$element
.attr('delete-group');
33 this.addGroup = function(op
) {
34 ctrl
.clauses
.push([op
, []]);
37 function onSort(event
, ui
) {
38 $($element
).closest('.api4-clause-fieldset').toggleClass('api4-sorting', event
.type
=== 'sortstart');
39 $('.api4-input.form-inline').css('margin-left', '');
42 // Indent clause while dragging between nested groups
43 function onSortOver(event
, ui
) {
46 offset
= $(ui
.placeholder
).offset().left
- $(ui
.sender
).offset().left
;
48 $('.api4-input.form-inline.ui-sortable-helper').css('margin-left', '' + offset
+ 'px');
51 this.addClause = function() {
54 ctrl
.clauses
.push([ctrl
.newClause
, '=', '']);
55 ctrl
.newClause
= null;
60 this.deleteRow = function(index
) {
61 ctrl
.clauses
.splice(index
, 1);
64 // Remove empty values
65 this.changeClauseField = function(clause
, index
) {
66 if (clause
[0] === '') {
67 ctrl
.deleteRow(index
);
71 // Add/remove value if operator allows for one
72 this.changeClauseOperator = function(clause
) {
73 if (_
.contains(clause
[1], 'NULL')) {
75 } else if (clause
.length
=== 2) {
83 })(angular
, CRM
.$, CRM
._
);