Skip to content

Commit

Permalink
Bug fix dashboard add
Browse files Browse the repository at this point in the history
Treat add button on dashboard page the same way as on add record page
  • Loading branch information
lsgs committed Oct 17, 2021
1 parent 9e8c696 commit 781058e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
31 changes: 21 additions & 10 deletions RecordAutonumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ public function __construct() {
$settingsArray = $this->getProjectSettings($this->project_id);

// only create object when module is actually enabled for project!
if (!$settingsArray['enabled']['value']) return;
if (!($settingsArray['enabled'] || $settingsArray['enabled']['value'])) return;

try {

$autonumberClassName = '';
foreach ($settingsArray as $settingKey => $settingValues) {
if ($settingKey==='autonumber-option') {
$autonumberClassName = $settingValues['value'];
$autonumberClassName = $settingValues;
} else if (strpos($settingKey, 'option-setting-')===0) {
$autonumberSettings[$settingKey] = $settingValues['value'];
$autonumberSettings[$settingKey] = $settingValues;
}
}

Expand Down Expand Up @@ -133,6 +133,10 @@ public function redcap_every_page_top($project_id) {
$gotoUrl = APP_PATH_WEBROOT."DataEntry/index.php?pid={$this->project_id}&id=$tempRecId&event_id=$armFirstEventId&page=$armFirstForm";
// use javascript to redirect to first form because can't use redirect($loc) due to EM framework exceptions
echo "<script type=\"text/javascript\">window.location.href=\"$gotoUrl\";</script>";
} else if ($this->page==='DataEntry/record_status_dashboard.php') {
if ($this->user_rights['record_create'] && !isset($this->autonumberGenerator)) {
$this->disableAddNewRecord();
}
}
if ($this->crossPageMessageIsSet()) {
$this->includeMessagePopup($this->getCrossPageMessage());
Expand Down Expand Up @@ -185,15 +189,19 @@ protected function handleAutonumberException($postRec, $msg) {
*/
public function redcap_add_edit_records_page($project_id, $instrument, $event_id) {
if ($this->user_rights['record_create'] && !isset($this->autonumberGenerator)) {
?>
<script type='text/javascript'>
$(document).ready( function() {
$('button:contains("<?php echo $this->lang['data_entry_46'];?>")').prop('disabled', 'disabled').attr('title', 'Fix the module configuration first!');
});
</script>
<?php
$this->disableAddNewRecord();
}
}

protected function disableAddNewRecord() {
?>
<script type='text/javascript'>
$(document).ready( function() {
$('button:contains("<?php echo $this->lang['data_entry_46'];?>")').prop('disabled', 'disabled').attr('title', 'Custom Record Auto-numbering external module is not yet configured properly!');
});
</script>
<?php
}

/**
* redcap_data_entry_form_top
Expand Down Expand Up @@ -224,6 +232,9 @@ protected function recordExists($recId) {
}

protected function getNextRecordId() {
if (is_null($this->autonumberGenerator)) {
throw new AutonumberGenerateFailedException('Invalid record auto-numbering module configuration.');
}
do {
$nextId = $this->autonumberGenerator->getNextRecordId();
if ($this->autonumberGenerator->idMatchesExpectedPattern($nextId) &&
Expand Down
18 changes: 14 additions & 4 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@

"description": "Allows users to create a custom record auto-numbering schema for their REDCap project. This works during data entry but not in public surveys or API/CSV data import.",

"permissions": [
"framework-version": 6,

"compatibility": {
"redcap-version-min": "10.4.1"
},

"permissions": [
"redcap_add_edit_records_page",
"redcap_data_entry_form_top",
"redcap_every_page_before_render",
Expand Down Expand Up @@ -86,7 +92,8 @@
{ "value": "2", "name": "2 digits 01 - 99, 100, 101, ..." },
{ "value": "3", "name": "3 digits 001 - 999, 1000, 1001, ..." },
{ "value": "4", "name": "4 digits 0001 - 9999, 10000, 10001, ..." },
{ "value": "5", "name": "5 digits 00001 - 99999, 100000, 100001, ..." }
{ "value": "5", "name": "5 digits 00001 - 99999, 100000, 100001, ..." },
{ "value": "6", "name": "6 digits 000001 - 999999, 1000000, 1000001, ..." }
],
"branchingLogic": {
"field": "autonumber-option",
Expand All @@ -104,11 +111,13 @@
{ "value": "3", "name": "First three characters" },
{ "value": "4", "name": "First four characters" },
{ "value": "5", "name": "First five characters" },
{ "value": "6", "name": "First six characters" },
{ "value": "-1", "name": "Last character" },
{ "value": "-2", "name": "Last two characters" },
{ "value": "-3", "name": "Last three characters" },
{ "value": "-4", "name": "Last four characters" },
{ "value": "-5", "name": "Last five characters" },
{ "value": "-6", "name": "Last six characters" },
{ "value": "id", "name": "Use Group ID" },
{ "value": "un", "name": "Use DAG unique name" }
],
Expand All @@ -129,15 +138,16 @@
},
{
"key": "option-setting-inc-part-len",
"name": "Specify the length of the incrementing part (will begin at 1 and be left-padded with zeros, overflows to additional digits)",
"name": "Specify the length of the incrementing part (will begin at 1 and be left-padded with zeros; overflows to additional digits)",
"required": true,
"type": "dropdown",
"choices": [
{ "value": "1", "name": "1 digit 1 - 9, 10, 11, ..." },
{ "value": "2", "name": "2 digits 01 - 99, 100, 101, ..." },
{ "value": "3", "name": "3 digits 001 - 999, 1000, 1001, ..." },
{ "value": "4", "name": "4 digits 0001 - 9999, 10000, 10001, ..." },
{ "value": "5", "name": "5 digits 00001 - 99999, 100000, 100001, ..." }
{ "value": "5", "name": "5 digits 00001 - 99999, 100000, 100001, ..." },
{ "value": "6", "name": "6 digits 000001 - 999999, 1000000, 1000001, ..." }
],
"branchingLogic": {
"field": "autonumber-option",
Expand Down

0 comments on commit 781058e

Please sign in to comment.