general: make it possible to add a note to mails
This commit is contained in:
parent
2b5f88bce5
commit
8f15a7e4e0
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('mail', '0005_auto_20151010_1819'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='mail',
|
||||
name='note',
|
||||
field=models.TextField(null=True, verbose_name='Note'),
|
||||
preserve_default=True,
|
||||
),
|
||||
]
|
|
@ -34,6 +34,7 @@ class Mail(models.Model):
|
|||
post_date = models.DateField(_('Post Date'), null=True)
|
||||
registered_mail_number = models.CharField(_('Registered Mail Number'),
|
||||
null=True, max_length=50)
|
||||
note = models.TextField(_('Note'), null=True)
|
||||
|
||||
# common to all source types:
|
||||
status = models.CharField(_('Status'), blank=True, max_length=50)
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{% load i18n %}
|
||||
<div>
|
||||
<h2>{% trans "Note" %}</h2>
|
||||
<form id="note" method="post" action="{% url 'mail-edit-note' %}?mail={{mail.id}}">
|
||||
<textarea name="note">{% firstof mail.note %}</textarea>
|
||||
<div class="buttons">
|
||||
<button>{% trans "Save" %}</button>
|
||||
<a class="cancel">{% trans "Cancel" %}</a>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
|
@ -17,6 +17,11 @@
|
|||
{{form.as_p}}
|
||||
<button data-action-url="{{source_form_url}}" class="save">✓</button>
|
||||
</form>
|
||||
<div id="postit" style="display: none"
|
||||
data-title-selector="h2"
|
||||
data-base-url="{% url 'mail-edit-note' %}"
|
||||
data-inplace-submit="true">
|
||||
</div>
|
||||
<iframe id="pdf-viewer" src="{% url 'mail-viewer' %}">
|
||||
</iframe>
|
||||
</div>
|
||||
|
|
|
@ -16,10 +16,12 @@
|
|||
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
from .views import viewer, feeder, qualification_save
|
||||
from .views import viewer, feeder, qualification_save, edit_note, note
|
||||
|
||||
urlpatterns = patterns('',
|
||||
url('viewer/$', viewer, name='mail-viewer'),
|
||||
url('mail/feeder/$', feeder, name='mail-feeder'),
|
||||
url(r'^ajax/qualification-mail-save$', qualification_save, name='qualif-mail-save'),
|
||||
url(r'^ajax/mail/edit-note/$', edit_note, name='mail-edit-note'),
|
||||
url(r'^ajax/mail/note/(?P<pk>\w+)$', note, name='mail-note'),
|
||||
)
|
||||
|
|
|
@ -14,7 +14,11 @@
|
|||
# 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/>.
|
||||
|
||||
import json
|
||||
import re
|
||||
|
||||
from django import template
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.contrib import messages
|
||||
from django.core.exceptions import PermissionDenied
|
||||
|
@ -79,3 +83,28 @@ def qualification_save(request, *args, **kwargs):
|
|||
return HttpResponseRedirect(reverse('qualif-zone') +
|
||||
'?source_type=%s&source_pk=%s' % (request.POST['source_type'],
|
||||
request.POST['source_pk']))
|
||||
|
||||
|
||||
class EditNote(TemplateView):
|
||||
template_name = 'welco/mail_edit_note.html'
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super(EditNote, self).get_context_data(**kwargs)
|
||||
context['mail'] = Mail.objects.get(id=self.request.GET['mail'])
|
||||
return context
|
||||
|
||||
def post(self, request, *args, **kwargs):
|
||||
mail = Mail.objects.get(id=self.request.GET['mail'])
|
||||
mail.note = self.request.POST['note']
|
||||
mail.save()
|
||||
return HttpResponse(json.dumps({'result': 'ok'}))
|
||||
|
||||
edit_note = login_required(csrf_exempt(EditNote.as_view()))
|
||||
|
||||
|
||||
@login_required
|
||||
def note(request, *args, **kwargs):
|
||||
mail = Mail.objects.get(id=kwargs['pk'])
|
||||
note = mail.note or '+'
|
||||
note = re.sub(r'[\r?\n]+', '<br><br>', note, re.DOTALL)
|
||||
return HttpResponse(note)
|
||||
|
|
|
@ -397,3 +397,21 @@ div.add-formdef-reference > div {
|
|||
display: inline-block;
|
||||
width: calc(100% - 6em);
|
||||
}
|
||||
|
||||
div#postit {
|
||||
position: absolute;
|
||||
right: 4em;
|
||||
top: 11em;
|
||||
padding: 1ex;
|
||||
max-width: 15em;
|
||||
background: rgba(241,231,103,1);
|
||||
overflow-x: none;
|
||||
overflow-y: auto;
|
||||
transform: rotate(2deg);
|
||||
box-shadow: 3px 3px 3px #aaa;
|
||||
}
|
||||
|
||||
form#note textarea {
|
||||
width: calc(100% - 2em);
|
||||
height: 8em;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,9 @@ $(function() {
|
|||
$('#id_registered_mail_number').val($(this).data('registered-mail-number'));
|
||||
var source_type = $('div.source div[data-source-type]').data('source-type');
|
||||
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
|
||||
$('#postit').data('url', $('#postit').data('base-url') + '?mail=' + source_pk);
|
||||
$('#postit').trigger('welco:load-mail-note');
|
||||
$('#postit').show();
|
||||
$('.cell[data-zone-url]').each(function(idx, zone) {
|
||||
$.ajax({url: $(zone).data('zone-url'),
|
||||
data: {source_type: source_type,
|
||||
|
@ -218,6 +221,11 @@ $(function() {
|
|||
$('.mails ul li[data-pdf-href]:first-child').trigger('click');
|
||||
});
|
||||
|
||||
$(document).on('gadjo:dialog-done welco:load-mail-note', function() {
|
||||
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
|
||||
$('#postit').load('/ajax/mail/note/' + source_pk);
|
||||
});
|
||||
|
||||
$(document).on('gadjo:dialog-done welco:load-copies', function() {
|
||||
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
|
||||
$.getJSON(
|
||||
|
@ -230,4 +238,6 @@ $(function() {
|
|||
);
|
||||
});
|
||||
|
||||
$('#postit').on('click', window.displayPopup);
|
||||
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue