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

7
sigi/apps/diagnosticos/forms.py

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

7
sigi/apps/diagnosticos/views.py

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

7
sigi/templates/diagnosticos/diagnosticos_categorias_form.html

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

Loading…
Cancel
Save