refactor various templates

This commit is contained in:
Frédéric Péters 2011-11-23 10:51:13 +01:00
parent 3159b95385
commit 46bf42acfe
13 changed files with 103 additions and 312 deletions

View File

@ -53,45 +53,9 @@
<div tal:replace="structure provider:plone.belowcontentbody" />
<script type="text/javascript" tal:content="string: var PORTAL_URL='${view/portal_url}';"/>
<script metal:use-macro="view/js_macros/macros/labelboxes"></script>
<script type="text/javascript">
function update_authors_input(input) {
var s = '';
jq(input).nextAll('span.labelbox').each(function() {
s = s + ' ' + jq(this).attr('class').split(' ')[1];
});
jq(input).attr('value', s);
}
function author_autocomplete_ready(event, data, formatted) {
(function($) {
var input_box = $(event.target);
// XXX: don't insert item if it's already present
labelbox = $('<span class="labelbox ' + data[1] + '">' + data[0] + '<' + '/span>');
$(input_box).before(labelbox);
$(labelbox).click(function() {
$(this).remove();
update_authors_input(jq(input_box).prevAll('input')[0]);
});
update_authors_input(jq(input_box).prevAll('input')[0]);
$(input_box).attr('value', '');
}(jQuery));
}
function sync_from_checkboxes(elem, dummyinput)
{
t = '';
$(elem).find('span.option').each(function(idx, el) {
if ($(el).find('input').attr('checked')) {
if (t.length > 0) {
t = t + ', ';
}
t = t + $(el).find('label span').text();
}
});
$(dummyinput).attr('value', t);
}
function setup_appearance(index, elem)
{
var dummyinput = $('<input type="text" readonly="readonly"/>');
@ -117,8 +81,6 @@ function setup_sort_on(index, elem)
(function($) {
$().ready(function() {
$('.author-autocomplete').autocomplete(PORTAL_URL+'/listAuthors', {
}).result(author_autocomplete_ready);
$('#formfield-document-widgets-l_doctypes').each(setup_appearance);
$('#formfield-document-widgets-l_topics').each(setup_appearance);
$('#formfield-document-widgets-l_polgroups').each(setup_appearance);

View File

@ -28,7 +28,8 @@
</form>
<div tal:define="search_results view/document_search_results;
<div id="documents-results"
tal:define="search_results view/document_search_results;
search_batch python:Batch(list(search_results or []), b_size, int(b_start), orphan=1);"
tal:condition="python: search_results is not None">
@ -36,6 +37,7 @@
<span>Nombre de résultats : <span tal:replace="python: len(search_results)"/></span>
</div>
<div class="results-var">
<div id="results">
<ul>
<tal:entry tal:repeat="item search_batch">
@ -51,6 +53,7 @@
<div tal:define="batch search_batch">
<div metal:use-macro="view/batch_macros/macros/navigation" />
<div metal:use-macro="view/batch_macros/macros/feed" />
</div>
</div>
</div>
@ -62,7 +65,8 @@
<div tal:replace="structure view/dossier_search_form"/>
</form>
<div tal:define="search_results view/dossier_search_results;
<div id="dossiers-results"
tal:define="search_results view/dossier_search_results;
search_batch python:Batch(list(search_results or []), b_size, int(b_start), orphan=1);"
tal:condition="python: search_results is not None">
@ -71,6 +75,7 @@
<span>Nombre de résultats : <span tal:replace="python: len(search_results)"/></span>
</div>
<div class="results-var">
<div id="results">
<ul>
<tal:entry tal:repeat="item search_batch">
@ -86,6 +91,7 @@
<div tal:define="batch search_batch">
<div metal:use-macro="view/batch_macros/macros/navigation" />
<div metal:use-macro="view/batch_macros/macros/feed" />
</div>
</div>
</div>
@ -97,7 +103,8 @@
<div tal:replace="structure view/question_search_form"/>
</form>
<div tal:define="search_results view/question_search_results;
<div id="questions-results"
tal:define="search_results view/question_search_results;
search_batch python:Batch(list(search_results or []), b_size, int(b_start), orphan=1);"
tal:condition="python: search_results is not None">
@ -106,6 +113,7 @@
<span>Nombre de résultats : <span tal:replace="python: len(search_results)"/></span>
</div>
<div class="results-var">
<div id="results">
<ul>
<tal:entry tal:repeat="item search_batch">
@ -121,6 +129,7 @@
<div tal:define="batch search_batch">
<div metal:use-macro="view/batch_macros/macros/navigation" />
<div metal:use-macro="view/batch_macros/macros/feed" />
</div>
</div>
</div>
@ -168,71 +177,7 @@
<div tal:replace="structure provider:plone.belowcontentbody" />
<script type="text/javascript" tal:content="string: var PORTAL_URL='${view/portal_url}';"/>
<script type="text/javascript">
function update_input(input) {
var s = '';
jq(input).nextAll('span.labelbox').each(function() {
s = s + ' ' + jq(this).attr('class').split(' ')[1];
});
jq(input).attr('value', s);
}
function create_labelbox(input_box, id, value)
{
labelbox = $('<span class="labelbox ' + id + '">' + value + '<' + '/span>');
$(labelbox).click(function() {
$(this).remove();
update_input(jq(input_box).prevAll('input')[0]);
});
return labelbox;
}
function autocomplete_ready(event, data, formatted) {
(function($) {
var input_box = $(event.target);
// XXX: don't insert item if it's already present
labelbox = create_labelbox(input_box, data[1], data[0]);
$(input_box).before(labelbox);
update_input(jq(input_box).prevAll('input')[0]);
$(input_box).attr('value', '');
}(jQuery));
}
function sync_elements(index, elem, url)
{
hidden = $(elem).prev();
values = $(hidden).attr('value').trim().split(' ');
for (i=0; i < values.length; i++) {
if (values[i]) {
labelbox = create_labelbox(elem, values[i], '...');
$(hidden).after(labelbox);
$(labelbox).load(url + '?id=' + values[i]);
}
}
}
function sync_authors(index, elem) { sync_elements(index, elem, PORTAL_URL+'/listAuthors'); }
function sync_polgroups(index, elem) { sync_elements(index, elem, PORTAL_URL+'/listPolgroups'); }
function sync_topics(index, elem) { sync_elements(index, elem, PORTAL_URL+'/listTopics'); }
if(typeof(String.prototype.trim) === "undefined") {
String.prototype.trim = function()
{
return String(this).replace(/^\s+|\s+$/g, '');
};
}
(function($) {
$().ready(function() {
$('.author-autocomplete').each(sync_authors).autocomplete(PORTAL_URL+'/listAuthors', {
}).result(autocomplete_ready);
$('.polgroup-autocomplete').each(sync_polgroups).autocomplete(PORTAL_URL+'/listPolgroups', {
}).result(autocomplete_ready);
$('.topic-autocomplete').each(sync_topics).autocomplete(PORTAL_URL+'/listTopics', {
}).result(autocomplete_ready);
});
})(jQuery);
</script>
<script metal:use-macro="view/js_macros/macros/labelboxes"></script>
</tal:block>
</tal:main-macro>

View File

@ -103,79 +103,7 @@
<div tal:replace="structure provider:plone.belowcontentbody" />
<script type="text/javascript" tal:content="string: var PORTAL_URL='${view/portal_url}';"/>
<script type="text/javascript">
function update_authors_input(input) {
var s = '';
jq(input).nextAll('span.labelbox').each(function() {
s = s + ' ' + jq(this).attr('class').split(' ')[1];
});
jq(input).attr('value', s);
}
function author_autocomplete_ready(event, data, formatted) {
(function($) {
var input_box = $(event.target);
// XXX: don't insert item if it's already present
labelbox = $('<span class="labelbox ' + data[1] + '">' + data[0] + '<' + '/span>');
$(input_box).before(labelbox);
$(labelbox).click(function() {
$(this).remove();
update_authors_input(jq(input_box).prevAll('input')[0]);
});
update_authors_input(jq(input_box).prevAll('input')[0]);
$(input_box).attr('value', '');
}(jQuery));
}
function sync_from_checkboxes(elem, dummyinput)
{
t = '';
$(elem).find('span.option').each(function(idx, el) {
if ($(el).find('input').attr('checked')) {
if (t.length > 0) {
t = t + ', ';
}
t = t + $(el).find('label span').text();
}
});
$(dummyinput).attr('value', t);
}
function setup_appearance(index, elem)
{
var dummyinput = $('<input type="text" readonly="readonly"/>');
sync_from_checkboxes(elem, dummyinput);
dummyinput.click(function() {
$(elem).find('div.droppedcheckboxes').toggle();
});
$(elem).find('.fieldErrorBox').after(dummyinput);
$(elem).find('span.option').wrapAll('<div class="droppedcheckboxes">').click(function() {
sync_from_checkboxes(elem, dummyinput);
});
$(elem).find('div.droppedcheckboxes').hide();
}
function setup_sort_on(index, elem)
{
$(elem).find('label.horizontal').click(function() {
$(elem).find('div.droppedradios').toggle();
});
$(elem).find('span.option').wrapAll('<div class="droppedradios">');
$(elem).find('div.droppedradios').hide();
}
(function($) {
$().ready(function() {
$('.author-autocomplete').autocomplete('./listAuthors', {
}).result(author_autocomplete_ready);
$('#formfield-document-widgets-l_doctypes').each(setup_appearance);
$('#formfield-document-widgets-l_topics').each(setup_appearance);
$('#formfield-document-widgets-l_polgroups').each(setup_appearance);
$('#formfield-document-widgets-sort_on').each(setup_sort_on);
});
})(jQuery);
</script>
<script metal:use-macro="view/js_macros/macros/labelboxes"></script>
</tal:block>
</tal:main-macro>

View File

@ -22,6 +22,7 @@ from z3c.form.browser.radio import RadioWidget
from z3c.relationfield.schema import RelationChoice, RelationList
from plone.formwidget.contenttree import ObjPathSourceBinder
import plone.directives.form
from tabellio.searchform.interfaces import MessageFactory as _
@ -278,6 +279,28 @@ def possible_polgroups(context):
terms.append(SimpleVocabulary.createTerm(polgroup_id, polgroup_id, polgroup_str))
return SimpleVocabulary(terms)
@grok.provider(IContextSourceBinder)
def possible_active_polgroups(context):
terms = []
current = getToolByName(context, 'portal_url').getPortalObject()
settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
for part in settings.polgroupsPath.split('/'):
if not part:
continue
current = getattr(current, part)
for object in current.objectValues():
if object.portal_type != 'themis.datatypes.polgroup':
continue
if not object.active:
continue
polgroup_id = object.id
polgroup_str = object.Title()
terms.append(SimpleVocabulary.createTerm(polgroup_id, polgroup_id, polgroup_str))
return SimpleVocabulary(terms)
@grok.provider(IContextSourceBinder)
def possible_topics(context):
@ -320,7 +343,7 @@ class DocumentSearchForm(form.Form):
fields['topics'].widgetFactory = FieldTopicsWidget
fields['sort_on'].widgetFactory = FieldRadioboxesWidget
ignoreContext = True
template = ViewPageTemplateFile('form_templates/view_effectivesearch.pt')
template = ViewPageTemplateFile('form_templates/view_form.pt')
def updateWidgets(self):
super(DocumentSearchForm, self).updateWidgets()
@ -369,7 +392,7 @@ class DossierSearchForm(form.Form):
fields['topics'].widgetFactory = FieldTopicsWidget
fields['sort_on'].widgetFactory = FieldRadioboxesWidget
ignoreContext = True
template = ViewPageTemplateFile('form_templates/view_dossier_search.pt')
template = ViewPageTemplateFile('form_templates/view_form.pt')
def updateWidgets(self):
super(DossierSearchForm, self).updateWidgets()
@ -412,7 +435,7 @@ class QuestionSearchForm(form.Form):
fields['topics'].widgetFactory = FieldTopicsWidget
fields['sort_on'].widgetFactory = FieldRadioboxesWidget
ignoreContext = True
template = ViewPageTemplateFile('form_templates/view_question_search.pt')
template = ViewPageTemplateFile('form_templates/view_form.pt')
def updateWidgets(self):
super(QuestionSearchForm, self).updateWidgets()
@ -464,7 +487,7 @@ class DocumentPfbSearchForm(form.Form):
fields['l_topics'].widgetFactory = FieldDroppedCheckboxWidget
fields['sort_on'].widgetFactory = FieldRadioboxesWidget
ignoreContext = True
template = ViewPageTemplateFile('form_templates/view_pfbdocsearch.pt')
template = ViewPageTemplateFile('form_templates/view_form.pt')
def updateWidgets(self):
super(DocumentPfbSearchForm, self).updateWidgets()
@ -485,14 +508,14 @@ class IDeputySearch(interface.Interface):
name = schema.TextLine(title=_(u'Name'), required=False)
polgroup = schema.Choice(title=_(u'Political Group'),
required=False, source=possible_polgroups)
required=False, source=possible_active_polgroups)
class DeputySearchForm(form.Form):
prefix = 'deputy'
fields = field.Fields(IDeputySearch)
ignoreContext = True
template = ViewPageTemplateFile('form_templates/view_deputy_search.pt')
template = ViewPageTemplateFile('form_templates/view_form.pt')
def updateWidgets(self):
super(DeputySearchForm, self).updateWidgets()
@ -529,7 +552,7 @@ class DeputySearchForm(form.Form):
prefix = 'deputy'
fields = field.Fields(IDeputySearch)
ignoreContext = True
template = ViewPageTemplateFile('form_templates/view_deputy_search.pt')
template = ViewPageTemplateFile('form_templates/view_form.pt')
def updateWidgets(self):
super(DeputySearchForm, self).updateWidgets()
@ -591,6 +614,7 @@ class GlobalSearchForm(form.Form):
class SearchView(BrowserView):
batch_macros = ViewPageTemplateFile('batch_macros.pt')
js_macros = ViewPageTemplateFile('js_macros.pt')
def portal_url(self):
return getToolByName(self.context, 'portal_url').getPortalPath()

View File

@ -1,40 +0,0 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
lang="en"
metal:use-macro="context/main_template/macros/master"
i18n:domain="tabellio.searchform">
<body>
<metal:main fill-slot="main">
<tal:main-macro metal:define-macro="main">
<div tal:replace="structure provider:plone.abovecontenttitle" />
<h1 class="documentFirstHeading" tal:content="context/title" />
<div tal:replace="structure provider:plone.belowcontenttitle" />
<dl class="enableFormTabbing" id="search-tabs">
<dt>Documents parlementaires</dt>
<dd>
<div tal:replace="structure view/doc_search_form"/>
</dd>
<dt>Dossiers parlementaires</dt>
<dd>
</dd>
<dt>Questions &amp; interpellations</dt>
<dd>
</dd>
<dt>Décrets</dt>
<dd>
</dd>
</dl>
<div tal:replace="structure provider:plone.belowcontentbody" />
</tal:main-macro>
</metal:main>
</body>
</html>

View File

@ -1,8 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal">
<body>
<metal:use use-macro="context/@@ploneform-macros/fields" />
<metal:use use-macro="context/@@ploneform-macros/actions" />
</body>
</html>

View File

@ -1,9 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal">
<body>
<metal:use use-macro="context/@@ploneform-macros/fields" />
<metal:use use-macro="context/@@ploneform-macros/actions" />
</body>
</html>

View File

@ -1,8 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal">
<body>
<metal:use use-macro="context/@@ploneform-macros/fields" />
<metal:use use-macro="context/@@ploneform-macros/actions" />
</body>
</html>

View File

@ -1,8 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal">
<body>
<metal:use use-macro="context/@@ploneform-macros/fields" />
<metal:use use-macro="context/@@ploneform-macros/actions" />
</body>
</html >

View File

@ -1,8 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal">
<body>
<metal:use use-macro="context/@@ploneform-macros/fields" />
<metal:use use-macro="context/@@ploneform-macros/actions" />
</body>
</html>

View File

@ -152,30 +152,8 @@
</div>
<script type="text/javascript">
<script metal:use-macro="view/js_macros/macros/livereload"></script>
function load_results(elem)
{
var base = $(elem).parents('.results-var');
var base_spec = ' #' + $(elem).parents('.results-var').parent()[0].id + ' .results-var > div';
jQuery.get($(elem).attr('href'), null, function(data, textStatus, jqXHR) {
if (textStatus == 'notmodified')
return;
if (textStatus == 'success') {
$(base).html($(data).find(base_spec));
console.log('ici:', $(base).find('.listingBar a'));
$(base).find('.listingBar a').click(function() { return load_results($(this)); });
}
});
return false;
}
(function($) {
$().ready(function() {
$('.results-var .listingBar a').click(function() { return load_results($(this)); });
});
})(jQuery);
</script>
</tal:main-macro>
</metal:main>

View File

@ -40,6 +40,9 @@
<div class="resultsinfobox">
<span>Nombre de résultats : <span tal:replace="python:len(deputy_results)"/></span>
<a class="button" tal:attributes="href view/deputy_form_url">Filtre avancé</a>
<form method="post" style="display: none;" tal:attributes="action string:${view/deputy_form_url}">
<div tal:replace="structure view/deputy_search_form"/>
</form>
</div>
<div class="results-var">
@ -76,6 +79,9 @@
<div class="resultsinfobox">
<span>Nombre de résultats : <span tal:replace="python:len(doc_results)"/></span>
<a class="button" tal:attributes="href view/docdos_form_url">Filtre avancé</a>
<form method="post" style="display: none;" tal:attributes="action string:${view/docdos_form_url}#resultsbox">
<div tal:replace="structure view/document_search_form"/>
</form>
</div>
<div class="results-var">
@ -102,6 +108,9 @@
<div class="resultsinfobox">
<span>Nombre de résultats : <span tal:replace="python:len(event_results)"/></span>
<a class="button" tal:attributes="href view/event_form_url">Filtre avancé</a>
<form method="post" style="display: none;" tal:attributes="action string:${view/event_form_url}">
<div tal:replace="structure view/event_search_form"/>
</form>
</div>
<div class="results-var">
@ -110,15 +119,17 @@
<tal:entry tal:repeat="event event_batch">
<li tal:define="oddrow repeat/event/odd;" tal:attributes="class python: oddrow and 'odd' or 'even'"><div>
<h4><a href="#" tal:attributes="href event/getURL" tal:content="event/Title">Véronique Salvi</a></h4>
<p><span tal:content="python: event.getObject().longdatetime"/> /
<span tal:content="python: event.getObject().place"/></p>
</div></li>
</tal:entry>
</ul>
</div>
</div>
<div tal:define="batch event_batch">
<div metal:use-macro="view/batch_macros/macros/navigation" />
</div>
</div>
</div>
@ -149,27 +160,17 @@
</div>
<script type="text/javascript" tal:content="string: var PORTAL_URL='${view/portal_url}';"/>
<script metal:use-macro="view/js_macros/macros/labelboxes"></script>
<script metal:use-macro="view/js_macros/macros/livereload"></script>
<script type="text/javascript">
function load_results(elem)
{
var base = $(elem).parents('.results-var');
var base_spec = ' #' + $(elem).parents('.results-var').parent()[0].id + ' .results-var > div';
jQuery.get($(elem).attr('href'), null, function(data, textStatus, jqXHR) {
if (textStatus == 'notmodified')
return;
if (textStatus == 'success') {
$(base).html($(data).find(base_spec));
console.log('ici:', $(base).find('.listingBar a'));
$(base).find('.listingBar a').click(function() { return load_results($(this)); });
}
});
return false;
}
(function($) {
$().ready(function() {
$('.results-var .listingBar a').click(function() { return load_results($(this)); });
$('.resultsinfobox form').hide();
$('.resultsinfobox a').click(function() {
$(this).next('form').toggle();
return false;
});
});
})(jQuery);
</script>

View File

@ -1,5 +1,5 @@
from zope import interface, schema
from z3c.form import form, field, button
from z3c.form import field, button
from plone.z3cform.layout import wrap_form
from Products.CMFCore.utils import getToolByName
@ -13,8 +13,41 @@ from tabellio.searchform.interfaces import MessageFactory as _
from Products.Five import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
import form
class SimpleSearchView(BrowserView):
batch_macros = ViewPageTemplateFile('batch_macros.pt')
js_macros = ViewPageTemplateFile('js_macros.pt')
def deputy_search_form(self):
f = form.DeputySearchForm(self.context, self.request)
f.update()
return f.render()
def document_pfb_search_form(self):
f = form.DocumentPfbSearchForm(self.context, self.request)
f.update()
return f.render()
def document_search_form(self):
f = form.DocumentSearchForm(self.context, self.request)
f.update()
return f.render()
def dossier_search_form(self):
f = form.DossierSearchForm(self.context, self.request)
f.update()
return f.render()
def question_search_form(self):
f = form.QuestionSearchForm(self.context, self.request)
f.update()
return f.render()
def event_search_form(self):
f = form.EventSearchForm(self.context, self.request)
f.update()
return f.render()
def deputy_form_url(self):
catalog = getToolByName(self.context, 'portal_catalog')
@ -81,7 +114,8 @@ class SimpleSearchView(BrowserView):
return catalog(
portal_type=['tabellio.agenda.parlevent', 'tabellio.agenda.event',
'tabellio.agenda.comevent'],
SearchableText=self.request.form.get('SearchableText'))
SearchableText=self.request.form.get('SearchableText'),
sort_on='start', sort_order='descending')
def get_batchlinkparams(self):
d = dict()