chartManD commited on
Commit
b5ae423
·
1 Parent(s): ea26a8a

Separacion de js de templates a static

Browse files
tecnicas/static/js/catador-craete.js ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const notifiactions = document.getElementsByClassName("ct-notificacion");
2
+ const inputs = document.getElementsByClassName("ct-inputs-pos-cata");
3
+
4
+ for (let index = 0; index < inputs.length; index++) {
5
+ inputs.item(index).addEventListener("change", hiddenErrorAndMessages);
6
+ }
7
+
8
+ function hiddenErrorAndMessages(e) {
9
+ for (let index = 0; index < notifiactions.length; index++) {
10
+ console.log("Oculto");
11
+ notifiactions.item(index).classList.add("hidden");
12
+ }
13
+ }
tecnicas/static/js/catador-search.js ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const inputs = document.getElementsByClassName("ct-inputs-pos-cata");
2
+ disableInputs();
3
+ setTimeout(() => {
4
+ const notifications = document.getElementsByClassName("ct-notifica");
5
+ for (let index = 0; index < notifications.length; index++) {
6
+ notifications.item(index).classList.add("hidden");
7
+ }
8
+ }, 1800);
9
+
10
+ function disableInputs() {
11
+ for (let index = 0; index < inputs.length; index++) {
12
+ inputs.item(index).disabled = true;
13
+ }
14
+ }
15
+
16
+ function enableInputs() {
17
+ for (let index = 0; index < inputs.length; index++) {
18
+ inputs.item(index).disabled = false;
19
+ }
20
+ changeButtons();
21
+ }
22
+
23
+ function changeButtons(callBack = function () {}) {
24
+ const btnUpdate = document.getElementsByClassName("ct-btn-actualizar")[0];
25
+ const btnSave = document.getElementsByClassName("ct-btn-guardar")[0];
26
+ const btnCancel = document.getElementsByClassName("ct-btn-cancel")[0];
27
+
28
+ if (btnUpdate.classList.contains("hidden")) {
29
+ btnUpdate.classList.remove("hidden");
30
+ btnSave.classList.add("hidden");
31
+ btnCancel.classList.add("hidden");
32
+ } else {
33
+ btnUpdate.classList.add("hidden");
34
+ btnSave.classList.remove("hidden");
35
+ btnCancel.classList.remove("hidden");
36
+ }
37
+
38
+ callBack();
39
+ }
tecnicas/static/js/panel-basic.js ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const descriptons = {
2
+ estructurada: ["Establece número de segmentos:", "Puede ser 5, 7 o 9"],
3
+ continua: ["Establece la longitud de la escala:", "Puede ser 9, 12 o 15"],
4
+ };
5
+
6
+ let labels;
7
+
8
+ let pSize;
9
+ let iSize;
10
+
11
+ initPanel();
12
+
13
+ function initPanel() {
14
+ initRadios();
15
+ }
16
+
17
+ function initRadios() {
18
+ labels = document.getElementsByClassName("ct-radio-escala");
19
+ pSize = document
20
+ .getElementsByClassName("ct-size-scale")
21
+ .item(0)
22
+ .getElementsByTagName("p")[0];
23
+ iSize = document
24
+ .getElementsByClassName("ct-size-scale")
25
+ .item(0)
26
+ .getElementsByTagName("input")[0];
27
+
28
+ pSize.textContent = descriptons["estructurada"][0];
29
+ iSize.placeholder = descriptons["estructurada"][1];
30
+
31
+ for (let i = 0; i < labels.length; i++) {
32
+ labels
33
+ .item(i)
34
+ .getElementsByTagName("input")[0]
35
+ .addEventListener("change", () => {
36
+ showDescriptionTamanoScale(labels.item(i));
37
+ });
38
+ }
39
+ }
40
+
41
+ function showDescriptionTamanoScale(label) {
42
+ const text = label.textContent.trim();
43
+ pSize.textContent = descriptons[text][0];
44
+ iSize.placeholder = descriptons[text][1];
45
+ }
tecnicas/static/js/panel-tags.js ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ const itemsSelects = document.getElementsByClassName("ct-select-op");
2
+ const options = itemsSelects.item(0).getElementsByTagName("option");
3
+ const values = [];
4
+
5
+ const extraPanel = document.getElementsByClassName("ct-new-tags")[0];
6
+ function showHiddeExtraTags() {
7
+ if (extraPanel.classList.contains("hidden")) {
8
+ extraPanel.classList.remove("hidden");
9
+ } else {
10
+ extraPanel.classList.add("hidden");
11
+ }
12
+ }
13
+
14
+ const formNewTag = document.getElementsByClassName("ct-form-new-tag")[0];
15
+ if (formNewTag) {
16
+ formNewTag.addEventListener("submit", postNewTag);
17
+ }
18
+
19
+ async function postNewTag(e) {
20
+ e.preventDefault();
21
+
22
+ const dataForm = new FormData(this);
23
+ const url = "/cata/nueva-etiqueta";
24
+
25
+ try {
26
+ const respone = await fetch(url, {
27
+ method: "POST",
28
+ headers: {
29
+ "X-CSRFToken": dataForm.get("csrfmiddlewaretoken"),
30
+ },
31
+ body: dataForm,
32
+ });
33
+
34
+ const jsonResponse = await respone.json();
35
+
36
+ if (jsonResponse.error) {
37
+ const errorp = document.getElementsByClassName("ct-error-tag")[0];
38
+ errorp.textContent = `error: ${jsonResponse.error}`;
39
+ errorp.classList.remove("hidden");
40
+ return;
41
+ }
42
+
43
+ const inputTag = document.getElementsByName("nueva_etiqueta")[0];
44
+ inputTag.value = "";
45
+ showHiddeExtraTags();
46
+
47
+ const newTag = jsonResponse["new_tag"];
48
+ addNewOptionToSelect(newTag);
49
+ } catch (error) {
50
+ console.log("Error:", error);
51
+ }
52
+ }
53
+
54
+ function createOptionSelect(value = 0, text = "define texto") {
55
+ const option = document.createElement("option");
56
+ option.value = value;
57
+ option.textContent = text;
58
+ return option;
59
+ }
60
+
61
+ function addNewOptionToSelect(newValues) {
62
+ for (let i = 0; i < itemsSelects.length; i++) {
63
+ const newOption = createOptionSelect(newValues.id, newValues.valor);
64
+ itemsSelects.item(i).appendChild(newOption);
65
+ }
66
+ }
tecnicas/templates/tecnicas/catador-buscar.html CHANGED
@@ -1,4 +1,5 @@
1
  {% extends 'tecnicas/base.html' %}
 
2
 
3
  {% block title %}Buscar Catador{% endblock %}
4
 
@@ -115,46 +116,5 @@
115
  {% endblock %}
116
 
117
  {% block extra_js %}
118
- <script>
119
- const inputs = document.getElementsByClassName("ct-inputs-pos-cata")
120
- disableInputs()
121
- setTimeout(() => {
122
- const notifications = document.getElementsByClassName("ct-notifica")
123
- for (let index = 0; index < notifications.length; index++) {
124
- notifications.item(index).classList.add("hidden")
125
- }
126
- }, 1800)
127
-
128
- function disableInputs () {
129
- for (let index = 0; index < inputs.length; index++) {
130
- inputs.item(index).disabled = true
131
- }
132
- }
133
-
134
- function enableInputs () {
135
- for (let index = 0; index < inputs.length; index++) {
136
- inputs.item(index).disabled = false
137
- }
138
- changeButtons()
139
- }
140
-
141
- function changeButtons (callBack = function () { }) {
142
- const btnUpdate = document.getElementsByClassName("ct-btn-actualizar")[0]
143
- const btnSave = document.getElementsByClassName("ct-btn-guardar")[0]
144
- const btnCancel = document.getElementsByClassName("ct-btn-cancel")[0]
145
-
146
- if (btnUpdate.classList.contains("hidden")) {
147
- btnUpdate.classList.remove("hidden")
148
- btnSave.classList.add("hidden")
149
- btnCancel.classList.add("hidden")
150
- } else {
151
- btnUpdate.classList.add("hidden")
152
- btnSave.classList.remove("hidden")
153
- btnCancel.classList.remove("hidden")
154
- }
155
-
156
- callBack()
157
- }
158
-
159
- </script>
160
  {% endblock %}
 
1
  {% extends 'tecnicas/base.html' %}
2
+ {% load static %}
3
 
4
  {% block title %}Buscar Catador{% endblock %}
5
 
 
116
  {% endblock %}
117
 
118
  {% block extra_js %}
119
+ <script src="{% static 'js/catador-search.js' %}"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  {% endblock %}
tecnicas/templates/tecnicas/catador-crear.html CHANGED
@@ -1,4 +1,5 @@
1
  {% extends 'tecnicas/base.html' %}
 
2
 
3
  {% block title %}Crear Catador{% endblock %}
4
 
@@ -84,19 +85,5 @@
84
  {% endblock %}
85
 
86
  {% block extra_js %}
87
- <script>
88
- const notifiactions = document.getElementsByClassName("ct-notificacion")
89
- const inputs = document.getElementsByClassName("ct-inputs-pos-cata")
90
-
91
- for (let index = 0; index < inputs.length; index++) {
92
- inputs.item(index).addEventListener("change", hiddenErrorAndMessages)
93
- }
94
-
95
- function hiddenErrorAndMessages (e) {
96
- for (let index = 0; index < notifiactions.length; index++) {
97
- console.log("Oculto")
98
- notifiactions.item(index).classList.add("hidden")
99
- }
100
- }
101
- </script>
102
  {% endblock %}
 
1
  {% extends 'tecnicas/base.html' %}
2
+ {% load static %}
3
 
4
  {% block title %}Crear Catador{% endblock %}
5
 
 
85
  {% endblock %}
86
 
87
  {% block extra_js %}
88
+ <script src="{% static 'js/catador-craete.js' %}"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  {% endblock %}
tecnicas/templates/tecnicas/configuracion-panel-basic.html CHANGED
@@ -1,4 +1,5 @@
1
  {% extends 'tecnicas/base.html' %}
 
2
 
3
  {% block title %}Panel Configuracion{% endblock %}
4
 
@@ -96,42 +97,5 @@
96
  {% endblock %}
97
 
98
  {% block extra_js %}
99
- <script>
100
- const descriptons = {
101
- "estructurada": ["Establece número de segmentos:", "Puede ser 5, 7 o 9"],
102
- "continua": ["Establece la longitud de la escala:", "Puede ser 9, 12 o 15"]
103
- }
104
-
105
- let labels
106
-
107
- let pSize
108
- let iSize
109
-
110
- initPanel()
111
-
112
- function initPanel () {
113
- initRadios()
114
- }
115
-
116
- function initRadios () {
117
- labels = document.getElementsByClassName("ct-radio-escala")
118
- pSize = document.getElementsByClassName("ct-size-scale").item(0).getElementsByTagName("p")[0]
119
- iSize = document.getElementsByClassName("ct-size-scale").item(0).getElementsByTagName("input")[0]
120
-
121
- pSize.textContent = descriptons["estructurada"][0]
122
- iSize.placeholder = descriptons["estructurada"][1]
123
-
124
- for (let i = 0; i < labels.length; i++) {
125
- labels.item(i).getElementsByTagName("input")[0].addEventListener("change", () => {
126
- showDescriptionTamanoScale(labels.item(i))
127
- })
128
- }
129
- }
130
-
131
- function showDescriptionTamanoScale (label) {
132
- const text = label.textContent.trim()
133
- pSize.textContent = descriptons[text][0]
134
- iSize.placeholder = descriptons[text][1]
135
- }
136
- </script>
137
  {% endblock %}
 
1
  {% extends 'tecnicas/base.html' %}
2
+ {% load static %}
3
 
4
  {% block title %}Panel Configuracion{% endblock %}
5
 
 
97
  {% endblock %}
98
 
99
  {% block extra_js %}
100
+ <script src="{% static 'js/panel-basic.js' %}"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  {% endblock %}
tecnicas/templates/tecnicas/configuracion-panel-tags.html CHANGED
@@ -1,4 +1,5 @@
1
  {% extends 'tecnicas/base.html' %}
 
2
 
3
  {% block title %}Panel Configuracion{% endblock %}
4
 
@@ -79,75 +80,7 @@
79
  {% endblock %}
80
 
81
  {% block extra_js %}
82
- <script>
83
- const itemsSelects = document.getElementsByClassName("ct-select-op")
84
- const options = itemsSelects.item(0).getElementsByTagName("option")
85
- const values = []
86
-
87
- const extraPanel = document.getElementsByClassName("ct-new-tags")[0]
88
- function showHiddeExtraTags () {
89
- if (extraPanel.classList.contains("hidden")) {
90
- extraPanel.classList.remove("hidden")
91
- } else {
92
- extraPanel.classList.add("hidden")
93
- }
94
- }
95
-
96
- const formNewTag = document.getElementsByClassName("ct-form-new-tag")[0]
97
- if (formNewTag) {
98
- formNewTag.addEventListener("submit", postNewTag)
99
- }
100
-
101
- async function postNewTag (e) {
102
- e.preventDefault()
103
-
104
- const dataForm = new FormData(this)
105
- const url = "/cata/nueva-etiqueta"
106
-
107
- try {
108
- const respone = await fetch(url, {
109
- method: "POST",
110
- headers: {
111
- 'X-CSRFToken': dataForm.get('csrfmiddlewaretoken'),
112
- },
113
- body: dataForm
114
- })
115
-
116
- const jsonResponse = await respone.json()
117
-
118
- if (jsonResponse.error) {
119
- const errorp = document.getElementsByClassName("ct-error-tag")[0]
120
- errorp.textContent = `error: ${jsonResponse.error}`
121
- errorp.classList.remove("hidden")
122
- return
123
- }
124
-
125
- const inputTag = document.getElementsByName("nueva_etiqueta")[0]
126
- inputTag.value = ""
127
- showHiddeExtraTags()
128
-
129
- const newTag = jsonResponse["new_tag"]
130
- addNewOptionToSelect(newTag)
131
- } catch (error) {
132
- console.log("Error:", error)
133
-
134
- }
135
- }
136
-
137
- function createOptionSelect (value = 0, text = "define texto") {
138
- const option = document.createElement("option")
139
- option.value = value
140
- option.textContent = text
141
- return option
142
- }
143
-
144
- function addNewOptionToSelect(newValues) {
145
- for (let i = 0; i < itemsSelects.length; i++) {
146
- const newOption = createOptionSelect(newValues.id, newValues.valor)
147
- itemsSelects.item(i).appendChild(newOption)
148
- }
149
- }
150
- </script>
151
 
152
  {%if escala == "estructurada"%}
153
  <script>
 
1
  {% extends 'tecnicas/base.html' %}
2
+ {% load static %}
3
 
4
  {% block title %}Panel Configuracion{% endblock %}
5
 
 
80
  {% endblock %}
81
 
82
  {% block extra_js %}
83
+ <script src="{% static 'js/panel-tags.js' %}"></script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
 
85
  {%if escala == "estructurada"%}
86
  <script>