From: <gem...@li...> - 2012-03-01 16:41:19
|
Revision: 532 http://gemstracker.svn.sourceforge.net/gemstracker/?rev=532&view=rev Author: matijsdejong Date: 2012-03-01 16:41:08 +0000 (Thu, 01 Mar 2012) Log Message: ----------- Second round in simplifying ModelSnippetActionAbstract 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/Gems/Default/OrganizationAction.php Added Paths: ----------- trunk/library/snippets/Generic/AutosearchFormSnippet.php trunk/library/snippets/Generic/ContentTitleSnippet.php Removed Paths: ------------- trunk/library/snippets/Generic/AutosearchForm.php Modified: trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php =================================================================== --- trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2012-03-01 16:05:31 UTC (rev 531) +++ trunk/library/classes/Gems/Controller/ModelSnippetActionAbstract.php 2012-03-01 16:41:08 UTC (rev 532) @@ -56,7 +56,7 @@ 'browse' => true, 'containingId' => 'autofilter_target', 'keyboard' => true, - 'onEmpty' => 'getOnEmpty', + 'onEmpty' => 'getOnEmptyText', ); /** @@ -78,7 +78,7 @@ * * @var mixed String or array of snippets name */ - protected $deleteSnippets = 'Generic_ModelItemYesNoDeleteSnippet'; + protected $deleteSnippets = array('Generic_ContentTitleSnippet', 'Generic_ModelItemYesNoDeleteSnippet'); /** * @@ -97,7 +97,7 @@ * * @var mixed String or array of snippets name */ - protected $indexStartSnippets = 'Generic_AutosearchForm'; + protected $indexStartSnippets = array('Generic_ContentTitleSnippet', 'Generic_AutosearchFormSnippet'); /** * The snippets used for the index action, after those in autofilter @@ -111,7 +111,7 @@ * * @var mixed String or array of snippets name */ - protected $showSnippets = 'Generic_ModelItemTableSnippet'; + protected $showSnippets = array('Generic_ContentTitleSnippet', 'Generic_ModelItemTableSnippet'); /** * @@ -245,7 +245,7 @@ * * @return string */ - public function getOnEmpty() + public function getOnEmptyText() { return $this->_('Nothing found...'); } Modified: trunk/library/classes/Gems/Default/MailJobAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailJobAction.php 2012-03-01 16:05:31 UTC (rev 531) +++ trunk/library/classes/Gems/Default/MailJobAction.php 2012-03-01 16:41:08 UTC (rev 532) @@ -170,7 +170,7 @@ * * @return string */ - public function getOnEmpty() + public function getOnEmptyText() { return $this->_('No automatic mail jobs found...'); } @@ -180,7 +180,7 @@ */ public function indexAction() { - $this->html->h3($this->_('Automatic mail jobs')); + $this->indexParameters['contentTitle'] = $this->_('Automatic mail jobs'); $lock = $this->util->getCronJobLock(); if ($lock->isLocked()) { Modified: trunk/library/classes/Gems/Default/MailLogAction.php =================================================================== --- trunk/library/classes/Gems/Default/MailLogAction.php 2012-03-01 16:05:31 UTC (rev 531) +++ trunk/library/classes/Gems/Default/MailLogAction.php 2012-03-01 16:41:08 UTC (rev 532) @@ -138,7 +138,7 @@ * * @return string */ - public function getOnEmpty() + public function getOnEmptyText() { return $this->_('No mail activity found...'); } @@ -148,7 +148,7 @@ */ public function indexAction() { - $this->html->h3($this->_('Mail Activity Log')); + $this->indexParameters['contentTitle'] = $this->_('Mail Activity Log'); parent::indexAction(); } Modified: trunk/library/classes/Gems/Default/OrganizationAction.php =================================================================== --- trunk/library/classes/Gems/Default/OrganizationAction.php 2012-03-01 16:05:31 UTC (rev 531) +++ trunk/library/classes/Gems/Default/OrganizationAction.php 2012-03-01 16:41:08 UTC (rev 532) @@ -191,7 +191,7 @@ */ public function deleteAction() { - $this->html->h3($this->_('Delete organization')); + $this->indexParameters['contentTitle'] = $this->_('Delete organization'); parent::deleteAction(); } @@ -211,7 +211,7 @@ * * @return string */ - public function getOnEmpty() + public function getOnEmptyText() { return $this->_('No organization found...'); } @@ -221,7 +221,7 @@ */ public function indexAction() { - $this->html->h3($this->_('Participating organizations')); + $this->indexParameters['contentTitle'] = $this->_('Participating organizations'); parent::indexAction(); } @@ -231,7 +231,7 @@ */ public function showAction() { - $this->html->h3($this->_('Show organization')); + $this->indexParameters['contentTitle'] = $this->_('Show organization'); parent::showAction(); } Deleted: trunk/library/snippets/Generic/AutosearchForm.php =================================================================== --- trunk/library/snippets/Generic/AutosearchForm.php 2012-03-01 16:05:31 UTC (rev 531) +++ trunk/library/snippets/Generic/AutosearchForm.php 2012-03-01 16:41:08 UTC (rev 532) @@ -1,237 +0,0 @@ -<?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. - * - * Short description of file - * - * @package Gems - * @subpackage Snippets\Generic - * @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 $ - */ - -/** - * Short description for class - * - * Long description for class (if any)... - * - * @package Gems - * @subpackage Snippets\Generic - * @copyright Copyright (c) 2011 Erasmus MC - * @license New BSD License - * @since Class available since version 1.4.2 - */ -class Generic_AutosearchForm extends MUtil_Snippets_SnippetAbstract -{ - /** - * - * @var string The id of a div that contains target that should be replaced. - */ - protected $containingId; - - /** - * - * @var MUtil_Model_ModelAbstract - */ - protected $model; - - /** - * - * @var Zend_Controller_Request_Abstract - */ - protected $request; - - /** - * Optional, otherwise created from $util - * - * @var Gems_Util_RequestCache - */ - public $requestCache; - - /** - * - * @var Gems_Util - */ - protected $util; - - /** - * - * @var string Id for auto search button - */ - protected $searchButtonId = 'AUTO_SEARCH_TEXT_BUTTON'; - - - /** - * Should be called after answering the request to allow the Target - * to check if all required registry values have been set correctly. - * - * @return boolean False if required are missing. - */ - public function checkRegistryRequestsAnswers() - { - if ($this->util && (! $this->requestCache)) { - $this->requestCache = $this->util->getRequestCache(); - } - if ($this->requestCache) { - // Do not store searchButtonId - $this->requestCache->removeParams($this->searchButtonId); - } - - return parent::checkRegistryRequestsAnswers(); - } - - /** - * Creates the form itself - * - * @param array $options - * @return Gems_Form - */ - protected function createForm($options = null) - { - $form = new Gems_Form($options); - - return $form; - } - - /** - * Returns a text element for autosearch. Can be overruled. - * - * The form / html elements to search on. Elements can be grouped by inserting null's between them. - * That creates a distinct group of elements - * - * @param array $data The $form field values (can be usefull, but no need to set them) - * @return array Of Zend_Form_Element's or static tekst to add to the html or null for group breaks. - */ - protected function getAutoSearchElements(array $data) - { - // Search text - $element = new Zend_Form_Element_Text($this->model->getTextFilter(), array('label' => $this->_('Free search text'), 'size' => 20, 'maxlength' => 30)); - - return array($element); - } - - /** - * Creates an autosearch form for indexAction. - * - * @return Gems_Form|null - */ - protected function getAutoSearchForm() - { - $data = $this->getSearchData(); - - $elements = $this->getAutoSearchElements($data); - - if ($elements) { - $form = $this->createForm(array('name' => 'autosubmit')); // Assign a name so autosubmit will only work on this form (when there are others) - $form->setHtml('div'); - - $div = $form->getHtml(); - $div->class = 'search'; - - $span = $div->div(array('class' => 'inputgroup')); - - $elements[] = $this->getAutoSearchSubmit(); - - foreach ($elements as $element) { - if ($element instanceof Zend_Form_Element) { - if ($element->getLabel()) { - $span->label($element); - } - $span->input($element); - // TODO: Elementen automatisch toevoegen in MUtil_Form - $form->addElement($element); - } elseif (null === $element) { - $span = $div->div(array('class' => 'inputgroup')); - } else { - $span[] = $element; - } - } - - if ($this->request->isPost()) { - if (! $form->isValid($data)) { - $this->addMessage($form->getErrorMessages()); - $this->addMessage($form->getMessages()); - } - } else { - $form->populate($data); - } - - $href = $this->getAutoSearchHref(); - $form->setAutoSubmit($href, $this->containingId); - - return $form; - } - } - - /** - * - * @return string Href attribute for type as you go autofilter - */ - protected function getAutoSearchHref() - { - return MUtil_Html::attrib('href', array('action' => 'autofilter', $this->model->getTextFilter() => null, 'RouteReset' => true)); - } - - /** - * Creates a submit button - * - * @param MUtil_Form $form - * @return Zend_Form_Element_Submit - */ - protected function getAutoSearchSubmit() - { - return new Zend_Form_Element_Submit($this->searchButtonId, array('label' => $this->_('Search'), 'class' => 'button small')); - } - - /** - * 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) - { - return $this->getAutoSearchForm(); - } - - /** - * - * @return array The data to fill the form with - */ - protected function getSearchData() - { - if ($this->requestCache) { - return $this->requestCache->getProgramParams(); - } else { - return $this->request->getParams(); - } - } -} Added: trunk/library/snippets/Generic/AutosearchFormSnippet.php =================================================================== --- trunk/library/snippets/Generic/AutosearchFormSnippet.php (rev 0) +++ trunk/library/snippets/Generic/AutosearchFormSnippet.php 2012-03-01 16:41:08 UTC (rev 532) @@ -0,0 +1,237 @@ +<?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. + * + * Short description of file + * + * @package Gems + * @subpackage Snippets\Generic + * @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 $ + */ + +/** + * Short description for class + * + * Long description for class (if any)... + * + * @package Gems + * @subpackage Snippets\Generic + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.4.2 + */ +class Generic_AutosearchFormSnippet extends MUtil_Snippets_SnippetAbstract +{ + /** + * + * @var string The id of a div that contains target that should be replaced. + */ + protected $containingId; + + /** + * + * @var MUtil_Model_ModelAbstract + */ + protected $model; + + /** + * + * @var Zend_Controller_Request_Abstract + */ + protected $request; + + /** + * Optional, otherwise created from $util + * + * @var Gems_Util_RequestCache + */ + public $requestCache; + + /** + * + * @var Gems_Util + */ + protected $util; + + /** + * + * @var string Id for auto search button + */ + protected $searchButtonId = 'AUTO_SEARCH_TEXT_BUTTON'; + + + /** + * Should be called after answering the request to allow the Target + * to check if all required registry values have been set correctly. + * + * @return boolean False if required are missing. + */ + public function checkRegistryRequestsAnswers() + { + if ($this->util && (! $this->requestCache)) { + $this->requestCache = $this->util->getRequestCache(); + } + if ($this->requestCache) { + // Do not store searchButtonId + $this->requestCache->removeParams($this->searchButtonId); + } + + return parent::checkRegistryRequestsAnswers(); + } + + /** + * Creates the form itself + * + * @param array $options + * @return Gems_Form + */ + protected function createForm($options = null) + { + $form = new Gems_Form($options); + + return $form; + } + + /** + * Returns a text element for autosearch. Can be overruled. + * + * The form / html elements to search on. Elements can be grouped by inserting null's between them. + * That creates a distinct group of elements + * + * @param array $data The $form field values (can be usefull, but no need to set them) + * @return array Of Zend_Form_Element's or static tekst to add to the html or null for group breaks. + */ + protected function getAutoSearchElements(array $data) + { + // Search text + $element = new Zend_Form_Element_Text($this->model->getTextFilter(), array('label' => $this->_('Free search text'), 'size' => 20, 'maxlength' => 30)); + + return array($element); + } + + /** + * Creates an autosearch form for indexAction. + * + * @return Gems_Form|null + */ + protected function getAutoSearchForm() + { + $data = $this->getSearchData(); + + $elements = $this->getAutoSearchElements($data); + + if ($elements) { + $form = $this->createForm(array('name' => 'autosubmit')); // Assign a name so autosubmit will only work on this form (when there are others) + $form->setHtml('div'); + + $div = $form->getHtml(); + $div->class = 'search'; + + $span = $div->div(array('class' => 'inputgroup')); + + $elements[] = $this->getAutoSearchSubmit(); + + foreach ($elements as $element) { + if ($element instanceof Zend_Form_Element) { + if ($element->getLabel()) { + $span->label($element); + } + $span->input($element); + // TODO: Elementen automatisch toevoegen in MUtil_Form + $form->addElement($element); + } elseif (null === $element) { + $span = $div->div(array('class' => 'inputgroup')); + } else { + $span[] = $element; + } + } + + if ($this->request->isPost()) { + if (! $form->isValid($data)) { + $this->addMessage($form->getErrorMessages()); + $this->addMessage($form->getMessages()); + } + } else { + $form->populate($data); + } + + $href = $this->getAutoSearchHref(); + $form->setAutoSubmit($href, $this->containingId); + + return $form; + } + } + + /** + * + * @return string Href attribute for type as you go autofilter + */ + protected function getAutoSearchHref() + { + return MUtil_Html::attrib('href', array('action' => 'autofilter', $this->model->getTextFilter() => null, 'RouteReset' => true)); + } + + /** + * Creates a submit button + * + * @param MUtil_Form $form + * @return Zend_Form_Element_Submit + */ + protected function getAutoSearchSubmit() + { + return new Zend_Form_Element_Submit($this->searchButtonId, array('label' => $this->_('Search'), 'class' => 'button small')); + } + + /** + * 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) + { + return $this->getAutoSearchForm(); + } + + /** + * + * @return array The data to fill the form with + */ + protected function getSearchData() + { + if ($this->requestCache) { + return $this->requestCache->getProgramParams(); + } else { + return $this->request->getParams(); + } + } +} Added: trunk/library/snippets/Generic/ContentTitleSnippet.php =================================================================== --- trunk/library/snippets/Generic/ContentTitleSnippet.php (rev 0) +++ trunk/library/snippets/Generic/ContentTitleSnippet.php 2012-03-01 16:41:08 UTC (rev 532) @@ -0,0 +1,93 @@ +<?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 <COPYRIGHT HOLDER> 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$ + */ + +/** + * + * + * @package Gems + * @subpackage Snippets + * @copyright Copyright (c) 2011 Erasmus MC + * @license New BSD License + * @since Class available since version 1.5 + */ +class Generic_ContentTitleSnippet extends MUtil_Snippets_SnippetAbstract +{ + /** + * The title to display + * + * @var string + */ + protected $contentTitle; + + /** + * Tagname of the HtmlElement to create + * + * @var string + */ + protected $tagName = 'h3'; + + /** + * 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 ($this->contentTitle) { + return MUtil_Html::create($this->tagName, $this->contentTitle); + } + } + + /** + * 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() + { + return $this->contentTitle && $this->tagName; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |