mail: add fields to qualify mail (post date / registered mail)
This commit is contained in:
parent
3f52dc76e4
commit
b2a58843ac
|
@ -0,0 +1,22 @@
|
|||
# welco - multichannel request processing
|
||||
# Copyright (C) 2015 Entr'ouvert
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify it
|
||||
# under the terms of the GNU Affero General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django import forms
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
class MailQualificationForm(forms.Form):
|
||||
post_date = forms.DateTimeField(label=_('Post Date'), required=False)
|
||||
registered_mail = forms.BooleanField(label=_('Registered Mail'), required=False)
|
|
@ -14,6 +14,7 @@
|
|||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.db import models
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
|
@ -29,3 +30,17 @@ class Mail(models.Model):
|
|||
|
||||
creation_timestamp = models.DateTimeField(auto_now_add=True)
|
||||
last_update_timestamp = models.DateTimeField(auto_now=True)
|
||||
|
||||
@classmethod
|
||||
def get_qualification_form_class(cls):
|
||||
from .forms import MailQualificationForm
|
||||
return MailQualificationForm
|
||||
|
||||
def get_qualification_form(self):
|
||||
return self.get_qualification_form_class()({
|
||||
'post_date': self.post_date,
|
||||
'registered_mail': self.registered_mail})
|
||||
|
||||
@classmethod
|
||||
def get_qualification_form_submit_url(cls):
|
||||
return reverse('qualif-mail-save')
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
from .views import viewer
|
||||
from .views import viewer, qualification_save
|
||||
|
||||
urlpatterns = patterns('', url('viewer/$', viewer, name='mail-viewer'))
|
||||
urlpatterns = patterns('',
|
||||
url('viewer/$', viewer, name='mail-viewer'),
|
||||
url(r'^ajax/qualification-mail-save$', qualification_save, name='qualif-mail-save'),
|
||||
)
|
||||
|
|
|
@ -16,10 +16,14 @@
|
|||
|
||||
from django import template
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.template import RequestContext
|
||||
from django.http import HttpResponse, HttpResponseRedirect
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
from .models import Mail
|
||||
from .forms import MailQualificationForm
|
||||
|
||||
def viewer(request, *args, **kwargs):
|
||||
if not 'file' in request.GET:
|
||||
|
@ -39,3 +43,16 @@ class Home(object):
|
|||
context['source_type'] = ContentType.objects.get_for_model(Mail)
|
||||
tmpl = template.loader.get_template('welco/mail_home.html')
|
||||
return tmpl.render(context)
|
||||
|
||||
|
||||
@csrf_exempt
|
||||
def qualification_save(request, *args, **kwargs):
|
||||
mail = Mail.objects.get(id=request.POST['source_pk'])
|
||||
form = MailQualificationForm(request.POST)
|
||||
if form.is_valid():
|
||||
mail.post_date = form.cleaned_data['post_date']
|
||||
mail.registered_mail = form.cleaned_data['registered_mail']
|
||||
mail.save()
|
||||
return HttpResponseRedirect(reverse('qualif-zone') +
|
||||
'?source_type=%s&source_pk=%s' % (request.POST['source_type'],
|
||||
request.POST['source_pk']))
|
||||
|
|
|
@ -262,3 +262,12 @@ table.dgs-summary button {
|
|||
overflow-y: auto;
|
||||
padding: 1ex;
|
||||
}
|
||||
|
||||
div.qualif-source p,
|
||||
div.qualif-source p label {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
div.qualif-source input#id_post_date {
|
||||
width: 12ex;
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ $(function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
$('.qualif').delegate('button.add', 'click', function() {
|
||||
var formdef_reference = $('#id_formdef_reference').val();
|
||||
var source_type = $('div.source div[data-source-type]').data('source-type');
|
||||
|
@ -59,6 +60,27 @@ $(function() {
|
|||
return false;
|
||||
});
|
||||
|
||||
$('.qualif').delegate('button.save', 'click', function() {
|
||||
var post_date = $('#id_post_date').val();
|
||||
var registered_mail = $('#id_registered_mail').prop('checked');
|
||||
var source_type = $('div.source div[data-source-type]').data('source-type');
|
||||
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
|
||||
$.ajax({url: $(this).data('action-url'),
|
||||
data: {post_date: post_date,
|
||||
registered_mail: registered_mail,
|
||||
source_type: source_type,
|
||||
source_pk: source_pk},
|
||||
method: 'POST',
|
||||
dataType: 'html',
|
||||
success: function(data) {
|
||||
$('.cell.qualif > div').replaceWith(data);
|
||||
$('.qualif').find('select').select2();
|
||||
},
|
||||
error: function(error) { console.log(':(', error); }
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$('.qualif').delegate('a.plus', 'click', function() {
|
||||
$(this).parents('li').hide();
|
||||
$('.qualif .add-formdef-reference').show();
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
</ul>
|
||||
{% endif %}
|
||||
<div class="add-formdef-reference" {% if association %}style="display: none"{% endif %}>
|
||||
<div class="qualif-source">
|
||||
{{source_form.as_p}}
|
||||
<button data-action-url="{{source_form_url}}" class="save">✓</button>
|
||||
</div>
|
||||
<div>
|
||||
{{form.formdef_reference}}
|
||||
</div>
|
||||
|
@ -20,3 +24,8 @@
|
|||
{% endif %}
|
||||
</form>
|
||||
</div>
|
||||
<script>
|
||||
$(function() {
|
||||
$('#id_post_date').datepicker($.datepicker.regional["fr"]);
|
||||
});
|
||||
</script>
|
||||
|
|
|
@ -64,6 +64,10 @@ class Qualification(TemplateView):
|
|||
def get_context_data(self, **kwargs):
|
||||
context = super(Qualification, self).get_context_data(**kwargs)
|
||||
context['form'] = QualificationForm()
|
||||
source_type = ContentType.objects.get(id=self.request.GET['source_type'])
|
||||
source_object = source_type.model_class().objects.get(id=self.request.GET['source_pk'])
|
||||
context['source_form'] = source_object.get_qualification_form()
|
||||
context['source_form_url'] = source_type.model_class().get_qualification_form_submit_url()
|
||||
try:
|
||||
context['association'] = Association.objects.get(
|
||||
source_type=ContentType.objects.get(id=self.request.GET['source_type']),
|
||||
|
|
Loading…
Reference in New Issue