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
|
/*!
* Piwik - free/libre analytics platform
*
* @link http://piwik.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
function sendGeneralSettingsAJAX() {
var enableBrowserTriggerArchiving = $('input[name=enableBrowserTriggerArchiving]:checked').val();
var enablePluginUpdateCommunication = $('input[name=enablePluginUpdateCommunication]:checked').val();
var releaseChannel = $('input[name=releaseChannel]:checked').val();
var todayArchiveTimeToLive = $('#todayArchiveTimeToLive').val();
var trustedHosts = [];
$('input[name=trusted_host]').each(function () {
trustedHosts.push($(this).val());
});
var ajaxHandler = new ajaxHelper();
ajaxHandler.setLoadingElement();
ajaxHandler.addParams({
format: 'json',
enableBrowserTriggerArchiving: enableBrowserTriggerArchiving,
enablePluginUpdateCommunication: enablePluginUpdateCommunication,
releaseChannel: releaseChannel,
todayArchiveTimeToLive: todayArchiveTimeToLive,
mailUseSmtp: isSmtpEnabled(),
mailPort: $('#mailPort').val(),
mailHost: $('#mailHost').val(),
mailType: $('#mailType').val(),
mailUsername: $('#mailUsername').val(),
mailPassword: $('#mailPassword').val(),
mailEncryption: $('#mailEncryption').val(),
useCustomLogo: isCustomLogoEnabled(),
trustedHosts: JSON.stringify(trustedHosts)
}, 'POST');
ajaxHandler.addParams({
module: 'CoreAdminHome',
action: 'setGeneralSettings'
}, 'GET');
ajaxHandler.withTokenInUrl();
ajaxHandler.redirectOnSuccess();
ajaxHandler.send(true);
}
function showSmtpSettings(value) {
$('#smtpSettings').toggle(value == 1);
}
function isSmtpEnabled() {
return $('input[name="mailUseSmtp"]:checked').val();
}
function showCustomLogoSettings(value) {
if (value == 1) {
// Refresh custom logo only if we're going to display it
refreshCustomLogo();
}
$('#logoSettings').toggle(value == 1);
}
function isCustomLogoEnabled() {
return $('input[name="useCustomLogo"]:checked').val();
}
function refreshCustomLogo() {
var selectors = ['#currentLogo', '#currentFavicon'];
var index;
for (index = 0; index < selectors.length; index++) {
var imageDiv = $(selectors[index]);
if (imageDiv && imageDiv.data("src") && imageDiv.data("srcExists")) {
var logoUrl = imageDiv.data("src");
imageDiv.attr("src", logoUrl + "?" + (new Date()).getTime());
}
}
}
$(document).ready(function () {
var originalTrustedHostCount = $('input[name=trusted_host]').length;
showSmtpSettings(isSmtpEnabled());
showCustomLogoSettings(isCustomLogoEnabled());
$('.generalSettingsSubmit').click(function () {
var doSubmit = function () {
sendGeneralSettingsAJAX();
};
var hasTrustedHostsChanged = false,
hosts = $('input[name=trusted_host]');
if (hosts.length != originalTrustedHostCount) {
hasTrustedHostsChanged = true;
}
else {
hosts.each(function () {
hasTrustedHostsChanged |= this.defaultValue != this.value;
});
}
// if trusted hosts have changed, make sure to ask for confirmation
if (hasTrustedHostsChanged) {
piwikHelper.modalConfirm('#confirmTrustedHostChange', {yes: doSubmit});
}
else {
doSubmit();
}
});
$('input[name=mailUseSmtp]').click(function () {
showSmtpSettings($(this).val());
});
$('input[name=useCustomLogo]').click(function () {
showCustomLogoSettings($(this).val());
});
$('input').keypress(function (e) {
var key = e.keyCode || e.which;
if (key == 13) {
$('.generalSettingsSubmit').click();
}
}
);
$("#logoUploadForm").submit(function (data) {
var submittingForm = $(this);
var isSubmittingLogo = ($('#customLogo').val() != '')
var isSubmittingFavicon = ($('#customFavicon').val() != '')
$('.uploaderror').fadeOut();
var frameName = "upload" + (new Date()).getTime();
var uploadFrame = $("<iframe name=\"" + frameName + "\" />");
uploadFrame.css("display", "none");
uploadFrame.load(function (data) {
setTimeout(function () {
var frameContent = $(uploadFrame.contents()).find('body').html();
frameContent = $.trim(frameContent);
if ('0' === frameContent) {
$('.uploaderror').show();
}
else {
// Upload succeed, so we update the images availability
// according to what have been uploaded
if (isSubmittingLogo) {
$('#currentLogo').data("srcExists", true)
}
if (isSubmittingFavicon) {
$('#currentFavicon').data("srcExists", true)
}
refreshCustomLogo();
}
if ('1' === frameContent || '0' === frameContent) {
uploadFrame.remove();
}
}, 1000);
});
$("body:first").append(uploadFrame);
submittingForm.attr("target", frameName);
});
$('#customLogo,#customFavicon').change(function () {
$("#logoUploadForm").submit();
$(this).val('');
});
// trusted hosts event handling
var trustedHostSettings = $('#trustedHostSettings');
trustedHostSettings.on('click', '.remove-trusted-host', function (e) {
e.preventDefault();
$(this).parent('li').remove();
return false;
});
trustedHostSettings.find('.add-trusted-host').click(function (e) {
e.preventDefault();
// append new row to the table
trustedHostSettings.find('ul').append(trustedHostSettings.find('li:last').clone());
trustedHostSettings.find('li:last input').val('').focus();
return false;
});
});
|