Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CO-2113_Refactor_CO_Person_Canvas_-_Co_Person_Attributes_Block #208

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/Controller/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@ public function beforeFilter() {

// XXX CO-351 Placeholder
$this->Session->write('Config.language', 'eng');
// CSRF token should expire along with the Session. This is the default in CAKEPHP 3.7.x+
// https://book.cakephp.org/3/en/controllers/middleware.html#csrf-middleware
// https://github.com/cakephp/cakephp/issues/13532
// - expiry, How long the CSRF token should last. Defaults to browser session.
$this->Security->csrfUseOnce = false;

Configure::write('Config.language', $this->Session->read('Config.language'));

// Tell the Auth module to call the controller's isAuthorized() function.
Expand Down
1 change: 1 addition & 0 deletions app/Controller/CoPeopleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ public function canvas($id) {
// This is pretty similar to the standard view or edit methods.

if(!$this->request->is('restful') && $this->request->is('get')) {
$this->set('vv_title_status_bg', true);
$this->edit($id);
}
}
Expand Down
18 changes: 17 additions & 1 deletion app/Controller/StandardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,15 @@ function edit($id) {

return;
}


// Complete the request with the `status` field if it is of type PUT
// Usefull for asychronous single-field Requests
if($req === 'CoPerson'
&& empty($this->request->data[$req]["status"])
&& !empty($curdata[$req]["status"])) {
$this->request->data[$req]["status"] = $curdata[$req]["status"];
}

$data = $this->request->data;

if(!isset($this->request->data[$req]['id'])) {
Expand Down Expand Up @@ -633,6 +641,14 @@ function edit($id) {

if($this->request->is('restful')) {
$this->Api->restResultHeader(200, "OK");
} elseif ($this->request->is('ajax')) {
// Return the new data
$this->layout = null;
$this->autoRender = false;
$this->response->type('json');
$this->response->statusCode(201);
$this->response->body(json_encode(array(0 => $data)));
return $this->response;
} else {
// Redirect to index view

Expand Down
1 change: 1 addition & 0 deletions app/Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,7 @@
'js.auth.reset' => 'Please confirm resetting \x22{0}\x22 for {1}.',
'js.auth.unlock' => 'Please confirm unlocking \x22{0}\x22 for {1}.',
'js.ois.inventory' => 'Are you sure you wish to retrieve the full inventory from this backend? This may be slow and result in a large page load.',
'js.reload' => 'Please Reload!',
'js.remove' => 'Are you sure you wish to remove \x22{0}\x22? This action cannot be undone.',
'js.remove.id.prov' => 'The identifier \x22{0}\x22 was created by the provisioning target, and removing it may cause operational problems. Are you sure you wish to remove it? This action cannot be undone.',
'js.remove.member' => 'Are you sure you wish to remove this member from group \x22{0}\x22? This action cannot be undone.',
Expand Down
185 changes: 106 additions & 79 deletions app/View/CoPeople/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,104 @@

<script type="text/javascript">
<!-- /* JS specific to these fields */ -->
var $status_hash = <?php print json_encode($cm_texts[$cm_lang]['en.status']); ?>;
var $badgecls_status_hash = <?php print json_encode($this->Badge->statusBadgeColorMap()); ?>;

$(".pageTitle .status-edit-link i.fa").css("visibility", "visible");

function js_confirm_autogenerate() {
// Open the dialog to confirm autogeneration of identifiers
var $tabs = $( "#tabs" ).tabs();
$('#autogenerate-dialog').dialog('open');
}

function inline_edit(is_on) {
if(is_on) {
$('.pageTitle .status-edit-link').hide();
$('.pageTitle .inline-edit-form').show();
} else {
$('.pageTitle .status-edit-link').show();
$('.pageTitle .inline-edit-form').hide();
}
}

function update_field(ok_btn, options) {
var $form = $(ok_btn).parent('form');
let jqxhr = $.ajax({
cache: false,
type: $form.attr('method'),
url: $form.attr('action'),
beforeSend: function(xhr) {
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
$parentdiv = $form.parent('div');
$parentdiv.addClass('disabled').addClass('inline-loader');
},
data: $form.serialize(),
});

jqxhr.done((data, textStatus, xhr) => {
inline_edit(false);
let vmodel = options['model'];
let vfield = options['field'];
let vstatus = $status_hash[data[0][vmodel][vfield]];
let vstatus_code = data[0][vmodel][vfield];
$form.parent('div').removeClass('disabled').removeClass('inline-loader');
// Badge Text
$badge = $('.status-edit-link .badge');
$badge.contents().filter(function() {
return this.nodeType == Node.TEXT_NODE;
})[0].nodeValue = vstatus;

// Update Badge color
// Badge Color
badgeClass = $badgecls_status_hash[vstatus];
$.each($badge.attr('class').split(' '), (idx, className) => {
if(className.match (/\bbadge-\S+/g)) {
$badge.removeClass(className);
$badge.addClass('badge-' + badgeClass);
}
})
// Update the Changelog
changelog_update(data,vmodel);
// Notify the user
let cn = data[0]['PrimaryName']['given'] + " " + data[0]['PrimaryName']['family'];
generateFlash('"' + cn + '" ' + vfield + ' Updated.', textStatus);
});

jqxhr.fail((xhr, textStatus, error) => {
let err_header = "";
let reload_message = '<?php print _txt('js.reload'); ?>';

// Show an error message
if (xhr.statusText != undefined
&& xhr.statusText != "") {
error = error + " (Status Code: " + xhr.status + ")";
}
if(xhr.responseText != undefined
&& xhr.responseText != "") {
// JSON text
try {
//try to parse JSON
encodedJson = $.parseJSON(xhr.responseText);
err_header = encodedJson.msg;
} catch (e) { // This is not JSON }
// HTML text
try {
let htmlparsed = $.parseHTML(xhr.responseText);
err_header = htmlparsed[0].textContent;
} catch (e) { // This is not HTML either }
// Found no error header. Should i look elsewhere?
}

error = (err_header != "") ? (error + "<br>" + err_header) : error;
error = (err_header.includes("CSRF")) ? (error + "<br>" + reload_message) : error;

generateFlash(error, textStatus);
inline_edit(false);
$form.parent('div').removeClass('disabled');
});
}

$(function() {
// Enable collapse effect on the entire row, except Action fraction
$('.field-data-container div.field-data').on('click', function() {
Expand Down Expand Up @@ -418,7 +509,7 @@
);
$linkparams = array(
'class' => 'addbutton',
//'escape' => false
'escape' => false
);

print $this->Html->link(_txt('op.add'),
Expand Down Expand Up @@ -566,9 +657,11 @@
_txt('fd.name.primary_name'),
$this->Badge->getBadgeColor('Secondary'),
false,
true
true,
null, null,
'ml-1'
);
$cn = $n['primary_name'] ? filter_var(generateCn($n),FILTER_SANITIZE_SPECIAL_CHARS) . "&nbsp" . $primary_name_with_bg
$cn = $n['primary_name'] ? filter_var(generateCn($n),FILTER_SANITIZE_SPECIAL_CHARS) . $primary_name_with_bg
: filter_var(generateCn($n),FILTER_SANITIZE_SPECIAL_CHARS);
if($perm == PermissionEnum::ReadWrite) {
print $this->Html->link(
Expand Down Expand Up @@ -945,59 +1038,20 @@
<!-- Person attributes form -->
<li id="fields-coperson" class="fieldGroup">
<?php
print $this->Form->create('CoPerson', array('url' => array('action'=>'edit','id'=>'CoPersonEditAttributesForm')));
print $this->Form->hidden('CoPerson.co_id', array('default' => $co_people[0]['CoPerson']['co_id'],'id'=>'CoPersonCoIdAgain')). "\n";
print $this->Form->create('CoPerson',
array(
'url' => array(
'action'=>'edit',
'id'=>'CoPersonEditAttributesForm',
$co_people[0]['CoPerson']['id'],
)));
print $this->Form->hidden('CoPerson.co_id', array('default' => $co_people[0]['CoPerson']['co_id'],'id'=>'CoPersonCoIdAgain')). PHP_EOL;
?>
<a href="#tabs-coperson" class="fieldGroupName">
<em class="material-icons">indeterminate_check_box</em>
<?php print _txt('fd.attrs.cop'); ?>
</a>
<ul id="tabs-coperson" class="fields form-list">
<li>
<div class="field-name vtop">
<label for="CoPersonStatusAgain"><?php print _txt('fd.status'); ?></label>
</div>
<div class="field-info">
<?php
if($e && $permissions['edit']
&& !$permissions['editself']) {
global $cm_lang, $cm_texts;

$attrs = array();
$attrs['value'] = $co_people[0]['CoPerson']['status'];
$attrs['empty'] = false;
$attrs['id'] = 'CoPersonStatusAgain';

print $this->Form->select('CoPerson.status',
$cm_texts[ $cm_lang ]['en.status'],
$attrs);

if($this->Form->isFieldError('CoPerson.status')) {
print $this->Form->error('CoPerson.status');
}
} else {
if(!empty($co_people[0]['CoPerson']['status'])) {
print _txt('en.status', null, $co_people[0]['CoPerson']['status']);

if($e) {
// Self service... we need to include current status so the form saves
print $this->Form->hidden('CoPerson.status');
}
}
}
?>
<?php if($e && $permissions['edit']
&& !$permissions['editself']
&&
($co_people[0]['CoPerson']['status'] == StatusEnum::PendingApproval
|| $co_people[0]['CoPerson']['status'] == StatusEnum::PendingConfirmation)): ?>
<div class="field-desc">
<span class="ui-icon ui-icon-info co-info"></span>
<?php print _txt('fd.status.change'); ?>
</div>
<?php endif; ?>
</div>
</li>
<li class="modelbox-data">
<div class="field-name">
<?php print $this->Form->label('CoPerson.date_of_birth', _txt('fd.date_of_birth')); ?>
Expand Down Expand Up @@ -1107,41 +1161,14 @@
$rcnt = 1;
foreach($co_people[0]['CoPersonRole'] as $r) {
$badge_list_role = array();
// Set the status styling
$statusClass = $this->Badge->getBadgeColor('Light');
// Set ordering
$bgOrder = $this->Badge->getBadgeOrder('Other');
// Store the action list
$action_args = array();
$action_args['vv_attr_mdl'] = "CoPersonRole";
$action_args['vv_attr_id'] = $r["id"];

if($r['status'] == StatusEnum::Suspended
|| $r['status'] == StatusEnum::Expired
|| $r['status'] == StatusEnum::Deleted) {
// Style status for suspended, expired, deleted
$bgOrder = $this->Badge->getBadgeOrder('Status');
$statusClass = $this->Badge->getBadgeColor('Danger'); // reddish
} elseif($r['status'] != StatusEnum::Active) {
// Style status if otherwise not active
$bgOrder = $this->Badge->getBadgeOrder('Status');
$statusClass = $this->Badge->getBadgeColor('Warning'); // yellowish
}
// Independent of status, set the style based on dates if needed:
$validThroughDate = !empty($r['valid_through']) ? $this->Time->format($r['valid_through'], "%F", false, $vv_tz) : false;
$validFromDate = !empty($r['valid_from']) ? $this->Time->format($r['valid_from'], "%F", false, $vv_tz) : false;

if ($validThroughDate && $this->Time->isPast($validThroughDate)) {
// valid through date exists and is in the past
$bgOrder = $this->Badge->getBadgeOrder('Status');
$statusClass = $this->Badge->getBadgeColor('Danger'); // reddish
} elseif ($validFromDate && $this->Time->isFuture($validFromDate)) {
// valid from date is in the future
$bgOrder = $this->Badge->getBadgeOrder('Status');
$statusClass = $this->Badge->getBadgeColor('Warning'); // yellowish
}
// Calculate the badge color,text and status
list($status, $statusClass, $bgOrder) = $this->Badge->calculateStatusNBadge($r, $vv_tz);

$status = !empty($r['status']) ? _txt('en.status', null, $r['status']) : '-';
if($r['status'] != StatusEnum::Active) {
$badge_list_role[] = array(
'order' => $bgOrder,
Expand Down
8 changes: 4 additions & 4 deletions app/View/Elements/changelog.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
<th>
<?php print _txt('fd.deleted'); ?>
</th>
<td>
<td id="<?php print $req . 'DeletedChangelog'; ?>">
<?php print (${$modelpl}[0][$req]['deleted'] ? _txt('fd.yes') : _txt('fd.no')); ?>
</td>
</tr>
<tr class="line<?php print ($l % 2); $l++; ?>">
<th>
<?php print _txt('fd.revision'); ?>
</th>
<td>
<td id="<?php print $req . 'RevisionChangelog'; ?>">
<?php
print ${$modelpl}[0][$req]['revision'];

Expand All @@ -82,7 +82,7 @@
<th>
<?php print _txt('fd.modified'); ?>
</th>
<td>
<td id="<?php print $req . 'ModifiedChangelog'; ?>">
<?php
print $this->Time->format(${$modelpl}[0][$req]['modified'], "%c $vv_tz", false, $vv_tz);
?>
Expand All @@ -92,7 +92,7 @@
<th>
<?php print _txt('fd.actor'); ?>
</th>
<td>
<td id="<?php print $req . 'ActorIdentifierChangelog'; ?>">
<?php
if(!empty(${$modelpl}[0][$req]['actor_identifier'])) {
print filter_var(${$modelpl}[0][$req]['actor_identifier'],FILTER_SANITIZE_SPECIAL_CHARS);
Expand Down
Loading