aboutsummaryrefslogtreecommitdiffstats
path: root/old/moon_gui/static/app/policy/edit/policy.controller.edit.js
blob: cd6e429b2524d6c26a56080970243a49232f21bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
(function() {

    'use strict';

    angular
        .module('moon')
        .controller('PolicyEditController', PolicyEditController);

    PolicyEditController.$inject = ['$scope', '$rootScope', 'policy', 'modelService'];

    function PolicyEditController($scope, $rootScope, policy, modelService) {

        var edit = this;

        edit.policy = policy;

        edit.editBasic = false;

        edit.showPerimeters = false;
        edit.showData = false;
        edit.showRules = false;
        edit.showAssignments = false;

        edit.showPart = showPart;


        activate();

        function showPart(partName) {
            var state = edit[partName];

            edit.showPerimeters = false;
            edit.showData = false;
            edit.showRules = false;
            edit.showAssignments = false;

            edit[partName] = !state;
        }


        function activate(){

            manageModel();

        }

        function manageModel(){

            edit.loadingModel = true;

            modelService.findOneWithCallback( edit.policy.model_id, function(model){

                edit.loadingModel = false;
                edit.policy.model = model;

            });

        }

        /*
         * ---- events
         */
        var rootListeners = {

            'event:policyUpdatedSuccess': $rootScope.$on('event:policyUpdatedSuccess', policyUpdatedSuccess)

        };

        for (var unbind in rootListeners) {
            $scope.$on('$destroy', rootListeners[unbind]);
        }

        /**
         * When the model is updated, this function refresh the current model with the new changes
         * @param event
         * @param policy
         */
        function policyUpdatedSuccess(event, policy){

            edit.policy = policy;

            manageModel();

        }

    }

})();