display service on topic selection (#957)

This commit is contained in:
Frédéric Péters 2011-11-18 12:25:22 +01:00
parent fe0af4b0ab
commit e3013ecc20
3 changed files with 37 additions and 7 deletions

View File

@ -13,6 +13,12 @@
<!-- Grok the package to initialise schema interfaces and content classes -->
<grok:grok package="." />
<browser:page
for=".form.IContactForm"
name="service"
class=".form.ServiceView"
permission="zope2.View"/>
<i18n:registerTranslations directory="locales" />
<five:registerPackage package="." initialize=".initialize" />

View File

@ -13,6 +13,7 @@ from plone.z3cform.layout import wrap_form
from z3c.form.ptcompat import ViewPageTemplateFile
from plone.dexterity.content import Item
from Products.Five import BrowserView
from plone.formwidget.captcha.widget import CaptchaFieldWidget
from plone.formwidget.captcha.validator import CaptchaValidator
@ -50,9 +51,11 @@ class View(grok.View):
def get_possible_subjects(context):
terms = []
for line in context.context.subjects.splitlines():
try:
if line.count('|') == 1:
topic, email = line.strip().split('|')
except ValueError:
elif line.count('|') == 2:
topic, email, service = line.strip().split('|')
else:
continue
if email == '->deputy':
terms.append(SimpleVocabulary.createTerm('-deputy', '-deputy', topic))
@ -62,16 +65,33 @@ def get_possible_subjects(context):
terms.append(SimpleVocabulary.createTerm('-', '-', '-'))
return SimpleVocabulary(terms)
def get_email_for_subject(context, topic):
def get_email_for_subject(context, selected_topic):
for line in context.context.subjects.splitlines():
try:
if line.count('|') == 1:
topic, email = line.strip().split('|')
except ValueError:
elif line.count('|') == 2:
topic, email, service = line.strip().split('|')
else:
continue
if topic == topic:
if topic == selected_topic:
return email
return None
class ServiceView(BrowserView):
def __call__(self):
selected_topic = self.request.form.get('id')
for line in self.context.subjects.splitlines():
if line.count('|') == 1:
topic, email = line.strip().split('|')
elif line.count('|') == 2:
topic, email, service = line.strip().split('|')
else:
continue
if selected_topic == topic.encode('ascii', 'replace'):
return _(u'Your request will be handled by: %s') % service
return None
class IEffectiveContact(interface.Interface):
subject = schema.Choice(title=_(u'Subject'), required=True,
source=get_possible_subjects)

View File

@ -8,11 +8,15 @@
<script type="text/javascript">
(function($) {
$().ready(function() {
$('#form-widgets-subject').after('<div id="service"' + '><' + '/div>');
$('div#service').hide();
$('#form-widgets-subject').change(function() { /* screw accessibility :/ */
console.log($(this));
if ($(this).attr('value') == '-deputy') {
window.location = window.location + '/deputy';
return false;
} else {
$('div#service').show().load(window.location + '/service?id=' + $(this).attr('value'));
return false;
}
});
});