/
ingresar_notas.html.erb
132 lines (111 loc) · 3.96 KB
/
ingresar_notas.html.erb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
<script type"text/javascript">
var camposForm=new Array();
$(document).ready(function(){
for (var i=0;i<camposForm.length;i++){
var nombreCampo = "div#"+"div"+camposForm[i];
//alert(nombreCampo);
$(nombreCampo).slideDown("slow");
}
/*$("#select_curso").change(function () {
$("#resultado").attr("action","/resultado/"+this.value);
$("#resultado").submit();
});*/
$("#boton").click(function(){
/*var cursoFormula = $("#select_curso").val();
var elementos = cursoFormula.split("+");
var promedio = 0.0;
var faltante = 0;
var notaNecesaria =0;
for (var i = 0; i< elementos.length;i++){
var elementoTemp = elementos[i].split("%");
var nomInput = "input#" + elementoTemp[1];
var nota = $(nomInput).val();
var porcentaje = elementoTemp[0]/100;
promedio = promedio + (nota*porcentaje);
promedio = Math.round(promedio*100)/100;
if (elementoTemp[1]=="TF"){
faltante = 12.5 - promedio;
if(faltante > 0)
{
notaNecesaria = faltante/porcentaje;
notaNecesaria = Math.round(notaNecesaria*100)/100;
}
}
}
alert("termino promedio : " + promedio);
alert("te falta : " + notaNecesaria)*/
$("#resultado").attr("action","/resultado");
$("#resultado").submit();
});
});
function seleccionarCurso(){
$("#resultado").attr("action","/ingresar_notas/"+$("#select_curso").val());
$("#resultado").submit();
}
function isNumberKey(evt,obj)
{
var charCode = (evt.which) ? evt.which : event.keyCode
var nota = (obj.value!="")?obj.value:0;
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
else
{
notaCheck = ""+nota + (parseInt(charCode) - 48);
if (parseInt(notaCheck)<0 || parseInt(notaCheck) >20 ){
return false;
}
return true;
}
}
</script>
<form accept-charset="UTF-8" action="/ingresar_notas" id="resultado" method="post">
<%if @curso != nil%>
<input type="hidden" value="<%=@curso.formula%>" id="formula" name="formula"/>
<%end %>
<%if @curso == nil%>
<input type="hidden" value="" id="formula" name="formula"/>
<%end%>
<div id="divSelect" data-role="fieldcontain">
<label for="select_curso">Curso:</label>
<select id="select_curso" data-native-menu="false" onchange="seleccionarCurso()">
<option >Escoger curso</option>
<%@cursos.each do |c|
if @curso != nil && c.id == @curso.id
%>
<option value="<%=c.id%>" selected><%=c.nombre%></option>
<%
else
%>
<option value="<%=c.id%>"><%=c.nombre%></option>
<%
end
end
%>
</select>
</div>
<%
if @curso != nil
cursoFormula = @curso.formula
#cursoFormula = "15%PC1+15%PC2+20%TP+20%PA+30%TF"
elementos = cursoFormula.split("+")
for i in 0..elementos.length
if elementos[i]
elementoTemp = elementos[i].split("%")
%>
<div style="display:none" id="div<%=elementoTemp[1]%>" data-role="fieldcontain" >
<label for="<%=elementoTemp[1]%>"><%=elementoTemp[1]%></label>
<input type="text" name="<%=elementoTemp[1]%>" id="<%=elementoTemp[1]%>" value="" onKeypress="return isNumberKey(event,this)"/>
</div>
<script type"text/javascript">
camposForm[<%=i%>] = "<%=elementoTemp[1]%>" ;
</script>
<%
end
end %>
<div data-role="fieldcontain">
<label for="calcular"></label>
<input type="button" value="Calcular" data-inline="true" id="boton"/>
</div>
<% end
%>
</form>