Skip to content
Permalink
main
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
* Provide tabbed subnavigation for related models. Deprecate Noty.js in favor of Boostrap Alerts. (CO-2229)

* Ensure flash messages are available on all pages. (CO-2229)

* Clean up information alert on reconcile page. (CO-2229)
2 contributors

Users who have contributed to this file

@arlen @Ioannis
272 lines (238 sloc) 10.6 KB
<?php
/**
* COmanage Match Generic View Template For Add/Edit/View Actions
*
* 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 http://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)
*/
declare(strict_types = 1);
use \Cake\Utility\Inflector;
$action = $this->request->getParam('action');
// $this->name = Models
$modelsName = $this->name;
// Include subnavigation structures on add/edit/view pages
// XXX: if fields.inc is made configuration only, move the contents of fields-nav.inc into fields.inc
// Include subnav on all but the top-level object's Add view when subnav exists.
if((!empty($vv_primary_link_model) && $vv_primary_link_model != 'Matchgrids') || $action != 'add') {
if(file_exists(ROOT . DS . "templates" . DS . $modelsName . DS . "fields-nav.inc")) {
include(ROOT . DS . "templates" . DS . $modelsName . DS . "fields-nav.inc");
}
}
// $flashArgs pass banner messages to the flash element container
$flashArgs = [];
if(!empty($banners)) {
// XXX this doesn't work yet because we don't include fields.inc until later
// either create a second file to include earlier, or use a function to emit
// the fields (which would be more consistent with how Views render...)
$flashArgs['vv_banners'] = $banners;
}
?>
<?php if(!empty($subnav)): ?>
<div id="subnavigation">
<div class="supertitle">
<h1>
<?php
if(!empty($vv_primary_link_obj)
&& !empty($vv_primary_link_model)
&& $vv_primary_link_model != 'Matchgrids') {
print $vv_primary_link_obj->name;
} else {
// we are editing the top-level object
print $vv_obj-> name;
}
?>
</h1>
</div>
<?php /* Flash Messages are placed below supertitle when subnavigation exists. */ ?>
<?= $this->element('flash', $flashArgs); ?>
<?= $this->element('subnavigation', $subnav); ?>
</div>
<?php endif; ?>
<div class="pageTitleContainer">
<div class="pageTitle">
<?php if(empty($subnav)): ?>
<h1><?= $vv_title; ?></h1>
<?php else: ?>
<h2><?= $vv_title; ?></h2>
<?php endif; ?>
</div>
<?php if(
$action == 'edit' &&
(!empty($topLinks) ||
(isset($vv_permissions['duplicate']) && $vv_permissions['duplicate']) ||
$vv_permissions['delete'])): ?>
<?php
// topLinks menu dropdown / button listing
$action_args = array();
$action_args['vv_attr_mdl'] = "Edit";
$action_args['vv_attr_id'] = $vv_obj->id;
$linkArgs = [$vv_obj->id];
// $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)]];
$linkArgs = array_merge_recursive($linkArgs, $linkFilter);
}
// Insert additional actions as per the .inc file
if(!empty($topLinks)) {
if(!isset($entity->status) || $entity->status == StatusEnum::Active) {
$actionOrderDefault = $this->Menu->getMenuOrder('Default');
foreach($topLinks as $a) {
if($vv_permissions[ $a['action'] ]) {
$actionOrder = !empty($a['order']) ? $a['order'] : $actionOrderDefault++;
$actionIcon = !empty($a['icon']) ? $a['icon'] : $this->Menu->getMenuIcon('Default');
$actionClass = !empty($a['class']) ? $a['class'] : '';
$actionUrl = '';
$actionLabel = '';
$actionOnClick = []; // used for confirmation dialog
// Generate the link text and urls:
// If we have a .confirm text, we need to generate a confirm dialog box
$confirmKey = 'match.op.'.$a['action'].'.confirm';
$confirmTxt = __($confirmKey);
if($confirmTxt != $confirmKey) {
// We found the localized string
$actionPostBtnArray = array_merge_recursive(['action' => $a['action']], $linkArgs);
$actionUrl = $this->Url->build(array_merge_recursive(['action' => $a['action']], $linkArgs));
// XXX should be configurable which field we put in, maybe displayField?
$action_args['vv_actions'][] = array(
'order' => $actionOrder,
'icon' => $actionIcon,
'url' => 'javascript:void(0);',
'label' => __('match.op.' . $a['action']),
'class' => !empty($actionClass) ? $actionClass . ' nospin' : 'nospin',
'onclick' => array(
'dg_bd_txt' => __($confirmKey, [$entity->id]), // dialog body text
'dg_post_btn_array' => $actionPostBtnArray, // postButton array for building the postButton
'dg_url' => $actionUrl, // action url for building a unique ID
'dg_conf_btn' => __('match.op.confirm'), // dialog confirm button text
'dg_cancel_btn' => __('match.op.cancel'), // dialog cancel button text
'dg_title' => __('match.op.confirm'), // dialog box title
'dg_bd_txt_repl_str' => '' // dialog body text replacement strings
),
);
} elseif(!empty($a['controller'])) {
// We're linking into a related controller
$queryParams = [ $tableFK => $entity->id ];
if(!empty($a['query']) && is_callable($a['query'])) {
$queryParams = $a['query']($vv_cur_mg->id, $entity);
}
$actionLabel = __('match.ct.' . Inflector::camelize(Inflector::pluralize($a['controller'])), [99]);
$actionUrl = $this->Url->build([
'controller' => $a['controller'],
'action' => $a['action'],
'?' => $queryParams
]);
} else {
$actionLabel = __('match.op.' . $a['action']);
$actionUrl = $this->Url->build(
array_merge_recursive(['action' => $a['action']], $linkArgs)
);
}
// If a specific label is sent in the config, use it instead
if(!empty($a['label'])) {
$actionLabel = $a['label'];
}
// Set the action link configuration
$action_args['vv_actions'][] = array(
'order' => $actionOrder,
'icon' => $actionIcon,
'url' => $actionUrl,
'label' => $actionLabel,
'class' => $actionClass,
'onclick' => $actionOnClick
);
}
}
}
}
// Duplicate
if(isset($vv_permissions['duplicate']) && $vv_permissions['duplicate']) {
$action_args['vv_actions'][] = array(
'order' => $this->Menu->getMenuOrder('Duplicate'),
'icon' => $this->Menu->getMenuIcon('Duplicate'),
'url' => $this->Url->build(array_merge_recursive(['action' => 'duplicate'], $linkArgs)),
'label' => __('match.op.duplicate')
);
}
// Delete
if($vv_permissions['delete']) {
$actionPostBtnArray = array_merge_recursive(['action' => 'delete'], $linkArgs);
$actionUrl = $this->Url->build(array_merge_recursive(['action' => 'delete'], $linkArgs));
$action_args['vv_actions'][] = array(
'order' => $this->Menu->getMenuOrder('Delete'),
'icon' => $this->Menu->getMenuIcon('Delete'),
'url' => 'javascript:void(0);',
'label' => __('match.op.delete'),
'class' => 'deletebutton nospin',
'onclick' => array(
'dg_bd_txt' => __('match.op.delete.confirm', [$vv_obj->id]),
'dg_post_btn_array' => $actionPostBtnArray,
'dg_url' => $actionUrl,
'dg_conf_btn' => __('match.op.remove'),
'dg_cancel_btn' => __('match.op.cancel'),
'dg_title' => __('match.op.remove'),
'dg_bd_txt_repl_str' => ''
),
);
}
if(!empty($action_args['vv_actions'])) {
print '<div id="topLinks" class="field-actions">';
print $this->element('menuAction', $action_args);
print '</div>';
}
?>
<?php endif; ?>
</div>
<?php if(empty($subnav)): ?>
<?php /* Flash Messages are placed below the main title when there's no subnavigation. */ ?>
<?= $this->element('flash', $flashArgs); ?>
<?php endif; ?>
<?php
// By default, the form will POST to the current controller
print $this->Form->create($vv_obj);
$linkId = null;
if(!empty($vv_primary_link)) {
if(!empty($this->request->getQuery($vv_primary_link))) {
$linkId = $this->request->getQuery($vv_primary_link);
} elseif(!empty($this->request->getData($vv_primary_link))) {
$linkId = $this->request->getData($vv_primary_link);
} elseif(!empty($vv_obj->$vv_primary_link)) {
$linkId = $vv_obj->$vv_primary_link;
}
}
print $this->Field->startControlSet($vv_obj, $this->name, $action, ($action == 'add' || $action == 'edit'));
include(TEMPLATES . $modelsName . DS . "fields.inc");
if(!empty($hidden)) {
// Inject any hidden variables set by the include file
foreach($hidden as $attr => $v) {
print $this->Form->hidden($attr, ['value' => $v]);
}
}
if($action == 'add' || $action == 'edit') {
if(!empty($linkId)) {
// Hidden values used to link to parent objects (eg: matchgrid_id)
print $this->Form->hidden($vv_primary_link, ['value' => $linkId]);
}
print $this->Field->submit(__('match.op.save'));
}
print $this->Form->end();
print $this->Field->endControlSet();