From d6f8f966b04b265e39a94b8c0852c7b5ffe137a7 Mon Sep 17 00:00:00 2001 From: Bozana Bokan Date: Mon, 24 Apr 2023 12:00:19 +0200 Subject: [PATCH] pkp/pkp-lib#8940 consider checkNo for default and custom pattern suffixes --- js/load.js | 2 + plugins/pubIds/urn/URNPubIdPlugin.php | 83 +++++++++++-------- .../pubIds/urn/classes/form/FieldPubIdUrn.php | 37 +++++++++ .../form/{FieldUrn.php => FieldTextUrn.php} | 10 +-- plugins/pubIds/urn/js/FieldPubIdUrn.js | 28 +++++++ .../urn/js/{FieldUrn.js => FieldTextUrn.js} | 8 +- plugins/pubIds/urn/js/checkNumber.js | 11 ++- 7 files changed, 130 insertions(+), 49 deletions(-) create mode 100644 plugins/pubIds/urn/classes/form/FieldPubIdUrn.php rename plugins/pubIds/urn/classes/form/{FieldUrn.php => FieldTextUrn.php} (74%) create mode 100644 plugins/pubIds/urn/js/FieldPubIdUrn.js rename plugins/pubIds/urn/js/{FieldUrn.js => FieldTextUrn.js} (90%) diff --git a/js/load.js b/js/load.js index 467cd216178..88287a42dc6 100644 --- a/js/load.js +++ b/js/load.js @@ -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, { @@ -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); diff --git a/plugins/pubIds/urn/URNPubIdPlugin.php b/plugins/pubIds/urn/URNPubIdPlugin.php index 4529354cf57..d0c7f8b5155 100755 --- a/plugins/pubIds/urn/URNPubIdPlugin.php +++ b/plugins/pubIds/urn/URNPubIdPlugin.php @@ -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; @@ -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 = [ @@ -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'); @@ -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, ])); } } @@ -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, + ] + ); + } } // diff --git a/plugins/pubIds/urn/classes/form/FieldPubIdUrn.php b/plugins/pubIds/urn/classes/form/FieldPubIdUrn.php new file mode 100644 index 00000000000..6d75de3a14e --- /dev/null +++ b/plugins/pubIds/urn/classes/form/FieldPubIdUrn.php @@ -0,0 +1,37 @@ +applyCheckNumber)) { + $config['applyCheckNumber'] = $this->applyCheckNumber; + } + return $config; + } +} diff --git a/plugins/pubIds/urn/classes/form/FieldUrn.php b/plugins/pubIds/urn/classes/form/FieldTextUrn.php similarity index 74% rename from plugins/pubIds/urn/classes/form/FieldUrn.php rename to plugins/pubIds/urn/classes/form/FieldTextUrn.php index aede7f551a4..7d693b6c773 100644 --- a/plugins/pubIds/urn/classes/form/FieldUrn.php +++ b/plugins/pubIds/urn/classes/form/FieldTextUrn.php @@ -1,25 +1,25 @@ ' + ' { + var urnPrefix = $('[id^="urnPrefix"]').val(), urnSuffix = $('[id^="urnSuffix"]').val(); + urn = urnPrefix + urnSuffix; + $('[id^="urnSuffix"]').val(urnSuffix + $.pkp.plugins.generic.urn.getCheckNumber(urn, urnPrefix)); + }); }(jQuery));