<?php $odd = true;

// build menu
$actionMenu = new OntoWiki_Menu();
$actionMenu->setEntry('Toggle show Permalink', "javascript:showPermaLink()");
$actionMenu->setEntry('Toggle show Resource Query', "javascript:showresQuery()");
$actionMenu->setEntry('Toggle show Value Query', "javascript:showvalQuery()");
$actions = new OntoWiki_Menu();
$actions->setEntry('View', $actionMenu);
$this->placeholder('main.window.menu')->set($actions->toArray());

$instances = $this->instances;
// get queries
$resourceQuery =  $instances->getResourceQuery();
$valueQuery = $instances->getQuery();
$permalink = $instances->getPermalink($this->listName);
$config = Erfurt_App::getInstance()->getConfig();
$urlBase = $config->urlBase;

$this->headScript()->prependScript(
    'function showPermaLink(){$("#permalink").slideToggle(400);}
    function showresQuery(){$("#resQuery").slideToggle(400);}
    function showvalQuery(){$("#valQuery").slideToggle(400);}
    function changeSorting(n){
        var mainInnerContent = $(n).parents(".innercontent");
        mainInnerContent.addClass("is-processing");
        mainInnerContent.load(
            reloadUrl+"",
            {"instancesconfig": $.toJSON({ sort : {
                "uri" : $(n).attr("p"),
                "asc" : $(n).hasClass("up")
            }}), "list":listName},
            function(){
                mainInnerContent.removeClass("is-processing");
                $(".statustool li a").removeClass("selected");
                $("body").trigger("ontowiki.resource-list.reloaded");
        });
    }'
);
?>
<div id="permalink" class="messagebox" style="display:none"><?php echo $permalink; ?></div>
<div id="resQuery" class="messagebox" style="display:none"><?php echo htmlentities($resourceQuery); ?><br><a href="<?php echo $urlBase; ?>queries/editor/?query=<?php echo urlencode($resourceQuery)?>">Open in editor</a></div>
<div id="valQuery" class="messagebox" style="display:none"><?php echo htmlentities($valueQuery); ?><br><a href="<?php echo $urlBase; ?>queries/editor/?query=<?php echo urlencode($valueQuery)?>">Open in editor</a></div>
<?php
    if ($this->instances->hasData()):
        ?>
<table class="resource-list separated-vertical"
        <?php foreach ($this->other->namespacePrefixes as $prefix => $namespace): ?>
                   <?php echo ' xmlns:' . $prefix . '="' . $namespace . '"' ?>
                   <?php endforeach; ?>>
        <?php if (!empty($this->propertyInfo)): ?>
    <tr>
        <?php /* column for the numbers*/?>
        <th></th>
        <?php /* column for the instance title/label*/?>
        <th></th>
        <?php /* a column for each property */
        foreach ($this->propertyInfo as $property): if($property['hidden']){continue;}?>
        <th>
            <a class="hasMenu Property"
               about="<?php echo $property['uri'] ?>"
               href="<?php echo $property['url'] ?>"><?php echo $property['title']; ?></a>
                <?php if ($property['inverse']){ ?><sup>-1</sup><?php } ?>
                <a class="tablesort up small" p="<?php echo $property['uri'] ?>" onclick="javascript:changeSorting(this)">&#9650;</a>
                <a class="tablesort down small" p="<?php echo $property['uri'] ?>" onclick="javascript:changeSorting(this)">&#9660;</a>
        </th>
        <?php endforeach; ?>
    </tr>
            <?php endif; ?>
            <?php $i = $this->start ?>
        <?php foreach ($this->instanceInfo as $instance){
            //call subtemplate in a loop (for each instance a row)
            echo $this->partial('partials/list_std_element.phtml',
                array(
                    'instanceUri'  => $instance['uri'],
                    'instance'     => $instance,
                    'instanceData' => $this->instanceData,
                    'instanceInfo' => $this->instanceInfo,
                    'propertyInfo' => $this->propertyInfo,
                    'other'        => $this->other,
                    'odd'          => $odd,
                    'i'            => $i
                )
             );
            $odd = !$odd;
            $i++;
        } ?>
</table>
    <?php else: ?>
<p class="messagebox info"><?php echo $this->_('No matches.') ?></p>
    <?php endif; ?>
