Skip to content

Commit

Permalink
Merge branch 'release/2.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
pbchase committed Apr 24, 2020
2 parents f042595 + 9162ee5 commit bba0d74
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log
All notable changes to the Auto-Populate Fields project will be documented in this file.

## [2.5.1] - 2020-04-24
### Changed
- Address issues found in REDCap 9.4.1 - 9.8.4 (Kyle Chesney)
- Rename license file to match Vandy's spec (Philip Chase)


## [2.5.0] - 2020-01-07
### Added
Expand Down
19 changes: 15 additions & 4 deletions ExternalModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function redcap_every_page_top($project_id) {
return;
}

$this->initializeJsObject();
if (PAGE == 'Design/online_designer.php') {
$this->includeJs('js/helper.js');
}
Expand All @@ -34,7 +35,7 @@ function redcap_every_page_top($project_id) {
$this->setDefaultValues();
}

if (isset($_GET['page']) && function_exists('getBranchingFields')) {
if (isset($_GET['page']) && (function_exists('getBranchingFields') || method_exists('\DataEntry', 'getBranchingFields')) ) {
$this->setDefaultWhenVisible();
}
}
Expand Down Expand Up @@ -89,7 +90,7 @@ function setDefaultValues() {
// Getting chronological sequence of events.
$events = array();

$log_event_table = method_exists('\REDCap', 'getLogEventTable') ? \REDCap::getLogEventTable($project_id) : "redcap_log_event";
$log_event_table = method_exists('\REDCap', 'getLogEventTable') ? \REDCap::getLogEventTable($Proj->project_id) : "redcap_log_event";

$sql = '
SELECT MIN(log_event_id), event_id FROM ' . $log_event_table . '
Expand Down Expand Up @@ -253,12 +254,17 @@ function setDefaultValues() {
*/
function setDefaultWhenVisible() {
$equations = array();
list($branching_fields, ) = getBranchingFields($_GET['page']);
list($branching_fields, ) = (function_exists('getBranchingFields')) ?
getBranchingFields($_GET['page']) :
\DataEntry::getBranchingFields($_GET['page']);

foreach ($branching_fields as $field => $equation) {
list($equations[$field], ) = LogicTester::formatLogicToJS($equation, false, $_GET['event_id'], true);
}

// More current versions of REDCap do not have all js libraries loaded in time
$this->setJsSetting('versionMod', version_compare(REDCAP_VERSION, '9.4.1', '>='));

$this->setJsSetting('defaultWhenVisible', array('branchingEquations' => $equations));
$this->includeJs('js/default_when_visible.js');
}
Expand Down Expand Up @@ -400,7 +406,12 @@ protected function includeJs($path) {
* The setting value.
*/
protected function setJsSetting($key, $value) {
echo '<script>autoPopulateFields = {' . $key . ': ' . json_encode($value) . '};</script>';
// initializeJsObject MUST be run once before this function
echo '<script>autoPopulateFields.' . $key . ' = ' . json_encode($value) . ';</script>';
}

protected function initializeJsObject() {
echo '<script>autoPopulateFields = {};</script>';
}

/**
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REDCap Auto-Populate Fields

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3561117.svg)](https://doi.org/10.5281/zenodo.3561117)
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.3561116.svg)](https://doi.org/10.5281/zenodo.3561116)

This REDCap module provides rich control of default values for data entry fields via a set of action tags. These action tags allow fields to be populated based on values from an ordered list of fields and static values. The fields can be read from the current event or the previous event in longitudinal projects.

Expand Down
15 changes: 11 additions & 4 deletions js/default_when_visible.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
autoPopulateFields.defaultWhenVisible.init = function() {
// Setting branching logic to do not show messages.
showEraseValuePrompt = 0;

// Extracting evalLogic function body.
var evalLogicBody = evalLogic.toString();
var evalLogicBody = evalLogicBody.slice(evalLogicBody.indexOf('{') + 1, evalLogicBody.lastIndexOf('}'));
Expand Down Expand Up @@ -31,13 +28,23 @@ autoPopulateFields.defaultWhenVisible.init = function() {
}
};

autoPopulateFields.defaultWhenVisible.init();
// Setting branching logic to not show messages.
showEraseValuePrompt = 0;

// In REDCap >= 9.4.1 evalLogic is not always in scope immediately
if (!autoPopulateFields.versionMod) {
autoPopulateFields.defaultWhenVisible.init();
}

/**
* This block of code prevents "leave with unsaved changes" alerts from being
* supressed due to showEraseValuePrompt = 0.
*/
$(document).ready(function() {
if (autoPopulateFields.versionMod) {
autoPopulateFields.defaultWhenVisible.init(); // override evalLogic when it is in scope
doBranching(); // recalculate branching logic with the modified evalLogic
}
var oldOnBeforeUnload = window.onbeforeunload;

window.onbeforeunload = function() {
Expand Down

0 comments on commit bba0d74

Please sign in to comment.