diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 545b2210cc87717a1c0e627950ddf881d84d25b8..92806792c769d68e0ffad346a9391f8c5996ff7f 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -90,6 +90,7 @@ $config = array( 'author' => 'VuFind\Controller\AuthorController', 'authority' => 'VuFind\Controller\AuthorityController', 'cart' => 'VuFind\Controller\CartController', + 'confirm' => 'VuFind\Controller\ConfirmController', 'cover' => 'VuFind\Controller\CoverController', 'error' => 'VuFind\Controller\ErrorController', 'feedback' => 'VuFind\Controller\FeedbackController', @@ -956,6 +957,7 @@ $staticRoutes = array( 'Browse/LCC', 'Browse/Region', 'Browse/Tag', 'Browse/Topic', 'Cart/doExport', 'Cart/Email', 'Cart/Export', 'Cart/Home', 'Cart/MyResearchBulk', 'Cart/Save', 'Collections/ByTitle', 'Collections/Home', + 'Confirm/Confirm', 'Cover/Show', 'Cover/Unavailable', 'Error/Unavailable', 'Feedback/Email', 'Feedback/Home', 'Help/Home', 'Install/Done', 'Install/FixBasicConfig', 'Install/FixCache', diff --git a/module/VuFind/src/VuFind/Controller/AbstractBase.php b/module/VuFind/src/VuFind/Controller/AbstractBase.php index 4d3eae751e3707b3965b2a850c682aaef8af6ce2..f713c03fd1565fea456bf95e8c3c47ad0d6063b5 100644 --- a/module/VuFind/src/VuFind/Controller/AbstractBase.php +++ b/module/VuFind/src/VuFind/Controller/AbstractBase.php @@ -269,8 +269,7 @@ class AbstractBase extends AbstractActionController * @param array $params Extra parameters for the RouteMatch object (no * need to provide action here, since $action takes care of that) * - * @return bool Returns false so this can be returned by a - * controller without causing duplicate ViewModel attachment. + * @return mixed */ public function forwardTo($controller, $action, $params = array()) { @@ -281,6 +280,34 @@ class AbstractBase extends AbstractActionController return $this->forward()->dispatch($controller, $params); } + /** + * Confirm an action. + * + * @param string $title Title of confirm dialog + * @param string $yesTarget Form target for "confirm" action + * @param string $noTarget Form target for "cancel" action + * @param string|array $messages Info messages for confirm dialog + * @param array $extras Extra details to include in form + * + * @return mixed + */ + public function confirm($title, $yesTarget, $noTarget, $messages = array(), + $extras = array() + ) { + return $this->forwardTo( + 'Confirm', 'Confirm', + array( + 'data' => array( + 'title' => $title, + 'confirm' => $yesTarget, + 'cancel' => $noTarget, + 'messages' => (array)$messages, + 'extras' => $extras + ) + ) + ); + } + /** * Write the session -- this is designed to be called prior to time-consuming * AJAX operations. This should help reduce the odds of a timing-related bug diff --git a/module/VuFind/src/VuFind/Controller/ConfirmController.php b/module/VuFind/src/VuFind/Controller/ConfirmController.php new file mode 100644 index 0000000000000000000000000000000000000000..4a2ff627ee92516cedef25a28a14868587364512 --- /dev/null +++ b/module/VuFind/src/VuFind/Controller/ConfirmController.php @@ -0,0 +1,73 @@ +<?php +/** + * Confirm Controller + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Controller + * @author Demian Katz <demian.katz@villanova.edu> + * @author Luke O'Sullivan <l.osullivan@swansea.ac.uk> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +namespace VuFind\Controller; + +/** + * Redirects the user to the appropriate VuFind action. + * + * @category VuFind2 + * @package Controller + * @author Demian Katz <demian.katz@villanova.edu> + * @author Luke O'Sullivan <l.osullivan@swansea.ac.uk> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +class ConfirmController extends AbstractBase +{ + /** + * Determines what elements are displayed on the home page based on whether + * the user is logged in. + * + * @return mixed + */ + public function confirmAction() + { + // Get Data from the route + $data = $this->params()->fromRoute('data'); + + // Assign Flash Messages + if (isset($data['messages'])) { + $this->flashMessenger()->setNamespace('info'); + + foreach ($data['messages'] as $message) { + $this->flashMessenger()->addMessage( + true === is_array($message) + ? array( + 'msg' => $message['msg'], + 'tokens' => $message['tokens'] + ) + : $message + ); + } + } + + // Assign Data + return $this->createViewModel($data); + } +} diff --git a/module/VuFind/src/VuFind/Controller/MyResearchController.php b/module/VuFind/src/VuFind/Controller/MyResearchController.php index 9729d0bd9da6dbeec7f865c77b437081738fa748..fcc57a6421ddf8e45a8c952c2bee07c2a8aac3f1 100644 --- a/module/VuFind/src/VuFind/Controller/MyResearchController.php +++ b/module/VuFind/src/VuFind/Controller/MyResearchController.php @@ -497,15 +497,10 @@ class MyResearchController extends AbstractBase } else { $url = $this->url()->fromRoute('userList', array('id' => $listID)); } - $this->getRequest()->getQuery()->set('confirmAction', $url); - $this->getRequest()->getQuery()->set('cancelAction', $url); - $this->getRequest()->getQuery()->set( - 'extraFields', array('delete' => $id, 'source' => $source) + return $this->confirm( + 'confirm_delete_brief', $url, $url, 'confirm_delete', + array('delete' => $id, 'source' => $source) ); - $this->getRequest()->getQuery() - ->set('confirmTitle', 'confirm_delete_brief'); - $this->getRequest()->getQuery()->set('confirmMessage', "confirm_delete"); - return $this->forwardTo('MyResearch', 'Confirm'); } /** @@ -653,24 +648,6 @@ class MyResearchController extends AbstractBase return $this->createViewModel(array('list' => $list)); } - /** - * Takes params from the request and uses them to display a confirmation box - * - * @return mixed - */ - public function confirmAction() - { - return $this->createViewModel( - array( - 'title' => $this->params()->fromQuery('confirmTitle'), - 'message' => $this->params()->fromQuery('confirmMessage'), - 'confirm' => $this->params()->fromQuery('confirmAction'), - 'cancel' => $this->params()->fromQuery('cancelAction'), - 'extras' => $this->params()->fromQuery('extraFields') - ) - ); - } - /** * Creates a confirmation box to delete or not delete the current list * @@ -710,21 +687,12 @@ class MyResearchController extends AbstractBase } // If we got this far, we must display a confirmation message: - $this->getRequest()->getQuery()->set( - 'confirmAction', $this->url()->fromRoute('myresearch-deletelist') - ); - $this->getRequest()->getQuery()->set( - 'cancelAction', - $this->url()->fromRoute('userList', array('id' => $listID)) - ); - $this->getRequest()->getQuery()->set( - 'extraFields', array('listID' => $listID) + return $this->confirm( + 'confirm_delete_list_brief', + $this->url()->fromRoute('myresearch-deletelist'), + $this->url()->fromRoute('userList', array('id' => $listID)), + 'confirm_delete_list_text', array('listID' => $listID) ); - $this->getRequest()->getQuery() - ->set('confirmTitle', 'confirm_delete_list_brief'); - $this->getRequest()->getQuery() - ->set('confirmMessage', 'confirm_delete_list_text'); - return $this->forwardTo('MyResearch', 'Confirm'); } /** diff --git a/themes/blueprint/templates/confirm/confirm.phtml b/themes/blueprint/templates/confirm/confirm.phtml new file mode 100644 index 0000000000000000000000000000000000000000..7e814bb5e58b134392e238e1d355f97e86eb7ac8 --- /dev/null +++ b/themes/blueprint/templates/confirm/confirm.phtml @@ -0,0 +1,26 @@ +<div class="alignleft"> + <h3><?=$this->transEsc($this->title) ?></h3> + + <?=$this->flashmessages();?> + + <div id="popupDetails" class="confirmDialog"> + <form action="<?=$this->escapeHtml($this->confirm)?>" method="post"> + <? if (isset($this->extras)): ?> + <? foreach ($this->extras as $extra=>$value): ?> + <? if (is_array($value)): ?> + <? foreach ($value as $current): ?> + <input type="hidden" name="<?=$this->escapeHtml($extra) ?>[]" value="<?=$this->escapeHtml($current) ?>" /> + <? endforeach; ?> + <? else: ?> + <input type="hidden" name="<?=$this->escapeHtml($extra) ?>" value="<?=$this->escapeHtml($value) ?>" /> + <? endif; ?> + <? endforeach; ?> + <? endif;?> + <input type="submit" name="confirm" value="<?=$this->transEsc('confirm_dialog_yes') ?>" /> + </form> + <form action="<?=$this->escapeHtml($this->cancel) ?>" method="post"> + <input type="submit" name="cancel" value="<?=$this->transEsc('confirm_dialog_no') ?>" /> + </form> + <div class="clearer"></div> + </div> +</div> diff --git a/themes/blueprint/templates/myresearch/confirm.phtml b/themes/blueprint/templates/myresearch/confirm.phtml deleted file mode 100644 index 9f0f2f8edeac82fe240cbd5c8e0bd47ebe2c5bc0..0000000000000000000000000000000000000000 --- a/themes/blueprint/templates/myresearch/confirm.phtml +++ /dev/null @@ -1,19 +0,0 @@ -<div class="alignleft" style="text-align:center"> - <h3><?=$this->transEsc($this->title) ?></h3> - - <?=$this->flashmessages();?> - - <?=$this->transEsc($this->message) ?> - <div id="popupDetails" class="confirmDialog" style="margin-top:.5em"> - <form action="<?=$this->escapeHtml($this->confirm)?>" method="post"> - <? foreach ($this->extras as $extra=>$value): ?> - <input type="hidden" name="<?=$this->escapeHtml($extra) ?>" value="<?=$this->escapeHtml($value) ?>" /> - <? endforeach; ?> - <input type="submit" name="confirm" value="<?=$this->transEsc('confirm_dialog_yes') ?>" /> - </form> - <form action="<?=$this->escapeHtml($this->cancel) ?>" method="post"> - <input type="submit" name="cancel" value="<?=$this->transEsc('confirm_dialog_no') ?>" /> - </form> - <div class="clearer"></div> - </div> -</div> \ No newline at end of file diff --git a/themes/jquerymobile/templates/myresearch/confirm.phtml b/themes/jquerymobile/templates/confirm/confirm.phtml similarity index 53% rename from themes/jquerymobile/templates/myresearch/confirm.phtml rename to themes/jquerymobile/templates/confirm/confirm.phtml index 39dfceeafd610da6dc4fe5ce5a456ba7e3011112..18028743ddf023a150690c0694429efed3c9aa09 100644 --- a/themes/jquerymobile/templates/myresearch/confirm.phtml +++ b/themes/jquerymobile/templates/confirm/confirm.phtml @@ -5,12 +5,18 @@ <?=$this->flashmessages();?> - <p><?=$this->transEsc($this->message) ?></p> - <form action="<?=$this->escapeHtml($this->confirm)?>" method="post" data-ajax="false"> - <? foreach ($this->extras as $extra=>$value): ?> - <input type="hidden" name="<?=$this->escapeHtml($extra) ?>" value="<?=$this->escapeHtml($value) ?>" /> - <? endforeach; ?> + <? if (isset($this->extras)): ?> + <? foreach ($this->extras as $extra=>$value): ?> + <? if (is_array($value)): ?> + <? foreach ($value as $current): ?> + <input type="hidden" name="<?=$this->escapeHtml($extra) ?>[]" value="<?=$this->escapeHtml($current) ?>" /> + <? endforeach; ?> + <? else: ?> + <input type="hidden" name="<?=$this->escapeHtml($extra) ?>" value="<?=$this->escapeHtml($value) ?>" /> + <? endif; ?> + <? endforeach; ?> + <? endif;?> <input type="submit" name="confirm" value="<?=$this->transEsc('confirm_dialog_yes') ?>" /> </form> <form action="<?=$this->escapeHtml($this->cancel) ?>" method="post" data-ajax="false"> @@ -18,4 +24,4 @@ </form> </div> <?=$this->mobileMenu()->footer()?> -</div> \ No newline at end of file +</div>