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

trustedhosts.controller.js « trustedhosts « angularjs « CoreAdminHome « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: adcaf69e29729760fc2f4bc50a0485e8f547e80f (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
/*!
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

/**
 * Controller to save archiving settings
 */
(function () {
    angular.module('piwikApp').controller('TrustedHostsController', TrustedHostsController);

    TrustedHostsController.$inject = ['$scope', 'piwikApi', '$timeout'];

    function TrustedHostsController($scope, piwikApi, $timeout) {

        var self = this;
        this.isLoading = false;

        this.addTrustedHost = function () {
            this.hosts.push({host: ''});

            $timeout(function () {
                $('#trustedHostSettings').find('li:last input').val('').focus();
            });
        };

        this.removeTrustedHost = function (index) {
            this.hosts.splice(index,1);
        };

        this.save = function () {
            var hosts = [];
            angular.forEach(self.hosts, function (host) {
                hosts.push(host.host);
            });

            var doSubmit = function () {
                self.isLoading = true;

                piwikApi.post({module: 'API', method: 'CoreAdminHome.setTrustedHosts'}, {
                    trustedHosts: hosts
                }).then(function (success) {
                    self.isLoading = false;

                    var UI = require('piwik/UI');
                    var notification = new UI.Notification();
                    notification.show(_pk_translate('CoreAdminHome_SettingsSaveSuccess'), {
                        id: 'generalSettings', context: 'success'
                    });
                    notification.scrollToNotification();
                }, function () {
                    self.isLoading = false;
                });
            };

            piwikHelper.modalConfirm('#confirmTrustedHostChange', {yes: doSubmit});
        };
    }
})();