diff --git a/static/css/create.css b/static/css/create.css index 3ef76fc..e4d0fe7 100644 --- a/static/css/create.css +++ b/static/css/create.css @@ -85,29 +85,19 @@ body { vertical-align: inherit; } -.createTable { - width: 100%; - table-layout: fixed; - border-collapse: separate; - border-spacing: 10px; -} - -.createTable .labelColumn { - width: 200px; -} - -.labelColumn { - vertical-align: center; -} - -.labelColumn strong:after { - content: ":"; +.torrent-form .form-group { + margin-left: 0px; + margin-right: 0px; } .form-group .control-label:after { content: ":"; } +.form-group .control-label.required:after { + content: "*:"; +} + .detectedFiles { max-height: 100px; overflow: auto; diff --git a/static/js/create.js b/static/js/create.js index a6870db..e16a055 100644 --- a/static/js/create.js +++ b/static/js/create.js @@ -118,56 +118,70 @@ function setButtonToFilename(event) { }); } +function setError(element) { + element.classList.add("has-error") + element.remove("has-success") +} + +function setSuccess(element) { + element.classList.add("has-success") + element.classList.remove("has-error") +} + function validateForm() { valid = true - file = document.querySelectorAll("input.file")[0] - category = document.querySelectorAll("#category")[0] - subcategory = document.querySelectorAll("#subcategory")[0] - torrentname = document.querySelectorAll("input.name")[0] - description = document.querySelectorAll("textarea.description")[0] + + /* TODO: Iterate over these to do dynamic requirement checking + form_groups = document.querySelectorAll(".torrent-form .form-group.required") + required_inputs = document.querySelectorAll(".torrent-form input.required") + required_dropdown = document.querySelectorAll(".torrent-form select.dropdown.required") + required_textarea = document.querySelectorAll(".torrent-form textarea.required") + */ + + file = document.querySelector(".torrent-form .file input") + category = document.querySelector("#category") + subcategory = document.querySelector("#subcategory") + torrentname = document.querySelector(".torrent-form .name input") + description = document.querySelector(".torrent-form .description textarea") + + file_label = document.querySelector(".torrent-form .file") + category_label = document.querySelector(".torrent-form .category") + name_label = document.querySelector(".torrent-form .name") + description_label = document.querySelector(".torrent-form .description") + if(file.value.length <= 0) { valid = false - file.parentElement.parentElement.classList.add("has-error") - file.parentElement.parentElement.classList.remove("has-success") + setError(file_label) } else { - file.parentElement.parentElement.classList.add("has-success") - file.parentElement.parentElement.classList.remove("has-error") + setSuccess(file_label) } if(category.value < 0) { valid = false - category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.add("has-error") - category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.remove("has-success") + setError(category_label) } else { - category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.add("has-success") - category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.remove("has-error") + setSuccess(category_label) } if(subcategory.value < 0) { valid = false - category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.add("has-error") - category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.remove("has-success") + setError(category_label) } else { - category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.add("has-success") - category.parentElement.parentElement.parentElement.parentElement.parentElement.parentElement.classList.remove("has-error") + setSuccess(category_label) } if(torrentname.value.length <= 0) { valid = false - torrentname.parentElement.parentElement.classList.add("has-error") - torrentname.parentElement.parentElement.classList.remove("has-success") + setError(name_label) } else { - torrentname.parentElement.parentElement.classList.add("has-success") - torrentname.parentElement.parentElement.classList.remove("has-error") + setSuccess(name_label) } if(description.value.length <= 0) { valid = false - description.parentElement.parentElement.classList.add("has-error") - description.parentElement.parentElement.classList.remove("has-success") + setError(description_label) } else { - description.parentElement.parentElement.classList.add("has-success") - description.parentElement.parentElement.classList.remove("has-error") + setSuccess(description_label) } return valid; diff --git a/templates/create.html b/templates/create.html index fd858c3..eee096e 100644 --- a/templates/create.html +++ b/templates/create.html @@ -25,11 +25,11 @@ vim: ts=2 noexpandtab {% endfor %} {% endif %} -
-
- + +
+
- +
@@ -52,12 +52,12 @@ vim: ts=2 noexpandtab
-
- +
+
- {% for category in categories %} @@ -65,27 +65,27 @@ vim: ts=2 noexpandtab
-
-
- +
+
- +
-
- +
+
-
- +
+
@@ -114,10 +114,10 @@ vim: ts=2 noexpandtab
--> -
- +
+
- +