Browse Source

modificando ajax para salvar dados aproveitando o form e modificando loader

diagnosticos
Felipe Vieira 13 years ago
parent
commit
8508df04e3
  1. 9
      media/js/diagnosticos/diagnosticos_categoria_form.js
  2. 7
      sigi/apps/diagnosticos/forms.py
  3. 9
      sigi/apps/diagnosticos/views.py
  4. 7
      sigi/templates/diagnosticos/diagnosticos_categorias_form.html

9
media/js/diagnosticos/diagnosticos_categoria_form.js

@ -12,12 +12,12 @@ $.ajaxSetup({
dataType: "text",
beforeSend: function() {
nun_ajax++
$('#working').show()
$.mobile.showPageLoadingMsg();
},
success: function() {
nun_ajax--
if (nun_ajax == 0) {
$('#working').hide()
$.mobile.hidePageLoadingMsg();
}
},
error: function(msg) {
@ -35,10 +35,7 @@ $(document).ready(function() {
// ao modificar o campo
$("div.ui-field-contain input").change(function () {
$.ajax({
data: {
schema: this.name,
value: this.value
}
data: $('#diagnostico').serializeArray()
})
})
});

7
sigi/apps/diagnosticos/forms.py

@ -28,9 +28,10 @@ class DiagnosticoMobileForm(BaseDynamicEntityForm):
self._build_dynamics_fields(category)
def __iter__(self):
fields_by_label = [ (field.label, field) for field in self.fields.values()]
for label, field in sorted(fields_by_label):
yield BoundField(self, field, field.label)
# ordena os campos do formulario usando o atributo label
fields_by_label = [(field.label, name, field) for name, field in self.fields.items()]
for label, name, field in sorted(fields_by_label):
yield BoundField(self, field, name)
def _build_dynamics_fields(self, category):
"""Método da classe ``BaseDynamicEntityForm`` sobrescrita,

9
sigi/apps/diagnosticos/views.py

@ -43,9 +43,12 @@ def categoria_detalhes(request, id_diagnostico, id_categoria):
context = RequestContext(request)
return render_to_response('mobile/404.html', {})
# Criando o formulário e passando o diagnóstico selecionado
# para ser editado pelo form.
form = DiagnosticoMobileForm(instance=diagnostico, category=id_categoria)
if request.POST:
form = DiagnosticoMobileForm(request.POST, instance=diagnostico, category=id_categoria)
if form.is_valid():
form.save()
else:
form = DiagnosticoMobileForm(instance=diagnostico, category=id_categoria)
context = RequestContext(request, {'form': form, 'categoria': categoria})
return render_to_response('diagnosticos/diagnosticos_categorias_form.html',

7
sigi/templates/diagnosticos/diagnosticos_categorias_form.html

@ -1,5 +1,10 @@
{% extends "base_mobile.html" %}
{% block media %}
{{ block.super }}
<script src="{{MEDIA_URL}}js/diagnosticos/diagnosticos_categoria_form.js"></script>
{% endblock %}
{% block cabecalho %}
<h1>{{ categoria.nome }}</h1>
<a href="{% url lista_categorias categoria.id %}" data-icon="arrow-l"
@ -8,7 +13,7 @@
{% block corpo %}
{% if form %}
<form action="." method="post">
<form id="diagnostico" action="." method="post">
{% for field in form %}
<div data-role="fieldcontain">
<label for="{{ field.name }}">{{ field.label }}</label>

Loading…
Cancel
Save