This commit is contained in:
zuzanna-maria 2024-05-28 18:43:17 +01:00
parent f03a05cac0
commit b6dcb3fc47
2 changed files with 132 additions and 154 deletions

View File

@ -23,11 +23,10 @@ define([
) {
var AppConfigScreen = {}
var AppConfigScreen = {};
const blocks = Sidebar.blocks;
AppConfigScreen.titleConfig = function (sendAdminDecree) {
AppConfigScreen.titleConfig = function (sendAdminDecree) {
const blocks = Sidebar.blocks;
@ -45,43 +44,42 @@ define([
var $description = $(textarea);
let inputLogo = blocks.input({
type: 'file',
accept: 'image/*',
'aria-labelledby': 'cp-admin-logo'
});
type: 'file',
accept: 'image/*',
'aria-labelledby': 'cp-admin-logo'
});
var currentContainer = blocks.block([], 'cp-admin-customize-logo');
let redraw = () => {
var current = h('img', {src: '/api/logo?'+(+new Date())});
$(currentContainer).empty().append(current);
};
redraw();
var currentContainer = blocks.block([], 'cp-admin-customize-logo');
let redraw = () => {
var current = h('img', {src: '/api/logo?'+(+new Date())});
$(currentContainer).empty().append(current);
};
redraw();
var upload = blocks.button('primary', '', Messages.admin_logoButton);
var remove = blocks.button('danger', '', Messages.admin_logoRemoveButton);
var upload = blocks.button('primary', '', Messages.admin_logoButton);
var remove = blocks.button('danger', '', Messages.admin_logoRemoveButton);
let spinnerBlock = blocks.inline();
let spinner = UI.makeSpinner($(spinnerBlock));
let formLogo = blocks.form([
currentContainer,
blocks.block(inputLogo),
blocks.nav([upload, remove, spinnerBlock])
]);
let spinnerBlock = blocks.inline();
let spinner = UI.makeSpinner($(spinnerBlock));
let formLogo = blocks.form([
currentContainer,
blocks.block(inputLogo),
blocks.nav([upload, remove, spinnerBlock])
]);
let $button = $(upload);
let $remove = $(remove);
Util.onClickEnter($button, function () {
let files = input.files;
if (files.length !== 1) {
UI.warn(Messages.error);
return;
}
spinner.spin();
$button.attr('disabled', 'disabled');
let reader = new FileReader();
reader.onloadend = function () {
let $button = $(upload);
let $remove = $(remove);
Util.onClickEnter($button, function () {
let files = input.files;
if (files.length !== 1) {
UI.warn(Messages.error);
return;
}
spinner.spin();
$button.attr('disabled', 'disabled');
let reader = new FileReader();
reader.onloadend = function () {
let dataURL = this.result;
sendAdminDecree('UPLOAD_LOGO', {dataURL}, function (e, response) {
$button.removeAttr('disabled');
@ -99,114 +97,106 @@ define([
UI.log(Messages.saved);
})
};
reader.readAsDataURL(files[0]);
});
UI.confirmButton($remove, {
classes: 'btn-danger',
multiple: true
}, function () {
spinner.spin();
$remove.attr('disabled', 'disabled');
};
reader.readAsDataURL(files[0]);
});
UI.confirmButton($remove, {
classes: 'btn-danger',
multiple: true
}, function () {
spinner.spin();
$remove.attr('disabled', 'disabled');
sendAdminDecree('REMOVE_LOGO', {}, function (e, response) {
$remove.removeAttr('disabled');
if (err) {
UI.warn(Messages.error);
console.error(err, response);
spinner.hide();
return;
}
redraw();
spinner.done();
UI.log(Messages.saved);
});
sendAdminDecree('REMOVE_LOGO', {}, function (e, response) {
$remove.removeAttr('disabled');
if (err) {
UI.warn(Messages.error);
console.error(err, response);
spinner.hide();
return;
}
redraw();
spinner.done();
UI.log(Messages.saved);
});
});
let inputColor = blocks.input({
type: 'color',
value: (Instance && Instance.color) || '#0087FF'
type: 'color',
value: (Instance && Instance.color) || '#0087FF'
});
let label = blocks.labelledInput(Messages.admin_colorPick, inputColor);
let current = blocks.block([], 'cp-admin-color-current');
let labelCurrent = blocks.labelledInput(Messages.admin_colorCurrent, current);
let preview = blocks.block([
blocks.block([
blocks.link('CryptPad', '/admin/#customize'),
blocks.button('primary', 'fa-floppy-o', Messages.settings_save),
blocks.button('secondary', 'fa-floppy-o', Messages.settings_save)
], 'cp-admin-color-preview-dark cp-sidebar-flex-block'),
blocks.block([
blocks.link('CryptPad', '/admin/#customize'),
blocks.button('primary', 'fa-floppy-o', Messages.settings_save),
blocks.button('secondary', 'fa-floppy-o', Messages.settings_save)
], 'cp-admin-color-preview-light cp-sidebar-flex-block')
], 'cp-admin-color-preview');
let labelPreview = blocks.labelledInput(Messages.admin_colorPreview, preview);
let $preview = $(preview);
let removeColor = blocks.button('danger', '', Messages.admin_logoRemoveButton);
let $removeColor = $(removeColor);
let setColor = (color, done) => {
sendAdminDecree('CHANGE_COLOR', {color}, function (e, response) {
if (err) {
UI.warn(Messages.error);
console.error(err, response);
done(false);
return;
}
done(true);
UI.log(Messages.saved);
});
let label = blocks.labelledInput(Messages.admin_colorPick, inputColor);
let current = blocks.block([], 'cp-admin-color-current');
let labelCurrent = blocks.labelledInput(Messages.admin_colorCurrent, current);
let preview = blocks.block([
blocks.block([
blocks.link('CryptPad', '/admin/#customize'),
blocks.button('primary', 'fa-floppy-o', Messages.settings_save),
blocks.button('secondary', 'fa-floppy-o', Messages.settings_save)
], 'cp-admin-color-preview-dark cp-sidebar-flex-block'),
blocks.block([
blocks.link('CryptPad', '/admin/#customize'),
blocks.button('primary', 'fa-floppy-o', Messages.settings_save),
blocks.button('secondary', 'fa-floppy-o', Messages.settings_save)
], 'cp-admin-color-preview-light cp-sidebar-flex-block')
], 'cp-admin-color-preview');
let labelPreview = blocks.labelledInput(Messages.admin_colorPreview, preview);
let $preview = $(preview);
};
let removeColor = blocks.button('danger', '', Messages.admin_logoRemoveButton);
let $removeColor = $(removeColor);
let btn = blocks.activeButton('primary', '',
Messages.admin_colorChange, (done) => {
let color = $input.val();
setColor(color, done);
});
let setColor = (color, done) => {
sendAdminDecree('CHANGE_COLOR', {color}, function (e, response) {
if (err) {
UI.warn(Messages.error);
console.error(err, response);
done(false);
return;
}
done(true);
UI.log(Messages.saved);
let $inputColor = $(inputColor).on('change', () => {
require(['/lib/less.min.js'], (Less) => {
let color = $inputColor.val();
let lColor = Less.color(color.slice(1));
let lighten = Less.functions.functionRegistry._data.lighten;
let lightColor = lighten(lColor, {value:30}).toRGB();
$preview.find('.btn-primary').css({
'background-color': color
});
};
let btn = blocks.activeButton('primary', '',
Messages.admin_colorChange, (done) => {
let color = $input.val();
setColor(color, done);
});
let $inputColor = $(inputColor).on('change', () => {
require(['/lib/less.min.js'], (Less) => {
let color = $inputColor.val();
let lColor = Less.color(color.slice(1));
let lighten = Less.functions.functionRegistry._data.lighten;
let lightColor = lighten(lColor, {value:30}).toRGB();
$preview.find('.btn-primary').css({
'background-color': color
});
$preview.find('.cp-admin-color-preview-dark .btn-secondary').css({
'border-color': lightColor,
'color': lightColor,
});
$preview.find('.cp-admin-color-preview-light .btn-secondary').css({
'border-color': color,
'color': color,
});
$preview.find('.cp-admin-color-preview-dark a').attr('style', `color: ${lightColor} !important`);
$preview.find('.cp-admin-color-preview-light a').attr('style', `color: ${color} !important`);
$preview.find('.cp-admin-color-preview-dark .btn-secondary').css({
'border-color': lightColor,
'color': lightColor,
});
$preview.find('.cp-admin-color-preview-light .btn-secondary').css({
'border-color': color,
'color': color,
});
$preview.find('.cp-admin-color-preview-dark a').attr('style', `color: ${lightColor} !important`);
$preview.find('.cp-admin-color-preview-light a').attr('style', `color: ${color} !important`);
});
});
UI.confirmButton($removeColor, {
classes: 'btn-danger',
multiple: true
}, function () {
$removeColor.attr('disabled', 'disabled');
setColor('', () => {});
});
// let form = blocks.form([
// labelCurrent,
// label
// ], blocks.nav([btn, remove, btn.spinner]));
UI.confirmButton($removeColor, {
classes: 'btn-danger',
multiple: true
}, function () {
$removeColor.attr('disabled', 'disabled');
setColor('', () => {});
});
var button = blocks.activeButton('primary', '', Messages.settings_save, function (done) {
sendAdminDecree('SET_INSTANCE_NAME', [$input.val().trim()], function (e, response) {
if (e || response.error) {
UI.warn(Messages.error);
$input.val('');
@ -220,7 +210,6 @@ define([
})
sendAdminDecree('SET_INSTANCE_DESCRIPTION', [$description.val().trim()], function (e, response) {
if (e || response.error) {
UI.warn(Messages.error);
$input.val('');
@ -260,7 +249,6 @@ define([
}
AppConfigScreen.mfaRegistrationScreen = function(sendAdminDecree) {
var restrict = blocks.activeCheckbox({
key: 'registration',
getState: function () {
@ -268,19 +256,18 @@ define([
},
query: function (val, setState) {
sendAdminDecree('RESTRICT_REGISTRATION', [val], function (e, response) {
if (e || response.error) {
UI.warn(Messages.error);
$input.val('');
console.error(e, response);
done(false);
return;
}
// flushCache();
done(true);
UI.log(Messages._getKey('ui_saved', [Messages.admin_appSelection]));
if (e || response.error) {
UI.warn(Messages.error);
$input.val('');
console.error(e, response);
done(false);
return;
}
// flushCache();
done(true);
UI.log(Messages._getKey('ui_saved', [Messages.admin_appSelection]));
})
})
},
});
@ -290,9 +277,7 @@ define([
return false
},
query: function (val, setState) {
sendAdminDecree('ENFORCE_MFA', [val], function (e, response) {
if (e || response.error) {
UI.warn(Messages.error);
$input.val('');
@ -316,7 +301,6 @@ define([
var form = blocks.form([restrict, forceMFA], [button])
return form
}
@ -324,7 +308,6 @@ define([
const blocks = Sidebar.blocks;
const grid = blocks.block([], 'cp-admin-customize-apps-grid');
const allApps = ['pad', 'code', 'kanban', 'slide', 'sheet', 'form', 'whiteboard', 'diagram'];
const availableApps = []
@ -350,7 +333,6 @@ define([
var save = blocks.activeButton('primary', '', Messages.settings_save, function (done) {
sendAdminDecree('DISABLE_APPS', availableApps, function (e, response) {
if (e || response.error) {
UI.warn(Messages.error);
$input.val('');
@ -381,12 +363,10 @@ define([
append();
});
let form = blocks.form([
grid
], blocks.nav([save]));
return form
}

View File

@ -222,8 +222,6 @@ define([
showTitleScreen(sendAdminDecree)
// showAppScreen(sendAdminDecree)
});
};