Skip to content
Snippets Groups Projects
Commit c97adf54 authored by Demian Katz's avatar Demian Katz
Browse files

Moved confirm action to its own controller.

Created convenience method to forward to confirm action.
Improved some style issues.
Use route parameters rather than query parameters for cleaner data passing.
Thanks to Luke O'Sullivan for development assistance.
parent d52fbf76
No related merge requests found
...@@ -90,6 +90,7 @@ $config = array( ...@@ -90,6 +90,7 @@ $config = array(
'author' => 'VuFind\Controller\AuthorController', 'author' => 'VuFind\Controller\AuthorController',
'authority' => 'VuFind\Controller\AuthorityController', 'authority' => 'VuFind\Controller\AuthorityController',
'cart' => 'VuFind\Controller\CartController', 'cart' => 'VuFind\Controller\CartController',
'confirm' => 'VuFind\Controller\ConfirmController',
'cover' => 'VuFind\Controller\CoverController', 'cover' => 'VuFind\Controller\CoverController',
'error' => 'VuFind\Controller\ErrorController', 'error' => 'VuFind\Controller\ErrorController',
'feedback' => 'VuFind\Controller\FeedbackController', 'feedback' => 'VuFind\Controller\FeedbackController',
...@@ -956,6 +957,7 @@ $staticRoutes = array( ...@@ -956,6 +957,7 @@ $staticRoutes = array(
'Browse/LCC', 'Browse/Region', 'Browse/Tag', 'Browse/Topic', 'Browse/LCC', 'Browse/Region', 'Browse/Tag', 'Browse/Topic',
'Cart/doExport', 'Cart/Email', 'Cart/Export', 'Cart/Home', 'Cart/MyResearchBulk', 'Cart/doExport', 'Cart/Email', 'Cart/Export', 'Cart/Home', 'Cart/MyResearchBulk',
'Cart/Save', 'Collections/ByTitle', 'Collections/Home', 'Cart/Save', 'Collections/ByTitle', 'Collections/Home',
'Confirm/Confirm',
'Cover/Show', 'Cover/Unavailable', 'Error/Unavailable', 'Cover/Show', 'Cover/Unavailable', 'Error/Unavailable',
'Feedback/Email', 'Feedback/Home', 'Help/Home', 'Feedback/Email', 'Feedback/Home', 'Help/Home',
'Install/Done', 'Install/FixBasicConfig', 'Install/FixCache', 'Install/Done', 'Install/FixBasicConfig', 'Install/FixCache',
......
...@@ -269,8 +269,7 @@ class AbstractBase extends AbstractActionController ...@@ -269,8 +269,7 @@ class AbstractBase extends AbstractActionController
* @param array $params Extra parameters for the RouteMatch object (no * @param array $params Extra parameters for the RouteMatch object (no
* need to provide action here, since $action takes care of that) * need to provide action here, since $action takes care of that)
* *
* @return bool Returns false so this can be returned by a * @return mixed
* controller without causing duplicate ViewModel attachment.
*/ */
public function forwardTo($controller, $action, $params = array()) public function forwardTo($controller, $action, $params = array())
{ {
...@@ -281,6 +280,34 @@ class AbstractBase extends AbstractActionController ...@@ -281,6 +280,34 @@ class AbstractBase extends AbstractActionController
return $this->forward()->dispatch($controller, $params); 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 * 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 * AJAX operations. This should help reduce the odds of a timing-related bug
......
<?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);
}
}
...@@ -497,15 +497,10 @@ class MyResearchController extends AbstractBase ...@@ -497,15 +497,10 @@ class MyResearchController extends AbstractBase
} else { } else {
$url = $this->url()->fromRoute('userList', array('id' => $listID)); $url = $this->url()->fromRoute('userList', array('id' => $listID));
} }
$this->getRequest()->getQuery()->set('confirmAction', $url); return $this->confirm(
$this->getRequest()->getQuery()->set('cancelAction', $url); 'confirm_delete_brief', $url, $url, 'confirm_delete',
$this->getRequest()->getQuery()->set( array('delete' => $id, 'source' => $source)
'extraFields', 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 ...@@ -653,24 +648,6 @@ class MyResearchController extends AbstractBase
return $this->createViewModel(array('list' => $list)); 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 * Creates a confirmation box to delete or not delete the current list
* *
...@@ -710,21 +687,12 @@ class MyResearchController extends AbstractBase ...@@ -710,21 +687,12 @@ class MyResearchController extends AbstractBase
} }
// If we got this far, we must display a confirmation message: // If we got this far, we must display a confirmation message:
$this->getRequest()->getQuery()->set( return $this->confirm(
'confirmAction', $this->url()->fromRoute('myresearch-deletelist') 'confirm_delete_list_brief',
); $this->url()->fromRoute('myresearch-deletelist'),
$this->getRequest()->getQuery()->set( $this->url()->fromRoute('userList', array('id' => $listID)),
'cancelAction', 'confirm_delete_list_text', array('listID' => $listID)
$this->url()->fromRoute('userList', array('id' => $listID))
);
$this->getRequest()->getQuery()->set(
'extraFields', 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');
} }
/** /**
......
<div class="alignleft" style="text-align:center"> <div class="alignleft">
<h3><?=$this->transEsc($this->title) ?></h3> <h3><?=$this->transEsc($this->title) ?></h3>
<?=$this->flashmessages();?> <?=$this->flashmessages();?>
<?=$this->transEsc($this->message) ?> <div id="popupDetails" class="confirmDialog">
<div id="popupDetails" class="confirmDialog" style="margin-top:.5em">
<form action="<?=$this->escapeHtml($this->confirm)?>" method="post"> <form action="<?=$this->escapeHtml($this->confirm)?>" method="post">
<? foreach ($this->extras as $extra=>$value): ?> <? if (isset($this->extras)): ?>
<input type="hidden" name="<?=$this->escapeHtml($extra) ?>" value="<?=$this->escapeHtml($value) ?>" /> <? foreach ($this->extras as $extra=>$value): ?>
<? endforeach; ?> <? 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') ?>" /> <input type="submit" name="confirm" value="<?=$this->transEsc('confirm_dialog_yes') ?>" />
</form> </form>
<form action="<?=$this->escapeHtml($this->cancel) ?>" method="post"> <form action="<?=$this->escapeHtml($this->cancel) ?>" method="post">
...@@ -16,4 +23,4 @@ ...@@ -16,4 +23,4 @@
</form> </form>
<div class="clearer"></div> <div class="clearer"></div>
</div> </div>
</div> </div>
\ No newline at end of file
...@@ -5,12 +5,18 @@ ...@@ -5,12 +5,18 @@
<?=$this->flashmessages();?> <?=$this->flashmessages();?>
<p><?=$this->transEsc($this->message) ?></p>
<form action="<?=$this->escapeHtml($this->confirm)?>" method="post" data-ajax="false"> <form action="<?=$this->escapeHtml($this->confirm)?>" method="post" data-ajax="false">
<? foreach ($this->extras as $extra=>$value): ?> <? if (isset($this->extras)): ?>
<input type="hidden" name="<?=$this->escapeHtml($extra) ?>" value="<?=$this->escapeHtml($value) ?>" /> <? foreach ($this->extras as $extra=>$value): ?>
<? endforeach; ?> <? 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') ?>" /> <input type="submit" name="confirm" value="<?=$this->transEsc('confirm_dialog_yes') ?>" />
</form> </form>
<form action="<?=$this->escapeHtml($this->cancel) ?>" method="post" data-ajax="false"> <form action="<?=$this->escapeHtml($this->cancel) ?>" method="post" data-ajax="false">
...@@ -18,4 +24,4 @@ ...@@ -18,4 +24,4 @@
</form> </form>
</div> </div>
<?=$this->mobileMenu()->footer()?> <?=$this->mobileMenu()->footer()?>
</div> </div>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment