Merge pull request #18076 from MegaphoneJon/better-on-behalf-of-2
[civicrm-core.git] / ext / search / ang / search / crmSearchFunction.component.js
CommitLineData
25523059
CW
1(function(angular, $, _) {
2 "use strict";
3
4 angular.module('search').component('crmSearchFunction', {
5 bindings: {
6 expr: '=',
7 cat: '<'
8 },
9 templateUrl: '~/search/crmSearchFunction.html',
10 controller: function($scope, formatForSelect2, searchMeta) {
11 var ts = $scope.ts = CRM.ts(),
12 ctrl = this;
13 this.functions = formatForSelect2(_.where(CRM.vars.search.functions, {category: this.cat}), 'name', 'title');
14
15 this.$onInit = function() {
16 var fieldInfo = searchMeta.parseExpr(ctrl.expr);
17 ctrl.path = fieldInfo.path;
18 ctrl.field = fieldInfo.field;
19 ctrl.fn = !fieldInfo.fn ? '' : fieldInfo.fn.name;
20 };
21
22 this.selectFunction = function() {
23 ctrl.expr = ctrl.fn ? (ctrl.fn + '(' + ctrl.path + ')') : ctrl.path;
24 };
25 }
26 });
27
28})(angular, CRM.$, CRM._);