recreate label boxes after post
This commit is contained in:
parent
cb738dfbab
commit
5405e6de6c
|
@ -1,6 +1,6 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
tal:omit-tag="">
|
||||
<input type="hidden" tal:attributes="id view/id; name view/name;"/>
|
||||
<input type="hidden" tal:attributes="id view/id; name view/name; value view/value"/>
|
||||
<input class="author-autocomplete" type="text" tal:attributes="name string:${view/name}-query"/>
|
||||
</html>
|
||||
|
|
|
@ -134,28 +134,58 @@ function update_input(input) {
|
|||
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 = $('<span class="labelbox ' + data[1] + '">' + data[0] + '<' + '/span>');
|
||||
labelbox = create_labelbox(input_box, data[1], data[0]);
|
||||
$(input_box).before(labelbox);
|
||||
$(labelbox).click(function() {
|
||||
$(this).remove();
|
||||
update_input(jq(input_box).prevAll('input')[0]);
|
||||
});
|
||||
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(hidden, values[i], '...');
|
||||
$(hidden).after(labelbox);
|
||||
$(labelbox).load(url + '?id=' + values[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function sync_authors(index, elem) { sync_elements(index, elem, './listAuthors'); }
|
||||
function sync_polgroups(index, elem) { sync_elements(index, elem, './listPolgroups'); }
|
||||
function sync_topics(index, elem) { sync_elements(index, elem, './listTopics'); }
|
||||
|
||||
if(typeof(String.prototype.trim) === "undefined") {
|
||||
String.prototype.trim = function()
|
||||
{
|
||||
return String(this).replace(/^\s+|\s+$/g, '');
|
||||
};
|
||||
}
|
||||
|
||||
(function($) {
|
||||
$().ready(function() {
|
||||
$('.author-autocomplete').autocomplete('./listAuthors', {
|
||||
$('.author-autocomplete').each(sync_authors).autocomplete('./listAuthors', {
|
||||
}).result(autocomplete_ready);
|
||||
$('.polgroup-autocomplete').autocomplete('./listPolgroups', {
|
||||
$('.polgroup-autocomplete').each(sync_polgroups).autocomplete('./listPolgroups', {
|
||||
}).result(autocomplete_ready);
|
||||
$('.topic-autocomplete').autocomplete('./listTopics', {
|
||||
$('.topic-autocomplete').each(sync_topics).autocomplete('./listTopics', {
|
||||
}).result(autocomplete_ready);
|
||||
});
|
||||
})(jQuery);
|
||||
|
|
|
@ -51,8 +51,16 @@ class ListAuthorsView(BrowserView):
|
|||
def __call__(self):
|
||||
self.portal = getToolByName(self.context, 'portal_url').getPortalObject()
|
||||
self.settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
||||
|
||||
self.request.response.setHeader('Content-type', 'text/plain')
|
||||
|
||||
id = self.request.form.get('id')
|
||||
if id:
|
||||
try:
|
||||
t = getattr(self.deputies_folder, id)
|
||||
except AttributeError:
|
||||
return 'XXX'
|
||||
return t.Title()
|
||||
|
||||
s = []
|
||||
q = self.request.form.get('q').lower()
|
||||
for object in self.deputies_folder.objectValues():
|
||||
|
@ -83,8 +91,16 @@ class ListPolgroupsView(BrowserView):
|
|||
def __call__(self):
|
||||
self.portal = getToolByName(self.context, 'portal_url').getPortalObject()
|
||||
self.settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False)
|
||||
|
||||
self.request.response.setHeader('Content-type', 'text/plain')
|
||||
|
||||
id = self.request.form.get('id')
|
||||
if id:
|
||||
try:
|
||||
t = getattr(self.polgroups_folder, id)
|
||||
except AttributeError:
|
||||
return 'XXX'
|
||||
return t.Title()
|
||||
|
||||
s = []
|
||||
q = self.request.form.get('q').lower()
|
||||
for object in self.polgroups_folder.objectValues():
|
||||
|
@ -98,9 +114,18 @@ class ListPolgroupsView(BrowserView):
|
|||
class ListTopicsView(BrowserView):
|
||||
def __call__(self):
|
||||
from plone.i18n.normalizer.fr import normalizer
|
||||
query_terms = [normalizer.normalize(x).lower() for x in self.request.form.get('q').split()]
|
||||
topics = tabellio.config.utils.get_topics_dict()
|
||||
self.request.response.setHeader('Content-type', 'text/plain')
|
||||
|
||||
id = self.request.form.get('id')
|
||||
if id:
|
||||
try:
|
||||
return '%s' % topics.get(id, id)[0]
|
||||
except KeyError:
|
||||
return 'XXX'
|
||||
|
||||
query_terms = [normalizer.normalize(x).lower() for x in self.request.form.get('q').split()]
|
||||
|
||||
r = []
|
||||
for key, value in topics.items():
|
||||
for term in query_terms:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
tal:omit-tag="">
|
||||
<input type="hidden" tal:attributes="id view/id; name view/name;"/>
|
||||
<input type="hidden" tal:attributes="id view/id; name view/name; value view/value"/>
|
||||
<input class="polgroup-autocomplete" type="text" tal:attributes="name string:${view/name}-query"/>
|
||||
</html>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml"
|
||||
xmlns:tal="http://xml.zope.org/namespaces/tal"
|
||||
tal:omit-tag="">
|
||||
<input type="hidden" tal:attributes="id view/id; name view/name;"/>
|
||||
<input type="hidden" tal:attributes="id view/id; name view/name; value view/value"/>
|
||||
<input class="topic-autocomplete" type="text" tal:attributes="name string:${view/name}-query"/>
|
||||
</html>
|
||||
|
|
Reference in New Issue