Welcome to mirror list, hosted at ThFree Co, Russian Federation.

privacySettings.js « javascripts « PrivacyManager « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 75de9b8caa6e1bbae398101977555a8076e5e243 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
/*!
 * Piwik - Web Analytics
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

$(document).ready(function () {
    function toggleBlock(id, value) {
        $('#' + id).toggle(value == 1);
    }

    function isEitherDeleteSectionEnabled() {
        return ($('input[name=deleteEnable]:checked').val() == 1)
            || ($('input[name=deleteReportsEnable]:checked').val() == 1);
    }

    function toggleOtherDeleteSections() {
        var showSection = isEitherDeleteSectionEnabled();
        toggleBlock('deleteDataEstimateSect', showSection);
        toggleBlock('deleteSchedulingSettings', showSection);
    }

    // reloads purged database size estimate
    var currentRequest;

    function reloadDbStats(forceEstimate) {
        if (currentRequest) {
            currentRequest.abort();
        }

        // if the section isn't visible or the manual estimate link is showing, abort
        // (unless on first load or forcing)
        var isFirstLoad = $('#deleteDataEstimate').html() == '';
        if (!isFirstLoad
            && forceEstimate !== true
            && (!isEitherDeleteSectionEnabled() || $('#getPurgeEstimateLink').length > 0)) {
            return;
        }

        $('#deleteDataEstimate').hide();

        var data = $('#formDeleteSettings').serializeArray();
        var formData = {};
        for (var i = 0; i < data.length; i++) {
            formData[data[i].name] = data[i].value;
        }
        if (forceEstimate === true) {
            formData['forceEstimate'] = 1;
        }

        currentRequest = new ajaxHelper();
        currentRequest.setLoadingElement('#deleteDataEstimateSect .loadingPiwik');
        currentRequest.addParams({
            module: 'PrivacyManager',
            action: 'getDatabaseSize'
        }, 'get');
        currentRequest.addParams(formData, 'post');
        currentRequest.setCallback(
            function (data) {
                currentRequest = undefined;
                $('#deleteDataEstimate').html(data).show();

                // lock size of db size estimate
                $('#deleteDataEstimateSect').height($('#deleteDataEstimateSect').height());
            }
        );
        currentRequest.setFormat('html');
        currentRequest.send(false);
    }

    // make sure certain sections only display if their corresponding features are enabled
    $('input[name=anonymizeIPEnable]').click(function () {
        toggleBlock("anonymizeIPenabled", $(this).val());
    });

    $('input[name=deleteEnable]').click(function () {
        toggleBlock("deleteLogSettings", $(this).val());
        toggleOtherDeleteSections();
    }).change(reloadDbStats);

    $('input[name=deleteReportsEnable]').click(function () {
        toggleBlock("deleteReportsSettings", $(this).val());
        toggleBlock("deleteOldReportsMoreInfo", $(this).val());
        toggleOtherDeleteSections();
    }).change(reloadDbStats);

    // initial toggling calls
    $(function () {
        toggleBlock("deleteLogSettings", $("input[name=deleteEnable]:checked").val());
        toggleBlock("anonymizeIPenabled", $("input[name=anonymizeIPEnable]:checked").val());
        toggleBlock("deleteReportsSettings", $("input[name=deleteReportsEnable]:checked").val());
        toggleBlock("deleteOldReportsMoreInfo", $("input[name=deleteReportsEnable]:checked").val());
        toggleOtherDeleteSections();
    });

    // make sure the DB size estimate is reloaded every time a delete logs/reports setting is changed
    $('#formDeleteSettings input[type=text]').each(function () {
        $(this).change(reloadDbStats);
    });
    $('#formDeleteSettings input[type=checkbox]').each(function () {
        $(this).click(reloadDbStats);
    });

    // make sure when the delete log/report settings are submitted, a confirmation popup is
    // displayed first
    $('#deleteLogSettingsSubmit').click(function (e) {
        var deletingLogs = $("input[name=deleteEnable]:checked").val() == 1,
            deletingReports = $("input[name=deleteReportsEnable]:checked").val() == 1,
            confirm_id;

        // hide all confirmation texts, then show the correct one based on what
        // type of deletion is enabled.
        $('#confirmDeleteSettings>h2').each(function () {
            $(this).hide();
        });

        if (deletingLogs) {
            confirm_id = deletingReports ? "deleteBothConfirm" : "deleteLogsConfirm";
        }
        else if (deletingReports) {
            confirm_id = "deleteReportsConfirm";
        }

        if (confirm_id) {
            $("#" + confirm_id).show();
            e.preventDefault();

            piwikHelper.modalConfirm('#confirmDeleteSettings', {
                yes: function () {
                    $('#formDeleteSettings').submit();
                }
            });
        }
        else {
            $('#formDeleteSettings').submit();
        }
    });

    // execute purge now link click
    $('#purgeDataNowLink').click(function (e) {
        e.preventDefault();

        var link = this;

        // if any option has been modified, abort purging and instruct user to save first
        var modified = false;
        $('#formDeleteSettings input').each(function () {
            if (this.type === 'checkbox' || this.type === 'radio') {
                modified |= this.defaultChecked !== this.checked;
            } else {
                modified |= this.defaultValue !== this.value;
            }
        });

        if (modified) {
            piwikHelper.modalConfirm('#saveSettingsBeforePurge', {yes: function () {}});
            return;
        }

        // ask user if they really want to delete their old data
        piwikHelper.modalConfirm('#confirmPurgeNow', {
            yes: function () {
                $(link).hide();

                // execute a data purge
                var ajaxRequest = new ajaxHelper();
                ajaxRequest.setLoadingElement('#deleteSchedulingSettings .loadingPiwik');
                ajaxRequest.addParams({
                    module: 'PrivacyManager',
                    action: 'executeDataPurge'
                }, 'get');
                ajaxRequest.setCallback(
                    function () {
                        // force reload
                        $('#deleteDataEstimate').html('');
                        reloadDbStats();

                        // show 'db purged' message
                        $('#db-purged-message').fadeIn('slow');
                        setTimeout(function () {
                            // hide 'db purged' message & show link
                            $('#db-purged-message').fadeOut('slow', function () {
                                $(link).show();
                            });
                        }, 2000);
                    }
                );
                ajaxRequest.setFormat('html');
                ajaxRequest.send(false);
            }
        });
    });

    // get estimate link click
    $('#getPurgeEstimateLink').click(function (e) {
        e.preventDefault();
        reloadDbStats(true);
    });

    // load initial db size estimate
    reloadDbStats();
});