Skip to content

Commit

Permalink
Minor fixes to standard index (NOJIRA)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Oct 3, 2021
1 parent 2051d24 commit 0950430
Showing 1 changed file with 49 additions and 50 deletions.
99 changes: 49 additions & 50 deletions app/templates/Standard/index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* COmanage Standard Index Template, shared between Match and Registry
* COmanage Standard Index Template
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
Expand All @@ -19,9 +19,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package common
* @since COmanage Common v1.0.0
* @link https://www.internet2.edu/comanage COmanage Project
* @package match
* @since COmanage Match v1.0.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

Expand All @@ -34,9 +34,6 @@
use \Cake\Utility\Inflector;
use \App\Lib\Enum\StatusEnum;

// Which product are we?
$product = __('product.code');

// $this->name = Models
$modelsName = $this->name;
// $tablefk = model_id
Expand All @@ -60,33 +57,31 @@
}

function _column_key($modelsName, $c, $tz=null) {
$product = __('product.code');

if(strpos($c, "_id", strlen($c)-3)) {
// Key is of the form field_id, use .ct label instead
$k = Inflector::camelize(Inflector::pluralize(substr($c, 0, strlen($c)-3)));

return __($product.'.ct.'.$k, [1]);
return __('match.ct.'.$k, [1]);
}

// Look for a model specific key first
$label = __($product.'.fd.'.$modelsName.'.'.$c);
$label = __('match.fd.'.$modelsName.'.'.$c);

if($label != $product.'.fd.'.$modelsName.'.'.$c) {
if($label != 'match.fd.'.$modelsName.'.'.$c) {
return $label;
}

if($tz) {
// If there is a timezone aware label, use that
$label = __($product.'.fd.'.$c.'.tz', [$tz]);
$label = __('match.fd.'.$c.'.tz', [$tz]);

if($label != $product.'.fd.'.$c.'.tz') {
if($label != 'match.fd.'.$c.'.tz') {
return $label;
}
}

// Otherwise look for the general key
return __($product.'.fd.'.$c);
return __('match.fd.'.$c);
}
?>
<div class="titleNavContainer">
Expand Down Expand Up @@ -161,7 +156,7 @@ function _column_key($modelsName, $c, $tz=null) {
}
?></th>
<?php endforeach; ?>
<th><?= __($product.'.fd.action'); ?></th>
<th><?= __('match.fd.action'); ?></th>
</tr>
<?php foreach(${$vv_tablename} as $entity): ?>
<?php
Expand All @@ -180,9 +175,9 @@ function _column_key($modelsName, $c, $tz=null) {
switch($cfg['type']) {
case 'boolean':
if(!empty($entity->$col) && $entity->$col) {
print __($product.'.en.'.$cfg['class'].'.1');
print __('match.en.'.$cfg['class'].'.1');
} else {
print __($product.'.en.'.$cfg['class'].'.0');
print __('match.en.'.$cfg['class'].'.0');
}
break;
case 'datetime':
Expand All @@ -191,7 +186,7 @@ function _column_key($modelsName, $c, $tz=null) {
break;
case 'enum':
if($entity->$col) {
print __($product.'.en.'.$cfg['class'].'.'.$entity->$col);
print __('match.en.'.$cfg['class'].'.'.$entity->$col);
}
break;
case 'fk':
Expand All @@ -215,32 +210,36 @@ function _column_key($modelsName, $c, $tz=null) {
}
break;
case 'button':
$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'])) {
$buttonText = (strlen($buttonText) > $cfg['truncate']) ? substr($buttonText,0,$cfg['truncate']).'...' : $buttonText;
}
if(!empty($cfg['button']['popover'])) {
if($cfg['button']['popover'] == 'fieldVal') {
$buttonAttrs['data-content'] = $entity->$col;
} else {
$buttonAttrs['data-content'] = $cfg['button']['popover'];
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-content'] = $entity->$col;
} else {
$buttonAttrs['data-content'] = $cfg['button']['popover'];
}
$label = !empty($cfg['label']) ? $cfg['label'] : _column_key($modelsName, $col, $vv_tz);
$buttonAttrs['title'] = $label;
$buttonAttrs['data-toggle'] = 'popover';
$buttonAttrs['data-container'] = 'body';
$buttonAttrs['data-placement'] = 'top';
$buttonAttrs['data-animation'] = 'false';
}
$label = !empty($cfg['label']) ? $cfg['label'] : _column_key($modelsName, $col, $vv_tz);
$buttonAttrs['title'] = $label;
$buttonAttrs['data-toggle'] = 'popover';
$buttonAttrs['data-container'] = 'body';
$buttonAttrs['data-placement'] = 'top';
$buttonAttrs['data-animation'] = 'false';
print $this->Form->button($buttonText, $buttonAttrs);
}
print $this->Form->button($buttonText, $buttonAttrs);
break;
case 'link':
case 'echo':
Expand Down Expand Up @@ -284,15 +283,15 @@ function _column_key($modelsName, $c, $tz=null) {
<?php
if($vv_permissions['edit']) {
print $this->Html->link(
__($product.'.op.edit'),
__('match.op.edit'),
array_merge_recursive(['action' => 'edit'], $linkArgs),
['class' => 'editbutton']
);
}

if(isset($vv_permissions['duplicate']) && $vv_permissions['duplicate']) {
print $this->Html->link(
__($product.'.op.duplicate'),
__('match.op.duplicate'),
array_merge_recursive(['action' => 'duplicate'], $linkArgs),
['class' => 'copybutton']
);
Expand All @@ -302,10 +301,10 @@ function _column_key($modelsName, $c, $tz=null) {
// 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(
__($product.'.op.delete'),
__('match.op.delete'),
array_merge_recursive(['action' => 'delete'], $linkArgs),
// XXX should be configurable which field we put in, maybe displayField?
['confirm' => __($product.'.op.delete.confirm', [$entity->id]),
['confirm' => __('match.op.delete.confirm', [$entity->id]),
'class' => 'deletebutton nospin']
);
}
Expand All @@ -318,14 +317,14 @@ function _column_key($modelsName, $c, $tz=null) {
if($vv_permissions[ $a['action'] ]) {
// If we have a .confirm text, use postLink instead

$confirmKey = $product.'.op.'.$a['action'].'.confirm';
$confirmKey = 'match.op.'.$a['action'].'.confirm';
$confirmTxt = __($confirmKey);

if($confirmTxt != $confirmKey) {
// We found the localized string

print $this->Form->postLink(
__($product.'.op.' . $a['action']),
__('match.op.' . $a['action']),
array_merge_recursive(['action' => $a['action']], $linkArgs),
// XXX should be configurable which field we put in, maybe displayField?
['confirm' => __($confirmKey, [$entity->id]),
Expand All @@ -342,7 +341,7 @@ function _column_key($modelsName, $c, $tz=null) {
);
} else {
print $this->Html->link(
__($product.'.op.' . $a['action']),
__('match.op.' . $a['action']),
array_merge_recursive(['action' => $a['action']], $linkArgs),
['class' => $a['class']]
);
Expand Down

0 comments on commit 0950430

Please sign in to comment.