summaryrefslogtreecommitdiff
path: root/day9/task5/static/js/editForm.js
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2019-07-08 13:29:53 +0400
committerAndrew <saintruler@gmail.com>2019-07-08 13:29:53 +0400
commitd48c3ccb5e273730d2643366ecd6aa0dcb22e6f4 (patch)
tree913bfd818395d1a0aa1ff8835b282e529f8cdafa /day9/task5/static/js/editForm.js
parent67c4adc2d26714ff5c5269be220fff90cec47353 (diff)
Рефакторинг javascript файла.
Diffstat (limited to 'day9/task5/static/js/editForm.js')
-rw-r--r--day9/task5/static/js/editForm.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/day9/task5/static/js/editForm.js b/day9/task5/static/js/editForm.js
new file mode 100644
index 0000000..f3f2bd8
--- /dev/null
+++ b/day9/task5/static/js/editForm.js
@@ -0,0 +1,56 @@
+function showContentBox() {
+ let elem = document.getElementById('backgroundTint');
+ elem.classList.remove('hidden');
+ elem.classList.add('shown');
+
+ elem = document.getElementById('contentBox');
+ elem.classList.remove('hidden');
+ elem.classList.add('shown');
+}
+
+function hideContentBox() {
+ let elem = document.getElementById('backgroundTint');
+ elem.classList.remove('shown');
+ elem.classList.add('hidden');
+
+ elem = document.getElementById('contentBox');
+ elem.classList.remove('shown');
+ elem.classList.add('hidden');
+}
+
+function showForm() {
+ let newEntryBtn = document.getElementById('newEntryBtn');
+ newEntryBtn.style.display = 'none';
+
+ showContentBox();
+ let contentBox = document.getElementById('contentBox');
+ while (contentBox.firstChild)
+ contentBox.removeChild(contentBox.firstChild);
+
+ contentBox.appendChild(elementFromHTML(baseFormFields));
+ return contentBox;
+}
+
+function hideForm() {
+ let newEntryBtn = document.getElementById('newEntryBtn');
+ newEntryBtn.style.display = 'inline';
+
+ let contentBox = document.getElementById('contentBox');
+ while (contentBox.firstChild)
+ contentBox.removeChild(contentBox.firstChild);
+
+ hideContentBox();
+}
+
+function showEditForm() {
+ let contentBox = showForm();
+ contentBox.firstChild.appendChild(elementFromHTML(formEditButtons));
+ contentBox.firstChild.action = '/api/update';
+}
+
+function showCreateForm() {
+ let contentBox = showForm();
+ contentBox.firstChild.appendChild(elementFromHTML(formCreateButtons));
+ contentBox.firstChild.action = '/api/add';
+ document.getElementById('formServiceId').disabled = false;
+}