|
From: <gem...@li...> - 2011-10-24 11:58:08
|
Revision: 132
http://gemstracker.svn.sourceforge.net/gemstracker/?rev=132&view=rev
Author: matijsdejong
Date: 2011-10-24 11:58:01 +0000 (Mon, 24 Oct 2011)
Log Message:
-----------
Completed first complete version of snippet based BrowseEditAction replacement. #10 is done.
Modified Paths:
--------------
trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php
trunk/library/classes/Gems/Default/MailJobAction.php
trunk/library/classes/Gems/Default/MailLogAction.php
trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php
trunk/library/classes/MUtil/Snippets/ModelVerticalTableSnippetAbstract.php
trunk/library/classes/MUtil/Snippets/Standard/ModelVerticalTableSnippet.php
trunk/library/snippets/Generic/ModelItemTableSnippet.php
Added Paths:
-----------
trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php
trunk/library/classes/Gems/Snippets/ModelItemTableSnippetGeneric.php
trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetAbstract.php
trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetGeneric.php
trunk/library/classes/MUtil/Snippets/ModelYesNoDeleteSnippetAbstract.php
trunk/library/classes/MUtil/Snippets/Standard/ModelYesNoDeleteSnippet.php
trunk/library/snippets/Generic/ModelItemYesNoDeleteSnippet.php
Modified: trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php
===================================================================
--- trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2011-10-24 11:45:14 UTC (rev 131)
+++ trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -72,7 +72,14 @@
protected $createEditSnippets = 'Generic_ModelFormSnippet';
/**
+ * The snippets used for the delete action.
*
+ * @var mixed String or array of snippets name
+ */
+ protected $deleteSnippets = 'Generic_ModelItemYesNoDeleteSnippet';
+
+ /**
+ *
* @var GemsEscort
*/
public $escort;
Modified: trunk/library/classes/Gems/Default/MailJobAction.php
===================================================================
--- trunk/library/classes/Gems/Default/MailJobAction.php 2011-10-24 11:45:14 UTC (rev 131)
+++ trunk/library/classes/Gems/Default/MailJobAction.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -125,12 +125,23 @@
}
/**
+ * Action for showing a delete item page
+ */
+ public function deleteAction()
+ {
+ $this->deleteParameters['deleteQuestion'] = $this->_('Do you want to delete this mail job?');
+ $this->deleteParameters['displayTitle'] = $this->deleteParameters['deleteQuestion'];
+
+ parent::deleteAction();
+ }
+
+ /**
* Action for showing a edit item page
*/
public function editAction()
{
$this->createEditParameters['formTitle'] = $this->_('Edit automatic mail job');
-
+
parent::editAction();
}
@@ -177,4 +188,14 @@
$this->html->pInfo($this->_('With automatic mail jobs and a cron job on the server, mails can be sent without manual user action.'));
}
+
+ /**
+ * Action for showing an item page
+ */
+ public function showAction()
+ {
+ $this->showParameters['displayTitle'] = $this->_('Automatic mail job details');
+
+ parent::showAction();
+ }
}
Modified: trunk/library/classes/Gems/Default/MailLogAction.php
===================================================================
--- trunk/library/classes/Gems/Default/MailLogAction.php 2011-10-24 11:45:14 UTC (rev 131)
+++ trunk/library/classes/Gems/Default/MailLogAction.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -137,7 +137,7 @@
*/
public function showAction()
{
- $this->html->h3($this->_('Show Mail Activity Log item'));
+ $this->showParameters['displayTitle'] = $this->_('Show Mail Activity Log item');
// MUtil_Echo::track($this->indexParameters);
parent::showAction();
Copied: trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php (from rev 127, trunk/library/snippets/Generic/ModelItemTableSnippet.php)
===================================================================
--- trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php (rev 0)
+++ trunk/library/classes/Gems/Snippets/ModelItemTableSnippetAbstract.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -0,0 +1,186 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package Gems
+ * @subpackage Snippets
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+
+/**
+ * Displays each fields of a single item in a model in a row in a Html table
+ * the model set through the $model snippet parameter.
+ *
+ * @package Gems
+ * @subpackage Snippets
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.2
+ */
+abstract class Gems_Snippets_ModelItemTableSnippetAbstract extends MUtil_Snippets_ModelVerticalTableSnippetAbstract
+{
+ /**
+ * Shortfix to add class attribute
+ *
+ * @var string
+ */
+ protected $class = 'displayer';
+
+ /**
+ * Optional title to display at the head of this page.
+ *
+ * @var string Optional
+ */
+ protected $displayTitle;
+
+ /**
+ * Required
+ *
+ * @var Gems_Loader
+ */
+ protected $loader;
+
+ /**
+ * Required
+ *
+ * @var Gems_Menu
+ */
+ protected $menu;
+
+ /**
+ * Required
+ *
+ * @var Zend_Controller_Request_Abstract
+ */
+ protected $request;
+
+ /**
+ * Adds rows from the model to the bridge that creates the browse table.
+ *
+ * Overrule this function to add different columns to the browse table, without
+ * having to recode the core table building code.
+ *
+ * @param MUtil_Model_TableBridge $bridge
+ * @param MUtil_Model_ModelAbstract $model
+ * @return void
+ */
+ protected function addShowTableRows(MUtil_Model_VerticalTableBridge $bridge, MUtil_Model_ModelAbstract $model)
+ {
+ if ($menuItem = $this->getEditMenuItem()) {
+ // Add click to edit
+ $bridge->tbody()->onclick = array('location.href=\'', $menuItem->toHRefAttribute($this->request), '\';');
+ }
+
+ parent::addShowTableRows($bridge, $model);
+ }
+
+ /**
+ * Finds a specific active menu item
+ *
+ * @param string $controller
+ * @param string $action
+ * @return Gems_Menu_SubMenuItem
+ */
+ protected function findMenuItem($controller, $action = 'index')
+ {
+ return $this->menu->find(array('controller' => $controller, 'action' => $action, 'allowed' => true));
+ }
+
+ /**
+ * Returns an edit menu item, if access is allowed by privileges
+ *
+ * @return Gems_Menu_SubMenuItem
+ */
+ protected function getEditMenuItem()
+ {
+ return $this->findMenuItem($this->request->getControllerName(), 'edit');
+ }
+
+ /**
+ * Create the snippets content
+ *
+ * This is a stub function either override getHtmlOutput() or override render()
+ *
+ * @param Zend_View_Abstract $view Just in case it is needed here
+ * @return MUtil_Html_HtmlInterface Something that can be rendered
+ */
+ public function getHtmlOutput(Zend_View_Abstract $view)
+ {
+ if ($table = parent::getHtmlOutput($view)) {
+ if ($title = $this->getTitle()) {
+ $htmlDiv = MUtil_Html::div();
+
+ $htmlDiv->h3($title);
+
+ $this->applyHtmlAttributes($table);
+
+ $htmlDiv[] = $table;
+
+ return $htmlDiv;
+ } else {
+ return $table;
+ }
+ }
+ }
+
+ /**
+ * An optional title for the head of the page.
+ *
+ * @return string
+ */
+ protected function getTitle()
+ {
+ return $this->displayTitle;
+ }
+
+ /**
+ * Set the footer of the browse table.
+ *
+ * Overrule this function to set the header differently, without
+ * having to recode the core table building code.
+ *
+ * @param MUtil_Model_TableBridge $bridge
+ * @param MUtil_Model_ModelAbstract $model
+ * @return void
+ */
+ protected function setShowTableFooter(MUtil_Model_VerticalTableBridge $bridge, MUtil_Model_ModelAbstract $model)
+ {
+ $controller = $this->request->getControllerName();
+
+ $menuList = $this->menu->getMenuList();
+ $menuList->addParameterSources($bridge)
+ ->addByController($controller, 'index', $this->_('Cancel'))
+ ->addByController($controller, 'edit')
+ ->addByController($controller, 'delete');
+
+ $bridge->tfrow($menuList, array('class' => 'centerAlign'));
+ }
+}
Copied: trunk/library/classes/Gems/Snippets/ModelItemTableSnippetGeneric.php (from rev 127, trunk/library/classes/Gems/Snippets/ModelFormSnippetGeneric.php)
===================================================================
--- trunk/library/classes/Gems/Snippets/ModelItemTableSnippetGeneric.php (rev 0)
+++ trunk/library/classes/Gems/Snippets/ModelItemTableSnippetGeneric.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -0,0 +1,71 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package MUtil
+ * @subpackage Snippets
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+
+/**
+ * Displays each fields of a single item in a model in a row in a Html table
+ * the model set through the $model snippet parameter.
+ *
+ * If you want to use this class "as is" use the 'Generic_ModelItemTableSnippet' snippet.
+ *
+ * This class is not in the standard snippet loading directories and does not follow
+ * their naming conventions, but exists only to make it simple to extend this class
+ * for a specific implementation.
+ *
+ * @package MUtil
+ * @subpackage Snippets
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.4
+ */
+class Gems_Snippets_ModelItemTableSnippetGeneric extends Gems_Snippets_ModelItemTableSnippetAbstract
+{
+ /**
+ *
+ * @var MUtil_Model_ModelAbstract
+ */
+ protected $model;
+
+ /**
+ * Creates the model
+ *
+ * @return MUtil_Model_ModelAbstract
+ */
+ protected function createModel()
+ {
+ return $this->model;
+ }
+}
Copied: trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetAbstract.php (from rev 127, trunk/library/snippets/Generic/ModelItemTableSnippet.php)
===================================================================
--- trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetAbstract.php (rev 0)
+++ trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetAbstract.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -0,0 +1,185 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package Gems
+ * @subpackage Snippets
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+
+/**
+ * Ask Yes/No conformation for deletion and deletes item when confirmed.
+ *
+ * Can be used for other uses than delete by overriding performAction().
+ *
+ * @package Gems
+ * @subpackage Snippets
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.4
+ */
+abstract class Gems_Snippets_ModelItemYesNoDeleteSnippetAbstract extends MUtil_Snippets_ModelYesNoDeleteSnippetAbstract
+{
+ /**
+ * Shortfix to add class attribute
+ *
+ * @var string
+ */
+ protected $class = 'displayer';
+
+ /**
+ * Optional title to display at the head of this page.
+ *
+ * @var string Optional
+ */
+ protected $displayTitle;
+
+ /**
+ * Required
+ *
+ * @var Gems_Loader
+ */
+ protected $loader;
+
+ /**
+ * Required
+ *
+ * @var Gems_Menu
+ */
+ protected $menu;
+
+ /**
+ * Required
+ *
+ * @var Zend_Controller_Request_Abstract
+ */
+ protected $request;
+
+ /**
+ * Adds rows from the model to the bridge that creates the browse table.
+ *
+ * Overrule this function to add different columns to the browse table, without
+ * having to recode the core table building code.
+ *
+ * @param MUtil_Model_TableBridge $bridge
+ * @param MUtil_Model_ModelAbstract $model
+ * @return void
+ */
+ protected function addShowTableRows(MUtil_Model_VerticalTableBridge $bridge, MUtil_Model_ModelAbstract $model)
+ {
+ if ($menuItem = $this->getEditMenuItem()) {
+ // Add click to edit
+ $bridge->tbody()->onclick = array('location.href=\'', $menuItem->toHRefAttribute($this->request), '\';');
+ }
+
+ parent::addShowTableRows($bridge, $model);
+ }
+
+ /**
+ * Finds a specific active menu item
+ *
+ * @param string $controller
+ * @param string $action
+ * @return Gems_Menu_SubMenuItem
+ */
+ protected function findMenuItem($controller, $action = 'index')
+ {
+ return $this->menu->find(array('controller' => $controller, 'action' => $action, 'allowed' => true));
+ }
+
+ /**
+ * Returns an edit menu item, if access is allowed by privileges
+ *
+ * @return Gems_Menu_SubMenuItem
+ */
+ protected function getEditMenuItem()
+ {
+ return $this->findMenuItem($this->request->getControllerName(), 'edit');
+ }
+
+ /**
+ * Create the snippets content
+ *
+ * This is a stub function either override getHtmlOutput() or override render()
+ *
+ * @param Zend_View_Abstract $view Just in case it is needed here
+ * @return MUtil_Html_HtmlInterface Something that can be rendered
+ */
+ public function getHtmlOutput(Zend_View_Abstract $view)
+ {
+ if ($table = parent::getHtmlOutput($view)) {
+ if ($title = $this->getTitle()) {
+ $htmlDiv = MUtil_Html::div();
+
+ $htmlDiv->h3($title);
+
+ $this->applyHtmlAttributes($table);
+
+ $htmlDiv[] = $table;
+
+ return $htmlDiv;
+ } else {
+ return $table;
+ }
+ }
+ }
+
+ /**
+ * An optional title for the head of the page.
+ *
+ * @return string
+ */
+ protected function getTitle()
+ {
+ return $this->displayTitle;
+ }
+
+ /**
+ * Set the footer of the browse table.
+ *
+ * Overrule this function to set the header differently, without
+ * having to recode the core table building code.
+ *
+ * @param MUtil_Model_TableBridge $bridge
+ * @param MUtil_Model_ModelAbstract $model
+ * @return void
+ */
+ protected function setShowTableFooter(MUtil_Model_VerticalTableBridge $bridge, MUtil_Model_ModelAbstract $model)
+ {
+ $footer = $bridge->tfrow();
+
+ $footer[] = $this->getQuestion();
+ $footer[] = ' ';
+ $footer->actionLink(array($this->confirmParameter => 1), $this->_('Yes'));
+ $footer[] = ' ';
+ $footer->actionLink(array($this->request->getActionKey() => $this->abortAction), $this->_('No'));
+ }
+}
Copied: trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetGeneric.php (from rev 127, trunk/library/classes/Gems/Snippets/ModelFormSnippetGeneric.php)
===================================================================
--- trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetGeneric.php (rev 0)
+++ trunk/library/classes/Gems/Snippets/ModelItemYesNoDeleteSnippetGeneric.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -0,0 +1,72 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package MUtil
+ * @subpackage Snippets
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+
+/**
+ * Ask Yes/No conformation for deletion and deletes item when confirmed.
+ *
+ * Can be used for other uses than delete by overriding performAction().
+ *
+ * If you want to use this class "as is" use the 'Generic_ModelItemYesNoDeleteSnippet' snippet.
+ *
+ * This class is not in the standard snippet loading directories and does not follow
+ * their naming conventions, but exists only to make it simple to extend this class
+ * for a specific implementation.
+ *
+ * @package MUtil
+ * @subpackage Snippets
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.4
+ */
+class Gems_Snippets_ModelItemYesNoDeleteSnippetGeneric extends Gems_Snippets_ModelItemYesNoDeleteSnippetAbstract
+{
+ /**
+ *
+ * @var MUtil_Model_ModelAbstract
+ */
+ protected $model;
+
+ /**
+ * Creates the model
+ *
+ * @return MUtil_Model_ModelAbstract
+ */
+ protected function createModel()
+ {
+ return $this->model;
+ }
+}
Modified: trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php
===================================================================
--- trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php 2011-10-24 11:45:14 UTC (rev 131)
+++ trunk/library/classes/MUtil/Controller/ModelSnippetActionAbstract.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -86,6 +86,20 @@
protected $createEditSnippets = 'ModelFormSnippet';
/**
+ * The parameters used for the delete action.
+ *
+ * @var array Mixed key => value array for snippet initialization
+ */
+ protected $deleteParameters = array();
+
+ /**
+ * The snippets used for the delete action.
+ *
+ * @var mixed String or array of snippets name
+ */
+ protected $deleteSnippets = 'ModelYesNoDeleteSnippet';
+
+ /**
* The parameters used for the index action minus those in autofilter.
*
* @var array Mixed key => value array for snippet initialization
@@ -211,6 +225,19 @@
}
/**
+ * Action for showing a delete item page
+ */
+ public function deleteAction()
+ {
+ if ($this->deleteSnippets) {
+ $this->deleteParameters['model'] = $this->getModel();
+ $this->deleteParameters['request'] = $this->getRequest();
+
+ $this->addSnippets($this->deleteSnippets, $this->deleteParameters);
+ }
+ }
+
+ /**
* Creates a model for getModel(). Called only for each new $action.
*
* The parameters allow you to easily adapt the model to the current action. The $detailed
Modified: trunk/library/classes/MUtil/Snippets/ModelVerticalTableSnippetAbstract.php
===================================================================
--- trunk/library/classes/MUtil/Snippets/ModelVerticalTableSnippetAbstract.php 2011-10-24 11:45:14 UTC (rev 131)
+++ trunk/library/classes/MUtil/Snippets/ModelVerticalTableSnippetAbstract.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -142,8 +142,36 @@
$bridge = new $this->bridgeClass($model);
$bridge->setColumnCount($this->bridgeColumns);
+ $this->setShowTableHeader($bridge, $model);
+ $this->setShowTableFooter($bridge, $model);
$this->addShowTableRows($bridge, $model);
return $bridge->getTable();
}
+
+ /**
+ * Set the footer of the browse table.
+ *
+ * Overrule this function to set the header differently, without
+ * having to recode the core table building code.
+ *
+ * @param MUtil_Model_TableBridge $bridge
+ * @param MUtil_Model_ModelAbstract $model
+ * @return void
+ */
+ protected function setShowTableFooter(MUtil_Model_VerticalTableBridge $bridge, MUtil_Model_ModelAbstract $model)
+ { }
+
+ /**
+ * Set the header of the browse table.
+ *
+ * Overrule this function to set the header differently, without
+ * having to recode the core table building code.
+ *
+ * @param MUtil_Model_TableBridge $bridge
+ * @param MUtil_Model_ModelAbstract $model
+ * @return void
+ */
+ protected function setShowTableHeader(MUtil_Model_VerticalTableBridge $bridge, MUtil_Model_ModelAbstract $model)
+ { }
}
Added: trunk/library/classes/MUtil/Snippets/ModelYesNoDeleteSnippetAbstract.php
===================================================================
--- trunk/library/classes/MUtil/Snippets/ModelYesNoDeleteSnippetAbstract.php (rev 0)
+++ trunk/library/classes/MUtil/Snippets/ModelYesNoDeleteSnippetAbstract.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -0,0 +1,196 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package MUtil
+ * @subpackage Snippets
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ * Ask Yes/No conformation for deletion and deletes item when confirmed.
+ *
+ * Can be used for other uses than delete by overriding performAction().
+ *
+ * @package MUtil
+ * @subpackage Snippets
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.4
+ */
+abstract class MUtil_Snippets_ModelYesNoDeleteSnippetAbstract extends MUtil_Snippets_ModelVerticalTableSnippetAbstract
+{
+ /**
+ * The action to go to when the user clicks 'No'.
+ *
+ * If you want to change to another controller you'll have to code it.
+ *
+ * @var string
+ */
+ protected $abortAction = 'show';
+
+ /**
+ * @see Zend_Controller_Action_Helper_Redirector
+ *
+ * @var mixed Nothing or either an array or a string that is acceptable for Redector->gotoRoute()
+ */
+ protected $afterSaveRouteUrl;
+
+ /**
+ * The request parameter used to store the confirmation
+ *
+ * @var string Required
+ */
+ protected $confirmParameter = 'confirmed';
+
+ /**
+ * The action to go to when the user clicks 'Yes' and the data is deleted.
+ *
+ * If you want to change to another controller you'll have to code it.
+ *
+ * @var string
+ */
+ protected $deleteAction = 'index';
+
+ /**
+ * The question to as the user.
+ *
+ * @var sting Optional
+ */
+ protected $deleteQuestion;
+
+ /**
+ * Variable to either keep or throw away the request data
+ * not specified in the route.
+ *
+ * @var boolean True then the route is reset
+ */
+ public $resetRoute = true;
+
+ /**
+ * The delete question.
+ *
+ * @return string
+ */
+ protected function getQuestion()
+ {
+ if ($this->deleteQuestion) {
+ return $this->deleteQuestion;
+ } else {
+ return $this->_('Do you really want to delete this item?');
+ }
+ }
+
+ /**
+ * When hasHtmlOutput() is false a snippet user should check
+ * for a redirectRoute.
+ *
+ * When hasHtmlOutput() is true this functions should not be called.
+ *
+ * @see Zend_Controller_Action_Helper_Redirector
+ *
+ * @return mixed Nothing or either an array or a string that is acceptable for Redector->gotoRoute()
+ */
+ public function getRedirectRoute()
+ {
+ return $this->afterSaveRouteUrl;
+ }
+
+ /**
+ * The place to check if the data set in the snippet is valid
+ * to generate the snippet.
+ *
+ * When invalid data should result in an error, you can throw it
+ * here but you can also perform the check in the
+ * checkRegistryRequestsAnswers() function from the
+ * {@see MUtil_Registry_TargetInterface}.
+ *
+ * @return boolean
+ */
+ public function hasHtmlOutput()
+ {
+ if ($this->request->getParam($this->confirmParameter)) {
+ $this->performAction();
+
+ return (boolean) $this->getRedirectRoute();
+
+ } else {
+ return parent::hasHtmlOutput();
+ }
+ }
+
+ /**
+ * Overrule this function if you want to perform a different
+ * action than deleting when the user choose 'yes'.
+ */
+ protected function performAction()
+ {
+ $model = $this->getModel();
+ // MUtil_Echo::track($model->getFilter());
+ $model->delete();
+
+ $this->setAfterDeleteRoute();
+ }
+
+ /**
+ * Set what to do when the form is 'finished'.
+ *
+ * @return MUtil_Snippets_ModelFormSnippetAbstract (continuation pattern)
+ */
+ protected function setAfterDeleteRoute()
+ {
+ // Default is just go to the index
+ if ($this->deleteAction && ($this->request->getActionName() !== $this->deleteAction)) {
+ $this->afterSaveRouteUrl = array($this->request->getControllerKey() => $this->request->getControllerName(), $this->request->getActionKey() => $this->deleteAction);
+ }
+ }
+
+ /**
+ * Set the footer of the browse table.
+ *
+ * Overrule this function to set the header differently, without
+ * having to recode the core table building code.
+ *
+ * @param MUtil_Model_TableBridge $bridge
+ * @param MUtil_Model_ModelAbstract $model
+ * @return void
+ */
+ protected function setShowTableFooter(MUtil_Model_VerticalTableBridge $bridge, MUtil_Model_ModelAbstract $model)
+ {
+ $footer = $bridge->tfrow();
+
+ $footer[] = $this->getQuestion();
+ $footer[] = ' ';
+ $footer->a(array($this->confirmParameter => 1), $this->_('Yes'));
+ $footer[] = ' ';
+ $footer->a(array($this->request->getActionKey() => $this->abortAction), $this->_('No'));
+ }
+}
Modified: trunk/library/classes/MUtil/Snippets/Standard/ModelVerticalTableSnippet.php
===================================================================
--- trunk/library/classes/MUtil/Snippets/Standard/ModelVerticalTableSnippet.php 2011-10-24 11:45:14 UTC (rev 131)
+++ trunk/library/classes/MUtil/Snippets/Standard/ModelVerticalTableSnippet.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -4,7 +4,7 @@
/**
* Copyright (c) 2011, Erasmus MC
* All rights reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
@@ -15,7 +15,7 @@
* * Neither the name of Erasmus MC nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
- *
+ *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@@ -26,8 +26,8 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- *
+ *
+ *
* @package MUtil
* @subpackage Snippets
* @author Matijs de Jong <mj...@ma...>
@@ -37,7 +37,7 @@
*/
/**
- * Displays each fields of a single item in a model in a row in a Html table
+ * Displays each field of a single item in a model in a row in a Html table
* the model set through the $model snippet parameter.
*
* @package MUtil
Added: trunk/library/classes/MUtil/Snippets/Standard/ModelYesNoDeleteSnippet.php
===================================================================
--- trunk/library/classes/MUtil/Snippets/Standard/ModelYesNoDeleteSnippet.php (rev 0)
+++ trunk/library/classes/MUtil/Snippets/Standard/ModelYesNoDeleteSnippet.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -0,0 +1,68 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package MUtil
+ * @subpackage Snippets
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id: Sample.php 203 2011-07-07 12:51:32Z matijs $
+ */
+
+/**
+ * Ask conformation for deletion and deletes item when confirmed.
+ *
+ * The model is set through the $model snippet parameter.
+ *
+ * @package MUtil
+ * @subpackage Snippets
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.4
+ */
+class ModelYesNoDeleteSnippet extends MUtil_Snippets_ModelYesNoDeleteSnippetAbstract
+{
+ /**
+ *
+ * @var MUtil_Model_ModelAbstract
+ */
+ protected $model;
+
+ /**
+ * Creates the model
+ *
+ * @return MUtil_Model_ModelAbstract
+ */
+ protected function createModel()
+ {
+ return $this->model;
+ }
+
+
+}
Modified: trunk/library/snippets/Generic/ModelItemTableSnippet.php
===================================================================
--- trunk/library/snippets/Generic/ModelItemTableSnippet.php 2011-10-24 11:45:14 UTC (rev 131)
+++ trunk/library/snippets/Generic/ModelItemTableSnippet.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -39,116 +39,11 @@
* Displays each fields of a single item in a model in a row in a Html table
* the model set through the $model snippet parameter.
*
- * @package MUtil
- * @subpackage Gems
+ * @package Gems
+ * @subpackage Snippets
* @copyright Copyright (c) 2011 Erasmus MC
* @license New BSD License
- * @since Class available since version 1.2
+ * @since Class available since version 1.4.4
*/
-class Generic_ModelItemTableSnippet extends MUtil_Snippets_ModelVerticalTableSnippetAbstract
-{
- /**
- * The PHP class used to create the VerticalTableBridge.
- *
- * Must be instanceof MUtil_Model_VerticalTableBridge.
- *
- * @var string Class name
- */
- // protected $bridgeClass = 'Gems_Model_ThreeColumnTableBridge';
-
- /**
- * Shortfix to add class attribute
- *
- * @var string
- */
- protected $class = 'displayer';
-
- /**
- * Required
- *
- * @var Gems_Loader
- */
- protected $loader;
-
- /**
- * Required
- *
- * @var Gems_Menu
- */
- protected $menu;
-
- /**
- *
- * @var MUtil_Model_ModelAbstract
- */
- protected $model;
-
- /**
- * Required
- *
- * @var Zend_Controller_Request_Abstract
- */
- protected $request;
-
- /**
- * Adds rows from the model to the bridge that creates the browse table.
- *
- * Overrule this function to add different columns to the browse table, without
- * having to recode the core table building code.
- *
- * @param MUtil_Model_TableBridge $bridge
- * @param MUtil_Model_ModelAbstract $model
- * @return void
- */
- protected function addShowTableRows(MUtil_Model_VerticalTableBridge $bridge, MUtil_Model_ModelAbstract $model)
- {
- if ($menuItem = $this->getEditMenuItem()) {
- // Add click to edit
- $bridge->tbody()->onclick = array('location.href=\'', $menuItem->toHRefAttribute($this->request), '\';');
- }
-
- parent::addShowTableRows($bridge, $model);
-
- $controller = $this->request->getControllerName();
-
- $menuList = $this->menu->getMenuList();
- $menuList->addParameterSources($bridge)
- ->addByController($controller, 'index', $this->_('Cancel'))
- ->addByController($controller, 'edit')
- ->addByController($controller, 'delete');
-
- $bridge->tfrow($menuList, array('class' => 'centerAlign'));
- }
-
- /**
- * Creates the model
- *
- * @return MUtil_Model_ModelAbstract
- */
- protected function createModel()
- {
- return $this->model;
- }
-
- /**
- * Finds a specific active menu item
- *
- * @param string $controller
- * @param string $action
- * @return Gems_Menu_SubMenuItem
- */
- protected function findMenuItem($controller, $action = 'index')
- {
- return $this->menu->find(array('controller' => $controller, 'action' => $action, 'allowed' => true));
- }
-
- /**
- * Returns an edit menu item, if access is allowed by privileges
- *
- * @return Gems_Menu_SubMenuItem
- */
- protected function getEditMenuItem()
- {
- return $this->findMenuItem($this->request->getControllerName(), 'edit');
- }
-}
+class Generic_ModelItemTableSnippet extends Gems_Snippets_ModelItemTableSnippetGeneric
+{ }
Copied: trunk/library/snippets/Generic/ModelItemYesNoDeleteSnippet.php (from rev 127, trunk/library/snippets/Generic/ModelItemTableSnippet.php)
===================================================================
--- trunk/library/snippets/Generic/ModelItemYesNoDeleteSnippet.php (rev 0)
+++ trunk/library/snippets/Generic/ModelItemYesNoDeleteSnippet.php 2011-10-24 11:58:01 UTC (rev 132)
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * Copyright (c) 2011, Erasmus MC
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * * Neither the name of Erasmus MC nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *
+ * @package Gems
+ * @subpackage Snippets
+ * @author Matijs de Jong <mj...@ma...>
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @version $Id$
+ */
+
+/**
+ * Displays each fields of a single item in a model in a row in a Html table
+ * the model set through the $model snippet parameter.
+ *
+ * @package Gems
+ * @subpackage Snippets
+ * @copyright Copyright (c) 2011 Erasmus MC
+ * @license New BSD License
+ * @since Class available since version 1.4.4
+ */
+class Generic_ModelItemYesNoDeleteSnippet extends Gems_Snippets_ModelItemYesNoDeleteSnippetGeneric
+{ }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|