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-2884_Enumerations_are_not_sorted #680

Merged
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
2 changes: 1 addition & 1 deletion app/Controller/ApplicationPreferencesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function store() {
// We expect a simple json doc of { "value": "foo" }, but if we don't have
// a valid value we'll just treat it as a null. The client can also pass
// { "value": null }
$value = !empty($this->request->data['value']) ? $this->request->data['value'] : null;
$value = $this->request->data['value'] ?? null;

try {
$this->ApplicationPreference->store($coPersonId, $this->request->params['tag'], $value);
Expand Down
4 changes: 2 additions & 2 deletions app/Controller/CoEnrollmentAttributesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function beforeRender() {
// the dropdown won't either).
if(!empty($this->viewVars['co_enrollment_attributes'][0]['CoEnrollmentAttribute']['attribute'])
&& $this->viewVars['co_enrollment_attributes'][0]['CoEnrollmentAttribute']['attribute'] == 'r:sponsor_co_person_id'
&& !empty($this->viewVars['co_enrollment_attributes'][0]['CoEnrollmentAttributeDefault'][0]['value'])) {
&& isset($this->viewVars['co_enrollment_attributes'][0]['CoEnrollmentAttributeDefault'][0]['value'])) {
// The default value is a CO Person ID
$args = array();
$args['conditions']['CoPerson.id'] = $this->viewVars['co_enrollment_attributes'][0]['CoEnrollmentAttributeDefault'][0]['value'];
Expand All @@ -315,7 +315,7 @@ function beforeRender() {
// Also populate the current manager, if set
if(!empty($this->viewVars['co_enrollment_attributes'][0]['CoEnrollmentAttribute']['attribute'])
&& $this->viewVars['co_enrollment_attributes'][0]['CoEnrollmentAttribute']['attribute'] == 'r:manager_co_person_id'
&& !empty($this->viewVars['co_enrollment_attributes'][0]['CoEnrollmentAttributeDefault'][0]['value'])) {
&& isset($this->viewVars['co_enrollment_attributes'][0]['CoEnrollmentAttributeDefault'][0]['value'])) {
// The default value is a CO Person ID
$args = array();
$args['conditions']['CoPerson.id'] = $this->viewVars['co_enrollment_attributes'][0]['CoEnrollmentAttributeDefault'][0]['value'];
Expand Down
2 changes: 1 addition & 1 deletion app/Model/CoEnrollmentAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ public function enrollmentFlowAttributes($coef, $defaultValues=array(), $archive
// Currently, they are always modifiable.
$attr['default'] = $defaultValues[ $attr['model'] ][ $attr['field'] ];
$attr['modifiable'] = true;
} elseif(!empty($efAttr['CoEnrollmentAttributeDefault'][0]['value'])) {
} elseif(isset($efAttr['CoEnrollmentAttributeDefault'][0]['value'])) {
// These are the default values configured per-enrollment flow attribute

if(($attrCode == 'r'
Expand Down
36 changes: 29 additions & 7 deletions app/View/CoEnrollmentAttributes/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@
break;
<?php endforeach; ?>
}

return ret;
if (ret != undefined) {
return sortProperties(ret)
}

return ret
}

function ext_attr_type(attrname) {
Expand Down Expand Up @@ -143,8 +146,8 @@
if(enums != undefined) {
// Enumerations are defined for the attribute, so generate an appropriate select
var options = "<option value=''></option>";
for(let id of Object.keys(enums)) {
options += "<option value='" + id + "'>" + enums[id] + "</option>";
for(let i=0; i<enums.length; i++) {
options += "<option value='" + enums[i][0] + "'>" + enums[i][1] + "</option>";
}
$("#def_enum_val").find('option').remove().end().append($(options));

Expand Down Expand Up @@ -356,7 +359,7 @@
}
if ($.inArray(cur_value, attributesProperty) !== -1) {
option.attr('selected', 'selected');
<?php if(!empty($co_enrollment_attributes[0]['CoEnrollmentAttributeDefault'][0]['value'])): ?>
<?php if(isset($co_enrollment_attributes[0]['CoEnrollmentAttributeDefault'][0]['value'])): ?>
option.attr('data-default', '<?php print filter_var($co_enrollment_attributes[0]['CoEnrollmentAttributeDefault'][0]['value'],FILTER_SANITIZE_SPECIAL_CHARS); ?>');
<?php endif; ?>
}
Expand Down Expand Up @@ -484,12 +487,12 @@
print $this->Form->hidden('CoEnrollmentAttributeDefault.0.co_enrollment_attribute_id') . "\n";
}

$co_enrollment_attribute_attribute = !empty($co_enrollment_attributes[0]['CoEnrollmentAttribute']['attribute'])
$co_enrollment_attribute_attribute = isset($co_enrollment_attributes[0]['CoEnrollmentAttribute']['attribute'])
? filter_var($co_enrollment_attributes[0]['CoEnrollmentAttribute']['attribute'],FILTER_SANITIZE_SPECIAL_CHARS)
: '';
print $this->Form->hidden('attribute', array('value' => $co_enrollment_attribute_attribute)) . "\n";

$co_enrollment_attribute_value_def = !empty($co_enrollment_attributes[0]['CoEnrollmentAttributeDefault'][0]['value'])
$co_enrollment_attribute_value_def = isset($co_enrollment_attributes[0]['CoEnrollmentAttributeDefault'][0]['value'])
? filter_var($co_enrollment_attributes[0]['CoEnrollmentAttributeDefault'][0]['value'],FILTER_SANITIZE_SPECIAL_CHARS)
: '';
print $this->Form->hidden('CoEnrollmentAttributeDefault.0.value', array('value' => filter_var($co_enrollment_attribute_value_def,FILTER_SANITIZE_SPECIAL_CHARS))) . "\n";
Expand All @@ -499,6 +502,7 @@
<div class="table-container">
<table id="<?php print $this->action; ?>_co_enrollment_attribute">
<tbody>
<!-- LABEL -->
<tr class="line<?php print ($l % 2); $l++; ?>">
<td width="50%"> <!-- force a width here and below so the two tables line up -->
<b><?php print _txt('fd.ea.label'); ?></b><br />
Expand All @@ -510,6 +514,7 @@
: filter_var($co_enrollment_attributes[0]['CoEnrollmentAttribute']['label'],FILTER_SANITIZE_SPECIAL_CHARS)); ?>
</td>
</tr>
<!-- DESCRIPTION -->
<tr class="line<?php print ($l % 2); $l++; ?>">
<td>
<b><?php print _txt('fd.ea.desc'); ?></b><br />
Expand All @@ -521,6 +526,7 @@
: filter_var($co_enrollment_attributes[0]['CoEnrollmentAttribute']['description'],FILTER_SANITIZE_SPECIAL_CHARS)); ?>
</td>
</tr>
<!-- ATTRIBUTE -->
<tr class="line<?php print ($l % 2); $l++; ?>">
<td>
<b><?php print _txt('fd.attribute'); ?></b>
Expand Down Expand Up @@ -634,6 +640,7 @@
</div>
</td>
</tr>
<!-- REQUIRED -->
<tr class="line<?php print ($l % 2); $l++; ?>">
<td>
<b><?php print _txt('fd.required'); ?></b>
Expand All @@ -660,6 +667,7 @@
?>
</td>
</tr>
<!-- ATTRIBUTES FROM ENV CONFIGURATIONS -->
<?php if(isset($vv_attributes_from_env) && $vv_attributes_from_env): ?>
<tr class="line<?php print ($l % 2); $l++; ?>">
<td>
Expand All @@ -677,6 +685,7 @@
</td>
</tr>
<?php endif; ?>
<!-- DEFAULT ENV VALUE -->
<tr class="line<?php print ($l % 2); $l++; ?>">
<td>
<b><?php print _txt('fd.ea.default_env'); ?></b><br />
Expand All @@ -688,6 +697,7 @@
: filter_var($co_enrollment_attributes[0]['CoEnrollmentAttribute']['default_env'],FILTER_SANITIZE_SPECIAL_CHARS)); ?>
</td>
</tr>
<!-- ORDER -->
<tr class="line<?php print ($l % 2); $l++; ?>">
<td>
<b><?php print _txt('fd.ea.order'); ?></b><br />
Expand All @@ -699,6 +709,7 @@
: filter_var($co_enrollment_attributes[0]['CoEnrollmentAttribute']['ordr'],FILTER_SANITIZE_SPECIAL_CHARS)); ?>
</td>
</tr>
<!-- CONFIGURATION LABEL -->
<tr id="filter_attributes_bylabel_div" class="line<?php print ($l % 2); $l++; ?>">
<td>
<b><?php print _txt('fd.ea.attr.filter'); ?></b><br />
Expand Down Expand Up @@ -729,11 +740,13 @@
</tr>
</tbody>
<tbody id="attr_def_div" style="display: <?php print $display;?>">
<!-- DEFAULT VALUE TEXTBOX/DROPDOWN/DATE PICKER -->
<tr class="line<?php print ($l % 2); $l++; ?>">
<td width="50%">
<b><?php print _txt('fd.ed.default'); ?></b><br />
</td>
<td>
<!-- DEFAULT DIV/TEXTBOX -->
<div id="attr_def_val_div">
<?php if($e): ?>
<input name="def_val_div"
Expand All @@ -747,6 +760,7 @@
<?php print filter_var($co_enrollment_attributes[0]['CoEnrollmentAttributeDefault'][0]['value'],FILTER_SANITIZE_SPECIAL_CHARS); ?>
<?php endif; ?>
</div>
<!-- DEFAULT AFFILIATION -->
<div id="attr_def_val_affil_div">
<?php if($e): ?>
<select name="def_affil_val"
Expand All @@ -761,6 +775,7 @@
</select>
<?php endif; ?>
</div>
<!-- DEFAULT COU -->
<div id="attr_def_val_cou_div">
<?php if($e): ?>
<select name="def_cou_val"
Expand All @@ -775,6 +790,7 @@
</select>
<?php endif; ?>
</div>
<!-- DEFAULT DATE -->
<div id="attr_def_val_date_div" class="modelbox-data">
<?php if($e): ?>
<input name="def_date_type"
Expand Down Expand Up @@ -824,6 +840,7 @@
<br />
<?php endif; ?>
</div>
<!-- DEFAULT ENUMERATOR DIV -->
<div id="attr_def_val_enum_div">
<?php if($e): ?>
<select name="def_enum_val"
Expand All @@ -833,6 +850,7 @@
</select>
<?php endif; ?>
</div>
<!-- DEFAULT GROUP -->
<div id="attr_def_val_group_div">
<?php if($e): ?>
<select name="def_group_val"
Expand All @@ -847,6 +865,7 @@
</select>
<?php endif; ?>
</div>
<!-- DEFAULT MANAGER -->
<div id="attr_def_val_manager_div">
<!-- Always use a people picker (unlike Sponsor) -->
<div class="cm-inline-editable-field">
Expand Down Expand Up @@ -890,6 +909,7 @@
</div>
</div>
</div>
<!-- DEFAULT SPONSOR -->
<div id="attr_def_val_sponsor_div">
<?php if($e && $vv_sponsor_mode != SponsorEligibilityEnum::None): ?>
<?php if(isset($vv_sponsors)): ?>
Expand Down Expand Up @@ -954,6 +974,7 @@
</div>
</td>
</tr>
<!-- MODIFY -->
<tr class="line<?php print ($l % 2); $l++; ?>">
<td>
<b><?php print _txt('fd.ed.modify'); ?></b><br />
Expand All @@ -967,6 +988,7 @@
? _txt('fd.yes') : _txt('fd.no'))); ?>
</td>
</tr>
<!-- HIDDEN -->
<tr class="line<?php print ($l % 2); $l++; ?>">
<td>
<b><?php print _txt('fd.hidden'); ?></b><br />
Expand Down
2 changes: 1 addition & 1 deletion app/View/CoPetitions/petition-attributes.inc
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@
'fieldName' => $fieldName,
'modelName' => $ea['model'],
'required' => $ea['required'],
'default' => $ea['default']
'default' => $ea['default'] ?? ''
);
print $this->element('enumerableField', $args);
break;
Expand Down
2 changes: 1 addition & 1 deletion app/View/Elements/enumerableField.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ $allowOther = isset($vv_enums[$field]['allow_other']) && $vv_enums[$field]['allo

<!-- (3) The actual field -->

<div id="<?php print $column; ?>-field" style="display:xxxnone" class="mb-1">
<div id="<?php print $column; ?>-field" style="display:none" class="mb-1">
<?php
$args = array();
$args['class'] = 'form-control';
Expand Down
90 changes: 54 additions & 36 deletions app/View/Elements/enumerations.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ $tname = Inflector::tableize($this->name);

// And whether or not other values are permitted
var other = [];


// Holding the default values
var p = {};

<?php
// Build javascript arrays based on our PHP configuration
foreach($vv_enums as $attr => $cfg) {
Expand All @@ -87,7 +90,7 @@ $tname = Inflector::tableize($this->name);
$cfg = $vv_enums[$attr];

// The current persisted value in the database (if any)
$curval = "";
$curval = '';

if(!empty($$tname[0][ $attrBits[0] ][ $attrBits[1] ])) {
// Regular model
Expand All @@ -98,12 +101,13 @@ $tname = Inflector::tableize($this->name);
if(isset($ea['model'])
&& $ea['model'] == $attrBits[0]
&& $ea['field'] == $attrBits[1]) {
$curval = $ea['default'];
$curval = $ea['default'] ?? '';
}
}
}

print "var p" . Inflector::camelize($attrBits[1]) . " = \""
// We are passing the defaultValue to a tmp variable
print "p['" . $attrBits[0] . Inflector::camelize($attrBits[1]) . "'] = \""
. $curval
. "\";\n";

Expand Down Expand Up @@ -213,42 +217,56 @@ $tname = Inflector::tableize($this->name);
// Always hide the actual value field when the dictionary is in use
$("#<?php print $bits[1]; ?>-field").hide("fade");

var select = document.getElementById(attrid + 'Select');

if(select.options.length > 0) {
select.options.length = 0;
}

var found = 0; // Did we find the current value in the select list?
var i = 0;

select.options[i++] = new Option('', '');

if(coded[curattr]) {
// We want the code as the select value
for(j in enums[curattr]) {
select.options[i++] = new Option(enums[curattr][j], j);

if(p<?php print Inflector::camelize($bits[1]); ?> == j) {
select.selectedIndex = i-1;
found++;
}
const select = document.getElementById(attrid + 'Select');

if(select !== undefined && select !== null) {
if(select.options.length > 0) {
select.options.length = 0;
}
} else {
// No code, so just use the entry as the value
for(j in enums[curattr]) {
select.options[i++] = new Option(enums[curattr][j]);

if(p<?php print Inflector::camelize($bits[1]); ?> == enums[curattr][j]) {
select.selectedIndex = i-1;
found++;

let found = 0; // Did we find the current value in the select list?
let i = 0;

// Add an empty option
select.options[i++] = new Option('', '', false, false);

if(coded[curattr]) {
// sort the fields
const sortedEnumCurAttr = sortProperties(enums[curattr])
// We want the code as the select value
for(let j in sortedEnumCurAttr) {
select.options[i++] = new Option(
sortedEnumCurAttr[j][1],
sortedEnumCurAttr[j][0],
false,
p[attrid] === sortedEnumCurAttr[j][0]
);

if(p[attrid] === sortedEnumCurAttr[j][0]) {
found++;
}
}
} else {
// No code, so use the entry as the value
// todo: when do i get in here??
for(let j in enums[curattr]) {
select.options[i++] = new Option(
enums[curattr][j],
enums[curattr][j],
false,
p[attrid] == j.toString()
);

if(p[attrid] == j.toString()) {
found++;
}
}
}
}

if(!found) {
// Set the default value in the other field
document.getElementById(attrid + 'Other').value = p<?php print Inflector::camelize($bits[1]); ?>;
if(found == 0) {
// Set the default value in the other field
document.getElementById(attrid + 'Other').value = p[attrid];
}
}
} else {
// Standard form element, hide the enumeration widgets
Expand Down
Loading