Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implemented form code for configuration
rmathis committed Jan 13, 2021
1 parent 665fa11 commit 78234e9
Showing 6 changed files with 310 additions and 29 deletions.
35 changes: 22 additions & 13 deletions Controller/CoGrouperLitesController.php
@@ -14,11 +14,24 @@ class CoGrouperLitesController extends SDWController {
"GrouperLite.CoGrouperLite"
);

/**
* Callback after controller methods are invoked but before views are rendered.
*
* @since COmanage Registry v3.2.0
*/

function beforeRender()
{
$this->set('title_for_layout', _txt('pl.grouperlite.config.edit.title'));

parent::beforeRender();
}

public function display($id)
{
//$cfg = $this->CoGrouperLite->getConfig();
$cfg = $this->CoGrouperLite->getConfig();

$this->set('title', "Grouper Configuration Settings");
$this->set('title_for_layout', _txt('pl.grouperlite.config.display.title'));
// Pass the config so we know which div to overwrite
$this->set('vv_config', $cfg);
}
@@ -32,8 +45,9 @@ public function display($id)
* @since COmanage Registry v3.2.0
* @return Array Permissions
*/
/*
function isAuthorized() {

function isAuthorized()
{
$roles = $this->Role->calculateCMRoles();

// Determine what operations this user can perform
@@ -43,21 +57,16 @@ function isAuthorized() {
// Note that the display permission is set at the Dashboard, not Dashboard Widget level.
$p = $this->calculateParentPermissions($roles);

// Delete an existing CO Services Widget?
// Delete an existing CO Announcements Widget?
$p['delete'] = ($roles['cmadmin'] || $roles['coadmin']);

// Edit an existing CO Services Widget?
// Edit an existing CO Announcements Widget?
$p['edit'] = ($roles['cmadmin'] || $roles['coadmin']);

// View an existing CO Services Widget?
// View an existing CO Announcements Widget?
$p['view'] = ($roles['cmadmin'] || $roles['coadmin']);

$this->set('permissions', $p);
return($p[$this->action]);
}*/

function isAuthorized()
{
return (true);
return ($p[$this->action]);
}
}
6 changes: 6 additions & 0 deletions Lib/lang.php
@@ -1,6 +1,12 @@
<?php

$cm_grouper_lite_texts['en_US'] = array(
'pl.grouperlite.config.display.title' => 'Grouper Configuration Settings',
'pl.grouperlite.config.edit.title' => 'Edit Grouper Configuration Settings',
'pl.grouperlite.config.grouper-url' => 'Grouper URL',
'pl.grouperlite.config.grouper-version' => 'Grouper Version',
'pl.grouperlite.config.grouper-un' => 'Username',
'pl.grouperlite.config.grouper-pw' => 'Password',

'pl.grouperlite.crumb.root' => 'Grouper groups',
'pl.grouperlite.nav.groups' => 'Groups',
4 changes: 2 additions & 2 deletions Model/CoGrouperLite.php
@@ -30,7 +30,7 @@ class CoGrouperLite extends CoDashboardWidgetBackend {
'rule' => 'numeric',
'required' => true,
'allowEmpty' => false
),
)/*,
'connUrl' => array(
'rule' => 'alphaNumeric',
'required' => true,
@@ -50,7 +50,7 @@ class CoGrouperLite extends CoDashboardWidgetBackend {
'rule' => 'alphaNumeric',
'required' => true,
'allowEmpty' => false
),
),*/
);

}
2 changes: 1 addition & 1 deletion View/CoGrouperLites/display.ctp
@@ -1 +1 @@
yoy are home
you are home
83 changes: 70 additions & 13 deletions View/CoGrouperLites/edit.ctp
@@ -1,14 +1,71 @@
<div id="grouper-plugin" class="pt-2">
<div class="d-flex align-items-center">
<h2><?php echo $title; ?></h2>
</div>
</div>
<?php
echo $this->Form->create('CoGrouperLites');
echo $this->Form->input('connUrl');
echo $this->Form->input('connVer');
echo $this->Form->input('connUser');
echo $this->Form->input('connPass');
echo $this->Form->input('id', array('type' => 'hidden'));
echo $this->Form->end('Save Post');
?>

/**
* COmanage Registry Standard Edit View
*
* 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 registry
* @since COmanage Registry v0.1
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

// Get a pointer to our model
$model = $this->name;
$req = Inflector::singularize($model);

// Add page title & page buttons
$params = array();
$params['title'] = $title_for_layout;

// For Authenticators during enrollment
if(!empty($vv_co_enrollment_authenticator)
&& ($vv_co_enrollment_authenticator['CoEnrollmentAuthenticator']['required'] == RequiredEnum::Optional)
&& !empty($this->request->params['named']['onFinish'])) {
$params['topLinks'][] = $this->Html->link(_txt('op.skip'),
urldecode($this->request->params['named']['onFinish']),
array('class' => 'forwardbutton'));
}

if(!empty($this->plugin)) {
if(file_exists(APP . "Plugin/" . $this->plugin . "/View/" . $model . "/buttons.inc")) {
include(APP . "Plugin/" . $this->plugin . "/View/" . $model . "/buttons.inc");
} elseif(file_exists(LOCAL . "Plugin/" . $this->plugin . "/View/" . $model . "/buttons.inc")) {
include(LOCAL . "Plugin/" . $this->plugin . "/View/" . $model . "/buttons.inc");
}
} else {
if(file_exists(APP . "View/" . $model . "/buttons.inc")) {
include(APP . "View/" . $model . "/buttons.inc");
}
}
print $this->element("pageTitleAndButtons", $params);

$submit_label = _txt('op.save');
print $this->Form->create($req, array('inputDefaults' => array('label' => false, 'div' => false)));
if(!empty($this->plugin)) {
if(file_exists(APP . "Plugin/" . $this->plugin . "/View/" . $model . "/fields.inc")) {
include(APP . "Plugin/" . $this->plugin . "/View/" . $model . "/fields.inc");
} elseif(file_exists(LOCAL . "Plugin/" . $this->plugin . "/View/" . $model . "/fields.inc")) {
include(LOCAL . "Plugin/" . $this->plugin . "/View/" . $model . "/fields.inc");
}
} else {
include(APP . "View/" . $model . "/fields.inc");
}
print $this->Form->end();
?>
209 changes: 209 additions & 0 deletions View/CoGrouperLites/fields.inc
@@ -0,0 +1,209 @@
<!--
/**
* COmanage Registry CO Grouper Groups Widgets Fields
*
* 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 registry-plugin
* @since COmanage Registry v3.2.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/
-->
<?php
// Determine if fields are editable
$addable = ($this->action === "add" && $permissions['add']);
$editable = ($this->action === "edit" && $permissions['edit']);

$e = (!$addable && !$editable) ? false : true;

// We shouldn't get here if we don't have at least read permission, but check just in case

if (!$e && !$permissions['view']) {
return false;
}

// Add breadcrumbs
print $this->element("coCrumb");

$args = array();
$args['plugin'] = null;
$args['controller'] = 'co_dashboards';
$args['action'] = 'index';
$args['co'] = $cur_co['Co']['id'];
$this->Html->addCrumb(_txt('ct.co_dashboards.pl'), $args);

$args = array();
$args['plugin'] = null;
$args['controller'] = 'co_dashboards';
$args['action'] = 'edit';
$args[] = $co_grouper_lites[0]['CoDashboardWidget']['co_dashboard_id'];
$this->Html->addCrumb(_txt('ct.co_dashboards.1'), $args);

$args = array();
$args['plugin'] = null;
$args['controller'] = 'co_dashboard_widgets';
$args['action'] = 'index';
$args['codashboard'] = $co_grouper_lites[0]['CoDashboardWidget']['co_dashboard_id'];
$this->Html->addCrumb(_txt('ct.co_dashboard_widgets.1'), $args);

$crumbTxt = _txt('op.' . $this->action . '-a', array(filter_var($co_grouper_widgets[0]['CoDashboardWidget']['description'], FILTER_SANITIZE_SPECIAL_CHARS)));
$this->Html->addCrumb($crumbTxt);

print $this->Form->hidden('co_dashboard_widget_id', array('default' => $vv_dwid)) . "\n";

?>
<ul id="<?php print $this->action; ?>_co_grouper_lite" class="fields form-list form-list-admin">
<li>
<div class="field-name">
<div class="field-title">
<?php print($e ? $this->Form->label('connUrl', _txt('pl.grouperlite.config.grouper-url')) : _txt('pl.grouperlite.config.grouper-url')); ?>
<span class="required">*</span>
</div>
</div>
<div class="field-info">
<?php
$attrs = array();
$attrs['value'] = (isset($co_grouper_lites[0]['CoGrouperLite']['connUrl'])
? $co_grouper_lites[0]['CoGrouperLite']['connUrl']
: '');
$attrs['empty'] = true;
$attrs['required'] = true;

if ($e) {
print $this->Form->input('connUrl', $attrs);

if ($this->Form->isFieldError('connUrl')) {
print $this->Form->error('connUrl');
}
} else {
if (!empty($co_grouper_lites[0]['CoGrouperLite']['connUrl'])) {
print filter_var($co_grouper_lites[0]['CoGrouperLite']['connUrl'], FILTER_SANITIZE_SPECIAL_CHARS);
}
}
?>
</div>
</li>
<li>
<div class="field-name">
<div class="field-title">
<?php print($e ? $this->Form->label('connVer', _txt('pl.grouperlite.config.grouper-version')) : _txt('pl.grouperlite.config.grouper-version')); ?>
<span class="required">*</span>
</div>
</div>
<div class="field-info">
<?php
$attrs = array();
$attrs['value'] = (isset($co_grouper_lites[0]['CoGrouperLite']['connVer'])
? $co_grouper_lites[0]['CoGrouperLite']['connVer']
: '');
$attrs['empty'] = true;
$attrs['required'] = true;

if ($e) {
print $this->Form->input('connVer', $attrs);

if ($this->Form->isFieldError('connVer')) {
print $this->Form->error('connVer');
}
} else {
if (!empty($co_grouper_lites[0]['CoGrouperLite']['connVer'])) {
print filter_var($co_grouper_lites[0]['CoGrouperLite']['connVer'], FILTER_SANITIZE_SPECIAL_CHARS);
}
}
?>
</div>
</li>
<li>
<div class="field-name">
<div class="field-title">
<?php print($e ? $this->Form->label('connUser', _txt('pl.grouperlite.config.grouper-un')) : _txt('pl.grouperlite.config.grouper-un')); ?>
<span class="required">*</span>
</div>
</div>
<div class="field-info">
<?php
$attrs = array();
$attrs['value'] = (isset($co_grouper_lites[0]['CoGrouperLite']['connUser'])
? $co_grouper_lites[0]['CoGrouperLite']['connUser']
: '');
$attrs['empty'] = true;
$attrs['required'] = true;

if ($e) {
print $this->Form->input('connUser', $attrs);

if ($this->Form->isFieldError('connUser')) {
print $this->Form->error('connUser');
}
} else {
if (!empty($co_grouper_lites[0]['CoGrouperLite']['connUser'])) {
print filter_var($co_grouper_lites[0]['CoGrouperLite']['connUser'], FILTER_SANITIZE_SPECIAL_CHARS);
}
}
?>
</div>
</li>
<li>
<div class="field-name">
<div class="field-title">
<?php print($e ? $this->Form->label('connPass', _txt('pl.grouperlite.config.grouper-pw')) : _txt('pl.grouperlite.config.grouper-pw')); ?>
<span class="required">*</span>
</div>
</div>
<div class="field-info">
<?php
$attrs = array();
$attrs['value'] = (isset($co_grouper_lites[0]['CoGrouperLite']['connPass'])
? $co_grouper_lites[0]['CoGrouperLite']['connPass']
: '');
$attrs['empty'] = true;
$attrs['required'] = true;

if ($e) {
print $this->Form->password('connPass', $attrs);

if ($this->Form->isFieldError('connPass')) {
print $this->Form->error('connPass');
}
} else {
if (!empty($co_grouper_lites[0]['CoGrouperLite']['connPass'])) {
print filter_var($co_grouper_lites[0]['CoGrouperLite']['connPass'], FILTER_SANITIZE_SPECIAL_CHARS);
}
}
?>
</div>
</li>

<?php if ($e) : ?>
<li class="fields-submit">
<div class="field-name">
<span class="required"><?php print _txt('fd.req'); ?></span>
</div>
<div class="field-info">
<?php print $this->Form->submit($submit_label); ?>
</div>
</li>
<?php endif; ?>
</ul>

<div id="grouper-plugin" class="pt-2">
<div class="d-flex align-items-center">
<h2><?php echo $title; ?></h2>
</div>
</div>

0 comments on commit 78234e9

Please sign in to comment.