From 3b5cdb2290876b94c833e2ff3f159ecf64ace029 Mon Sep 17 00:00:00 2001 From: Gregor Gawol <gawol@ub.uni-leipzig.de> Date: Fri, 26 Feb 2021 11:56:59 +0100 Subject: [PATCH] refs #19158 [master] dds mapping in zend-form for details see issue/19158 --- composer.local.0.finc.json | 5 + local/languages/DDS/de.ini | 8 +- local/languages/DDS/en.ini | 8 +- module/finc/config/dds-form.php | 403 ++++++++++++++++++ module/finc/config/module.config.php | 3 + .../DocumentDeliveryServiceController.php | 74 ++-- themes/finc/scss/compiled.scss | 11 + .../documentdeliveryservice/form.phtml | 302 ------------- .../documentdeliveryservice/home.phtml | 2 +- .../documentdeliveryservice/zform.phtml | 390 +++++++++++++++++ 10 files changed, 864 insertions(+), 342 deletions(-) create mode 100644 module/finc/config/dds-form.php delete mode 100644 themes/finc/templates/documentdeliveryservice/form.phtml create mode 100644 themes/finc/templates/documentdeliveryservice/zform.phtml diff --git a/composer.local.0.finc.json b/composer.local.0.finc.json index 4bc3bf8c419..76e927c42a0 100644 --- a/composer.local.0.finc.json +++ b/composer.local.0.finc.json @@ -17,6 +17,11 @@ "extra": { "vufind": { "modules": [ + "Zend\\Filter", + "Zend\\Hydrator", + "Zend\\Validator", + "Zend\\Serializer", + "Zend\\InputFilter", "finc" ] } diff --git a/local/languages/DDS/de.ini b/local/languages/DDS/de.ini index 9bcc3f8b5be..fc735434269 100644 --- a/local/languages/DDS/de.ini +++ b/local/languages/DDS/de.ini @@ -21,4 +21,10 @@ dds_text_mandatory_fields = "Pflichtfelder" ; Flashmessages dds_order_success = "Ihre Bestellung wurde erfolgreich an die Universitätsbibliothek Leipzig übermittelt." -dds_restriction_text = "Dieser Dienst steht nur Mitarbeiterinnen und Mitarbeitern der Universität sowie der Medizinischen Fakultät (Universitätsklinikum) zur Verfügung." \ No newline at end of file +dds_restriction_text = "Dieser Dienst steht nur Mitarbeiterinnen und Mitarbeitern der Universität sowie der Medizinischen Fakultät (Universitätsklinikum) zur Verfügung." +dds_issn = "Bitte eine korrekte ISSN-10 oder ISSN-13 angeben." +dds_error_publishdate_too_short = "Mindestens ein zweistelliges Erscheinungsjahr angeben." +dds_error_publishdate_too_long = "Maximal ein vierstelliges Erscheinungsjahr angeben." +acquisition_error_publishdate_pattern = "Bitte ein korrektes Jahr eingeben." +dds_error_pages_too_short = "Mindestens einstellige Seitenzahlen angeben." +acquisition_error_pages_pattern = "Bitte einen Seitenzahl (z.B. 20 oder 20-29) angeben." \ No newline at end of file diff --git a/local/languages/DDS/en.ini b/local/languages/DDS/en.ini index d4d3d579790..f5f96b23225 100644 --- a/local/languages/DDS/en.ini +++ b/local/languages/DDS/en.ini @@ -21,4 +21,10 @@ dds_text_mandatory_fields = "Mandatory fields" ; Flashmessages dds_order_success = "Your order has been sent successfully." -dds_restriction_text = "This service is only available for members of Leipzig University and department of medicine (Universitätsklinikum)." \ No newline at end of file +dds_restriction_text = "This service is only available for members of Leipzig University and department of medicine (Universitätsklinikum)." +dds_issn = "Only correct ISSN-10 or ISSN-13" +dds_error_publishdate_too_short = "min. a two digit publishdate" +dds_error_publishdate_too_long = "max. a four digit publishdate" +acquisition_error_publishdate_pattern = "Please enter a correct year." +dds_error_pages_too_short = "min. page 1" +acquisition_error_pages_pattern = "Please specify a number of pages (e.g. 20 or 20-29). " \ No newline at end of file diff --git a/module/finc/config/dds-form.php b/module/finc/config/dds-form.php new file mode 100644 index 00000000000..af25773ce24 --- /dev/null +++ b/module/finc/config/dds-form.php @@ -0,0 +1,403 @@ +<?php +/** + * Copyright (C) 2019 Leipzig University Library + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * @author Sebastian Kehr <kehr@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + */ + +use fid\Hydrator\UserHydrator; +use Zend\Filter\Boolean; +use Zend\Filter\PregReplace; +use Zend\Filter\StringTrim; +use Zend\Form\Element\Checkbox; +use Zend\Form\Element\Email; +use Zend\Form\Element\Select; +use Zend\Form\Element\Submit; +use Zend\Form\Element\Text; +use Zend\Form\Element\Textarea; +use Zend\Validator\EmailAddress; +use Zend\Validator\Identical; +use Zend\Validator\Isbn; +use Zend\Validator\NotEmpty; +use Zend\Validator\Regex; +use Zend\Validator\StringLength; + +return [ + 'name' => 'dds-form', + 'elements' => [ + 'username' => [ + 'spec' => [ + 'name' => 'username', + 'type' => Text::class, + 'options' => [ + 'label' => 'Name', + ], + 'attributes' => [ + 'required' => true, + 'id' => 'username', + 'readonly' => true, + ], + ], + ], + 'phone' => [ + 'spec' => [ + 'name' => 'phone', + 'type' => Text::class, + 'options' => [ + 'label' => 'form_field_phone', + ], + 'attributes' => [ + 'required' => false, + 'id' => 'phone', + 'readonly' => true, + ], + ], + ], + 'email' => [ + 'spec' => [ + 'name' => 'email', + 'type' => Email::class, + 'options' => [ + 'label' => 'form_field_email', + ], + 'attributes' => [ + 'required' => true, + 'id' => 'email', + 'readonly' => true, + ], + ], + ], + 'userid' => [ + 'spec' => [ + 'name' => 'userid', + 'type' => Text::class, + 'options' => [ + 'label' => 'form_field_library_id', + ], + 'attributes' => [ + 'required' => true, + 'id' => 'userid', + 'readonly' => true, + ], + ], + ], + 'division' => [ + 'spec' => [ + 'name' => 'division', + 'type' => Select::class, + 'options' => [ + 'label' => 'form_field_division', + 'disable_inarray_validator' => true, + 'empty_option' => '', + ], + 'attributes' => [ + 'required' => true, + 'id' => 'division', + ], + ], + ], + 'department' => [ + 'spec' => [ + 'name' => 'department', + 'type' => Select::class, + 'options' => [ + 'label' => 'form_field_department', + 'disable_inarray_validator' => true, + ], + 'attributes' => [ + 'required' => true, + 'id' => 'department', + ], + ], + ], + 'inputdepartment' => [ + 'spec' => [ + 'name' => 'inputdepartment', + 'type' => Text::class, + 'options' => [ + 'label' => 'form_field_department', + ], + 'attributes' => [ + 'required' => true, + 'id' => 'inputdepartment', + ], + ], + ], + 'author' => [ + 'spec' => [ + 'name' => 'author', + 'type' => Text::class, + 'options' => [ + 'label' => 'form_field_author', + ], + 'attributes' => [ + 'required' => true, + 'id' => 'author', + ], + ], + ], + 'article' => [ + 'spec' => [ + 'name' => 'article', + 'type' => Text::class, + 'options' => [ + 'label' => 'form_field_title', + ], + 'attributes' => [ + 'required' => false, + 'id' => 'article', + ], + ], + ], + 'journal' => [ + 'spec' => [ + 'name' => 'journal', + 'type' => Text::class, + 'options' => [ + 'label' => 'form_field_journal', + ], + 'attributes' => [ + 'required' => false, + 'id' => 'journal', + ], + ], + ], + 'issn' => [ + 'spec' => [ + 'name' => 'issn', + 'type' => Text::class, + 'options' => [ + 'label' => 'ISSN', + ], + 'attributes' => [ + 'required' => false, + 'id' => 'issn', + ], + ], + ], + 'publishdate' => [ + 'spec' => [ + 'name' => 'publishdate', + 'type' => Text::class, + 'options' => [ + 'label' => 'form_field_publishing_date', + ], + 'attributes' => [ + 'required' => true, + 'id' => 'publishdate', + ], + ], + ], + 'number' => [ + 'spec' => [ + 'name' => 'number', + 'type' => Text::class, + 'options' => [ + 'label' => 'form_field_volume', + ], + 'attributes' => [ + 'required' => true, + 'id' => 'number', + ], + ], + ], + 'pages' => [ + 'spec' => [ + 'name' => 'pages', + 'type' => Text::class, + 'options' => [ + 'label' => 'form_field_pages', + ], + 'attributes' => [ + 'required' => true, + 'id' => 'pages', + ], + ], + ], + 'remarks' => [ + 'spec' => [ + 'name' => 'remarks', + 'type' => Textarea::class, + 'options' => [ + 'label' => 'form_fields_remarks', + ], + 'attributes' => [ + 'required' => false, + 'id' => 'remarks', + ], + ], + ], + 'submit' => [ + 'spec' => [ + 'name' => 'submit', + 'type' => Submit::class, + 'attributes' => [ + 'value' => 'form_button_submit', + 'id' => 'submit', + ], + ], + ], + ], + 'input_filter' => [ + 'division' => [ + 'name' => 'division', + 'required' => true, + 'filters' => [ + StringTrim::class => [ + 'name' => StringTrim::class, + ], + ], + 'validators' => [ + NotEmpty::class => [ + 'name' => NotEmpty::class, + 'options' => [ + NotEmpty::INTEGER => 'dds_division', + NotEmpty::IS_EMPTY => 'dds_division', + NotEmpty::NULL => 'dds_division' + ] + ] + ], + ], + 'journal' => [ + 'name' => 'journal', + 'required' => false, + 'filters' => [ + StringTrim::class => [ + 'name' => StringTrim::class, + ], + ], + 'validators' => [ + StringLength::class => [ + 'name' => StringLength::class, + 'options' => [ + 'max' => 255 + ] + ] + ], + ], + 'issn' => [ + 'name' => 'issn', + 'required' => false, + 'filters' => [ + StringTrim::class => [ + 'name' => StringTrim::class, + ], + ], + 'validators' => [ + StringLength::class => [ + 'name' => StringLength::class, + 'options' => [ + 'max' => 255 + ] + ], + ], + ], + 'email' => [ + 'name' => 'email', + 'required' => true, + 'validators' => [ + EmailAddress::class => [ + 'name' => EmailAddress::class, + ], + ], + ], + 'publishdate' => [ + 'name' => 'publishdate', + 'filters' => [ + StringTrim::class => [ + 'name' => StringTrim::class, + ], + ], + 'validators' => [ + StringLength::class => [ + 'name' => StringLength::class, + 'options' => [ + 'min' => 2, + 'max' => 4, + 'messages' => [ + StringLength::TOO_SHORT => 'dds_error_publishdate_too_short', + StringLength::TOO_LONG => 'dds_error_publishdate_too_long', + ], + ], + ], + Regex::class => [ + 'name' => Regex::class, + 'break_chain_on_failure' => true, + 'options' => [ + 'pattern' => '/^(0|[1-9]\d*)$/', + 'messages' => [ + Regex::NOT_MATCH => 'acquisition_error_publishdate_pattern', + ], + ], + ], + ], + ], + 'pages' => [ + 'name' => 'pages', + 'filters' => [ + StringTrim::class => [ + 'name' => StringTrim::class, + ], + PregReplace::class => [ + 'name' => PregReplace::class, + 'options' => [ + 'pattern' => '/(-|–|—|−)/', + 'replacement' => '-' + ] + ], + ], + 'validators' => [ + StringLength::class => [ + 'name' => StringLength::class, + 'options' => [ + 'min' => 1, + 'messages' => [ + StringLength::TOO_SHORT => 'dds_error_pages_too_short', + ], + ], + ], + Regex::class => [ + 'name' => Regex::class, + 'break_chain_on_failure' => true, + 'options' => [ + 'pattern' => '/^(((0|[1-9]\d*)(-([1-9]\d*)|)|,|;)*)$/', + 'messages' => [ + Regex::NOT_MATCH => 'acquisition_error_pages_pattern', + ], + ], + ], + ], + ], + 'remarks' => [ + 'name' => 'remarks', + 'required' => false, + 'filters' => [ + StringTrim::class => [ + 'name' => StringTrim::class, + ], + ], + 'validators' => [ + StringLength::class => [ + 'name' => StringLength::class, + 'options' => [ + 'max' => 5000 + ] + ], + ], + ], + ], +]; \ No newline at end of file diff --git a/module/finc/config/module.config.php b/module/finc/config/module.config.php index 7673bcd88c9..a5dfdc53287 100644 --- a/module/finc/config/module.config.php +++ b/module/finc/config/module.config.php @@ -2,6 +2,9 @@ namespace finc\Module\Configuration; $config = [ + 'forms' => [ + 'dds-form' => require 'dds-form.php', + ], 'listeners' => [ 'finc\Listener\I18nDataDirListener', ], diff --git a/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php b/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php index 5393de813a4..23d91a76fd2 100644 --- a/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php +++ b/module/finc/src/finc/Controller/DocumentDeliveryServiceController.php @@ -31,6 +31,9 @@ namespace finc\Controller; use VuFind\Exception\Mail as MailException; use finc\Exception\DDS as DDSException; use finc\Mailer\Mailer as Mailer; +use Zend\Form\Element\Select; +use Zend\Form\Form; +use Zend\Http\PhpEnvironment\Request; use Zend\Mail\Address as Address; use Zend\ServiceManager\ServiceLocatorInterface; use Zend\Validator as Validator; @@ -172,7 +175,7 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase /** * Display Feedback home form. * - * @return \Zend\View\Model\ViewModel + * @return mixed * @access public * @throws MailException * @throws DDSException @@ -181,31 +184,17 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase { $content = $this->getContent(); - // Validation - $isError = false; - $fields = ['author', 'division', 'email', 'journal', 'username', - 'number', 'publishdate','pages' - ]; - $departmentfield = ($content['division'] == '15') - ? 'inputdepartment' : 'department'; - array_push($fields, $departmentfield); - - $validator = new Validator\NotEmpty(); - foreach ($fields as $field) { - if (false === $validator->isValid($content[$field])) { - $isError = true; - $error[$field] = ucfirst($field) . ' should not be blank'; + /** @var Form $form */ + /** @var Request $request */ + + //$request = $this->getRequest(); + $form = $this->serviceLocator->get('dds-form'); + if ($this->formWasSubmitted()) { + $form->setData($content); + if (!$form->isValid()) { + return $this->createDDSViewModel($content); } } - $validator = new Validator\EmailAddress(); - if (false === $validator->isValid($content['email'])) { - $isError = true; - $error['email'] = 'The email is not valid '; - } - if (true === $isError) { - $content['error'] = (object) $error; - return $this->createDDSViewModel($content); - } // Prepare Email Template $body = $this->buildEmailTemplates($content); @@ -406,9 +395,8 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase // Define obligated fields // obligated at least one of ss or jt if (empty($fields['issn']) && empty($fields['journal'])) { - throw new DDSException( - 'At least issn or title of journal is necessary for an order at - Subito service.' + $this->flashMessenger()->addMessage( + 'DDS::dds_issn_journal', 'error' ); } // all fields of vol, apy, pg @@ -416,8 +404,8 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase empty($fields['publishdate']) || empty($fields['pages']) ) { - throw new DDSException( - 'Pages, publish date and volume are binding statements., ' + $this->flashMessenger()->addMessage( + 'DDS::dds_binding_statements', 'error' ); } // build subito url @@ -443,14 +431,24 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase */ protected function createDDSViewModel($params = null) { - $view = $this->createViewModel(); - // Assign vars to view. + /** @var Form $form */ + $form = $this->serviceLocator->get('dds-form'); + foreach ($params as $key => $value) { - $view->$key = $value; + $elem = $form->get($key); + $elem->setValue($value); } + + $action = $this->url()->fromRoute('dds-email'); + $form->setAttribute('action', $action); + $form->prepare(); + + $view = $this->createViewModel(); + $view->setVariables(compact('form')); // Assign vars for select menu to view. + $elemSdivision = $form->get('division'); + $elemSdivision->setValueOptions($this->getDivisions()); $view->departments = $this->getDepartments(); - $view->divisions = $this->getDivisions(); $view->loadForm = true; $view->setTemplate('documentdeliveryservice/home'); return $view; @@ -485,7 +483,7 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase $post = []; if ($this->getRequest()->isPost()) { $getPost = $this->getRequest()->getPost()->toArray(); - $post = isset($getPost['subito']) ? $getPost['subito'] : []; + $post = !empty($getPost) ? $getPost : []; } // populate the view with data given by User catalog account @@ -698,7 +696,7 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase foreach ($t as $arr) { // Build and normalize dataset of division if (false === array_key_exists($arr['fakultaetid'], $this->division)) { - $this->division[$arr['fakultaetid']] = $arr['fakultaet']; + $this->division[$arr['fakultaetid']] = html_entity_decode($arr['fakultaet']); } // Build options dataset $this->department[$arr['fakultaetid']][$arr['institutid']] @@ -966,13 +964,15 @@ class DocumentDeliveryServiceController extends \VuFind\Controller\AbstractBase } $responseArray = $this->parseJsonAsArray($response->getContent()); - if (array_key_exists('error', $responseArray)) { + if ($responseArray !== null && array_key_exists('error', $responseArray)) { $message = $responseArray['error']; } } else { $message = 'HTTP status ' . $response->getStatusCode() . ' received'; } - throw new DDSException($message); + if (!empty($message)) { + throw new DDSException($message); + } } return $this->parseJsonAsArray($response->getBody()); diff --git a/themes/finc/scss/compiled.scss b/themes/finc/scss/compiled.scss index a7fbd375f82..7b324eb9c67 100644 --- a/themes/finc/scss/compiled.scss +++ b/themes/finc/scss/compiled.scss @@ -3305,3 +3305,14 @@ input { } } // CHANNELS - END + +// ZEND-FORMS + +#dds-form { + + label[data-required="true"][for]::after { + content: ' *'; + } +} + +// ZEND-FORMS - END diff --git a/themes/finc/templates/documentdeliveryservice/form.phtml b/themes/finc/templates/documentdeliveryservice/form.phtml deleted file mode 100644 index c724f5e2ef1..00000000000 --- a/themes/finc/templates/documentdeliveryservice/form.phtml +++ /dev/null @@ -1,302 +0,0 @@ -<!-- finc - documentdeliveryservice - form --> -<div class="<?=$this->layoutClass('mainbody')?>"> - <h1><?=$this->transEsc('DDS::dds_form_headline')?></h1> - <?=$this->flashmessages()?> - <form method="post" action="<?=$this->url('dds-email')?>" name="docdelisForm"> - <?php if ($this->department): ?> - <input type="hidden" name="subito[hdepartment]" value="<?=$this->department?>"/> - <?php endif; ?> - <legend><?=$this->transEsc("DDS::dds_form_delivery_data")?>:</legend> - <!-- name --> - <div class="form-group"> - <label for="sname" class="control-label"><?=$this->transEsc("Name")?>:*</label> - <?php if (isset($this->error->username)): ?> - <div class="error-field"> - <?=$this->error->username;?> - </div> - <?php endif; ?> - - <input type="text" id="sname" name="subito[username]" class="form-control" <?=(!empty($this->username) ? 'value="' . $this->username . '"' : '')?>/> - - </div> - <!-- phone --> - <div class="form-group"> - <label class="inline control-label" for="sphone"><?=$this->transEsc("DDS::form_field_phone")?>:</label> - <?php if (isset($this->error->phone)): ?> - <div class="error-field"> - <?=$this->error->phone;?> - </div> - <?php endif; ?> - <input type="text" id="sphone" name="subito[phone]" class="form-control" <?=(!empty($this->phone) ? 'value="' . $this->phone . '"' : '')?>/> - </div> - <!-- email --> - <div class="form-group"> - <label class="inline control-label" for="semail"><?=$this->transEsc("DDS::form_field_email")?>:*</label> - <?php if (isset($this->error->email)): ?> - <div class="error-field"> - <?=$this->error->email;?> - </div> - <?php endif; ?> - <input type="text" id="semail" name="subito[email]" class="form-control" <?=(!empty($this->email) ? 'value="' . $this->email . '"' : '')?>/> - </div> - <!-- user id --> - <div class="form-group"> - <label class="inline control-label" for="suserid"><?=$this->transEsc("DDS::form_field_library_id")?>:*</label> - <?php if (isset($this->error->userid)): ?> - <div class="error-field"> - <?=$this->error->userid;?> - </div> - <?php endif; ?> - <input type="text" id="suserid" name="subito[userid]" class="form-control" <?=(!empty($this->userid) ? 'value="' . $this->userid . '"' : '')?>/> - </div> - <!-- division --> - <div class="form-group"> - <label class="inline control-label" for="sdivision"><?=$this->transEsc("DDS::form_field_division")?>:*</label> - <?php if (isset($this->error->division)): ?> - <div class="error-field"> - <?=$this->error->division;?> - </div> - <?php endif; ?> - <select id="sdivision" name="subito[division]" size="1" class="form-control"/> - <option value=""></option> - <?php foreach ($this->divisions as $cat => $division): ?> - <option value="<?=$cat?>" <?=($this->division == $cat) ? 'selected="selected"' : ''?>><?=$division?></option> - <?php endforeach; ?> - </select> - </div> - <!-- department --> - <div class="form-group input-sdepartment"> - <label class="inline control-label" for="sdepartment"><?=$this->transEsc("DDS::form_field_department")?>:*</label> - <?php if (isset($this->error->department)): ?> - <div class="error-field"> - <?=$this->error->department;?> - </div> - <?php endif; ?> - <select id="sdepartment" name="subito[department]" size="1" class="form-control"/> - <option value=""></option> - </select> - </div> - <!-- department medicine --> - <div class="form-group input-department"> - <label class="inline control-label" for="smdepartment"><?=$this->transEsc("DDS::form_field_department")?>:*</label> - <input type="text" id="smdepartment" name="subito[inputdepartment]" class="form-control" <?=(!empty($this->inputdepartment) ? 'value="' . $this->inputdepartment . '"' : '')?>/> - </div> - - <legend><?=$this->transEsc("DDS::dds_form_details_ordered_title")?>:</legend> - <!-- author --> - <div class="form-group"> - <label class="inline control-label" for="sauthor"><?=$this->transEsc("DDS::form_field_author")?>:*</label> - <?php if (isset($this->error->author)): ?> - <div class="error-field"> - <?=$this->error->author;?> - </div> - <?php endif; ?> - <input type="text" id="sauthor" name="subito[author]" class="form-control" <?=(!empty($this->author) ? 'value="' . $this->author . '"' : '')?>/> - </div> - <!-- title of issue --> - <div class="form-group"> - <label class="inline control-label" for="sarticle"><?=$this->transEsc("DDS::form_field_title")?>:</label> - <?php if (isset($this->error->article)): ?> - <div class="error-field"> - <?=$this->error->article;?> - </div> - <?php endif; ?> - <input type="text" id="sarticle" name="subito[article]" class="form-control" <?=(!empty($this->article) ? 'value="' . $this->article . '"' : '')?>/> - </div> - <!-- title of journal --> - <div class="form-group"> - <label class="inline control-label" for="sjournal"><?=$this->transEsc("DDS::form_field_journal")?>:*</label> - <?php if (isset($this->error->journal)): ?> - <div class="error-field"> - <?=$this->error->journal;?> - </div> - <?php endif; ?> - <input type="text" id="sjournal" name="subito[journal]" class="form-control" <?=(!empty($this->journal) ? 'value="' . $this->journal . '"' : '')?>/> - </div> - <!-- issn --> - <div class="form-group"> - <label class="inline control-label" for="sjournal"><?=$this->transEsc("ISSN")?>:</label> - <?php if (isset($this->error->issn)): ?> - <div class="error-field"> - <?=$this->error->issn;?> - </div> - <?php endif; ?> - <input type="text" id="sissn" name="subito[issn]" class="form-control" <?=(!empty($this->issn) ? 'value="' . $this->issn . '"' : '')?>/> - </div> - <!-- publish date --> - <div class="form-group"> - <label class="inline control-label" for="spublishdate"><?=$this->transEsc("DDS::form_field_publishing_date")?>:*</label> - <?php if (isset($this->error->publishdate)): ?> - <div class="error-field"> - <?=$this->error->publishdate;?> - </div> - <?php endif; ?> - <input type="text" id="spublishdate" name="subito[publishdate]" class="form-control" <?=(!empty($this->publishdate) ? 'value="' . $this->publishdate . '"' : '')?>/> - </div> - <!-- journal number --> - <div class="form-group"> - <label class="inline control-label" for="snumber"><?=$this->transEsc("DDS::form_field_volume")?>:*</label> - <?php if (isset($this->error->number)): ?> - <div class="error-field"> - <?=$this->error->number;?> - </div> - <?php endif; ?> - <input type="text" id="snumber" name="subito[number]" class="form-control" <?=(!empty($this->number) ? 'value="' . $this->number . '"' : '')?>/> - </div> - <!-- pages --> - <div class="form-group"> - <label class="inline control-label" for="spages"><?=$this->transEsc("DDS::form_field_pages")?>:*</label> - <?php if (isset($this->error->pages)): ?> - <div class="error-field"> - <?=$this->error->pages;?> - </div> - <?php endif; ?> - <input type="text" id="spages" name="subito[pages]" class="form-control" <?=(!empty($this->pages) ? 'value="' . $this->pages . '"' : '')?>/> - </div> - <!-- remarks --> - <div class="form-group"> - <label class="inline control-label" for="sremarks"><?=$this->transEsc("DDS::form_fields_remarks")?>:</label> - <?php if (isset($this->error->remarks)): ?> - <div class="error-field"> - <?=$this->error->remarks;?> - </div> - <?php endif; ?> - <textarea id="sremarks" name="subito[remarks]" class="form-control"><?=(!empty($this->remarks) ? $this->remarks : '')?></textarea> - </div> - <input role="button" type="submit" class="btn btn-primary" value="<?=$this->transEsc("DDS::form_button_submit")?>"/> - - </form> - <div class="subito-pg margin-t"> - <?=$this->transEsc("DDS::dds_text_questions")?> - <a href="mailto:info@ub.uni-leipzig.de?subject=<?=$this->transEsc("Dokumentenlieferdienst")?>">info@ub.uni-leipzig.de</a> - </div> - - <div class="input-department subito-pg"> - <div><?=$this->transEsc("Bei eventuellen Rückfragen wenden Sie sich bitte an die Abteilung Fernleihe der Medizin")?>:</div> - <div><?=$this->transEsc("Phone")?>: +49 (0)341 - 97 14014</div> - <div><?=$this->transEsc("Email")?>: <a href="mailto:zbmed.fernleihe@medizin.uni-leipzig.de?subject=<?=$this->transEsc("Dokumentenlieferdienst")?>">zbmed.fernleihe@medizin.uni-leipzig.de</a> - </div> - </div> - <div class="subito-pg"> - <p class="required"> - * <?=$this->transEsc("DDS::dds_text_mandatory_fields")?></p> - </div> -</div> - -<?php -$this->inlineScript()->captureStart(); -echo <<<JS - $(document).ready(function(){ - // if department already selected and post request failed then - // rebuild select menu - if ( $('input:hidden[name="subito\\[hdepartment\\]"]').val() != 'undefined') { - department.addDepartmentSelect( - $('input[name="subito\\[hdepartment\\]"]').val(), - $('select[name="subito\\[division\\]"]').val() - ); - } - $('select[name="subito\\[division\\]"]').change(function() { - department.init($(this).val()); - }); - $('.form-group input').focus(function() { - $(this).parent().prev('.error-field').hide(200); - }); - $('.form-group select').focus(function() { - $(this).parent().prev('.error-field').hide(200); - }); - /*if ( $('#loginOptions a.login').length ) { - var loginUrl = { - followup: true, - followupModule: 'Subito', - followupAction: 'Subito' - }; - $('#loginOptions a.login').attr('href', function ( index, value ) { - return value + '?' + $.param( loginUrl ); - }); - // console.log($('#loginOptions a.login').attr('href')); - }*/ - }); -/** -* Show & hide of subito form elements regarding select menu status. -* Add options for department select menu -* -* @author Frank Morgner<morgnerf@ub.uni-leipzig.de> -* @see https://katalog.ub.uni-leipzig.de/Subito/Subito -**/ - -var department = { - init: function ( divisionid ) { - addOptions = false; - var elements = []; - if ( divisionid == '15') { - elements = { - "department":"show", - "costcentre":"show", - "sdepartment":"hide" - } - } else if (divisionid == '') { - elements = { - "department":"hide", - "costcentre":"hide", - "sdepartment":"hide" - } - } else { - elements = { - "department":"hide", - "costcentre":"hide", - "sdepartment":"show" - } - var addOptions = true; - } - department.showHideElements(elements); - if (addOptions == true) { - department.addDepartmentOptions( divisionid ); - } - }, - addDepartmentOptions: function ( divisionid ) { - $('select[name="subito\\[department\\]"]').empty(); - var departments = $this->departments; - department.addOptionElement('',''); - $.each(departments[divisionid], function (index, value) { - department.addOptionElement(value,index); - }); - }, - addDepartmentSelect: function (departmentid, divisionid) { - department.init ( divisionid ); - department.addSelectElement ( departmentid ); - }, - addOptionElement: function ( text, value ) { - jQuery('<option/>', { - text: department.htmlEntitiesDecode(text), - value: value - }).appendTo('select[name="subito\\[department\\]"]'); - }, - addSelectElement: function ( departmentid ) { - $('select[name="subito\\[department\\]"] option').filter(function () { - //console.log($(this).val() + ' == ' + departmentid); - return $(this).val() == departmentid; - }).prop('selected', true); - }, - htmlEntitiesDecode: function ( value ) { - if (value) { - return jQuery('<div/>').html(value).text(); - } - return value; - }, - showHideElements: function ( elements ) { - $.each(elements, function (index, value) { - if (value == 'show') { - $('.input-' + index).show(200); - } - if (value == 'hide') { - $('.input-' + index).hide(200); - } - }); - } -} -JS; -$this->inlineScript()->captureEnd(); - -echo $this->inlineScript(); -?> -<!-- finc - documentdeliveryservice - form - END --> diff --git a/themes/finc/templates/documentdeliveryservice/home.phtml b/themes/finc/templates/documentdeliveryservice/home.phtml index 7b19271a9f9..d92c526dd57 100644 --- a/themes/finc/templates/documentdeliveryservice/home.phtml +++ b/themes/finc/templates/documentdeliveryservice/home.phtml @@ -3,4 +3,4 @@ $this->headTitle($this->translate('Delivery service for documents') . ' | ' . $this->translate("LibraryName")); ?> -<?=($this->loadForm ? $this->render('documentdeliveryservice/form.phtml') : $this->flashmessages());?> \ No newline at end of file +<?=($this->loadForm ? $this->render('documentdeliveryservice/zform.phtml') : $this->flashmessages());?> \ No newline at end of file diff --git a/themes/finc/templates/documentdeliveryservice/zform.phtml b/themes/finc/templates/documentdeliveryservice/zform.phtml new file mode 100644 index 00000000000..4f9481ef157 --- /dev/null +++ b/themes/finc/templates/documentdeliveryservice/zform.phtml @@ -0,0 +1,390 @@ +<!-- finc - documentdeliveryservice - form --> +<?php +/** + * Copyright (C) 2021 Leipzig University Library + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * @author Gregor Gawol <gawol@ub.uni-leipzig.de> + * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2 + */ + +use Zend\Form\Element; +use Zend\Form\Element\Submit; +use Zend\Form\Form; +use Zend\Form\View\Helper\FormElementErrors; +use Zend\Form\View\Helper\FormLabel; +use Zend\Form\View\Helper\FormSelect; +use Zend\Form\View\Helper\FormSubmit; + +/** @var Form $form */ +/** @var FormLabel $formLabel */ +/** @var FormSelect $formSelect */ +/** @var FormSubmit $formSubmit */ +/** @var FormElementErrors $formElementErrors */ +$form = $this->form; +$formLabel = $this->formLabel(); +$formSelect = $this->formSelect(); +$formSubmit = $this->formSubmit(); +$formElementErrors = $this->formElementErrors(); +$formLabel->setTranslatorTextDomain('DDS'); +$formSelect->setTranslatorTextDomain('DDS'); +$formSubmit->setTranslatorTextDomain('DDS'); +$formElementErrors->setTranslatorTextDomain('DDS'); +?> +<div class="<?=$this->layoutClass('mainbody')?>"> + <h1><?=$this->transEsc('DDS::dds_form_headline')?></h1> + <?=$this->flashmessages()?> + <?=$this->form()->openTag($form)?> + <?php if ($this->department): ?> + <input type="hidden" name="subito[hdepartment]" value="<?=$this->department?>"/> + <?php endif; ?> + <? /* name */ ?> + <?php + /** @var Element\Text $elemName */ + $elemName = $form->get('username'); + $elemName->setLabelAttributes(['class' => 'control-label']); + $elemName->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemName)?> + <?=$this->formElement($elemName)?> + <?=$this->formElementErrors($elemName)?> + </div> + + <? /* phone */ ?> + <?php + /** @var Element\Text $elemPhone */ + $elemPhone = $form->get('phone'); + $elemPhone->setLabelAttributes(['class' => 'control-label']); + $elemPhone->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemPhone)?> + <?=$this->formElement($elemPhone)?> + </div> + + <? /* email */ ?> + <?php + /** @var Element\Email $elemEmail */ + $elemEmail = $form->get('email'); + $elemEmail->setLabelAttributes(['class' => 'control-label']); + $elemEmail->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemEmail)?> + <?=$this->formElement($elemEmail)?> + <?=$this->formElementErrors($elemEmail)?> + </div> + + <? /* userid */ ?> + <?php + /** @var Element\Text $elemUserid */ + $elemUserid = $form->get('userid'); + $elemUserid->setLabelAttributes(['class' => 'control-label']); + $elemUserid->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemUserid)?> + <?=$this->formElement($elemUserid)?> + <?=$this->formElementErrors($elemUserid)?> + </div> + + <? /* division */ ?> + <?php + /** @var Element\Select $elemDivision */ + $elemDivision = $form->get('division'); + $elemDivision->setLabelAttributes(['class' => 'inline control-label']); + $elemDivision->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemDivision)?> + <?=$this->formSelect($elemDivision)?> + <?=$this->formElementErrors($elemDivision)?> + </div> + + <? /* department */ ?> + <?php + /** @var Element\Select $elemDepartment */ + $elemDepartment = $form->get('department'); + $elemDepartment->setLabelAttributes(['class' => 'inline control-label']); + $elemDepartment->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group input-sdepartment"> + <?=$this->formLabel($elemDepartment)?> + <?=$this->formSelect($elemDepartment)?> + <?=$this->formElementErrors($elemDepartment)?> + </div> + + <? /* department medicine */ ?> + <?php + /** @var Element\Text $elemMdepartment */ + $elemMdepartment = $form->get('inputdepartment'); + $elemMdepartment->setLabelAttributes(['class' => 'control-label']); + $elemMdepartment->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group input-department"> + <?=$this->formLabel($elemMdepartment)?> + <?=$this->formElement($elemMdepartment)?> + <?=$this->formElementErrors($elemMdepartment)?> + </div> + + <? /* author */ ?> + <?php + /** @var Element\Text $elemAuthor */ + $elemAuthor = $form->get('author'); + $elemAuthor->setLabelAttributes(['class' => 'control-label']); + $elemAuthor->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemAuthor)?> + <?=$this->formElement($elemAuthor)?> + <?=$this->formElementErrors($elemAuthor)?> + </div> + + <? /* title of issue */ ?> + <?php + /** @var Element\Text $elemArticle */ + $elemArticle = $form->get('article'); + $elemArticle->setLabelAttributes(['class' => 'control-label']); + $elemArticle->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemArticle)?> + <?=$this->formElement($elemArticle)?> + <?=$this->formElementErrors($elemArticle)?> + </div> + + <? /* title of journal */ ?> + <?php + /** @var Element\Text $elemJournal */ + $elemJournal = $form->get('journal'); + $elemJournal->setLabelAttributes(['class' => 'control-label']); + $elemJournal->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemJournal)?> + <?=$this->formElement($elemJournal)?> + <?=$this->formElementErrors($elemJournal)?> + </div> + + <? /* issn */ ?> + <?php + /** @var Element\Text $elemIssn */ + $elemIssn = $form->get('issn'); + $elemIssn->setLabelAttributes(['class' => 'control-label']); + $elemIssn->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemIssn)?> + <?=$this->formElement($elemIssn)?> + <?=$this->formElementErrors($elemIssn)?> + </div> + + <? /* publish date */ ?> + <?php + /** @var Element\Text $elemPublishdate */ + $elemPublishdate = $form->get('publishdate'); + $elemPublishdate->setLabelAttributes(['class' => 'control-label']); + $elemPublishdate->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemPublishdate)?> + <?=$this->formElement($elemPublishdate)?> + <?=$this->formElementErrors($elemPublishdate)?> + </div> + + <? /* journal number */ ?> + <?php + /** @var Element\Text $elemNumber */ + $elemNumber = $form->get('number'); + $elemNumber->setLabelAttributes(['class' => 'control-label']); + $elemNumber->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemNumber)?> + <?=$this->formElement($elemNumber)?> + <?=$this->formElementErrors($elemNumber)?> + </div> + + <? /* pages */ ?> + <?php + /** @var Element\Text $elemPages */ + $elemPages = $form->get('pages'); + $elemPages->setLabelAttributes(['class' => 'control-label']); + $elemPages->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemPages)?> + <?=$this->formElement($elemPages)?> + <?=$this->formElementErrors($elemPages)?> + </div> + + <? /* remarks */ ?> + <?php + /** @var Element\Textarea $elemRemarks */ + $elemRemarks = $form->get('remarks'); + $elemRemarks->setLabelAttributes(['class' => 'control-label']); + $elemRemarks->setAttributes(['class' => 'form-control']); + ?> + <div class="form-group"> + <?=$this->formLabel($elemRemarks)?> + <?=$this->formElement($elemRemarks)?> + <?=$this->formElementErrors($elemRemarks)?> + </div> + + <? /* submit button */ ?> + <?php + /** @var Submit $elemSubmit */ + $elemSubmit = $form->get('submit'); + $elemSubmit->setAttributes(['class' => 'btn btn-primary']); + ?> + + <div class="form-group"><?= $this->formSubmit($elemSubmit) ?></div> + <?= $this->form()->closeTag($form)?> + + <div class="subito-pg margin-t"> + <?=$this->transEsc("DDS::dds_text_questions")?> + <a href="mailto:info@ub.uni-leipzig.de?subject=<?=$this->transEsc("Dokumentenlieferdienst")?>">info@ub.uni-leipzig.de</a> + </div> + + <div class="input-department subito-pg"> + <div><?=$this->transEsc("Bei eventuellen Rückfragen wenden Sie sich bitte an die Abteilung Fernleihe der Medizin")?>:</div> + <div><?=$this->transEsc("Phone")?>: +49 (0)341 - 97 14014</div> + <div><?=$this->transEsc("Email")?>: <a href="mailto:zbmed.fernleihe@medizin.uni-leipzig.de?subject=<?=$this->transEsc("Dokumentenlieferdienst")?>">zbmed.fernleihe@medizin.uni-leipzig.de</a> + </div> + </div> + <div class="subito-pg"> + <p class="required"> + * <?=$this->transEsc("DDS::dds_text_mandatory_fields")?></p> + </div> +</div> + +<?php +$this->inlineScript()->captureStart(); +echo <<<JS + $(document).ready(function(){ + // if department already selected and post request failed then + // rebuild select menu + if ( $('input:hidden[name="department"]').val() != 'undefined') { + department.addDepartmentSelect( + $('input[name="department"]').val(), + $('select[name="division"]').val() + ); + } + $('select[name="division"]').change(function() { + department.init($(this).val()); + }); + // $('.form-group input').focus(function() { + // $(this).parent().prev('.error-field').hide(200); + // }); + // $('.form-group select').focus(function() { + // $(this).parent().prev('.error-field').hide(200); + // }); + /*if ( $('#loginOptions a.login').length ) { + var loginUrl = { + followup: true, + followupModule: 'Subito', + followupAction: 'Subito' + }; + $('#loginOptions a.login').attr('href', function ( index, value ) { + return value + '?' + $.param( loginUrl ); + }); + // console.log($('#loginOptions a.login').attr('href')); + }*/ + }); +/** +* Show & hide of subito form elements regarding select menu status. +* Add options for department select menu +* +* @author Frank Morgner<morgnerf@ub.uni-leipzig.de> +* @see https://katalog.ub.uni-leipzig.de/Subito/Subito +**/ + +var department = { + init: function ( divisionid ) { + addOptions = false; + var elements = []; + if ( divisionid == '15') { + elements = { + "department":"show", + "costcentre":"show", + "sdepartment":"hide" + } + } else if (divisionid == '') { + elements = { + "department":"hide", + "costcentre":"hide", + "sdepartment":"hide" + } + } else { + elements = { + "department":"hide", + "costcentre":"hide", + "sdepartment":"show" + } + var addOptions = true; + } + department.showHideElements(elements); + if (addOptions == true) { + department.addDepartmentOptions( divisionid ); + } + }, + addDepartmentOptions: function ( divisionid ) { + $('select[name="department"]').empty(); + var departments = $this->departments; + department.addOptionElement('',''); + $.each(departments[divisionid], function (index, value) { + department.addOptionElement(value,index); + }); + }, + addDepartmentSelect: function (departmentid, divisionid) { + department.init ( divisionid ); + department.addSelectElement ( departmentid ); + }, + addOptionElement: function ( text, value ) { + jQuery('<option/>', { + text: department.htmlEntitiesDecode(text), + value: value + }).appendTo('select[name="department"]'); + }, + addSelectElement: function ( departmentid ) { + $('select[name="department"] option').filter(function () { + //console.log($(this).val() + ' == ' + departmentid); + return $(this).val() == departmentid; + }).prop('selected', true); + }, + htmlEntitiesDecode: function ( value ) { + if (value) { + return jQuery('<div/>').html(value).text(); + } + return value; + }, + showHideElements: function ( elements ) { + $.each(elements, function (index, value) { + if (value == 'show') { + $('.input-' + index).show(200); + } + if (value == 'hide') { + $('.input-' + index).hide(200); + } + }); + } +} +JS; +$this->inlineScript()->captureEnd(); + +echo $this->inlineScript(); +?> +<!-- finc - documentdeliveryservice - form - END --> -- GitLab