diff --git a/fHDHR_web/api/channels.py b/fHDHR_web/api/channels.py
index b334234..978d0cc 100644
--- a/fHDHR_web/api/channels.py
+++ b/fHDHR_web/api/channels.py
@@ -114,7 +114,7 @@ class Channels():
self.fhdhr.device.channels.set_channel_status("id", channel_id, updatedict)
elif method == "modify":
- channels_list = eval(request.form.get('channels', []))
+ channels_list = json.loads(request.form.get('channels', []))
for channel in channels_list:
updatedict = {}
for key in list(channel.keys()):
diff --git a/fHDHR_web/brython/brython_code.py b/fHDHR_web/brython/brython_code.py
index 0012967..04ed0eb 100644
--- a/fHDHR_web/brython/brython_code.py
+++ b/fHDHR_web/brython/brython_code.py
@@ -1,18 +1,85 @@
from browser import document, bind # alert, window
+import json
-@bind("#enable_button", "click")
-def enable_all(event):
- for element in document.get(selector='input[type="checkbox"]'):
- if element.name.endswith("enabled"):
- if document["enable_button"].value == "0":
- element.checked = False
- element.value = False
+def chan_edit_data(items, channel_id):
+
+ chanlist = []
+ chandict = {}
+
+ for element in items:
+ if element.name == "id":
+ if len(chandict.keys()) >= 2 and "id" in list(chandict.keys()):
+ chanlist.append(chandict)
+ chandict = {"id": element.value}
+ if element.type == "checkbox":
+ if element.name in ["enabled"]:
+ save_val = element.checked
else:
- element.checked = True
- element.value = True
+ save_val = int(element.checked)
+ else:
+ save_val = element.value
+ if element.name != "id":
+ cur_value = element.placeholder
+ if element.type == "checkbox":
+ if element.name in ["enabled"]:
+ cur_value = element.placeholder
+ else:
+ cur_value = int(element.placeholder)
+ if str(save_val) != str(cur_value):
+ chandict[element.name] = save_val
- if document["enable_button"].value == "0":
+ if channel_id != "all":
+ chanlist == [x for x in chanlist if x["id"] == channel_id]
+
+ return chanlist
+
+
+def chan_edit_postform(chanlist):
+ postForm = document.createElement('form')
+ postForm.method = "POST"
+ postForm.action = "/api/channels?method=modify&redirect=/channels_editor"
+ postForm.setRequestHeader = "('Content-Type', 'application/json')"
+
+ postData = document.createElement('input')
+ postData.type = 'hidden'
+ postData.name = "channels"
+ postData.value = json.dumps(chanlist)
+
+ postForm.appendChild(postData)
+ document.body.appendChild(postForm)
+ return postForm
+
+
+@bind("#Chan_Edit_Reset", "submit")
+def chan_edit_reset(evt):
+ chanlist = chan_edit_data(
+ document.select(".reset"),
+ str(evt.currentTarget.children[0].id).replace("reset_", ""))
+ postForm = chan_edit_postform(chanlist)
+ postForm.submit()
+ evt.preventDefault()
+
+
+@bind("#Chan_Edit_Modify", "submit")
+def chan_edit_modify(evt):
+ chanlist = chan_edit_data(
+ document.select(".channels"),
+ str(evt.currentTarget.children[0].id).replace("update_", ""))
+ postForm = chan_edit_postform(chanlist)
+ postForm.submit()
+ evt.preventDefault()
+
+
+@bind("#Chan_Edit_Enable_Toggle", "click")
+def chan_edit_enable(event):
+ enable_bool = bool(int(document["enable_button"].value))
+ for element in document.get(selector='input[type="checkbox"]'):
+ if element.name == "enabled":
+ element.checked = enable_bool
+ element.value = enable_bool
+
+ if not enable_bool:
document["enable_button"].value = "1"
document["enable_button"].text = "Enable All"
else:
@@ -20,41 +87,17 @@ def enable_all(event):
document["enable_button"].text = "Disable All"
-@bind("#chanSubmit", "submit")
-def submit_fixup(evt):
+@bind("#Chan_Edit_Favorite_Toggle", "click")
+def chan_edit_favorite(event):
+ enable_bool = bool(int(document["favorite_button"].value))
for element in document.get(selector='input[type="checkbox"]'):
- if element.name.endswith("enabled"):
- if element.checked is False:
- element.checked = True
- element.value = False
- if element.name.endswith("favorite"):
- if element.checked is False:
- element.checked = True
- element.value = 0
+ if element.name == "favorite":
+ element.checked = enable_bool
+ element.value = int(enable_bool)
- items = document.select(".channels")
- chanlist = []
- chandict = {}
-
- for element in items:
- if element.name == "id":
- if len(chandict.keys()):
- chanlist.append(chandict)
- chandict = {}
- chandict[element.name] = element.value
- element.clear()
-
- postForm = document.createElement('form')
- postData = document.createElement('input')
- postForm.method = "POST"
- postForm.action = "/api/channels?method=modify&redirect=/channels_editor"
- postForm.setRequestHeader = "('Content-Type', 'application/json')"
- postData.name = "channels"
- postData.value = chanlist
- postForm.appendChild(postData)
-
- document.body.appendChild(postForm)
-
- postForm.submit()
-
- evt.preventDefault()
+ if not enable_bool:
+ document["favorite_button"].value = "1"
+ document["favorite_button"].text = "Favorite All"
+ else:
+ document["favorite_button"].value = "0"
+ document["favorite_button"].text = "Unfavorite All"
diff --git a/fHDHR_web/templates/channels_editor.html b/fHDHR_web/templates/channels_editor.html
index 05854b6..ae32f4c 100644
--- a/fHDHR_web/templates/channels_editor.html
+++ b/fHDHR_web/templates/channels_editor.html
@@ -4,13 +4,33 @@
{{ fhdhr.config.dict["fhdhr"]["friendlyname"] }} Channels Editor
-
-
-
+
+
+
+
+ |
+
+ |
+
+
+ |
+
+
+
+ |
+
+
+
+