mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Working config.json from page
This commit is contained in:
parent
bea48d9059
commit
8d8b065e41
@ -1724,19 +1724,30 @@ class PanelHandler(BaseHandler):
|
|||||||
try:
|
try:
|
||||||
data = {}
|
data = {}
|
||||||
with open(self.helper.settings_file, "r", encoding="utf-8") as f:
|
with open(self.helper.settings_file, "r", encoding="utf-8") as f:
|
||||||
print("open")
|
|
||||||
keys = json.load(f).keys()
|
keys = json.load(f).keys()
|
||||||
|
this_uuid = self.get_argument("uuid")
|
||||||
for key in keys:
|
for key in keys:
|
||||||
print(self.get_argument(key))
|
arg_data = self.get_argument(key)
|
||||||
data[key] = self.get_argument(key)
|
if arg_data.startswith(this_uuid):
|
||||||
print("data:", data)
|
arg_data = arg_data.split(",")
|
||||||
"""
|
arg_data.pop(0)
|
||||||
|
data[key] = arg_data
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
data[key] = int(arg_data)
|
||||||
|
except:
|
||||||
|
if arg_data == "True":
|
||||||
|
data[key] = True
|
||||||
|
elif arg_data == "False":
|
||||||
|
data[key] = False
|
||||||
|
else:
|
||||||
|
data[key] = arg_data
|
||||||
with open(self.helper.settings_file, "w", encoding="utf-8") as f:
|
with open(self.helper.settings_file, "w", encoding="utf-8") as f:
|
||||||
json.dump(data, f, indent=4)
|
json.dump(data, f, indent=4)
|
||||||
"""
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.critical(
|
logger.critical(
|
||||||
f"Config File Error: Unable to read {self.helper.settings_file} due to {e}"
|
"Config File Error: Unable to read "
|
||||||
|
f"{self.helper.settings_file} due to {e}"
|
||||||
)
|
)
|
||||||
|
|
||||||
self.redirect("/panel/config_json")
|
self.redirect("/panel/config_json")
|
||||||
|
@ -46,12 +46,9 @@
|
|||||||
<small class="text-muted ml-1">
|
<small class="text-muted ml-1">
|
||||||
</small> </label>
|
</small> </label>
|
||||||
{% if isinstance(item[1], list) %}
|
{% if isinstance(item[1], list) %}
|
||||||
<ul>
|
<br>
|
||||||
{% for li in item[1] %}
|
<textarea value="{{','.join(item[1])}}" type="text" name="{{item[0]}}"
|
||||||
<input style="color: black;" form="config-form" class="form-control" type="text" value="{{li}}"
|
class="list">{{','.join(item[1])}}</textarea>
|
||||||
name="{{item[0]}}" readonly><br />
|
|
||||||
{% end %}
|
|
||||||
</ul>
|
|
||||||
{% elif isinstance(item[1], bool) %}
|
{% elif isinstance(item[1], bool) %}
|
||||||
|
|
||||||
{% if item[1] == True %}
|
{% if item[1] == True %}
|
||||||
@ -107,6 +104,43 @@
|
|||||||
|
|
||||||
{% block js %}
|
{% block js %}
|
||||||
<script>
|
<script>
|
||||||
|
$("#config-form").submit(function (e) {
|
||||||
|
let uuid = uuidv4();
|
||||||
|
var token = getCookie("_xsrf")
|
||||||
|
e.preventDefault();
|
||||||
|
let class_list = document.getElementsByClassName("list");
|
||||||
|
let form_json = convertFormToJSON($("#config-form"));
|
||||||
|
for (let i = 0; i < class_list.length; i++) {
|
||||||
|
let str = String($(class_list.item(i)).val())
|
||||||
|
form_json[$(class_list.item(i)).attr("name")] = uuid + "," + str.replace(/\s/g, '');
|
||||||
|
};
|
||||||
|
form_json['uuid'] = uuid;
|
||||||
|
$.ajax({
|
||||||
|
type: "POST",
|
||||||
|
headers: { 'X-XSRFToken': token },
|
||||||
|
dataType: "json",
|
||||||
|
url: '/panel/config_json',
|
||||||
|
data: form_json,
|
||||||
|
success: function (data) {
|
||||||
|
window.location.reload();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function uuidv4() {
|
||||||
|
return ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c =>
|
||||||
|
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
function convertFormToJSON(form) {
|
||||||
|
const array = $(form).serializeArray(); // Encodes the set of form elements as an array of names and values.
|
||||||
|
const json = {};
|
||||||
|
$.each(array, function () {
|
||||||
|
json[this.name] = this.value || "";
|
||||||
|
});
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
$(document).ready(function () {
|
$(document).ready(function () {
|
||||||
$('[data-toggle="popover"]').popover();
|
$('[data-toggle="popover"]').popover();
|
||||||
if ($(window).width() < 1000) {
|
if ($(window).width() < 1000) {
|
||||||
|
Loading…
Reference in New Issue
Block a user