Commit 0d7cbc43 authored by Nigel McNie's avatar Nigel McNie
Browse files

Add support to the artefact chooser for a 'search' tab that allows drilling...

Add support to the artefact chooser for a 'search' tab that allows drilling through the artefacts that can be chosen.

It works in firefox fine, and works without javascript fine (therefore it works in ie6). Opera also works. Konqueror and IE7 do not work properly.
parent 27c2130c
......@@ -47,11 +47,19 @@ function pieform_element_artefactchooser(Pieform $form, $element) {
$smarty->assign('artefacts', $html);
$smarty->assign('pagination', $pagination['html']);
$formname = $form->get_name();
$smarty->assign('blockinstance', substr($formname, strpos($formname, '_') + 1));
// Save the pagination javascript for later, when it is asked for. This is
// messy, but can't be helped until Pieforms goes to a more OO way of
// managing stuff.
$pagination_js = $pagination['javascript'];
$baseurl = view::make_base_url();
$smarty->assign('browseurl', $baseurl);
$smarty->assign('searchurl', $baseurl . '&s=1');
$smarty->assign('searchable', !empty($element['search']));
return $smarty->fetch('form/artefactchooser.tpl');
}
......@@ -112,6 +120,9 @@ function pieform_element_artefactchooser_set_attributes($element) {
if (!isset($element['template'])) {
$element['template'] = 'form/artefactchooser-element.tpl';
}
if (!isset($element['search'])) {
$element['search'] = true;
}
return $element;
}
......@@ -128,6 +139,77 @@ function pieform_element_artefactchooser_set_attributes($element) {
*/
function pieform_element_artefactchooser_views_js(Pieform $form, $element) {
global $pagination_js;
// NOTE: $element['name'] is not set properly at this point
$element = pieform_element_artefactchooser_set_attributes($element);
$element['name'] = (!empty($element['selectone'])) ? 'artefactid' : 'artefactids';
$pagination_js = 'var p = ' . $pagination_js;
$pagination_js .= <<<EOF
var ul = getFirstElementByTagAndClassName('ul', 'artefactchooser-tabs', '{$form->get_name()}_{$element['name']}_container');
var doneBrowse = false;
var browseA = null;
var searchA = null;
forEach(getElementsByTagAndClassName('a', null, ul), function(a) {
p.rewritePaginatorLink(a);
if (!doneBrowse) {
doneBrowse = true;
browseA = a;
// Hide the search form
connect(a, 'onclick', function(e) {
hideElement('artefactchooser-searchform');
removeElementClass(searchA.parentNode, 'current');
addElementClass(browseA.parentNode, 'current');
browseA.blur();
$('artefactchooser-searchfield').value = ''; // forget the search for now, easier than making the tabs remember it
e.stop();
});
}
else {
searchA = a;
// Display the search form
connect(a, 'onclick', function(e) {
showElement('artefactchooser-searchform');
removeElementClass(browseA.parentNode, 'current');
addElementClass(searchA.parentNode, 'current');
$('artefactchooser-searchfield').focus();
e.stop();
});
// Wire up the search button
connect('artefactchooser-searchsubmit', 'onclick', function(e) {
e.stop();
var loc = searchA.href.indexOf('?');
var queryData = [];
if (loc != -1) {
queryData = parseQueryString(searchA.href.substring(loc + 1, searchA.href.length));
queryData.extradata = serializeJSON(p.extraData);
queryData.search = $('artefactchooser-searchfield').value;
}
sendjsonrequest(p.jsonScript, queryData, 'GET', function(data) {
getFirstElementByTagAndClassName('tbody', null, p.datatable).innerHTML = data['data']['tablerows'];
// Update the pagination
var tmp = DIV();
tmp.innerHTML = data['data']['pagination'];
swapDOM(p.id, tmp.firstChild);
// Run the pagination js to make it live
eval(data['data']['pagination_js']);
// Update the result count
getFirstElementByTagAndClassName('div', 'results', p.id).innerHTML = data['data']['count'] + ' results'; // TODO i18n and pluralisation
});
});
}
});
EOF;
return $pagination_js;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment