Skip to content

Commit

Permalink
Merge pull request #10 from lsgs/dev
Browse files Browse the repository at this point in the history
Bug fix PrefixAndPad - fix crash, allow blank prefix
UI tweaks - use fa-cube instead of puzzle gif to indicate module functionality
  • Loading branch information
lsgs authored Mar 13, 2021
2 parents 9e956e0 + 68865a7 commit edc55a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
11 changes: 7 additions & 4 deletions AutonumberGenerators/PrefixAndPad.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@ protected function validateConfiguration() {
$prefixOpt = 'option-setting-prefixandpad-prefix';
$padlenOpt = 'option-setting-prefixandpad-padlen';

if (!array_key_exists($prefixOpt, $this->config)) {
throw new AutonumberConfigException('Prefix configuration required');
}
if (!empty($this->config[$prefixOpt])) {
if (array_key_exists($prefixOpt, $this->config)) {
$this->prefix = trim($this->config[$prefixOpt]);
} else {
$this->prefix = '';
}

if (!array_key_exists($padlenOpt, $this->config)) {
Expand Down Expand Up @@ -91,4 +90,8 @@ public function idMatchesExpectedPattern($id) {
public function requireDAG() {
return false;
}

public function getRequiredDataEntryFields() {
return array();
}
}
26 changes: 12 additions & 14 deletions RecordAutonumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
*/
class RecordAutonumber extends AbstractExternalModule
{
const TEMP_RECORD_STEM = 'auto_';
const MODULE_VARNAME = 'MCRI_Record_Autonumber';
const DAG_ELEMENT_NAME = '__GROUPID__';

Expand Down Expand Up @@ -142,10 +141,8 @@ public function redcap_every_page_top($project_id) {

/**
* redcap_every_page_before_render
* Detect when new record is being saved and attempt to generate a new
* record id.
* I.e. data entry form page has been sumbmitted and is reloading after
* the submit POST.
* Detect when new record is being saved and attempt to generate a new record id.
* I.e. data entry form page has been sumbmitted and is reloading after the submit POST.
* @param int project_id
*/
public function redcap_every_page_before_render($project_id) {
Expand All @@ -169,6 +166,7 @@ public function redcap_every_page_before_render($project_id) {
unset($_GET['auto']);
// continue and save record (with default, temp id if could not generate)...
}

}
}

Expand Down Expand Up @@ -209,14 +207,12 @@ public function redcap_data_entry_form_top($project_id, $record, $instrument, $e
}

/**
* When records are created by a survey response, it is not possible to
* prevent integer incrementing. The only way to generate custom record
* numbers is to catch a new record after it is first saved and rename
* it.
* When records are created by a survey response or randomisation, it is not possible to prevent integer incrementing.
* Branch auto-on-randomise is unsuccessful attempt to catch a new record after it is first saved and rename it.
* Can't get it to return new rec id in randomisation confirmation dialog and update page (so saves with default autonumber)
* NOT YET IMPLEMENTED
*/
public function redcap_save_record($project_id, $record, $instrument, $event_id, $group_id, $survey_hash, $response_id, $repeat_instance) {
//
}

protected function recordExists($recId) {
Expand Down Expand Up @@ -253,9 +249,11 @@ protected function includeProjectSetupPageContent() {
$disabled = (SUPER_USER || $this->user_rights['design']==='1') ? '' : 'disabled=""';
?>
<div id="emAutoNumConfigDiv" style="text-indent:-75px;margin-left:75px;margin-bottom:2px;color:green;display:none;">
<button class="btn btn-defaultrc btn-xs fs11" id="emAutoNumConfigBtn" <?php echo $disabled;?>>Configure</button>
<img src="<?php echo APP_PATH_IMAGES;?>accept.png" style="margin-left:8px;">
<?php echo $this->lang['setup_94'];?><img src="<?php echo APP_PATH_IMAGES;?>puzzle_small.png" style="margin-left:5px;"><a href="javascript:;" class="help" title="Tell me more" id="emAutoNumQuestionDialog">?</a>
<button class="btn btn-defaultrc btn-xs fs11" style="min-width:49px;" id="emAutoNumConfigBtn" <?=$disabled?>><?=$this->lang['rights_142']?></button>
<i class="ml-1 fas fa-check-circle" style="text-indent:0;"></i>
<?=$this->lang['setup_94']?>
<i class="fas fa-cube ml-1" style="text-indent:0;"></i>
<a href="javascript:;" class="help" title="Tell me more" id="emAutoNumQuestionDialog">?</a>
</div>
<script type="text/javascript">
$(document).ready(function() {
Expand All @@ -265,7 +263,7 @@ protected function includeProjectSetupPageContent() {
$('#emAutoNumQuestionDialog').click(function() {
simpleDialog(
'<div title="<?php echo REDCap::escapeHtml($this->getModuleName());?>"><?php echo REDCap::escapeHtml($this->getProjectSetting('project-setup-dialog-text'));?></div>',
'<img src="'+app_path_images+'puzzle_small.png"/> <?php echo REDCap::escapeHtml($this->getModuleName());?>'
'<i class="fas fa-cube mr-1"></i><?php echo REDCap::escapeHtml($this->getModuleName());?>'
);
});
$('button[onclick*="auto_inc_set"]').parent('div').replaceWith($('#emAutoNumConfigDiv'));
Expand Down

0 comments on commit edc55a8

Please sign in to comment.