Onionr/onionr/static-data/www/shared/configeditor.js

56 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-04-29 02:08:10 +00:00
/*
Onionr - Private P2P Communication
2019-04-29 02:08:10 +00:00
This file is for configuration editing in the web interface
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2019-04-27 15:43:16 +00:00
var saveBtns = document.getElementsByClassName('saveConfig')
var saveBtn = document.getElementsByClassName('saveConfig')[0]
var configEditor = document.getElementsByClassName('configEditor')[0]
var config = {}
fetch('/config/get', {
headers: {
"token": webpass
}})
2019-04-29 02:08:10 +00:00
.then((resp) => resp.text()) // Transform the data into text
2019-04-27 15:43:16 +00:00
.then(function(resp) {
2019-04-29 02:08:10 +00:00
configEditor.value = resp
config = JSON.parse(resp) //parse here so we can set the text field to pretty json
2019-04-27 15:43:16 +00:00
})
saveBtn.onclick = function(){
2019-04-29 02:08:10 +00:00
var postData = configEditor.value
try {
JSON.parse(postData)
} catch (e) {
alert('Configuration is not valid JSON')
return false
}
fetch('/config/setall', {
method: 'POST',
body: postData,
headers: {
"content-type": "application/json",
"token": webpass
}})
.then((resp) => resp.text()) // Transform the data into text
.then(function(data) {
2019-09-17 06:56:13 +00:00
PNotify.success({
text: 'Config saved'
})
2019-04-29 02:08:10 +00:00
})
2019-04-27 15:43:16 +00:00
}