2020-08-27 17:21:34 +02:00
|
|
|
import {api} from './Common/Api';
|
2020-05-17 13:39:01 +02:00
|
|
|
import './Manager/App.scss';
|
|
|
|
|
2020-04-26 11:36:41 +02:00
|
|
|
declare const OCP: any;
|
|
|
|
|
|
|
|
$(() => {
|
2020-05-17 13:39:01 +02:00
|
|
|
function generateWarningElement(message: string) {
|
|
|
|
return $(`<div id="bbb-warning"><span class="icon icon-error-color icon-visible"></span> ${message}</div>`);
|
|
|
|
}
|
|
|
|
|
|
|
|
function generateSuccessElement(message: string) {
|
|
|
|
return $(`<div id="bbb-success"><span class="icon icon-checkmark-color icon-visible"></span> ${message}</div>`);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function checkServer(url: string, secret: string) {
|
|
|
|
const result = await api.checkServer(url, secret);
|
|
|
|
|
|
|
|
if (result === 'success') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
throw result;
|
|
|
|
}
|
|
|
|
|
|
|
|
function checkPasswordConfirmation() {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
if (OC.PasswordConfirmation && OC.PasswordConfirmation.requiresPasswordConfirmation()) {
|
|
|
|
OC.PasswordConfirmation.requirePasswordConfirmation(() => resolve());
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function saveSettings(url: string, secret: string) {
|
|
|
|
url += url.endsWith('/') ? '' : '/';
|
|
|
|
|
|
|
|
await checkServer(url, secret);
|
|
|
|
await checkPasswordConfirmation();
|
|
|
|
|
|
|
|
OCP.AppConfig.setValue('bbb', 'api.url', url);
|
|
|
|
OCP.AppConfig.setValue('bbb', 'api.secret', secret);
|
|
|
|
}
|
|
|
|
|
2020-04-27 16:47:32 +02:00
|
|
|
$('#bbb-settings form').submit(function (ev) {
|
|
|
|
ev.preventDefault();
|
2020-04-26 11:36:41 +02:00
|
|
|
|
2020-05-17 13:39:01 +02:00
|
|
|
$('#bbb-result').empty();
|
|
|
|
|
|
|
|
saveSettings(this['api.url'].value, this['api.secret'].value).then(() => {
|
|
|
|
const successElement = generateSuccessElement(t('bbb', 'Settings saved'));
|
|
|
|
|
2020-08-26 10:54:26 +02:00
|
|
|
setTimeout(() => {
|
|
|
|
$('#bbb-result').empty();
|
|
|
|
}, 3000);
|
|
|
|
|
2020-05-17 13:39:01 +02:00
|
|
|
$('#bbb-result').append(successElement);
|
|
|
|
}).catch(err => {
|
|
|
|
let message = t('bbb', 'Unexpected error occurred');
|
|
|
|
|
|
|
|
if (err === 'invalid-url') {
|
2020-05-22 09:33:30 +02:00
|
|
|
message = t('bbb', 'API URL is invalid');
|
2020-05-17 13:39:01 +02:00
|
|
|
} else if (err === 'invalid-secret') {
|
|
|
|
message = t('bbb', 'API secret is invalid');
|
|
|
|
}
|
|
|
|
|
|
|
|
const warningElement = generateWarningElement(message);
|
|
|
|
|
|
|
|
$('#bbb-result').append(warningElement);
|
|
|
|
});
|
2020-04-27 16:50:45 +02:00
|
|
|
});
|
2020-08-26 10:57:31 +02:00
|
|
|
|
|
|
|
$<HTMLInputElement>('#bbb-settings [name="app.navigation"]').change((ev) => {
|
|
|
|
ev.preventDefault();
|
|
|
|
|
|
|
|
console.log('checkbox changed to', ev.target.checked);
|
|
|
|
|
|
|
|
OCP.AppConfig.setValue('bbb', 'app.navigation', ev.target.checked);
|
|
|
|
});
|
2020-05-22 09:33:30 +02:00
|
|
|
});
|