d691913931151f620e7fe81687ae390e200f9fb2
[motion.git] / public / assets / plugins / angular-elastic-builder / src / directives / Group.js
1 /**
2  * angular-elastic-builder
3  *
4  * /src/directives/Group.js
5  */
6
7 (function(angular) {
8   'use strict';
9
10   var app = angular.module('angular-elastic-builder');
11
12   app.directive('elasticBuilderGroup', [
13     'RecursionHelper',
14     'groupClassHelper',
15
16     function elasticBuilderGroup(RH, groupClassHelper) {
17
18       return {
19         scope: {
20           elasticFields: '=',
21           group: '=elasticBuilderGroup',
22           onRemove: '&',
23         },
24
25         templateUrl: 'angular-elastic-builder/GroupDirective.html',
26
27         compile: function(element) {
28           return RH.compile(element, function(scope, el, attrs) {
29             var depth = scope.depth = (+ attrs.depth);
30             var group = scope.group;
31
32             scope.addRule = function() {
33               group.rules.push({});
34             };
35             scope.addGroup = function() {
36               group.rules.push({
37                 type: 'group',
38                 subType: 'and',
39                 rules: [],
40               });
41             };
42
43             scope.removeChild = function(idx) {
44               group.rules.splice(idx, 1);
45             };
46
47             scope.getGroupClassName = function() {
48               return groupClassHelper(depth + 1);
49             };
50           });
51         }
52       };
53     }
54
55   ]);
56
57 })(window.angular);