aboutsummaryrefslogtreecommitdiffstats
path: root/moonv4/moon_gui/static/app/policy/action/policy.controller.delete.js
blob: 9a718ddc8214dba91997f2095061ce52d4c050f3 (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
(function() {

    'use strict';

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

    PolicyDeleteController.$inject = ['$scope', '$translate', 'alertService', 'policyService'];

    function PolicyDeleteController($scope, $translate, alertService, policyService) {

        var del = this;

        /*
         *
         */

        del.policy = $scope.policy;
        del.loading = false;

        del.remove = deletePolicy;

        activate();

        /**
         *
         */

        function activate(){

        }


        function deletePolicy(){

            del.loading = true;

            policyService.delete(del.policy, deleteSuccess, deleteError);

            function deleteSuccess(data) {

                $translate('moon.policy.remove.success', { policyName: del.policy.name }).then(function (translatedValue) {
                    alertService.alertSuccess(translatedValue);
                });

                del.loading = false;

                $scope.$emit('event:policyDeletedSuccess', del.policy);

            }

            function deleteError(reason) {

                $translate('moon.policy.remove.error', { policyName: del.policy.name, errorCode: reason.data.error.code, message : reason.data.error.message } ).then(function (translatedValue) {
                    alertService.alertError(translatedValue);
                });

                del.loading = false;

                $scope.$emit('event:policyDeletedError', del.policy);

            }

        }
    }

})();