Skip to content

Commit

Permalink
pkp/pkp-lib#8940 consider checkNo for default and custom pattern suff…
Browse files Browse the repository at this point in the history
…ixes
  • Loading branch information
bozana committed Apr 25, 2023
1 parent e8bfbf8 commit d6f8f96
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 49 deletions.
2 changes: 2 additions & 0 deletions js/load.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import FailedJobDetailsPage from '@/components/Container/FailedJobDetailsPage.vu

// Required by the URN plugin
import FieldText from '@/components/Form/fields/FieldText.vue';
import FieldPubId from '@/components/Form/fields/FieldPubId.vue';

// Expose Vue, the registry and controllers in a global var
window.pkp = Object.assign(PkpLoad, {
Expand Down Expand Up @@ -65,3 +66,4 @@ window.pkp = Object.assign(PkpLoad, {

// Required by the URN plugin
window.pkp.Vue.component('field-text', FieldText);
window.pkp.Vue.component('field-pub-id', FieldPubId);
83 changes: 49 additions & 34 deletions plugins/pubIds/urn/URNPubIdPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
use APP\issue\Issue;
use APP\issue\IssueGalley;
use APP\plugins\PubIdPlugin;
use APP\plugins\pubIds\urn\classes\form\FieldUrn;
use APP\plugins\pubIds\urn\classes\form\FieldPubIdUrn;
use APP\plugins\pubIds\urn\classes\form\FieldTextUrn;
use APP\publication\Publication;
use APP\template\TemplateManager;
use PKP\galley\Galley;
Expand Down Expand Up @@ -402,6 +403,9 @@ public function addPublicationFormFields($hookName, $form)
$pattern = $this->getSetting($form->submissionContext->getId(), 'urnPublicationSuffixPattern');
}

// Load the checkNumber.js file that is required for this field
$this->addJavaScript(Application::get()->getRequest(), TemplateManager::getManager(Application::get()->getRequest()));

// If a pattern exists, use a DOI-like field to generate the URN
if ($pattern) {
$fieldData = [
Expand All @@ -411,8 +415,9 @@ public function addPublicationFormFields($hookName, $form)
'pattern' => $pattern,
'contextInitials' => $form->submissionContext->getData('acronym', $form->submissionContext->getData('primaryLocale')) ?? '',
'submissionId' => $form->publication->getData('submissionId'),
'assignId' => __('plugins.pubIds.urn.editor.urn.assignUrn'),
'clearId' => __('plugins.pubIds.urn.editor.clearObjectsURN'),
'assignIdLabel' => __('plugins.pubIds.urn.editor.urn.assignUrn'),
'clearIdLabel' => __('plugins.pubIds.urn.editor.clearObjectsURN'),
'applyCheckNumber' => true
];
if ($form->publication->getData('pub-id::publisher-id')) {
$fieldData['publisherId'] = $form->publication->getData('pub-id::publisher-id');
Expand All @@ -433,18 +438,16 @@ public function addPublicationFormFields($hookName, $form)
} else {
$fieldData['missingPartsLabel'] = __('plugins.pubIds.urn.editor.missingParts');
}
$form->addField(new \PKP\components\forms\FieldPubId('pub-id::other::urn', $fieldData));
$form->addField(new FieldPubIdUrn('pub-id::other::urn', $fieldData));

// Otherwise add a field for manual entry that includes a button to generate
// the check number
} else {
// Load the checkNumber.js file that is required for this field
$this->addJavaScript(Application::get()->getRequest(), TemplateManager::getManager(Application::get()->getRequest()));

$form->addField(new FieldUrn('pub-id::other::urn', [
$form->addField(new FieldTextUrn('pub-id::other::urn', [
'label' => __('plugins.pubIds.urn.displayName'),
'description' => __('plugins.pubIds.urn.editor.urn.description', ['prefix' => $prefix]),
'value' => $form->publication->getData('pub-id::other::urn'),
'urnPrefix' => $prefix,
]));
}
}
Expand Down Expand Up @@ -533,33 +536,45 @@ public function loadUrnFieldComponent($hookName, $args)
return;
}

$templateMgr->addJavaScript(
'urn-field-component',
Application::get()->getRequest()->getBaseUrl() . '/' . $this->getPluginPath() . '/js/FieldUrn.js',
[
'contexts' => 'backend',
'priority' => TemplateManager::STYLE_SEQUENCE_LAST,
]
);
$context = $templateMgr->getTemplateVars('currentContext');
$suffixType = $this->getSetting($context->getId(), 'urnSuffix');
if ($suffixType === 'default' || $suffixType === 'pattern') {
$templateMgr->addJavaScript(
'field-pub-id-urn-component',
Application::get()->getRequest()->getBaseUrl() . '/' . $this->getPluginPath() . '/js/FieldPubIdUrn.js',
[
'contexts' => 'backend',
'priority' => TemplateManager::STYLE_SEQUENCE_LAST,
]
);
} else {
$templateMgr->addJavaScript(
'field-text-urn-component',
Application::get()->getRequest()->getBaseUrl() . '/' . $this->getPluginPath() . '/js/FieldTextUrn.js',
[
'contexts' => 'backend',
'priority' => TemplateManager::STYLE_SEQUENCE_LAST,
]
);
$templateMgr->addStyleSheet(
'field-text-urn-component',
'
.pkpFormField--urn__input {
display: inline-block;
}
$templateMgr->addStyleSheet(
'urn-field-component',
'
.pkpFormField--urn__input {
display: inline-block;
}
.pkpFormField--urn__button {
margin-left: 0.25rem;
height: 2.5rem; // Match input height
}
',
[
'contexts' => 'backend',
'inline' => true,
'priority' => TemplateManager::STYLE_SEQUENCE_LAST,
]
);
.pkpFormField--urn__button {
margin-left: 0.25rem;
height: 2.5rem; // Match input height
}
',
[
'contexts' => 'backend',
'inline' => true,
'priority' => TemplateManager::STYLE_SEQUENCE_LAST,
]
);
}
}

//
Expand Down
37 changes: 37 additions & 0 deletions plugins/pubIds/urn/classes/form/FieldPubIdUrn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* @file plugins/pubIds/urn/classes/form/FieldPubIdUrn.php
*
* Copyright (c) 2014-2022 Simon Fraser University
* Copyright (c) 2000-2022 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class FieldPubIdUrn
*
* @brief A pub ID field that considers check number.
*/

namespace APP\plugins\pubIds\urn\classes\form;

use PKP\components\forms\FieldPubId;

class FieldPubIdUrn extends FieldPubId
{
/** @copydoc Field::$component */
public $component = 'field-pub-id-urn';

public bool $applyCheckNumber = false;

/**
* @copydoc Field::getConfig()
*/
public function getConfig()
{
$config = parent::getConfig();
if (isset($this->applyCheckNumber)) {
$config['applyCheckNumber'] = $this->applyCheckNumber;
}
return $config;
}
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
<?php

/**
* @file plugins/pubIds/urn/classes/form/FieldUrn.php
* @file plugins/pubIds/urn/classes/form/FieldTextUrn.php
*
* Copyright (c) 2014-2022 Simon Fraser University
* Copyright (c) 2000-2022 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class FieldUrn
* @class FieldTextUrn
*
* @brief A field for entering a URN and then having the check number generated.
* @brief A field for entering a custom URN and then having the check number generated.
*/

namespace APP\plugins\pubIds\urn\classes\form;

use PKP\components\forms\FieldText;

class FieldUrn extends FieldText
class FieldTextUrn extends FieldText
{
/** @copydoc Field::$component */
public $component = 'field-urn';
public $component = 'field-text-urn';

/** @var string The urnPrefix from the urn plugin settings */
public $urnPrefix = '';
Expand Down
28 changes: 28 additions & 0 deletions plugins/pubIds/urn/js/FieldPubIdUrn.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @defgroup plugins_pubIds_urn_js
*/
/**
* @file plugins/pubIds/urn/js/FieldPubIdUrn.js
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @brief A Vue.js component for a pub ID field that considers check number.
*/

pkp.Vue.component('field-pub-id-urn', {
name: 'FieldPubIdUrn',
extends: pkp.Vue.component('field-pub-id'),
props: {
applyCheckNumber: Boolean,
},
methods: {
generateId() {
let id = pkp.Vue.component('field-pub-id').options.methods['generateId'].apply(this);
return this.applyCheckNumber
? id + $.pkp.plugins.generic.urn.getCheckNumber(id, this.prefix)
: id;
}
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
* @defgroup plugins_pubIds_urn_js
*/
/**
* @file plugins/pubIds/urn/js/FieldUrn.js
* @file plugins/pubIds/urn/js/FieldTextUrn.js
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @brief A Vue.js component for a URN form field that adds a check number.
* @brief A Vue.js component for a URN text form field, used for custom suffixes, and that adds a check number.
*/
var template = pkp.Vue.compile('<div class="pkpFormField pkpFormField--text pkpFormField--urn" :class="classes">' +
' <form-field-label' +
Expand Down Expand Up @@ -53,8 +53,8 @@ var template = pkp.Vue.compile('<div class="pkpFormField pkpFormField--text pkpF
' </div>' +
' </div>');

pkp.Vue.component('field-urn', {
name: 'FieldUrn',
pkp.Vue.component('field-text-urn', {
name: 'FieldTextUrn',
extends: pkp.Vue.component('field-text'),
props: {
addCheckNumberLabel: {
Expand Down
11 changes: 5 additions & 6 deletions plugins/pubIds/urn/js/checkNumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@
};

// Apply the check number when the button is clicked
$('#checkNo').click(function() {
var urnPrefix = $('[id^="urnPrefix"]').val(),
urnSuffix = $('[id^="urnSuffix"]').val();
urn = urnPrefix + urnSuffix;
$('[id^="urnSuffix"]').val(urnSuffix + $.pkp.plugins.generic.urn.getCheckNumber(urn, urnPrefix));
});
$('#checkNo').on('click', () => {
var urnPrefix = $('[id^="urnPrefix"]').val(), urnSuffix = $('[id^="urnSuffix"]').val();
urn = urnPrefix + urnSuffix;
$('[id^="urnSuffix"]').val(urnSuffix + $.pkp.plugins.generic.urn.getCheckNumber(urn, urnPrefix));
});

}(jQuery));

0 comments on commit d6f8f96

Please sign in to comment.