2016-06-06 15:40:38 +00:00
|
|
|
/**
|
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2016, Bjoern Schiessle
|
|
|
|
* @license AGPL-3.0
|
|
|
|
*
|
|
|
|
* This code is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
2016-06-22 11:44:33 +00:00
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
2016-06-06 15:40:38 +00:00
|
|
|
* License, or (at your opinion) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
|
|
*
|
|
|
|
*/
|
2016-06-09 19:46:30 +00:00
|
|
|
|
2017-04-28 16:23:15 +00:00
|
|
|
function startLoading() {
|
2016-06-16 15:30:18 +00:00
|
|
|
OC.msg.startSaving('#theming_settings_msg');
|
2017-04-28 15:55:59 +00:00
|
|
|
$('#theming_settings_loading').show();
|
2017-04-28 16:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function setThemingValue(setting, value) {
|
|
|
|
startLoading();
|
2016-06-09 19:46:30 +00:00
|
|
|
$.post(
|
|
|
|
OC.generateUrl('/apps/theming/ajax/updateStylesheet'), {'setting' : setting, 'value' : value}
|
2016-06-16 15:30:18 +00:00
|
|
|
).done(function(response) {
|
2016-08-29 15:42:43 +00:00
|
|
|
hideUndoButton(setting, value);
|
2017-08-04 12:41:44 +00:00
|
|
|
preview(setting, value, response.data.serverCssUrl);
|
2016-06-16 15:30:18 +00:00
|
|
|
}).fail(function(response) {
|
|
|
|
OC.msg.finishedSaving('#theming_settings_msg', response);
|
2017-04-28 15:55:59 +00:00
|
|
|
$('#theming_settings_loading').hide();
|
2016-06-16 15:30:18 +00:00
|
|
|
});
|
2016-06-09 19:46:30 +00:00
|
|
|
}
|
|
|
|
|
2017-08-04 12:41:44 +00:00
|
|
|
function preview(setting, value, serverCssUrl) {
|
2017-04-28 16:23:15 +00:00
|
|
|
OC.msg.startAction('#theming_settings_msg', t('theming', 'Loading preview…'));
|
2017-08-04 12:41:44 +00:00
|
|
|
var stylesheetsLoaded = 1;
|
2017-04-28 15:55:59 +00:00
|
|
|
var reloadStylesheets = function(cssFile) {
|
|
|
|
var queryString = '?reload=' + new Date().getTime();
|
2017-08-04 12:27:37 +00:00
|
|
|
var url = cssFile + queryString;
|
2018-10-17 16:27:09 +00:00
|
|
|
var old = $('link[href*="' + cssFile + '"]');
|
2017-04-28 15:55:59 +00:00
|
|
|
var stylesheet = $("<link/>", {
|
|
|
|
rel: "stylesheet",
|
|
|
|
type: "text/css",
|
|
|
|
href: url
|
|
|
|
});
|
|
|
|
stylesheet.load(function () {
|
|
|
|
$(old).remove();
|
|
|
|
stylesheetsLoaded--;
|
|
|
|
if(stylesheetsLoaded === 0) {
|
|
|
|
$('#theming_settings_loading').hide();
|
|
|
|
var response = { status: 'success', data: {message: t('theming', 'Saved')}};
|
|
|
|
OC.msg.finishedSaving('#theming_settings_msg', response);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
stylesheet.appendTo("head");
|
|
|
|
};
|
2016-07-12 12:59:28 +00:00
|
|
|
|
2017-08-04 12:41:44 +00:00
|
|
|
if (serverCssUrl !== undefined) {
|
|
|
|
stylesheetsLoaded++;
|
|
|
|
|
|
|
|
reloadStylesheets(serverCssUrl);
|
|
|
|
}
|
2017-08-04 12:27:37 +00:00
|
|
|
reloadStylesheets(OC.generateUrl('/apps/theming/styles'));
|
2016-08-24 09:33:54 +00:00
|
|
|
|
2016-08-26 16:21:05 +00:00
|
|
|
if (setting === 'name') {
|
|
|
|
window.document.title = t('core', 'Admin') + " - " + value;
|
|
|
|
}
|
2016-10-12 14:45:07 +00:00
|
|
|
|
|
|
|
hideUndoButton(setting, value);
|
|
|
|
|
2016-08-24 09:34:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function hideUndoButton(setting, value) {
|
|
|
|
var themingDefaults = {
|
|
|
|
name: 'Nextcloud',
|
|
|
|
slogan: t('lib', 'a safe home for all your data'),
|
|
|
|
url: 'https://nextcloud.com',
|
|
|
|
color: '#0082c9',
|
|
|
|
logoMime: '',
|
2018-05-11 13:57:32 +00:00
|
|
|
backgroundMime: '',
|
2018-05-24 12:45:49 +00:00
|
|
|
imprintUrl: '',
|
|
|
|
privacyUrl: ''
|
2016-08-24 09:34:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (value === themingDefaults[setting] || value === '') {
|
|
|
|
$('.theme-undo[data-setting=' + setting + ']').hide();
|
|
|
|
} else {
|
|
|
|
$('.theme-undo[data-setting=' + setting + ']').show();
|
2016-06-09 19:46:30 +00:00
|
|
|
}
|
2016-10-12 14:45:07 +00:00
|
|
|
|
|
|
|
if(setting === 'backgroundMime' && value !== 'backgroundColor') {
|
|
|
|
$('.theme-remove-bg').show();
|
|
|
|
}
|
|
|
|
if(setting === 'backgroundMime' && value === 'backgroundColor') {
|
|
|
|
$('.theme-remove-bg').hide();
|
|
|
|
$('.theme-undo[data-setting=backgroundMime]').show();
|
|
|
|
}
|
2016-06-09 19:46:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$(document).ready(function () {
|
2016-06-27 18:36:23 +00:00
|
|
|
$('#theming [data-toggle="tooltip"]').tooltip();
|
2016-06-09 19:46:30 +00:00
|
|
|
|
2018-10-02 08:16:45 +00:00
|
|
|
// manually instantiate jscolor to work around new Function call which violates strict CSP
|
|
|
|
var colorElement = $('#theming-color')[0];
|
|
|
|
var jscolor = new window.jscolor(colorElement, {hash: true});
|
|
|
|
|
2016-08-24 09:34:45 +00:00
|
|
|
$('#theming .theme-undo').each(function() {
|
|
|
|
var setting = $(this).data('setting');
|
|
|
|
var value = $('#theming-'+setting).val();
|
|
|
|
hideUndoButton(setting, value);
|
|
|
|
});
|
2016-10-12 14:45:07 +00:00
|
|
|
|
2018-02-26 13:06:28 +00:00
|
|
|
$('.fileupload').fileupload({
|
2016-06-09 19:46:30 +00:00
|
|
|
pasteZone: null,
|
2016-06-21 19:46:27 +00:00
|
|
|
dropZone: null,
|
2016-06-16 15:30:18 +00:00
|
|
|
done: function (e, response) {
|
2018-02-26 13:06:28 +00:00
|
|
|
var $form = $(e.target).closest('form');
|
|
|
|
var key = $form.data('image-key');
|
|
|
|
|
|
|
|
preview(key + 'Mime', response.result.data.name, response.result.data.serverCssUrl);
|
|
|
|
$form.find('.image-preview').css('backgroundImage', response.result.data.url + '?v=' + new Date().getTime());
|
2016-06-16 15:30:18 +00:00
|
|
|
OC.msg.finishedSaving('#theming_settings_msg', response.result);
|
2018-02-26 13:06:28 +00:00
|
|
|
$form.find('label.button').addClass('icon-upload').removeClass('icon-loading-small');
|
|
|
|
$form.find('.theme-undo').show();
|
2016-06-09 19:46:30 +00:00
|
|
|
},
|
2016-06-16 15:30:18 +00:00
|
|
|
submit: function(e, response) {
|
2018-02-26 13:06:28 +00:00
|
|
|
var $form = $(e.target).closest('form');
|
|
|
|
var key = $form.data('image-key');
|
2017-04-28 16:23:15 +00:00
|
|
|
startLoading();
|
2018-02-26 13:06:28 +00:00
|
|
|
$form.find('label.button').removeClass('icon-upload').addClass('icon-loading-small');
|
2016-06-09 19:46:30 +00:00
|
|
|
},
|
2016-08-27 10:38:15 +00:00
|
|
|
fail: function (e, response){
|
2018-02-26 13:06:28 +00:00
|
|
|
var $form = $(e.target).closest('form');
|
2016-08-27 10:38:15 +00:00
|
|
|
OC.msg.finishedError('#theming_settings_msg', response._response.jqXHR.responseJSON.data.message);
|
2018-02-26 13:06:28 +00:00
|
|
|
$form.find('label.button').addClass('icon-upload').removeClass('icon-loading-small');
|
2017-09-21 09:35:40 +00:00
|
|
|
$('#theming_settings_loading').hide();
|
2016-06-09 19:46:30 +00:00
|
|
|
}
|
2018-02-26 13:06:28 +00:00
|
|
|
});
|
2016-06-22 11:44:33 +00:00
|
|
|
|
2017-05-12 00:49:32 +00:00
|
|
|
// clicking preview should also trigger file upload dialog
|
2017-05-12 07:48:51 +00:00
|
|
|
$('#theming-preview-logo').on('click', function(e) {
|
|
|
|
e.stopPropagation();
|
2017-05-12 00:49:32 +00:00
|
|
|
$('#uploadlogo').click();
|
|
|
|
});
|
|
|
|
$('#theming-preview').on('click', function() {
|
|
|
|
$('#upload-login-background').click();
|
|
|
|
});
|
2016-06-09 19:46:30 +00:00
|
|
|
|
2018-02-21 07:44:19 +00:00
|
|
|
function checkName () {
|
|
|
|
var length = $('#theming-name').val().length;
|
|
|
|
try {
|
|
|
|
if (length > 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
throw t('theming', 'Name cannot be empty');
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
$('#theming-name').attr('title', error);
|
|
|
|
$('#theming-name').tooltip({placement: 'top', trigger: 'manual'});
|
|
|
|
$('#theming-name').tooltip('fixTitle');
|
|
|
|
$('#theming-name').tooltip('show');
|
|
|
|
$('#theming-name').addClass('error');
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
$('#theming-name').keyup(function() {
|
|
|
|
if (checkName()) {
|
|
|
|
$('#theming-name').tooltip('hide');
|
|
|
|
$('#theming-name').removeClass('error');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-06-27 18:46:12 +00:00
|
|
|
$('#theming-name').change(function(e) {
|
|
|
|
var el = $(this);
|
2016-06-09 19:46:30 +00:00
|
|
|
});
|
|
|
|
|
2018-05-09 13:52:41 +00:00
|
|
|
function onChange(e) {
|
2016-06-27 18:46:12 +00:00
|
|
|
var el = $(this);
|
2018-02-26 13:13:17 +00:00
|
|
|
var setting = el.parent().find('div[data-setting]').data('setting');
|
|
|
|
var value = $(this).val();
|
|
|
|
|
|
|
|
if(setting === 'color') {
|
|
|
|
if (value.indexOf('#') !== 0) {
|
|
|
|
value = '#' + value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(setting === 'name') {
|
2018-05-09 13:52:41 +00:00
|
|
|
if(checkName()){
|
|
|
|
$.when(el.focusout()).then(function() {
|
|
|
|
setThemingValue('name', value);
|
|
|
|
});
|
|
|
|
if (e.keyCode == 13) {
|
|
|
|
setThemingValue('name', value);
|
|
|
|
}
|
|
|
|
}
|
2016-06-09 19:46:30 +00:00
|
|
|
}
|
|
|
|
|
2016-06-27 18:46:12 +00:00
|
|
|
$.when(el.focusout()).then(function() {
|
2018-02-26 13:13:17 +00:00
|
|
|
setThemingValue(setting, value);
|
2016-06-27 18:46:12 +00:00
|
|
|
});
|
2016-06-09 19:46:30 +00:00
|
|
|
if (e.keyCode == 13) {
|
2018-02-26 13:13:17 +00:00
|
|
|
setThemingValue(setting, value);
|
2016-06-09 19:46:30 +00:00
|
|
|
}
|
2018-05-09 13:52:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
$('#theming input[type="text"]').change(onChange);
|
|
|
|
$('#theming input[type="url"]').change(onChange);
|
2016-06-09 19:46:30 +00:00
|
|
|
|
|
|
|
$('.theme-undo').click(function (e) {
|
|
|
|
var setting = $(this).data('setting');
|
2018-02-26 13:13:17 +00:00
|
|
|
var $form = $(this).closest('form');
|
|
|
|
var image = $form.data('image-key');
|
|
|
|
|
2017-04-28 16:23:15 +00:00
|
|
|
startLoading();
|
2016-08-29 15:42:43 +00:00
|
|
|
$('.theme-undo[data-setting=' + setting + ']').hide();
|
2016-06-09 19:46:30 +00:00
|
|
|
$.post(
|
|
|
|
OC.generateUrl('/apps/theming/ajax/undoChanges'), {'setting' : setting}
|
2016-06-16 15:30:18 +00:00
|
|
|
).done(function(response) {
|
2016-06-09 19:46:30 +00:00
|
|
|
if (setting === 'color') {
|
|
|
|
var colorPicker = document.getElementById('theming-color');
|
2016-06-16 15:30:18 +00:00
|
|
|
colorPicker.style.backgroundColor = response.data.value;
|
2016-08-24 09:34:45 +00:00
|
|
|
colorPicker.value = response.data.value.slice(1).toUpperCase();
|
2018-02-26 13:13:17 +00:00
|
|
|
} else if (!image) {
|
2016-06-09 19:46:30 +00:00
|
|
|
var input = document.getElementById('theming-'+setting);
|
2016-06-16 15:30:18 +00:00
|
|
|
input.value = response.data.value;
|
2016-06-09 19:46:30 +00:00
|
|
|
}
|
2017-08-04 12:41:44 +00:00
|
|
|
preview(setting, response.data.value, response.data.serverCssUrl);
|
2016-06-09 19:46:30 +00:00
|
|
|
});
|
|
|
|
});
|
2016-10-12 14:45:07 +00:00
|
|
|
|
|
|
|
$('.theme-remove-bg').click(function() {
|
|
|
|
startLoading();
|
|
|
|
$.post(
|
2018-02-26 13:06:28 +00:00
|
|
|
OC.generateUrl('/apps/theming/ajax/updateStylesheet'), {'setting' : 'backgroundMime', 'value' : 'backgroundColor'}
|
2016-10-12 14:45:07 +00:00
|
|
|
).done(function(response) {
|
2018-02-26 13:06:28 +00:00
|
|
|
preview('backgroundMime', 'backgroundColor', response.data.serverCssUrl);
|
2016-10-12 14:45:07 +00:00
|
|
|
}).fail(function(response) {
|
|
|
|
OC.msg.finishedSaving('#theming_settings_msg', response);
|
2018-02-26 13:06:28 +00:00
|
|
|
$('#theming_settings_loading').hide();
|
2016-10-12 14:45:07 +00:00
|
|
|
});
|
|
|
|
});
|
2017-06-07 14:06:19 +00:00
|
|
|
|
2016-06-09 19:46:30 +00:00
|
|
|
});
|