Commit | Line | Data |
---|---|---|
c7e96654 CW |
1 | (function(angular, $, _) { |
2 | "use strict"; | |
3 | ||
4 | angular.module('crmSearchAdmin').component('crmSearchAdminTokenSelect', { | |
5 | bindings: { | |
6 | apiEntity: '<', | |
7 | apiParams: '<', | |
8 | model: '<', | |
9 | field: '@' | |
10 | }, | |
11 | templateUrl: '~/crmSearchAdmin/crmSearchAdminTokenSelect.html', | |
12 | controller: function ($scope, $element, searchMeta) { | |
13 | var ts = $scope.ts = CRM.ts(), | |
14 | ctrl = this; | |
15 | ||
16 | this.initTokens = function() { | |
17 | ctrl.tokens = ctrl.tokens || getTokens(); | |
18 | }; | |
19 | ||
20 | this.insertToken = function(key) { | |
21 | ctrl.model[ctrl.field] = (ctrl.model[ctrl.field] || '') + ctrl.tokens[key].token; | |
22 | }; | |
23 | ||
24 | function getTokens() { | |
25 | var tokens = { | |
26 | id: { | |
27 | token: '[id]', | |
28 | label: searchMeta.getField('id', ctrl.apiEntity).label | |
29 | } | |
30 | }; | |
31 | _.each(ctrl.apiParams.join, function(joinParams) { | |
32 | var info = searchMeta.parseExpr(joinParams[0].split(' AS ')[1] + '.id'); | |
33 | tokens[info.alias] = { | |
34 | token: '[' + info.alias + ']', | |
35 | label: info.field ? info.field.label : info.alias | |
36 | }; | |
37 | }); | |
38 | _.each(ctrl.apiParams.select, function(expr) { | |
39 | var info = searchMeta.parseExpr(expr); | |
40 | tokens[info.alias] = { | |
41 | token: '[' + info.alias + ']', | |
42 | label: info.field ? info.field.label : info.alias | |
43 | }; | |
44 | }); | |
45 | return tokens; | |
46 | } | |
47 | ||
48 | } | |
49 | }); | |
50 | ||
51 | })(angular, CRM.$, CRM._); |