refactoring

This commit is contained in:
zuzanna-maria 2024-05-28 17:48:59 +01:00
parent 8a36160729
commit f03a05cac0
2 changed files with 212 additions and 215 deletions

View File

@ -27,70 +27,7 @@ define([
const blocks = Sidebar.blocks; const blocks = Sidebar.blocks;
AppConfigScreen.mfaRegistrationScreen = function(sendAdminDecree) { AppConfigScreen.titleConfig = function (sendAdminDecree) {
console.log('mreao1')
var restrict = blocks.activeCheckbox({
key: 'registration',
getState: function () {
return false
},
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]));
// })
},
});
var forceMFA = blocks.activeCheckbox({
key: 'forcemfa',
getState: function () {
return false
},
query: function (val, setState) {
// sendAdminDecree('ENFORCE_MFA', [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]));
// })
},
});
var button = blocks.activeButton('primary', '', Messages.settings_save, function (done) {
// document.location.href = '/drive/';
return;
})
var form = blocks.form([restrict, forceMFA], [button])
return form
}
AppConfigScreen.titleConfig = function (sendAdminDecree) {
const blocks = Sidebar.blocks; const blocks = Sidebar.blocks;
@ -145,7 +82,6 @@ define([
let reader = new FileReader(); let reader = new FileReader();
reader.onloadend = function () { reader.onloadend = function () {
console.log('belp')
let dataURL = this.result; let dataURL = this.result;
sendAdminDecree('UPLOAD_LOGO', {dataURL}, function (e, response) { sendAdminDecree('UPLOAD_LOGO', {dataURL}, function (e, response) {
$button.removeAttr('disabled'); $button.removeAttr('disabled');
@ -268,37 +204,36 @@ define([
// ], blocks.nav([btn, remove, btn.spinner])); // ], blocks.nav([btn, remove, btn.spinner]));
var button = blocks.activeButton('primary', '', Messages.settings_save, function (done) { var button = blocks.activeButton('primary', '', Messages.settings_save, function (done) {
console.log('mreao')
// sendAdminDecree('SET_INSTANCE_NAME', [$input.val().trim()], function (e, response) { sendAdminDecree('SET_INSTANCE_NAME', [$input.val().trim()], function (e, response) {
// if (e || response.error) { if (e || response.error) {
// UI.warn(Messages.error); UI.warn(Messages.error);
// $input.val(''); $input.val('');
// console.error(e, response); console.error(e, response);
// done(false); done(false);
// return; return;
// } }
// // flushCache(); // flushCache();
// done(true); done(true);
// UI.log(Messages._getKey('ui_saved', [Messages.admin_appSelection])); UI.log(Messages._getKey('ui_saved', [Messages.admin_appSelection]));
// }) })
// sendAdminDecree('SET_INSTANCE_DESCRIPTION', [$description.val().trim()], function (e, response) { sendAdminDecree('SET_INSTANCE_DESCRIPTION', [$description.val().trim()], function (e, response) {
// if (e || response.error) { if (e || response.error) {
// UI.warn(Messages.error); UI.warn(Messages.error);
// $input.val(''); $input.val('');
// console.error(e, response); console.error(e, response);
// done(false); done(false);
// return; return;
// } }
// // flushCache(); // flushCache();
// done(true); done(true);
// UI.log(Messages._getKey('ui_saved', [Messages.admin_appSelection])); UI.log(Messages._getKey('ui_saved', [Messages.admin_appSelection]));
// }) })
var nextPageForm = AppConfigScreen.appConfig() var nextPageForm = AppConfigScreen.appConfig(sendAdminDecree)
var elem = document.createElement('div'); var elem = document.createElement('div');
elem.setAttribute('id', 'cp-loading'); elem.setAttribute('id', 'cp-loading');
let frame = h('div.configscreen', {style: 'width: 70%; height: 75%; background-color: white'}, nextPageForm) let frame = h('div.configscreen', {style: 'width: 70%; height: 75%; background-color: white'}, nextPageForm)
@ -324,6 +259,67 @@ define([
} }
AppConfigScreen.mfaRegistrationScreen = function(sendAdminDecree) {
var restrict = blocks.activeCheckbox({
key: 'registration',
getState: function () {
return false
},
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]));
})
},
});
var forceMFA = blocks.activeCheckbox({
key: 'forcemfa',
getState: function () {
return false
},
query: function (val, setState) {
sendAdminDecree('ENFORCE_MFA', [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]));
})
},
});
var button = blocks.activeButton('primary', '', Messages.settings_save, function (done) {
document.location.href = '/drive/';
return;
})
var form = blocks.form([restrict, forceMFA], [button])
return form
}
AppConfigScreen.appConfig = function (sendAdminDecree) { AppConfigScreen.appConfig = function (sendAdminDecree) {
const blocks = Sidebar.blocks; const blocks = Sidebar.blocks;
@ -353,23 +349,22 @@ define([
}); });
var save = blocks.activeButton('primary', '', Messages.settings_save, function (done) { var save = blocks.activeButton('primary', '', Messages.settings_save, function (done) {
// sendAdminDecree('DISABLE_APPS', availableApps, function (e, response) { sendAdminDecree('DISABLE_APPS', availableApps, function (e, response) {
// if (e || response.error) { if (e || response.error) {
// UI.warn(Messages.error); UI.warn(Messages.error);
// $input.val(''); $input.val('');
// console.error(e, response); console.error(e, response);
// done(false); done(false);
// return; return;
// } }
// // flushCache(); // flushCache();
// done(true); done(true);
// UI.log(Messages._getKey('ui_saved', [Messages.admin_appSelection])); UI.log(Messages._getKey('ui_saved', [Messages.admin_appSelection]));
// window.location.href = '/drive/';
// }) })
UI.log('Messages._getKey(, [Messages.admin_appSelection])'); UI.log('Messages._getKey(, [Messages.admin_appSelection])');
var nextPageForm = AppConfigScreen.mfaRegistrationScreen() var nextPageForm = AppConfigScreen.mfaRegistrationScreen(sendAdminDecree)
var elem = document.createElement('div'); var elem = document.createElement('div');
elem.setAttribute('id', 'cp-loading'); elem.setAttribute('id', 'cp-loading');
let frame = h('div.configscreen', {style: 'width: 70%; height: 75%; background-color: white'}, nextPageForm) let frame = h('div.configscreen', {style: 'width: 70%; height: 75%; background-color: white'}, nextPageForm)

View File

@ -148,138 +148,140 @@ define([
} }
var registerClick = function () { var registerClick = function () {
showTitleScreen() // showTitleScreen()
document.location.href = '/drive/'; // document.location.href = '/drive/';
// var uname = $uname.val().trim(); var uname = $uname.val().trim();
// // trim whitespace surrounding the username since it is otherwise included in key derivation // trim whitespace surrounding the username since it is otherwise included in key derivation
// // most people won't realize that its presence is significant // most people won't realize that its presence is significant
// $uname.val(uname); $uname.val(uname);
// var passwd = $passwd.val(); var passwd = $passwd.val();
// var confirmPassword = $confirm.val(); var confirmPassword = $confirm.val();
// if (!token) { token = $token.val().trim(); } if (!token) { token = $token.val().trim(); }
// var shouldImport = false; var shouldImport = false;
// var doesAccept; var doesAccept;
// try { try {
// // if this throws there's either a horrible bug (which someone will report) // if this throws there's either a horrible bug (which someone will report)
// // or the instance admins did not configure a terms page. // or the instance admins did not configure a terms page.
// doesAccept = true; doesAccept = true;
// } catch (err) { } catch (err) {
// console.error(err); console.error(err);
// } }
// if (Cred.isEmail(uname) && !I_REALLY_WANT_TO_USE_MY_EMAIL_FOR_MY_USERNAME) { if (Cred.isEmail(uname) && !I_REALLY_WANT_TO_USE_MY_EMAIL_FOR_MY_USERNAME) {
// var emailWarning = [ var emailWarning = [
// Messages.register_emailWarning0, Messages.register_emailWarning0,
// br(), br(), br(), br(),
// Messages.register_emailWarning1, Messages.register_emailWarning1,
// br(), br(), br(), br(),
// Messages.register_emailWarning2, Messages.register_emailWarning2,
// br(), br(), br(), br(),
// Messages.register_emailWarning3, Messages.register_emailWarning3,
// ]; ];
// Feedback.send("EMAIL_USERNAME_WARNING", true); Feedback.send("EMAIL_USERNAME_WARNING", true);
// return void UI.confirm(emailWarning, function (yes) { return void UI.confirm(emailWarning, function (yes) {
// if (!yes) { return; } if (!yes) { return; }
// I_REALLY_WANT_TO_USE_MY_EMAIL_FOR_MY_USERNAME = true; I_REALLY_WANT_TO_USE_MY_EMAIL_FOR_MY_USERNAME = true;
// registerClick(); registerClick();
// }); });
// } }
// /* basic validation */ /* basic validation */
// if (!Cred.isLongEnoughPassword(passwd)) { if (!Cred.isLongEnoughPassword(passwd)) {
// var warning = Messages._getKey('register_passwordTooShort', [ var warning = Messages._getKey('register_passwordTooShort', [
// Cred.MINIMUM_PASSWORD_LENGTH Cred.MINIMUM_PASSWORD_LENGTH
// ]); ]);
// return void UI.alert(warning); return void UI.alert(warning);
// } }
// if (passwd !== confirmPassword) { // do their passwords match? if (passwd !== confirmPassword) { // do their passwords match?
// return void UI.alert(Messages.register_passwordsDontMatch); return void UI.alert(Messages.register_passwordsDontMatch);
// } }
// if (Pages.customURLs.terms && !doesAccept) { // do they accept the terms of service? (if they exist) if (Pages.customURLs.terms && !doesAccept) { // do they accept the terms of service? (if they exist)
// return void UI.alert(Messages.register_mustAcceptTerms); return void UI.alert(Messages.register_mustAcceptTerms);
// } }
// let startOnboarding = function (network, proxy) { let startOnboarding = function (network, proxy) {
// Rpc.create(network, proxy.edPrivate, proxy.edPublic, function (e, rpc) { Rpc.create(network, proxy.edPrivate, proxy.edPublic, function (e, rpc) {
// if (e) { if (e) {
// // TODO: handle error // TODO: handle error
// return; return;
// } }
// let sendAdminDecree = function (command, data, callback) { let sendAdminDecree = function (command, data, callback) {
// var params = ['ADMIN_DECREE', [command, data]]; var params = ['ADMIN_DECREE', [command, data]];
// rpc.send('ADMIN', params, callback) rpc.send('ADMIN', params, callback)
// }; };
// showAppScreen(sendAdminDecree) showTitleScreen(sendAdminDecree)
// showAppScreen(sendAdminDecree)
// }); });
// }; };
// setTimeout(function () { setTimeout(function () {
// var span = h('span', [ var span = h('span', [
// h('h2', [ h('h2', [
// h('i.fa.fa-warning'), h('i.fa.fa-warning'),
// ' ', ' ',
// Messages.register_warning, Messages.register_warning,
// ]), ]),
// Messages.register_warning_note Messages.register_warning_note
// ]); ]);
// UI.confirm(span, UI.confirm(span,
// function (yes) { function (yes) {
// if (!yes) { return; } if (!yes) { return; }
// Login.loginOrRegisterUI({ Login.loginOrRegisterUI({
// uname, uname,
// passwd, passwd,
// isRegister: true, isRegister: true,
// onOTP: UI.getOTPScreen, onOTP: UI.getOTPScreen,
// shouldImport, shouldImport,
// cb: function (data) { cb: function (data) {
// var proxy = data.proxy; var proxy = data.proxy;
// if (!proxy || !proxy.edPublic) { UI.alert(Messages.error); return true; } if (!proxy || !proxy.edPublic) { UI.alert(Messages.error); return true; }
// Rpc.createAnonymous(data.network, function (e, call) { Rpc.createAnonymous(data.network, function (e, call) {
// if (e) { UI.alert(Messages.error); return console.error(e); } if (e) { UI.alert(Messages.error); return console.error(e); }
// var anon_rpc = call; var anon_rpc = call;
// anon_rpc.send('ADD_FIRST_ADMIN', { anon_rpc.send('ADD_FIRST_ADMIN', {
// token: token, token: token,
// edPublic: proxy.edPublic edPublic: proxy.edPublic
// }, function (e) { }, function (e) {
// if (e) { UI.alert(Messages.error); return console.error(e); } if (e) { UI.alert(Messages.error); return console.error(e); }
// startOnboarding(data.network, proxy); startOnboarding(data.network, proxy);
// }); });
// }); });
// return true; return true;
// } }
// }); });
// }, { }, {
// ok: Messages.register_writtenPassword, ok: Messages.register_writtenPassword,
// cancel: Messages.register_cancel, cancel: Messages.register_cancel,
// /* If we're certain that we aren't using these "*Class" APIs /* If we're certain that we aren't using these "*Class" APIs
// anywhere else then we can deprecate them and make this a anywhere else then we can deprecate them and make this a
// custom modal in common-interface (or here). */ custom modal in common-interface (or here). */
// cancelClass: 'btn.btn-cancel.btn-register', cancelClass: 'btn.btn-cancel.btn-register',
// okClass: 'btn.btn-danger.btn-register', okClass: 'btn.btn-danger.btn-register',
// reverseOrder: true, reverseOrder: true,
// done: function ($dialog) { done: function ($dialog) {
// $dialog.find('> div').addClass('half'); $dialog.find('> div').addClass('half');
// }, },
// }); });
// }, 150); }, 150);
}; };
$register.click(registerClick); $register.click(registerClick);