8df37c1e4601c91dc55b7e48954501a6156763cd
[motion.git] / public / assets / plugins / angular-elastic-builder / src / directives / RuleTypes.js
1 /**
2  * angular-elastic-builder
3  *
4  * /src/directives/RuleTypes.js
5  *
6  * Determines which Rule type should be displayed
7  */
8
9 (function(angular) {
10   'use strict';
11
12   var app = angular.module('angular-elastic-builder');
13
14   app.directive('elasticType', [
15
16     function() {
17       return {
18         scope: {
19           type: '=elasticType',
20           rule: '=',
21           guide: '=',
22         },
23
24         template: '<ng-include src="getTemplateUrl()" />',
25
26         link: function(scope) {
27           scope.getTemplateUrl = function() {
28             var type = scope.type;
29             if (! type) return;
30
31             type = type.charAt(0).toUpperCase() + type.slice(1);
32
33             return 'angular-elastic-builder/types/' + type + '.html';
34           };
35
36           // This is a weird hack to make sure these are numbers
37           scope.booleans = [ 'False', 'True' ];
38           scope.booleansOrder = [ 'True', 'False' ];
39
40           scope.inputNeeded = function() {
41             var needs = [
42               'equals',
43               'notEquals',
44
45               'gt',
46               'gte',
47               'lt',
48               'lte',
49             ];
50
51             return ~needs.indexOf(scope.rule.subType);
52           };
53         },
54       };
55     }
56
57   ]);
58
59 })(window.angular);