Author: nicolas Date: 2010-03-27 16:50:38 +0100 (Sat, 27 Mar 2010) New Revision: 28827
Added: plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/config/ plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/config/cache.yml plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/lib/ plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/lib/BasesfEditableComponentActions.class.php plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/lib/BasesfEditableComponentComponents.class.php Removed: plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponentTestUtility/ plugins/sfDoctrineEditableComponentPlugin/trunk/test/functional/ Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/README plugins/sfDoctrineEditableComponentPlugin/trunk/config/app.yml plugins/sfDoctrineEditableComponentPlugin/trunk/config/sfDoctrineEditableComponentPluginConfiguration.class.php plugins/sfDoctrineEditableComponentPlugin/trunk/lib/filter/doctrine/PluginsfEditableComponentFormFilter.class.php plugins/sfDoctrineEditableComponentPlugin/trunk/lib/filter/doctrine/PluginsfEditableComponentTranslationFormFilter.class.php plugins/sfDoctrineEditableComponentPlugin/trunk/lib/form/doctrine/PluginsfEditableComponentForm.class.php plugins/sfDoctrineEditableComponentPlugin/trunk/lib/form/doctrine/PluginsfEditableComponentTranslationForm.class.php plugins/sfDoctrineEditableComponentPlugin/trunk/lib/helper/sfEditableHelper.php plugins/sfDoctrineEditableComponentPlugin/trunk/lib/model/doctrine/PluginsfEditableComponent.class.php plugins/sfDoctrineEditableComponentPlugin/trunk/lib/model/doctrine/PluginsfEditableComponentTable.class.php plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/actions/actions.class.php plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/actions/components.class.php plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/templates/cssSuccess.css.php plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/templates/jsSuccess.js.php plugins/sfDoctrineEditableComponentPlugin/trunk/test/bootstrap.php plugins/sfDoctrineEditableComponentPlugin/trunk/test/unit/model/doctrine/PluginsfEditableComponentTableTest.php Log: [sfDoctrineEditableComponent] refactored plugin, enabled ckeditor wysiwyg edition mode, added convenient helpers, polished javascript and css integration, added events for filtering submitted contents and automatic component cache invalidation. Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/README =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/README 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/README 2010-03-27 15:50:38 UTC (rev 28827) @@ -79,6 +79,8 @@ Components become editable when the current user is authenticated and has the `editable_content_admin` credential (you can change this by editing the `app.yml` configuration, check the *Custom configuration* section below). +Don't bother with components cache invalidation, it's already handled automatically on update. You can override the `cache.yml` of the `sfEditableComponent` module if you want to tweak its cache TTL though. + **Note:** The plugin doesn't provide any authentication nor credential persistence features. You can use the [sfDoctrineGuardPlugin](http://www.symfony-project.org/plugins/sfDoctrineGuardPlugin) plugin in order to easily obtain them. Custom configuration Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/config/app.yml =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/config/app.yml 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/config/app.yml 2010-03-27 15:50:38 UTC (rev 28827) @@ -10,4 +10,4 @@ stylesheets: - /facebox/facebox.css component_css_class_name: sfEditableComponent - default_content: 'Double-click to edit me' \ No newline at end of file + default_content: 'This is a placeholder. In editing mode, double-click me to edit.' \ No newline at end of file Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/config/sfDoctrineEditableComponentPluginConfiguration.class.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/config/sfDoctrineEditableComponentPluginConfiguration.class.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/config/sfDoctrineEditableComponentPluginConfiguration.class.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -13,22 +13,34 @@ */ public function configure() { - $this->dispatcher->connect('context.load_factories', array($this, 'listenForContextLoadFactories')); + $this->dispatcher->connect('context.load_factories', array($this, 'listenToContextLoadFactories')); + $this->dispatcher->connect('editable_component.updated', array($this, 'listenToComponentUpdated')); } - public function listenForContextLoadFactories(sfEvent $event) + /** + * Dynamic component cache invalidation + * + * @param sfEvent $event + */ + public function listenToComponentUpdated(sfEvent $event) { - $pluginModules = array('sfEditableComponent'); - - // Enables the auth testing service utility only in 'test' env - if ('test' === sfConfig::get('sf_environment')) + if ($event['view_cache'] instanceof sfViewCacheManager) { - $pluginModules[] = 'sfEditableComponentTestUtility'; + $event['view_cache']->remove(sprintf('@sf_cache_partial?module=sfEditableComponent&action=_show&sf_cache_key=%s', $event->getSubject()->getCacheKey($event['culture']))); } + } + + /** + * Automatic plugin modules and helper loading + * + * @param sfEvent $event + */ + public function listenToContextLoadFactories(sfEvent $event) + { + // Enable module automatically + sfConfig::set('sf_enabled_modules', array_merge(sfConfig::get('sf_enabled_modules', array()), array('sfEditableComponent'))); - sfConfig::set('sf_enabled_modules', array_merge(sfConfig::get('sf_enabled_modules', array()), $pluginModules)); - - // Helper loading + // Load helper as well $event->getSubject()->getConfiguration()->loadHelpers(array('sfEditable')); } } \ No newline at end of file Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/lib/filter/doctrine/PluginsfEditableComponentFormFilter.class.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/lib/filter/doctrine/PluginsfEditableComponentFormFilter.class.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/lib/filter/doctrine/PluginsfEditableComponentFormFilter.class.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -1,11 +1,10 @@ <?php - /** - * PluginsfEditableComponent form. + * PluginsfEditableComponent filter form. * - * @package filters - * @subpackage sfEditableComponent * - * @version SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ + * @package sfDoctrineEditableComponent + * @subpackage form + * @author [email protected] */ abstract class PluginsfEditableComponentFormFilter extends BasesfEditableComponentFormFilter { Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/lib/filter/doctrine/PluginsfEditableComponentTranslationFormFilter.class.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/lib/filter/doctrine/PluginsfEditableComponentTranslationFormFilter.class.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/lib/filter/doctrine/PluginsfEditableComponentTranslationFormFilter.class.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -1,12 +1,10 @@ <?php - /** - * PluginsfEditableComponentTranslation form. + * PluginsfEditableComponentTranslation filter form. * - * @package ##PROJECT_NAME## - * @subpackage filter - * @author ##AUTHOR_NAME## - * @version SVN: $Id: sfDoctrineFormFilterPluginTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ + * @package sfDoctrineEditableComponent + * @subpackage form + * @author [email protected] */ abstract class PluginsfEditableComponentTranslationFormFilter extends BasesfEditableComponentTranslationFormFilter { Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/lib/form/doctrine/PluginsfEditableComponentForm.class.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/lib/form/doctrine/PluginsfEditableComponentForm.class.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/lib/form/doctrine/PluginsfEditableComponentForm.class.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -1,11 +1,10 @@ <?php - /** * PluginsfEditableComponent form. * - * @package form - * @subpackage sfEditableComponent - * @version SVN: $Id: sfDoctrineFormTemplate.php 6174 2007-11-27 06:22:40Z fabien $ + * @package sfDoctrineEditableComponent + * @subpackage form + * @author [email protected] */ abstract class PluginsfEditableComponentForm extends BasesfEditableComponentForm { Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/lib/form/doctrine/PluginsfEditableComponentTranslationForm.class.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/lib/form/doctrine/PluginsfEditableComponentTranslationForm.class.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/lib/form/doctrine/PluginsfEditableComponentTranslationForm.class.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -1,12 +1,10 @@ <?php - /** * PluginsfEditableComponentTranslation form. * - * @package ##PROJECT_NAME## + * @package sfDoctrineEditableComponent * @subpackage form - * @author ##AUTHOR_NAME## - * @version SVN: $Id: sfDoctrineFormPluginTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ + * @author [email protected] */ abstract class PluginsfEditableComponentTranslationForm extends BasesfEditableComponentTranslationForm { Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/lib/helper/sfEditableHelper.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/lib/helper/sfEditableHelper.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/lib/helper/sfEditableHelper.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -1,36 +1,34 @@ <?php /** - * Retrieves an editable component html code (convient proxy for a direct call to - * get_component('sfEditableComponent', 'show', array(...options...))) + * Retrieves an editable component html code * - * @param string $name The editable component name - * @param string $type The type of component - * @param string $tag The tag name to embed the component contents in + * @param string $name The editable component name + * @param string $type The type of component + * @param string $tag The tag name to embed the component contents in + * @param array $options An array of options * * @return string */ -function editable_component($name, $type = 'html', $tag = 'div') +function editable_component($name, $type = 'html', $tag = 'div', array $options = array()) { return get_component('sfEditableComponent', 'show', array( - 'name' => $name, - 'type' => $type, - 'tag' => $tag, + 'name' => $name, + 'type' => $type, + 'tag' => $tag, + 'options' => $options, // ↓ dont blame me, have a look at I18NHelper.php + 'sf_cache_key' => sprintf('%s-%s', $name, sfContext::getInstance()->getUser()->getCulture()), )); } /** - * Echo an editable component contents (convient proxy for a direct call to - * include_component('sfEditableComponent', 'show', array(...options...))) + * Echo an editable component contents * - * @param string $name The editable component name - * @param string $type The type of component - * @param string $tag The tag name to embed the component contents in + * @param string $name The editable component name + * @param string $type The type of component + * @param string $tag The tag name to embed the component contents in + * @param array $options An array of options */ -function include_editable_component($name, $type = 'html', $tag = 'div') +function include_editable_component($name, $type = 'html', $tag = 'div', array $options = array()) { - include_component('sfEditableComponent', 'show', array( - 'name' => $name, - 'type' => $type, - 'tag' => $tag, - )); + echo editable_component($name, $type, $tag, $options); } \ No newline at end of file Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/lib/model/doctrine/PluginsfEditableComponent.class.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/lib/model/doctrine/PluginsfEditableComponent.class.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/lib/model/doctrine/PluginsfEditableComponent.class.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -1,9 +1,22 @@ <?php - /** - * This class has been auto-generated by the Doctrine ORM Framework + * Editable component Doctrine record class + * + * @package sfDoctrineEditableComponentPlugin + * @subpackage model + * @author [email protected] */ abstract class PluginsfEditableComponent extends BasesfEditableComponent { - + /** + * Computes a cache key from current instance properties + * + * @param string $culture + * + * @return string + */ + public function getCacheKey($culture) + { + return sprintf('%s-%s', $this->name, $culture); + } } \ No newline at end of file Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/lib/model/doctrine/PluginsfEditableComponentTable.class.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/lib/model/doctrine/PluginsfEditableComponentTable.class.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/lib/model/doctrine/PluginsfEditableComponentTable.class.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -1,6 +1,10 @@ <?php /** - * This class has been auto-generated by the Doctrine ORM Framework + * Editable component Doctrine table class + * + * @package sfDoctrineEditableComponentPlugin + * @subpackage model + * @author [email protected] */ class PluginsfEditableComponentTable extends Doctrine_Table { @@ -14,6 +18,8 @@ * @param string|null $type The component type (html, plain) (optional) * * @return sfEditableComponent + * + * @throws Doctrine_Exception */ static function updateComponent($name, $content, $type = self::DEFAULT_TYPE) { @@ -21,7 +27,9 @@ $component->setContent($content); - return $component->save(); + $component->save(); + + return $component; } /** @@ -32,6 +40,8 @@ * @param Boolean $createAndSave Create a new record if component not found? * * @return sfEditableComponent + * + * @throws Doctrine_Exception */ static public function getComponent($name, $type = self::DEFAULT_TYPE, $createAndSave = true) { @@ -43,14 +53,17 @@ ->fetchOne() ; - if (!$component instanceof sfEditableComponent && true === $createAndSave) + if (!$component instanceof sfEditableComponent) { $component = $table->create(array( 'name' => $name, 'type' => $type, - 'content' => sfConfig::get(sprintf('app_sfDoctrineEditableComponentPlugin_default_content.%s', $type), ''), + 'content' => sfConfig::get(sprintf('app_sfDoctrineEditableComponentPlugin_default_content'), ''), )); - + } + + if (true === $createAndSave) + { $component->save(); } Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/actions/actions.class.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/actions/actions.class.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/actions/actions.class.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -1,4 +1,6 @@ <?php +require_once dirname(__FILE__).'/../lib/BasesfEditableComponentActions.class.php'; + /** * sfDoctrineEditableComponent actions * @@ -6,85 +8,6 @@ * @subpackage action * @author [email protected] */ -class sfEditableComponentActions extends sfActions +class sfEditableComponentActions extends BasesfEditableComponentActions { - public function preExecute() - { - $assetsConfig = sfConfig::get('app_sfDoctrineEditableComponentPlugin_assets', array()); - $this->pluginWebRoot = isset($assetsConfig['web_root']) ? $assetsConfig['web_root'] : ''; - $this->componentCssClassName = sfConfig::get('app_sfDoctrineEditableComponentPlugin_component_css_class_name', 'sfEditableComponent'); - $this->defaultContent = sfConfig::get('app_sfDoctrineEditableComponentPlugin_default_content', 'Edit me'); - } - - public function executeCss(sfWebRequest $request) - { - } - - public function executeJs(sfWebRequest $request) - { - } - - /** - * Retrieves a component content - * - * @param sfWebRequest $request - */ - public function executeGet(sfWebRequest $request) - { - $result = $error = ''; - - try - { - $component = sfEditableComponentTable::getComponent($this->name, $this->type); - } - catch (Exception $e) - { - $error = $e->getMessage(); - } - - return $this->renderText(json_encode(array( - 'error' => $error, - 'result' => $component ? $component->getContent() : '', - ))); - } - - /** - * Update an editable component - * - * @param sfRequest $request A request object - */ - public function executeUpdate(sfWebRequest $request) - { - $result = $error = ''; - - if (!$this->getUser()->hasCredential(sfConfig::get('app_sfDoctrineEditableComponentPlugin_admin_credential', 'editable_content_admin'))) - { - $this->getResponse()->setStatusCode(403); - - $error = 'Forbidden'; - } - - if (!$request->hasParameter('id') || !$request->hasParameter('value')) - { - $error = 'Missing parameters'; - } - - try - { - sfEditableComponentTable::updateComponent( - $name = $request->getParameter('id'), - $result = $request->getParameter('value'), - $type = $request->getParameter('type', PluginsfEditableComponentTable::DEFAULT_TYPE) - ); - } - catch (Doctrine_Exception $e) - { - $error = sprintf('Unable to update component "%s": %s', $name, $e->getMessage()); - } - - return $this->renderText(json_encode(array( - 'error' => $error, - 'result' => $result, - ))); - } } Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/actions/components.class.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/actions/components.class.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/actions/components.class.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -1,4 +1,6 @@ <?php +require_once dirname(__FILE__).'/../lib/BasesfEditableComponentComponents.class.php'; + /** * sfDoctrineEditableComponentPlugin components * @@ -6,16 +8,6 @@ * @subpackage component * @author [email protected] */ -class sfEditableComponentComponents extends sfComponents +class sfEditableComponentComponents extends BasesfEditableComponentComponents { - /** - * Shows a component - * - */ - public function executeShow() - { - $this->componentCssClassName = sfConfig::get('app_sfDoctrineEditableComponentPlugin_component_css_class_name', 'sfEditableComponent'); - - $this->component = sfEditableComponentTable::getComponent($this->name, $this->type); - } } \ No newline at end of file Added: plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/config/cache.yml =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/config/cache.yml (rev 0) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/config/cache.yml 2010-03-27 15:50:38 UTC (rev 28827) @@ -0,0 +1,4 @@ +_show: + enabled: true + with_layout: false + lifetime: 86400 \ No newline at end of file Added: plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/lib/BasesfEditableComponentActions.class.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/lib/BasesfEditableComponentActions.class.php (rev 0) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/lib/BasesfEditableComponentActions.class.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -0,0 +1,98 @@ +<?php +/** + * sfDoctrineEditableComponent base actions + * + * @package sfDoctrineEditableComponent + * @subpackage action + * @author [email protected] + */ +class BasesfEditableComponentActions extends sfActions +{ + public function preExecute() + { + $assetsConfig = sfConfig::get('app_sfDoctrineEditableComponentPlugin_assets', array()); + $this->pluginWebRoot = isset($assetsConfig['web_root']) ? $assetsConfig['web_root'] : ''; + $this->componentCssClassName = sfConfig::get('app_sfDoctrineEditableComponentPlugin_component_css_class_name', 'sfEditableComponent'); + $this->defaultContent = sfConfig::get('app_sfDoctrineEditableComponentPlugin_default_content', 'Edit me'); + } + + public function executeCss(sfWebRequest $request) + { + $this->forward404Unless($this->getUser()->hasCredential(sfConfig::get('app_sfDoctrineEditableComponentPlugin_admin_credential', 'editable_content_admin'))); + } + + public function executeJs(sfWebRequest $request) + { + $this->forward404Unless($this->getUser()->hasCredential(sfConfig::get('app_sfDoctrineEditableComponentPlugin_admin_credential', 'editable_content_admin'))); + } + + /** + * Retrieves a component content + * + * @param sfWebRequest $request + */ + public function executeGet(sfWebRequest $request) + { + $result = $error = ''; + + try + { + $component = sfEditableComponentTable::getComponent($this->name, $this->type); + } + catch (Exception $e) + { + $error = $e->getMessage(); + } + + return $this->renderText(json_encode(array( + 'error' => $error, + 'result' => $component ? $component->getContent() : '', + ))); + } + + /** + * Update an editable component + * + * @param sfRequest $request A request object + */ + public function executeUpdate(sfWebRequest $request) + { + $result = $error = ''; + + if (!$this->getUser()->hasCredential(sfConfig::get('app_sfDoctrineEditableComponentPlugin_admin_credential', 'editable_content_admin'))) + { + $this->getResponse()->setStatusCode(403); + + $error = 'Forbidden'; + } + + if (!$request->hasParameter('id') || !$request->hasParameter('value')) + { + $error = 'Missing parameters'; + } + + $result = $this->dispatcher->filter(new sfEvent($this, 'editable_component.filter_contents', array( + 'name' => $name = $request->getParameter('id'), + 'type' => $type = $request->getParameter('type', PluginsfEditableComponentTable::DEFAULT_TYPE), + )), $request->getParameter('value'))->getReturnValue(); + + try + { + $component = sfEditableComponentTable::updateComponent($name, $result, $type); + } + catch (Doctrine_Exception $e) + { + $error = sprintf('Unable to update component "%s": %s', $name, $e->getMessage()); + } + + $this->dispatcher->notify(new sfEvent($component, 'editable_component.updated', array( + 'view_cache' => $this->context->getViewCacheManager(), + 'culture' => $this->getUser()->getCulture(), + ))); + + return $this->renderText(json_encode(array( + 'error' => $error, + 'result' => $result, + ))); + } +} \ No newline at end of file Added: plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/lib/BasesfEditableComponentComponents.class.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/lib/BasesfEditableComponentComponents.class.php (rev 0) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/lib/BasesfEditableComponentComponents.class.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -0,0 +1,22 @@ +<?php +/** + * sfDoctrineEditableComponentPlugin base components + * + * @package sfDoctrineEditableComponentPlugin + * @subpackage component + * @author [email protected] + */ + +class BasesfEditableComponentComponents extends sfComponents +{ + /** + * Shows a component + * + */ + public function executeShow() + { + $this->componentCssClassName = sfConfig::get('app_sfDoctrineEditableComponentPlugin_component_css_class_name', 'sfEditableComponent'); + + $this->component = sfEditableComponentTable::getComponent($this->name, $this->type); + } +} \ No newline at end of file Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/templates/cssSuccess.css.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/templates/cssSuccess.css.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/templates/cssSuccess.css.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -1,3 +1,4 @@ +/** frontend styles **/ .<?php echo $componentCssClassName ?> { background-color: #ffe; } @@ -14,3 +15,19 @@ float: right; padding: .2em .2em 0 0; } + +/** Edition form **/ +#sfEditableComponentForm { +} + #sfEditableComponentForm textarea { + width: 98%; + height: 120px; + } + #sfEditableComponentForm p { + text-align: right; + } + +/** Facebox redefinitions **/ +#facebox .body { + width: 640px; +} \ No newline at end of file Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/templates/jsSuccess.js.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/templates/jsSuccess.js.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/modules/sfEditableComponent/templates/jsSuccess.js.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -1,12 +1,35 @@ -$(document).ready(function() { +$(document).ready(function(){ // Configuration var getServiceUrl = '<?php echo url_for('@editable_component_service_get') ?>'; var updateServiceUrl = '<?php echo url_for('@editable_component_service_update') ?>'; + var CKConfig = { + toolbar : 'Basic', + language : '<?php echo $sf_user->getCulture() ?>', + width : 640, + tabSpaces: 2, + toolbar : [ + ['Source', '-', 'RemoveFormat'], + ['Bold', 'Italic', 'Underline', 'Strike'], + ['Link', 'Unlink', 'Anchor'], + ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', 'Blockquote'], + ['JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock'], + '/', + ['Styles', 'Format'], + ['Image', 'Table', 'HorizontalRule', 'SpecialChar'], + ['Maximize', 'ShowBlocks'] + ] + }; // Facebox settings $.facebox.settings.opacity = 0.4; $.facebox.settings.loadingImage = '<?php echo $pluginWebRoot ?>/facebox/loading.gif'; $.facebox.settings.closeImage = '<?php echo $pluginWebRoot ?>/facebox/closelabel.gif'; + $(this).bind('close.facebox', function() { + // Removes every CKEditor opened instance + if (CKEDITOR.instances['sfEditableComponentTextarea']) { + CKEDITOR.remove(CKEDITOR.instances['sfEditableComponentTextarea']); + } + }); // Components behaviors // Empty content check @@ -25,17 +48,21 @@ // Editing mode trigger $('.<?php echo $componentCssClassName ?>').dblclick(function() { var component = $(this); + var type = $(component).hasClass('plain') ? 'plain' : 'html'; $.facebox(function(){ $.get(getServiceUrl, function(result) { $.facebox( '<form action="' + updateServiceUrl + '" method="post" id="sfEditableComponentForm">' + '<h2>Edit ' + $(component).attr('id') + '</h2>' - + '<textarea name="value">' + $(component).html().trim() + '</textarea>' - + '<input type="hidden" value="' + $(component).attr('id') + '" name="id"/>' - + '<input type="hidden" value="' + ($(component).hasClass('plain') ? 'plain' : 'html') + '" name="type"/>' - + '<input type="submit" value="<?php echo __('Update') ?>"/>' + + '<p><textarea name="value" id="sfEditableComponentTextarea">' + $(component).html().trim() + '</textarea></p>' + + '<input type="hidden" value="' + $(component).attr('id') + '" name="id" id="sfEditableComponentId"/>' + + '<input type="hidden" value="' + type + '" name="type" id="sfEditableComponentType"/>' + + '<p><input type="submit" value="<?php echo __('Update') ?>"/></p>' + '</form>' ); + if ('html' == type) { + CKEDITOR.replace('sfEditableComponentTextarea', CKConfig); + } }, 'json'); }); }); @@ -47,12 +74,10 @@ $(form).children('h2').after('<p class="error">Error encountered: ' + result.error + '</p>'); return false; } - var content = $(form).children('textarea').val(); - var id = $(form).children('input[type=hidden]').val(); - $('#' + id).html(content); + $('#' + $('#sfEditableComponentId').val()).html($('#sfEditableComponentTextarea').val()); $.facebox.close(); return true; }, 'json'); return false; - }); -}); \ No newline at end of file + }); +}); Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/test/bootstrap.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/test/bootstrap.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/test/bootstrap.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -5,7 +5,9 @@ foreach (array_reverse(glob(dirname(__FILE__).'/../../../apps/*', GLOB_ONLYDIR)) as $dir) { - if (preg_match('/([a-z0-9_-])/i', $app = array_pop(explode(DIRECTORY_SEPARATOR, $dir)))) + $apps = explode(DIRECTORY_SEPARATOR, $dir); + + if (preg_match('/([a-z0-9_-])/i', $app = array_pop($apps))) { break; } Modified: plugins/sfDoctrineEditableComponentPlugin/trunk/test/unit/model/doctrine/PluginsfEditableComponentTableTest.php =================================================================== --- plugins/sfDoctrineEditableComponentPlugin/trunk/test/unit/model/doctrine/PluginsfEditableComponentTableTest.php 2010-03-27 15:50:09 UTC (rev 28826) +++ plugins/sfDoctrineEditableComponentPlugin/trunk/test/unit/model/doctrine/PluginsfEditableComponentTableTest.php 2010-03-27 15:50:38 UTC (rev 28827) @@ -2,32 +2,31 @@ require_once dirname(__FILE__).'/../../../bootstrap.php'; -$t = new lime_test(12, new lime_output_color()); +$t = new lime_test(11, new lime_output_color()); // removes old test records Doctrine::getTable('sfEditableComponent')->createQuery('e')->delete()->execute(); // getComponent() $t->diag('getComponent()'); -$c = PluginsfEditableComponentTable::getComponent('bar', 'html', 'foo'); -$t->isa_ok($c, 'sfEditableComponent', 'getComponent() returns a sfEditableComponent when createAndSave=true'); -$t->is($c->getName(), 'bar', 'getComponent() saves the name when createAndSave=true'); -$t->is($c->getNamespace(), 'foo', 'getComponent() saves the namespace when createAndSave=true'); -$t->is($c->getType(), 'html', 'getComponent() saves the type when createAndSave=true'); -$t->is($c->exists(), true, 'getComponent() saved the object when createAndSave=true'); +$c = PluginsfEditableComponentTable::getComponent('bar', 'html', true); +$t->isa_ok($c, 'sfEditableComponent', 'getComponent() returns a "sfEditableComponent" when "createAndSave=true"'); +$t->is($c->getName(), 'bar', 'getComponent() saves the name when "createAndSave=true"'); +$t->is($c->getType(), 'html', 'getComponent() saves the type when "createAndSave=true"'); +$t->is($c->exists(), true, 'getComponent() saved the object when "createAndSave=true"'); -$c2 = PluginsfEditableComponentTable::getComponent('bar', 'html', 'foo'); +$c2 = PluginsfEditableComponentTable::getComponent('bar', 'html'); $t->is($c2->getId(), $c->getId(), 'getComponent() do not create duplicate components'); -$c = PluginsfEditableComponentTable::getComponent('bar2', 'html', 'foo', false); -$t->isa_ok($c, 'sfEditableComponent', 'getComponent() returns a sfEditableComponent when createAndSave=false'); -$t->is($c->getName(), 'bar2', 'getComponent() saves the name when createAndSave=false'); -$t->is($c->getNamespace(), 'foo', 'getComponent() saves the namespace when createAndSave=false'); -$t->is($c->getType(), 'html', 'getComponent() saves the type when createAndSave=false'); -$t->is($c->exists(), false, 'getComponent() did not save the object when createAndSave=false'); +$c = PluginsfEditableComponentTable::getComponent('bar2', 'html', false); +$t->isa_ok($c, 'sfEditableComponent', 'getComponent() returns a "sfEditableComponent" when "createAndSave=false"'); +$t->is($c->getName(), 'bar2', 'getComponent() has the name when "createAndSave=false"'); +$t->is($c->getType(), 'html', 'getComponent() has the type when "createAndSave=false"'); +$t->is($c->exists(), false, 'getComponent() did not save the object when "createAndSave=false"'); // updateComponent() $t->diag('updateComponent()'); -PluginsfEditableComponentTable::updateComponent('bar2', 'my beautiful content', 'html', 'foo'); -$c = PluginsfEditableComponentTable::getComponent('bar2', 'html', 'foo', false); +PluginsfEditableComponentTable::updateComponent('bar2', 'my beautiful content', 'html'); +$c = PluginsfEditableComponentTable::getComponent('bar2', 'html', false); +$t->is($c->exists(), true, 'updateComponent() saved the object'); $t->is($c->getContent(), 'my beautiful content', 'updateComponent() updates component content'); \ No newline at end of file -- You received this message because you are subscribed to the Google Groups "symfony SVN" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/symfony-svn?hl=en.
