This repository has been archived on 2023-02-21. You can view files and clone it, but cannot push or open issues or pull requests.
tabellio.searchform/tabellio/searchform/js_macros.pt

166 lines
5.3 KiB
XML

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="plone">
<body>
<script tppe="text/javascript" metal:define-macro="labelboxes">
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)
{
$(elem).parent().find('input').wrapAll('<div class="labelboxes">');
$('div.labelboxes').click(function() { $(this).find('input').focus(); });
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', {
'matchContains': true, 'scroll': true, 'max': 30}).result(autocomplete_ready);
$('.polgroup-autocomplete').each(sync_polgroups).autocomplete(PORTAL_URL+'/listPolgroups', {
}).result(autocomplete_ready);
$('.topic-autocomplete').each(sync_topics).autocomplete(PORTAL_URL+'/listTopics', {
'matchContains': true, 'scroll': true, 'max': 30}).result(autocomplete_ready);
});
})(jQuery);
</script>
<script type="text/javascript" metal:define-macro="livereload">
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>
<script type="text/javascript" metal:define-macro="sorton">
(function($) {
$().ready(function() {
$('#formfield-document-widgets-sort_on').hide();
$('#formfield-dossier-widgets-sort_on').hide();
$('#formfield-question-widgets-sort_on').hide();
$('#resultsbox').each(function() {
form = $($(this).prevAll('input').attr('value')).find('form');
field_array = $(form).find('div.field');
sort_on_options = $(field_array[field_array.length-1]).find('option').clone();
$('#sorton select').append(sort_on_options).change(function() {
selected_option = $(this).val();
$(field_array[field_array.length-1]).find('option').each(function() {
if ($(this).attr('value') == selected_option) {
$(this).attr('selected', 'selected');
$(form).submit();
} else {
$(this).attr('selected', null);
}
});
});
});
});
})(jQuery);
</script>
<script type="text/javascript" metal:define-macro="droppablecheckboxes">
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_droppedcheckboxes(index, elem)
{
var dummyinput = $('<input class="dummyinput" type="text" readonly="readonly"/>');
sync_from_checkboxes(elem, dummyinput);
dummyinput.click(function() {
$(elem).toggle().parent().toggleClass('openboxes');
});
$(elem).parent().find('.fieldErrorBox').after(dummyinput);
$(elem).find('span.option').click(function() {
sync_from_checkboxes(elem, dummyinput);
});
$(elem).hide();
}
(function($) {
$().ready(function() {
$('div.droppedcheckboxes').each(setup_droppedcheckboxes);
});
})(jQuery);
</script>
</body>
</html>