Author: ornicar2
Date: 2010-01-18 15:19:22 +0100 (Mon, 18 Jan 2010)
New Revision: 26818

Modified:
   plugins/diemPlugin/trunk/dmCorePlugin/lib/action/dmBaseActions.php
   plugins/diemPlugin/trunk/dmCorePlugin/lib/test/dmFrontTestFunctional.php
   
plugins/diemPlugin/trunk/dmCorePlugin/test/project/config/ProjectConfiguration.class.php
   
plugins/diemPlugin/trunk/dmCorePlugin/test/project/test/functional/front/dmEditWidgetTest.php
   plugins/diemPlugin/trunk/dmFrontPlugin/config/dm/assets.yml
   plugins/diemPlugin/trunk/dmFrontPlugin/lib/action/base/dmFrontBaseActions.php
   
plugins/diemPlugin/trunk/dmFrontPlugin/lib/action/base/dmFrontModuleComponents.php
   plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/base/dmWidgetBaseForm.php
   plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/base/dmWidgetBaseView.php
   
plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/text/dmWidgetContentTextForm.php
   plugins/diemPlugin/trunk/dmFrontPlugin/lib/pager/dmFrontPagerView.php
   
plugins/diemPlugin/trunk/dmFrontPlugin/modules/dmWidget/lib/BasedmWidgetActions.class.php
Log:
[Diem]
- refactored front widgets edition to no more use json encode data but raw HTML
- enhanced dmBaseActions->renderAsync to allow to pass asynchronous assets to 
load
- fixed datepicker translation
- improved front pager to allow ajax links
- removed deprecated methods dmForm->addJavascript & dmForm->addStylesheet
- renamed dmWidgetBaseView->addRequiredJavascript to addJavascript & 
addRequiredStylesheet to addStylesheet
- added dmFrontAjaxPager javascript controller

Modified: plugins/diemPlugin/trunk/dmCorePlugin/lib/action/dmBaseActions.php
===================================================================
--- plugins/diemPlugin/trunk/dmCorePlugin/lib/action/dmBaseActions.php  
2010-01-18 14:19:10 UTC (rev 26817)
+++ plugins/diemPlugin/trunk/dmCorePlugin/lib/action/dmBaseActions.php  
2010-01-18 14:19:22 UTC (rev 26818)
@@ -53,22 +53,45 @@
     return sfView::NONE;
   }
 
-  protected function renderAsync(array $parts)
+  protected function renderAsync(array $parts, $encodeAssets = false)
   {
-    $html = dmArray::get($parts, 'html');
-
-    foreach(dmArray::get($parts, 'css', array()) as $css)
+    $parts = array_merge(array('html' => '', 'css' => array(), 'js' => 
array()), $parts);
+    
+    // translate asset aliases to web paths
+    foreach($parts['css'] as $index => $asset)
     {
-      $html .= '<link rel="stylesheet" type="text/css" 
href="'.$this->getHelper()->getStylesheetWebPath($css).'"/>';
+      $parts['css'][$index] = $this->getHelper()->getStylesheetWebPath($asset);
     }
+    foreach($parts['js'] as $index => $asset)
+    {
+      $parts['js'][$index] = $this->getHelper()->getJavascriptWebPath($asset);
+    }
 
-    foreach(dmArray::get($parts, 'js', array()) as $js)
+    if(!empty($parts['css']) || !empty($parts['js']))
     {
-      $html .= '<script type="text/javascript" 
src="'.$this->getHelper()->getJavascriptWebPath($js).'"></script>';
+      if ($encodeAssets)
+      {
+        $parts['html'] .= $this->getHelper()->£('div.dm_encoded_assets.none', 
json_encode(array(
+          'css' => $parts['css'],
+          'js'  => $parts['js']
+        )));
+      }
+      else
+      {
+        foreach($parts['css'] as $css)
+        {
+          $parts['html'] .= '<link rel="stylesheet" type="text/css" 
href="'.$css.'"/>';
+        }
+
+        foreach($parts['js'] as $js)
+        {
+          $parts['html'] .= '<script type="text/javascript" 
src="'.$js.'"></script>';
+        }
+      }
     }
 
     $this->response->setContentType('text/html');
-    $this->response->setContent($html);
+    $this->response->setContent($parts['html']);
 
     return sfView::NONE;
   }

Modified: 
plugins/diemPlugin/trunk/dmCorePlugin/lib/test/dmFrontTestFunctional.php
===================================================================
--- plugins/diemPlugin/trunk/dmCorePlugin/lib/test/dmFrontTestFunctional.php    
2010-01-18 14:19:10 UTC (rev 26817)
+++ plugins/diemPlugin/trunk/dmCorePlugin/lib/test/dmFrontTestFunctional.php    
2010-01-18 14:19:22 UTC (rev 26818)
@@ -63,15 +63,6 @@
     ->get(sprintf('/index.php/+/dmWidget/edit?widget_id=%d&dm_cpi=%d', 
$widget->id, $this->getPage()->id))
     ->checks(array('module_action' => 'dmWidget/edit', 'method' => 'get'));
 
-    $response = $this->getResponse();
-    $this->test()->is($response->getContentType(), 'application/json', 'Edit 
widget return json');
-    $this->test()->ok($html = 
dmArray::get(json_decode($response->getContent(), true), 'html'), 'json 
contains html');
-
-    $response->setContentType('text/html');
-    $response->setContent($html);
-
-    $this->browser->setResponse($response);
-
     return $this;
   }
 

Modified: 
plugins/diemPlugin/trunk/dmCorePlugin/test/project/config/ProjectConfiguration.class.php
===================================================================
--- 
plugins/diemPlugin/trunk/dmCorePlugin/test/project/config/ProjectConfiguration.class.php
    2010-01-18 14:19:10 UTC (rev 26817)
+++ 
plugins/diemPlugin/trunk/dmCorePlugin/test/project/config/ProjectConfiguration.class.php
    2010-01-18 14:19:22 UTC (rev 26818)
@@ -71,10 +71,9 @@
   
   public function cleanup(sfFilesystem $filesystem)
   {
-//    sfToolkit::clearDirectory(sfConfig::get('sf_log_dir'));
+    sfToolkit::clearDirectory(sfConfig::get('sf_log_dir'));
     sfToolkit::clearDirectory(dmOs::join(sfConfig::get('sf_web_dir'), 
'cache'));
     sfToolkit::clearDirectory(dmOs::join(sfConfig::get('sf_root_dir'), 
'cache'));
-    sfToolkit::clearDirectory(dmOs::join(sfConfig::get('sf_root_dir'), 'log'));
     
$filesystem->remove(sfFinder::type('any')->not_name('*.sqlite')->in(sfConfig::get('sf_data_dir')));
     
$filesystem->remove(sfFinder::type('file')->name('sitemap*')->in(sfConfig::get('sf_web_dir')));
     copy(dmOs::join(sfConfig::get('sf_data_dir'), 'fresh_db.sqlite'), 
dmOs::join(sfConfig::get('sf_data_dir'), 'db.sqlite'));

Modified: 
plugins/diemPlugin/trunk/dmCorePlugin/test/project/test/functional/front/dmEditWidgetTest.php
===================================================================
--- 
plugins/diemPlugin/trunk/dmCorePlugin/test/project/test/functional/front/dmEditWidgetTest.php
       2010-01-18 14:19:10 UTC (rev 26817)
+++ 
plugins/diemPlugin/trunk/dmCorePlugin/test/project/test/functional/front/dmEditWidgetTest.php
       2010-01-18 14:19:22 UTC (rev 26818)
@@ -23,7 +23,6 @@
   'tag' => 'h1',
   'cssClass' => 'test_title_class'
 ))
-->testResponseContent('{"type":"close","widget_html":"<h1 
class=\"test_title_class\">Title 1<\/h1>","widget_classes":["dm_widget 
dm_widget_content_title","dm_widget_inner"],"js":"","stylesheets":[]}')
 ->get('/index.php')
 ->checks()
 ->has('.test_title_class', 'Title 1')
@@ -35,7 +34,6 @@
   'tag' => 'h1',
   'cssClass' => 'test_title_class'
 ))
-->testResponseContent('{"type":"close","widget_html":"<h1 
class=\"test_title_class\">Title 1 modified<\/h1>","widget_classes":["dm_widget 
dm_widget_content_title","dm_widget_inner"],"js":"","stylesheets":[]}')
 ->get('/index.php')
 ->checks()
 ->has('.test_title_class', 'Title 1 modified')

Modified: plugins/diemPlugin/trunk/dmFrontPlugin/config/dm/assets.yml
===================================================================
--- plugins/diemPlugin/trunk/dmFrontPlugin/config/dm/assets.yml 2010-01-18 
14:19:10 UTC (rev 26817)
+++ plugins/diemPlugin/trunk/dmFrontPlugin/config/dm/assets.yml 2010-01-18 
14:19:22 UTC (rev 26818)
@@ -15,6 +15,7 @@
     widgetForms:      page/dmWidgetForms
     pageEditForm:     dmFrontPageEditForm
     pageAddForm:      dmFrontPageAddForm
+    ajaxPager:        dmFrontAjaxPager
 
 css:
 

Modified: 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/action/base/dmFrontBaseActions.php
===================================================================
--- 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/action/base/dmFrontBaseActions.php   
    2010-01-18 14:19:10 UTC (rev 26817)
+++ 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/action/base/dmFrontBaseActions.php   
    2010-01-18 14:19:22 UTC (rev 26818)
@@ -70,11 +70,11 @@
     {
       if ($page = $this->getPage())
       {
-        $refererUrl = 
$this->context->getHelper()->£link($page)->getAbsoluteHref();
+        $refererUrl = $this->getHelper()->£link($page)->getAbsoluteHref();
       }
       else
       {
-        $refererUrl = $this->context->getHelper()->£link()->getAbsoluteHref();
+        $refererUrl = $this->getHelper()->£link()->getAbsoluteHref();
       }
     }
     

Modified: 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/action/base/dmFrontModuleComponents.php
===================================================================
--- 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/action/base/dmFrontModuleComponents.php
  2010-01-18 14:19:10 UTC (rev 26817)
+++ 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/action/base/dmFrontModuleComponents.php
  2010-01-18 14:19:22 UTC (rev 26818)
@@ -2,7 +2,6 @@
 
 class dmFrontModuleComponents extends myFrontBaseComponents
 {
-
   protected
   $dmModule;
   
@@ -134,7 +133,8 @@
     $pager = $this->getService('front_pager_view')
     ->setPager($doctrinePager)
     ->setOption('navigation_top', $this->navTop)
-    ->setOption('navigation_bottom', $this->navBottom);
+    ->setOption('navigation_bottom', $this->navBottom)
+    ->setOption('widget_id', $this->dm_widget ? $this->dm_widget['id'] : null);
 
     try
     {

Modified: 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/base/dmWidgetBaseForm.php
===================================================================
--- 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/base/dmWidgetBaseForm.php   
    2010-01-18 14:19:10 UTC (rev 26817)
+++ 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/base/dmWidgetBaseForm.php   
    2010-01-18 14:19:22 UTC (rev 26818)
@@ -22,8 +22,9 @@
     }
     
     $this->dmWidget = $widget;
-    
-    parent::__construct($widget->values, $options, $CSRFSecret);
+
+    // disable CSRF protection
+    parent::__construct($widget->values, $options, false);
   }
   
   public function setup()
@@ -49,27 +50,7 @@
   {
     return $this->dmWidget;
   }
-
-  protected function addRequiredJavascript($keys)
-  {
-    $this->javascripts = array_merge($this->javascripts, (array) $keys);
-  }
   
-  public function getJavascripts()
-  {
-    return $this->javascripts;
-  }
-  
-  protected function addRequiredStylesheet($keys)
-  {
-    $this->stylesheets = array_merge($this->stylesheets, (array) $keys);
-  }
-  
-  public function getStylesheets()
-  {
-    return $this->stylesheets;
-  }
-  
   /*
    * Overload this method to alter form values
    * when form has been validated

Modified: 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/base/dmWidgetBaseView.php
===================================================================
--- 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/base/dmWidgetBaseView.php   
    2010-01-18 14:19:10 UTC (rev 26817)
+++ 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/base/dmWidgetBaseView.php   
    2010-01-18 14:19:22 UTC (rev 26818)
@@ -32,7 +32,7 @@
     return $this->context->getHelper();
   }
   
-  protected function addRequiredJavascript($keys)
+  protected function addJavascript($keys)
   {
     $this->javascripts = array_merge($this->javascripts, (array) $keys);
   }
@@ -42,7 +42,7 @@
     return $this->javascripts;
   }
   
-  protected function addRequiredStylesheet($keys)
+  protected function addStylesheet($keys)
   {
     $this->stylesheets = array_merge($this->stylesheets, (array) $keys);
   }

Modified: 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/text/dmWidgetContentTextForm.php
===================================================================
--- 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/text/dmWidgetContentTextForm.php
        2010-01-18 14:19:10 UTC (rev 26817)
+++ 
plugins/diemPlugin/trunk/dmFrontPlugin/lib/dmWidget/text/dmWidgetContentTextForm.php
        2010-01-18 14:19:22 UTC (rev 26818)
@@ -7,22 +7,6 @@
   {
     parent::configure();
     
-    $this->addRequiredStylesheet(array(
-      'lib.ui-tabs',
-      'lib.markitup',
-      'lib.markitupSet',
-      'lib.ui-resizable'
-    ));
-    $this->addRequiredJavascript(array(
-      'lib.ui-tabs',
-      'lib.markitup',
-      'lib.markitupSet',
-      'lib.ui-resizable',
-      'lib.fieldSelection',
-      'core.tabForm',
-      'core.markdown'
-    ));
-    
     $this->widgetSchema['title'] = new sfWidgetFormInputText();
     $this->validatorSchema['title'] = new sfValidatorString(array('required' 
=> false));
     
@@ -44,6 +28,29 @@
     
     $this->widgetSchema['titlePosition']->setLabel('Title position');
   }
+
+  public function getStylesheets()
+  {
+    return array(
+      'lib.ui-tabs',
+      'lib.markitup',
+      'lib.markitupSet',
+      'lib.ui-resizable'
+    );
+  }
+
+  public function getJavascripts()
+  {
+    return array(
+      'lib.ui-tabs',
+      'lib.markitup',
+      'lib.markitupSet',
+      'lib.ui-resizable',
+      'lib.fieldSelection',
+      'core.tabForm',
+      'core.markdown'
+    );
+  }
   
   protected function renderContent($attributes)
   {

Modified: plugins/diemPlugin/trunk/dmFrontPlugin/lib/pager/dmFrontPagerView.php
===================================================================
--- plugins/diemPlugin/trunk/dmFrontPlugin/lib/pager/dmFrontPagerView.php       
2010-01-18 14:19:10 UTC (rev 26817)
+++ plugins/diemPlugin/trunk/dmFrontPlugin/lib/pager/dmFrontPagerView.php       
2010-01-18 14:19:22 UTC (rev 26818)
@@ -6,6 +6,7 @@
   $pager,
   $context,
   $helper,
+  $baseHref,
   $navigationCache = array();
 
   public function __construct(dmContext $context, array $options = array())
@@ -29,9 +30,8 @@
       'next'              => dmString::escape('>'),
       'last'              => dmString::escape('>>'),
       'nb_links'          => 9,
-      'uri'               => $this->context->getPage()
-      ? $this->helper->£link($this->context->getPage())->getAbsoluteHref()
-      : $this->context->getRequest()->getUri()
+      'ajax'              => false,
+      'widget_id'         => null   // only used when ajax = true
     );
   }
 
@@ -40,6 +40,24 @@
     $this->configure($options);
   }
 
+  protected function initBaseHref()
+  {
+    $this->setBaseHref(($page = $this->context->getPage())
+    ? $this->helper->£link($page)->getAbsoluteHref()
+    : preg_replace('|/page/([0-9]+)|', '?page=$1', 
$this->context->getRequest()->getUri())
+    );
+  }
+
+  public function setBaseHref($baseHref)
+  {
+    $this->baseHref = $baseHref;
+  }
+
+  public function getBaseHref()
+  {
+    return $this->baseHref;
+  }
+
   public function setPager(sfPager $pager)
   {
     $this->pager = $pager;
@@ -75,13 +93,13 @@
       $this->setOptions(array_merge($this->getOptions(), 
dmString::toArray($options, true)));
     }
 
-    $this->setOption('uri', preg_replace('|/page/([0-9]+)|', '?page=$1', 
$this->getOption('uri')));
+    $this->initBaseHref();
     
-    $hash = md5(var_export($this->getOptions(), true));
+    $cacheKey = md5(var_export($this->getOptions(), 
true).$this->getBaseHref());
 
-    if (isset($this->navigationCache[$hash]))
+    if (isset($this->navigationCache[$cacheKey]))
     {
-      return $this->navigationCache[$hash];
+      return $this->navigationCache[$cacheKey];
     }
 
     $html =
@@ -91,9 +109,12 @@
     $this->renderNextAndLastLinks().
     $this->closePager();
 
-    $html = preg_replace('|\?page=([0-9]+)|', '/page/$1', $html);
+    if($this->getOption('ajax'))
+    {
+      $this->context->getResponse()->addJavascript('front.ajaxPager');
+    }
 
-    $this->navigationCache[$hash] = $html;
+    $this->navigationCache[$cacheKey] = $html;
 
     return $html;
   }
@@ -101,7 +122,11 @@
   protected function openPager()
   {
     return
-    $this->helper->£o('div', array('class' => 
dmArray::toHtmlCssClasses(array('pager', $this->getOption('class'))))).
+    $this->helper->£o('div', array('class' => dmArray::toHtmlCssClasses(array(
+      'pager',
+      $this->getOption('class'),
+      $this->getOption('ajax') ? 'dm_pager_ajax_links' : null
+    )))).
     $this->helper->£o('ul.clearfix');
   }
 
@@ -113,20 +138,12 @@
     {
       if($first = $this->getOption('first'))
       {
-        $html .= $this->helper->£('li.page.first',
-          $this->helper->£link($this->getOption('uri'))
-          ->param('page', $this->getFirstPage())
-          ->text($first)
-        );
+        $html .= $this->helper->£('li.page.first', 
$this->renderLink($this->getFirstPage(), $first));
       }
 
       if($prev = $this->getOption('prev'))
       {
-        $html .= $this->helper->£('li.page.prev',
-          $this->helper->£link($this->getOption('uri'))
-          ->param('page', $this->getPreviousPage())
-          ->text($prev)
-        );
+        $html .= $this->helper->£('li.page.prev', 
$this->renderLink($this->getPreviousPage(), $prev));
       }
     }
 
@@ -142,15 +159,11 @@
       // current page
       if($page === $this->pager->getPage())
       {
-        $links[] = 
$this->helper->£('li.page.'.$this->getOption('current_class'),
-          $this->helper->£('span.link', $page)
-        );
+        $links[] = 
$this->helper->£('li.page.'.$this->getOption('current_class'), 
$this->helper->£('span.link', $page));
       }
       else
       {
-        $links[] = $this->helper->£('li.page',
-          $this->helper->£link($this->getOption('uri'))->param('page', 
$page)->text($page)
-        );
+        $links[] = $this->helper->£('li.page', $this->renderLink($page, 
$page));
       }
     }
 
@@ -165,15 +178,11 @@
     {
       if($next = $this->getOption('next'))
       {
-        $html .= $this->helper->£('li.page.next',
-          $this->helper->£link($this->getOption('uri'))->param('page', 
$this->getNextPage())->text($next)
-        );
+        $html .= $this->helper->£('li.page.next', 
$this->renderLink($this->getNextPage(), $next));
       }
       if($last = $this->getOption('last'))
       {
-        $html .= $this->helper->£('li.page.last',
-          $this->helper->£link($this->getOption('uri'))->param('page', 
$this->getLastPage())->text($last)
-        );
+        $html .= $this->helper->£('li.page.last', 
$this->renderLink($this->getLastPage(), $last));
       }
     }
 
@@ -185,6 +194,22 @@
     return '</ul></div>';
   }
 
+  protected function renderLink($page, $text)
+  {
+    $link = $this->helper->£link($this->getBaseHref())->param('page', 
$page)->text($text);
+
+    if($this->getOption('ajax'))
+    {
+      $link->json(array('href' => $this->helper->£link('+/dmWidget/render')
+      ->param('page', $page)
+      ->param('widget_id', $this->getOption('widget_id'))
+      ->param('page_id', ($page = $this->context->getPage()) ? $page->id : 
null)
+      ->getHref()));
+    }
+
+    return $link;
+  }
+
   /*
    * Proxy to sfPager
    */

Modified: 
plugins/diemPlugin/trunk/dmFrontPlugin/modules/dmWidget/lib/BasedmWidgetActions.class.php
===================================================================
--- 
plugins/diemPlugin/trunk/dmFrontPlugin/modules/dmWidget/lib/BasedmWidgetActions.class.php
   2010-01-18 14:19:10 UTC (rev 26817)
+++ 
plugins/diemPlugin/trunk/dmFrontPlugin/modules/dmWidget/lib/BasedmWidgetActions.class.php
   2010-01-18 14:19:22 UTC (rev 26818)
@@ -30,106 +30,45 @@
   {
     $this->forward404Unless($widget = 
dmDb::table('DmWidget')->find($request->getParameter('widget_id')));
   
-    if (!$widgetType = 
$this->context->get('widget_type_manager')->getWidgetTypeOrNull($widget))
-    {
-      return $this->renderError();
-    }
-    
-    $formClass = $widgetType->getFormClass();
-    
     try
     {
+      $widgetType = 
$this->getService('widget_type_manager')->getWidgetType($widget);
+      $formClass = $widgetType->getFormClass();
       $form = new $formClass($widget);
     }
-    catch(dmException $e)
+    catch(Exception $e)
     {
       return $this->renderError();
     }
     
-    $js = '';
-    $stylesheets = array();
-    
-    $form->removeCsrfProtection();
-    
-    if ($request->isMethod('post'))
+    if ($request->isMethod('post') && $form->bindAndValid($request))
     {
-      if ($form->bindAndValid($request))
+      $form->updateWidget();
+
+      if ($request->hasParameter('and_save'))
       {
-        $form->updateWidget();
+        $widget->save();
+        return $this->renderText('saved');
+      }
 
-        $widgetArray = $widget->toArrayWithMappedValue();
-        
-        
$this->context->getServiceContainer()->setParameter('widget_renderer.widget', 
$widgetArray);
-        
-        $widgetRenderer = 
$this->context->getServiceContainer()->getService('widget_renderer');
-        
-        // gather widget assets to load asynchronously
-        foreach($widgetRenderer->getStylesheets() as $stylesheet)
-        {
-          $stylesheets[] = 
$this->context->getHelper()->getStylesheetWebPath($stylesheet);
-        }
-        foreach($widgetRenderer->getJavascripts() as $javascript)
-        {
-          $js .= 
file_get_contents($this->context->getHelper()->getJavascriptFullPath($javascript)).';';
-        }
-        
-        if ($request->hasParameter('and_save'))
-        {
-          $widget->save();
-          return $this->renderJson(array(
-            'type' => 'close',
-            'widget_html' => $widgetRenderer->getHtml(),
-            'widget_classes' => 
$this->context->get('page_helper')->getWidgetContainerClasses($widgetArray),
-            'js'   => $js,
-            'stylesheets' => $stylesheets
-          ));
-        }
+      $widgetArray = $widget->toArrayWithMappedValue();
 
-        $form = new $formClass($widget);
-        $form->removeCsrfProtection();
-        
-        /* when a file is uploaded with ajax,
-         * do not render witdget html content
-         * because if it contains JSON metadata
-         * it will cause problems
-         */
-        if ($this->request->isMethod('post') && 
$this->request->isXmlHttpRequest() && !in_array('application/json', 
$this->request->getAcceptableContentTypes()))
-        {
-          $widgetHtml = '__DM_ASYNC__';
-        }
-        else
-        {
-          $widgetHtml = $widgetRenderer->getHtml();
-        }
+      $widgetRenderer = $this->getServiceContainer()
+      ->setParameter('widget_renderer.widget', $widgetArray)
+      ->getService('widget_renderer');
 
-        return $this->renderJson(array(
-          'type' => 'form',
-          'html' => $this->renderEdit($form, $widgetType),
-          'widget_html' => $widgetHtml,
-          'widget_classes' => 
$this->context->get('page_helper')->getWidgetContainerClasses($widgetArray),
-          'js'   => $js,
-          'stylesheets' => $stylesheets
-        ));
-      }
+      return $this->renderAsync(array(
+        'html'  => $this->renderEdit(new $formClass($widget), 
$widgetType).dmString::ENCODING_SEPARATOR.$this->getService('page_helper')->renderWidget($widgetArray),
+        'js'    => $widgetRenderer->getJavascripts(),
+        'css'   => $widgetRenderer->getStylesheets()
+      ));
     }
     
-    $html = $this->renderEdit($form, $widgetType);
-    
-    foreach($form->getStylesheets() as $stylesheet)
-    {
-      $stylesheets[] = 
$this->context->getHelper()->getStylesheetWebPath($stylesheet);
-    }
-    foreach($form->getJavascripts() as $javascript)
-    {
-      $js .= 
file_get_contents($this->context->getHelper()->getJavascriptFullPath($javascript)).';';
-    }
-    
-    return $this->renderJson(array(
-      'type' => 'form',
-      'html' => $html,
-      'js'   => $js,
-      'stylesheets' => $stylesheets
-    ));
+    return $this->renderAsync(array(
+      'html'  => $this->renderEdit($form, $widgetType),
+      'js'    => $form->getJavascripts(),
+      'css'   => $form->getStylesheets()
+    ), true);
   }
   
   protected function renderError()
@@ -191,17 +130,12 @@
     }
     
     return 
$helper->£('div.dm.dm_widget_edit.'.dmString::underscore($widgetType->getFullKey()).'_form',
-    // don't use json_encode here because the whole response will be json 
encoded
-    array('class' => sprintf(
-      '{ form_class: \'%s\', form_name: \'%s\' }',
-      $widgetType->getFullKey().'Form',
-      $form->getName()
-    )),
+    array('json' => array('form_class' => $widgetType->getFullKey().'Form', 
'form_name' => $form->getName())),
     $form->render('.dm_form.list.little').$devActions.$copyActions
     );
   }
 
-  public function executeGetInner(sfWebRequest $request)
+  public function executeGetFull(sfWebRequest $request)
   {
     $this->forwardSecureUnless(
       $this->getUser()->can('widget_edit')
@@ -211,14 +145,17 @@
       $widget = 
dmDb::table('DmWidget')->find($request->getParameter('widget_id'))
     );
 
-    $helper = $this->context->get('page_helper');
-
     $widgetArray = $widget->toArrayWithMappedValue();
-    
-    return $this->renderJson(array(
-      'widget_html' => $helper->renderWidgetInner($widgetArray),
-      'widget_classes' => $helper->getWidgetContainerClasses($widgetArray)
-    ));
+
+    $widgetRenderer = $this->getServiceContainer()
+    ->setParameter('widget_renderer.widget', $widgetArray)
+    ->getService('widget_renderer');
+
+    return $this->renderAsync(array(
+      'html'  => $this->getService('page_helper')->renderWidget($widgetArray),
+      'css'   => $widgetRenderer->getStylesheets(),
+      'js'    => $widgetRenderer->getJavascripts()
+    ), true);
   }
 
   public function executeDelete(sfWebRequest $request)
@@ -270,7 +207,7 @@
       'Can not find widget action'
     );
 
-    $widgetType = 
$this->context->get('widget_type_manager')->getWidgetType($widgetModule, 
$widgetAction);
+    $widgetType = 
$this->getService('widget_type_manager')->getWidgetType($widgetModule, 
$widgetAction);
 
     $formClass = $widgetType->getFormClass();
     $form = new $formClass($widgetType->getNewWidget());
@@ -284,7 +221,7 @@
       'values' => $form->getDefaults()
     ))->saveGet();
 
-    return 
$this->renderText($this->context->get('page_helper')->renderWidget($widget->toArrayWithMappedValue(),
 true));
+    return 
$this->renderText($this->getService('page_helper')->renderWidget($widget->toArrayWithMappedValue(),
 true));
   }
 
   public function executeMove(sfWebRequest $request)

-- 
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.


Reply via email to