contacts: basic UI to add contacts

This commit is contained in:
Frédéric Péters 2015-11-16 10:19:44 +01:00
parent 0f3abdf5db
commit 4d7d626cf9
7 changed files with 92 additions and 4 deletions

30
welco/contacts/forms.py Normal file
View File

@ -0,0 +1,30 @@
# 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 ContactAddForm(forms.Form):
first_name = forms.CharField(label=_('First Name'))
last_name = forms.CharField(label=_('Last Name'))
email = forms.CharField(label=_('Email'))
address = forms.CharField(label=_('Address'))
zipcode = forms.CharField(label=_('Zip Code'))
city = forms.CharField(label=_('City'))
country = forms.CharField(label=_('Country'))
phone = forms.CharField(label=_('Phone'))
mobile = forms.CharField(label=_('Mobile'))

View File

@ -0,0 +1,11 @@
{% load i18n %}
<div>
<form class="contact-add">
{{form.as_p}}
<div class="buttons">
<button>{% trans "Save" %}</button>
<a class="cancel" href="#">{% trans 'Cancel' %}</a>
</div>
</form>
</div>

View File

@ -5,7 +5,8 @@
<ul class="result">
</ul>
</div>
<button id="create-new-contact">+</button>
<button id="create-new-contact" data-inplace-submit="true"
data-url="{% url 'contacts-add' %}">+</button>
<div class="contact">
{% if contact_user_id %}

View File

@ -21,11 +21,13 @@ from django.contrib.contenttypes.models import ContentType
from django.http import HttpResponse
from django.template import RequestContext
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import TemplateView
from django.views.generic import TemplateView, FormView
from welco.qualif.models import Association
from welco.utils import get_wcs_data
from .forms import ContactAddForm
class HomeZone(object):
def __init__(self, request):
self.request = request
@ -101,3 +103,20 @@ class ContactDetailFragmentView(TemplateView):
return context
contact_detail_fragment = ContactDetailFragmentView.as_view()
class ContactAdd(FormView):
template_name = 'contacts/contact_add.html'
form_class = ContactAddForm
def post(self, request):
form = self.get_form(self.get_form_class())
msg = {}
for field_key in form.fields:
msg[field_key] = form[field_key].value()
response = HttpResponse(content_type='application/json')
result = {'data': []}
json.dump(result, response, indent=2)
return response
contact_add = csrf_exempt(ContactAdd.as_view())

View File

@ -523,3 +523,13 @@ a.icon-phone:before {
content: "\f095 "; /* phone */
padding-right: 1ex;
}
form.contact-add p label {
display: inline-block;
width: 6em;
}
div.ui-dialog form.contact-add p input {
display: inline-block;
width: 20em;
}

View File

@ -13,6 +13,7 @@ $(function() {
$(zone).find('select').select2();
$(zone).removeClass('has-page-displayed');
$(zone).removeClass('has-contact-displayed');
$('#create-new-contact').off('click').on('click', window.displayPopup);
if (typeof(callback) === 'function') callback();
},
error: function(error) { console.log(':(', error); }
@ -260,12 +261,14 @@ $(function() {
$('.mails ul li[data-pdf-href]:first-child').trigger('click');
});
$(document).on('gadjo:dialog-done welco:load-mail-note', function() {
$(document).on('gadjo:dialog-done welco:load-mail-note', function(ev) {
if (ev.target && ev.target.id == 'create-new-contact') return;
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() {
$(document).on('gadjo:dialog-done welco:load-copies', function(ev) {
if (ev.target && ev.target.id == 'create-new-contact') return;
var source_pk = $('div.source .active[data-source-pk]').data('source-pk');
$.getJSON(
'/ajax/copies/' + source_pk + '/',
@ -277,6 +280,19 @@ $(function() {
);
});
$(document).on('gadjo:dialog-done', function(ev) {
if (ev.target && ev.target.id != 'create-new-contact') return;
$.ajax({url: $('#create-new-contact').data('url'),
data: $('form.contact-add').serialize(),
method: 'POST',
dataType: 'json',
success: function(data) {
console.log('got data', data);
},
error: function(error) { console.log(':/', error); }
});
});
$('#postit').on('click', window.displayPopup);
$('#id_post_date').datepicker($.datepicker.regional["fr"]);

View File

@ -48,6 +48,7 @@ urlpatterns = patterns('',
url(r'^contacts/search/json/$', 'welco.contacts.views.search_json', name='contacts-search-json'),
url(r'^ajax/contacts/(?P<slug>[\w-]+)/$',
'welco.contacts.views.contact_detail_fragment', name='contact-page-fragment'),
url(r'^contacts/add/$', 'welco.contacts.views.contact_add', name='contacts-add'),
url(r'^ajax/summary/(?P<source_type>\w+)/(?P<source_pk>\w+)/$',
'welco.views.wcs_summary', name='wcs-summary'),