Commit 26d770f0 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Change tag using json script; show number of results when hovering on tag

parent 0da03fd9
......@@ -87,6 +87,7 @@ $string['youhavenottaggedanythingyet'] = 'You have not tagged anything yet';
$string['mytags'] = 'My Tags';
$string['Tag'] = 'Tag';
$string['itemstaggedwith'] = 'Items tagged with "%s"';
$string['numitems'] = '%s items';
$string['selfsearch'] = 'Search My Portfolio';
......
......@@ -2790,7 +2790,7 @@ function build_pagination($params) {
$datatable = json_encode($params['datatable']);
$jsonscript = json_encode($params['jsonscript']);
$extradata = json_encode($params['extradata']);
$js .= "new Paginator($id, $datatable, $jsonscript, $extradata);";
$js .= "var {$params['datatable']}_pager = new Paginator($id, $datatable, $jsonscript, $extradata);";
}
// Output the count of results
......
......@@ -30,15 +30,45 @@ require('init.php');
require('searchlib.php');
define('TITLE', get_string('mytags'));
if ($tag = param_variable('tag', null)) {
$tags = get_my_tags();
$tag = param_variable('tag', null);
if ($tags && is_null($tag)) {
$tag = $tags[0]->tag;
}
if ($tag) {
$limit = param_integer('limit', 10);
$offset = param_integer('offset', 0);
$owner = (object) array('type' => 'user', 'id' => $USER->get('id'));
$data = get_portfolio_items_by_tag($tag, $owner, $limit, $offset);
build_portfolio_search_html($data);
$pagerjs = $data->pagination_js;
}
else {
$pagerjs = 'var results_pager = new Paginator("portfoliosearch_pagination", "results", "json\\/tagsearch.php", null);';
}
$tags = get_my_tags();
$js .= <<<EOF
addLoadEvent(function() {
{$pagerjs}
forEach(getElementsByTagAndClassName('a', 'tag', 'main-column-container'), function(elem) {
disconnectAll(elem);
connect(elem, 'onclick', function(e) {
e.stop();
var href = getNodeAttribute(this, 'href');
var params = parseQueryString(href.substring(href.indexOf('?')+1, href.length));
sendjsonrequest(config.wwwroot + 'json/tagsearch.php', params, 'POST', function(data) {
results_pager.updateResults(data);
forEach(getElementsByTagAndClassName('a', 'selected', 'main-column-container'), function(selected) {
removeElementClass(selected, 'selected');
});
addElementClass(elem, 'selected');
});
return false;
});
});
});
EOF;
$smarty = smarty(array('paginator'));
$smarty->assign('PAGEHEADING', hsc(TITLE));
......@@ -46,7 +76,7 @@ $smarty->assign('tags', $tags);
if (!is_null($tag) && isset($data)) {
$smarty->assign('tag', $tag);
$smarty->assign_by_ref('results', $data);
$smarty->assign('INLINEJAVASCRIPT', 'addLoadEvent(function() {' . $data->pagination_js . '});');
}
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->display('tags.tpl');
?>
......@@ -2,7 +2,7 @@
<h3>{str tag="mytags"}</h3>
<div class="sidebar-content mytags">
{foreach from=$data.tags item=tag}
<a class="tag" style="font-size: {$tag->size}em;" href="{$WWWROOT}tags.php?tag={$tag->tag|urlencode}">{$tag->tag|escape}</a>
<a class="tag" style="font-size: {$tag->size}em;" href="{$WWWROOT}tags.php?tag={$tag->tag|urlencode}" title="{str tag=numitems arg1=$tag->count}">{$tag->tag|escape}</a>
{/foreach}
</div>
{/if}
\ No newline at end of file
......@@ -3,23 +3,23 @@
{if $tags}
<div class="mytags">
{foreach from=$tags item=t}
<a class="tag{if $t->tag == $tag} selected{/if}" style="font-size: {$t->size}em;" href="{$WWWROOT}tags.php?tag={$t->tag|urlencode}">{$t->tag|escape}</a>
<a class="tag{if $t->tag == $tag} selected{/if}" style="font-size: {$t->size}em;" href="{$WWWROOT}tags.php?tag={$t->tag|urlencode}" title="{str tag=numitems arg1=$t->count}">{$t->tag|escape}</a>
{/foreach}
</div>
{else}
<div>{str tag=youhavenottaggedanythingyet}</div>
{/if}
{if !empty($results->data)}
<table id="results" class="tablerenderer fullwidth">
<thead>
<tr><th></th><th></th><th></th></tr>
</thead>
<tbody>
{if !empty($results->data)}
{$results->tablerows}
{/if}
</tbody>
</table>
{$results->pagination}
{/if}
{include file="footer.tpl"}
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