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

COMCL-803: Show previous uploaded file name #96

Merged
merged 2 commits into from
Sep 26, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ jobs:
working-directory: ${{ env.CIVICRM_EXTENSIONS_DIR }}
run: |
git clone --depth 1 https://github.com/civicrm/org.civicrm.shoreditch.git
git clone --depth 1 -b 4.2.0-dev --no-single-branch https://github.com/compucorp/uk.co.compucorp.civicase.git
git clone --depth 1 -b 2.1.0-dev https://github.com/compucorp/uk.co.compucorp.usermenu.git
git clone --depth 1 -b master --no-single-branch https://github.com/compucorp/uk.co.compucorp.civicase.git
git clone --depth 1 -b master https://github.com/compucorp/uk.co.compucorp.usermenu.git

- name: Setup Test DB
run: echo "CREATE DATABASE civicrm_test;" | mysql -u root --password=root --host=mysql
Expand Down
17 changes: 17 additions & 0 deletions CRM/Certificate/Form/CertificateConfigure.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ public function buildQuickForm() {
$elementWithHelpTexts = ['relationship_types', 'min_valid_from_date', 'max_valid_through_date', 'download_type'];

$this->assign('help', $elementWithHelpTexts);
$this->assign('previousFile', $this->getPreviousFileURL());
$this->assign('elementNames', $this->getRenderableElementNames());
$this->assign('entityRefs', CRM_Certificate_Enum_CertificateType::getEnityRefs());
$this->assign('entityStatusRefs', CRM_Certificate_Enum_CertificateType::getEntityStatusRefs());
Expand Down Expand Up @@ -408,4 +409,20 @@ public function validateDateFields($values, &$errors) {
}
}

public function getPreviousFileURL() {
$fileURL = "";

if (empty($this->_id)) {
return json_encode($fileURL);
}

$configuredCertificate = $this->getConfiguredCertificateById($this->_id);
if ($configuredCertificate['download_type'] == DownloadType::FILE_DOWNLOAD) {
$file = \CRM_Core_BAO_File::getEntityFile(CompuCertificate::getTableName(), $this->_id);
$fileURL = end($file)['url'] ?? "";
}

return json_encode($fileURL);
}

}
14 changes: 14 additions & 0 deletions templates/CRM/Certificate/Form/CertificateConfigure.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@
const TYPE_MEMBERSHIP = "3";
const FORMAT_IMAGE = "2";
const TYPE_TEMPLATE = "1";
const previousFileURL = { $previousFile }

{ literal }


let toggleRequiredMarker = ($, val) => {
if (val === TYPE_CASES) {
$('.participant_type_id').hide()
Expand Down Expand Up @@ -66,6 +68,18 @@
CRM.$(function ($) {

$('.participant_type_id').hide();

if (previousFileURL && previousFileURL.length > 0) {
// Create the anchor element
const fileLink = $('<a>')
.attr('href', previousFileURL) // Set the href attribute to the file URL
.text('Uploaded File') // Text for the link
.attr('target', '_blank'); // Open in a new tab

// Append the anchor to the div with the specified class
$('.row.download_file > .col-sm-7.col-md-5').append(fileLink);
}

toggleValidityDateFields($, CRM.$('[name=type]').val());

/**
Expand Down
Loading