Skip to content
Permalink
ac2726ddc4
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
361 lines (325 sloc) 13.2 KB
<?php
/**
* COmanage Registry Standard Index Template
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link https://www.internet2.edu/comanage COmanage Project
* @package registry
* @since COmanage Registry v5.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/
/*
* XXX Replace this file with the version from COMMON once pagination is fixed
* - need to pull pagination since COs now has 21 entries (registrytest)
*/
declare(strict_types = 1);
//use \App\Lib\Enum\StatusEnum;
// $this->name = Models
$modelsName = $this->name;
// $tablename = models
// XXX backport to match?
$tableName = \Cake\Utility\Inflector::tableize(\Cake\Utility\Inflector::singularize($this->name));
// Do we have records for this index? This will be set to true during render if we do.
// Otherwise, we'll print out a "no records" message.
$recordsExist = false;
// Our default link actions, in order of preference, unless the column config overrides it
$linkActions = ['edit', 'view'];
// Read the index configuration ($indexColumns) for this model
include(ROOT . DS . "templates" . DS . $modelsName . DS . "columns.inc");
// $linkFilter is used for models that belong to a specific parent model (eg: co_id)
$linkFilter = [];
if(!empty($vv_primary_link) && !empty($this->request->getQuery($vv_primary_link))) {
$linkFilter = [$vv_primary_link => $this->request->getQuery($vv_primary_link)];
}
function _column_key($modelsName, $c, $tz=null) {
if(strpos($c, "_id", strlen($c)-3)) {
// Key is of the form field_id, use .ct label instead
$k = \Cake\Utility\Inflector::classify(\Cake\Utility\Inflector::pluralize(substr($c, 0, strlen($c)-3)));
return __d('controller' ,$k, [1]);
}
// Look for a model specific key first
$label = __d('field', $modelsName.'.'.$c);
if($label != $modelsName.'.'.$c) {
return $label;
}
if($tz) {
// If there is a timezone aware label, use that
$label = __d('field', $c.'.tz', [$tz]);
if($label != $c.'.tz') {
return $label;
}
}
// Otherwise look for the general key
return __d('field', $c);
}
?>
<div class="titleNavContainer">
<div class="pageTitle">
<h1><?= $vv_title; ?></h1>
</div>
<?php if($vv_permissions['add']): ?>
<ul id="topLinks">
<li>
<?= $this->Html->link('<em class="material-icons" aria-hidden="true">add_circle</em> ' .
__d('operation', 'add.a', __d('controller', $modelsName, [1])),
['action' => 'add', '?' => $linkFilter],
['escape' => false]); ?>
</li>
<?php
if(!empty($topLinks)) {
foreach($topLinks as $t) {
if($vv_permissions[ $t['link']['action'] ]) {
// We need to inject $linkFilter, but not overwrite any existing query params
if(!empty($t['link']['?'])) {
$t['link']['?'] = array_merge($t['link']['?'], $linkFilter);
} else {
$t['link']['?'] = $linkFilter;
}
print '<li>' .
$this->Html->link(
'<em class="material-icons" aria-hidden="true">' . $t['icon']. '</em> ' . $t['label'],
$t['link'],
['escape' => false, 'class' => $t['class']]
) . '
</li>';
}
}
}
?>
</ul>
<?php endif; ?>
</div>
<?php if(!empty($indexBanners)): ?>
<?php foreach($indexBanners as $b): ?>
<div class="co-info-topbox">
<em class="material-icons">info</em>
<?= $b; ?>
</div>
<?php endforeach; // $indexBanners ?>
<?php endif; // $indexBanners ?>
<?php if(!empty($banners)): ?>
<?php foreach($banners as $b): ?>
<div class="co-info-topbox">
<em class="material-icons">info</em>
<?= $b; ?>
</div>
<?php endforeach; // $banners ?>
<?php endif; // $banners ?>
<!-- Search block -->
<?php if(!empty($enableSearch)): ?>
<?= $this->element('search'); ?>
<?php endif; // $enableSearch ?>
<!-- Index table -->
<div class="table-container">
<table id="<?= $tableName . '-table'; ?>">
<tr>
<?php foreach($indexColumns as $col => $cfg): ?>
<th<?= !empty($cfg['cssClass']) ? ' class="' . $cfg['cssClass'] . '"' : ''; ?>>
<?php
$label = !empty($cfg['label']) ? $cfg['label'] : _column_key($modelsName, $col, $vv_tz);
if(isset($cfg['sortable']) && $cfg['sortable']) {
if(is_string($cfg['sortable'])) {
print $this->Paginator->sort($cfg['sortable'], $label);
} else {
print $this->Paginator->sort($col, $label);
}
} else {
print $label;
}
?>
</th>
<?php endforeach; ?>
<th><?= __d('field', 'action'); ?></th>
</tr>
<?php foreach($$tableName as $entity): ?>
<tr>
<?php foreach($indexColumns as $col => $cfg): ?>
<td<?= !empty($cfg['cssClass']) ? ' class="' . $cfg['cssClass'] . '"' : ''; ?>>
<?php
switch($cfg['type']) {
case 'boolean':
if(!empty($entity->$col) && $entity->$col) {
print __d('enumeration', $cfg['class'].'.1');
} else {
print __d('enumeration', $cfg['class'].'.0');
}
break;
case 'datetime':
print $this->Time->nice($entity->$col, $vv_tz);
break;
case 'enum':
if($entity->$col) {
// XXX Need to add badging - see index.php in Match
print __d('enumeration', $cfg['class'].'.'.$entity->$col);
}
break;
case 'fk':
// Assuming $col is of the form foo_id, look to see if the corresponding
// AutoViewVar $foos is set, and if so render the lookup value instead
$f = null;
if(preg_match('/^(.*?)_id$/', $col, $f)) {
$avv = \Cake\Utility\Inflector::variable(\Cake\Utility\Inflector::pluralize($f[1]));
if(!empty(${$avv}[$entity->$col])) {
// We found the viewvar (eg: $foos), and it has a corresponding value
// (eg: $foos[3]), so render it
print ${$avv}[$entity->$col]; // XXX filter_var?
} else {
// No match, just render the value
print $entity->$col;
}
} else {
// Just print the value
print $entity->$col;
}
break;
case 'button':
if(!empty($entity->$col)) {
$buttonAttrs = [];
$buttonText = $entity->$col;
if(!empty($cfg['button']['attrs'])) {
$buttonAttrs = $cfg['button']['attrs'];
}
$buttonAttrs['type'] = 'button';
if(!empty($cfg['button']['text']) && $cfg['button']['text'] != 'fieldVal') {
$buttonText = $cfg['button']['text'];
}
if(!empty($cfg['truncate']) && is_int($cfg['truncate'])) {
// We check for $truncate + 1 because there's no point trimming
// the last character if we're just going to replace it with ...
$buttonText = (strlen($buttonText) > $cfg['truncate'] + 1) ? substr($buttonText,0,$cfg['truncate']).'...' : $buttonText;
}
if(!empty($cfg['button']['popover'])) {
if($cfg['button']['popover'] == 'fieldVal') {
$buttonAttrs['data-bs-content'] = $entity->$col;
} else {
$buttonAttrs['data-bs-content'] = $cfg['button']['popover'];
}
$label = !empty($cfg['label']) ? $cfg['label'] : _column_key($modelsName, $col, $vv_tz);
$buttonAttrs['title'] = $label;
$buttonAttrs['data-bs-toggle'] = 'popover';
$buttonAttrs['data-bs-container'] = 'body';
$buttonAttrs['data-bs-placement'] = 'top';
$buttonAttrs['data-bs-animation'] = 'false';
}
print $this->Form->button($buttonText, $buttonAttrs);
}
break;
case 'link':
case 'echo':
default:
// By default our label is the column value, but it might be overridden
$label = $entity->$col;
if(!empty($cfg['model']) && !empty($cfg['field'])) {
$m = $cfg['model'];
$f = $cfg['field'];
if(!empty($entity->$m->$f)) {
$label = $entity->$m->$f;
}
}
$linked = false;
if($cfg['type'] == 'link') {
foreach($linkActions as $a) {
// Does this user have permission for this action?
if($vv_permission_set[$entity->id][$a]) {
// XXX Check this against Match
print $this->Html->link($label, ['action' => $a, $entity->id]);
$linked = true;
break 2;
}
}
}
if(!$linked) {
// Just echo the value
print $label;
}
break;
// XXX dates can be rendered as eg $entity->created->format(DATE_RFC850);
}
?>
</td>
<?php endforeach; // $indexColumns ?>
<td class="actions">
<?php
// XXX Convert this to use the actionMenu element as in Match 1.0
if($vv_permission_set[$entity->id]['edit']) {
print $this->Html->link(
__d('operation', 'edit'),
['action' => 'edit', $entity->id],
['class' => 'editbutton']
);
} elseif($vv_permission_set[$entity->id]['view']) {
print $this->Html->link(
__d('operation', 'view'),
['action' => 'view', $entity->id],
['class' => 'viewbutton']
);
}
if($vv_permission_set[$entity->id]['delete']) {
// XXX this is throwing CSRF error even though delete button on edit-record page is working?
// probably because this is using Form helper, but we're outside of a form?
print $this->Form->postLink(
__d('operation', 'delete'),
['action' => 'delete', $entity->id],
// XXX should be configurable which field we put in, maybe displayField?
['confirm' => __d('operation', 'delete.confirm', [$entity->id]),
'class' => 'deletebutton']
);
}
// Insert additional actions as per the .inc file
// XXX Check all this against Match 1.0 (which should be newer)
if(!empty($indexActions)) {
// XXX this isn't quite the right test
// if(isset($entity->status) && $entity->status == StatusEnum::Active) {
foreach($indexActions as $a) {
if($vv_permission_set[$entity->id][ $a['action'] ]) {
// If we have a .confirm text, use postLink instead
$confirmKey = $a['action'].'.confirm';
$confirmTxt = __d('operation', $confirmKey);
if($confirmTxt != $confirmKey) {
// We found the localized string
print $this->Form->postLink(
__d('operation', $a['action']),
['action' => $a['action'], $entity->id],
// XXX should be configurable which field we put in, maybe displayField?
['confirm' => __d('operation', $confirmKey, [$entity->id]),
'class' => $a['class']]
);
} else {
print $this->Html->link(
__d('operation', $a['action']),
['action' => $a['action'], $entity->id],
['class' => $a['class']]
);
}
}
}
// }
}
?>
</td>
</tr>
<?php $recordsExist = true; ?>
<?php endforeach; // $$tablename ?>
<?php if(!$recordsExist): ?>
<tr><td colspan="<?= count($indexColumns); ?>"><?= __d('information','global.records.none') ?></td></tr>
<?php endif; ?>
</table>
</div>
<?php
print $this->element("pagination");