Author: KRavEN
Date: 2010-05-21 19:11:05 +0200 (Fri, 21 May 2010)
New Revision: 29575

Modified:
   plugins/ExtjsGeneratorPlugin/trunk/TODO.txt
   
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsForm/default/template/ExtjsFormBaseTemplate.php
   
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsForm/default/template/ExtjsFormGeneratedTemplate.php
   
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/configuration.php
   
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/editAction.php
   
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/filterpanelAction.php
   
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/_filterpanel.js.php
   
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/_formpanel.js.php
   
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/editSuccess.json.php
   
plugins/ExtjsGeneratorPlugin/trunk/lib/generator/ExtjsModelGeneratorConfiguration.class.php
Log:
moved needsId checks into configuration class to always add csrf and id in 
getFormFields.  added addCSRFProtection to BaseExtjsFormPropel template to 
override the widget used for the csrf field.  refactored _formpanel.js to 
remove eval calls, id checks, and csrf additions.

Modified: plugins/ExtjsGeneratorPlugin/trunk/TODO.txt
===================================================================
--- plugins/ExtjsGeneratorPlugin/trunk/TODO.txt 2010-05-21 16:05:34 UTC (rev 
29574)
+++ plugins/ExtjsGeneratorPlugin/trunk/TODO.txt 2010-05-21 17:11:05 UTC (rev 
29575)
@@ -1,6 +1,4 @@
 ### forms
-add a hiddenfield widget
-
 show combobox for related fields (field is not always added)
 - this is a problem with the standard generator too
 
@@ -23,11 +21,10 @@
 
 ### generic
 add time display for datetime fields to list, filter, and edit
-refactor evals in generator partials
-add default fieldset styles
+find alternate way to do filterpanel without eval, needs it now to get filter 
values from user session
 fix widgetOptions for the itemselector for many to many in formpanels
 use heredoc in ExtjsGenerator for getStandardPartials, 
createStandardConstructorPartial, createStandardInitComponentPartial, 
createStandardInitEventsPartial methods
-
+expand generated partials with examples
 add support for objects with multiple fields as primary key
 
 error handling
@@ -43,7 +40,5 @@
 remote json combos
 remote json itemselector
 
-expand generated partials with examples
+use sfGrid (once it is ready)
 
-use sfGrid (once it is ready) 
-

Modified: 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsForm/default/template/ExtjsFormBaseTemplate.php
===================================================================
--- 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsForm/default/template/ExtjsFormBaseTemplate.php
      2010-05-21 16:05:34 UTC (rev 29574)
+++ 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsForm/default/template/ExtjsFormBaseTemplate.php
      2010-05-21 17:11:05 UTC (rev 29575)
@@ -12,4 +12,42 @@
   public function setup()
   {
   }
+
+  /**
+   * Adds CSRF protection to the current form.
+   *
+   * @param string $secret The secret to use to compute the CSRF token
+   *
+   * @return sfForm The current form instance
+   */
+  public function addCSRFProtection($secret = null)
+  {
+    if (null === $secret)
+    {
+      $secret = $this->localCSRFSecret;
+    }
+
+    if (false === $secret || (null === $secret && false === self::$CSRFSecret))
+    {
+      return $this;
+    }
+
+    if (null === $secret)
+    {
+      if (null === self::$CSRFSecret)
+      {
+        self::$CSRFSecret = md5(__FILE__.php_uname());
+      }
+
+      $secret = self::$CSRFSecret;
+    }
+
+    $token = $this->getCSRFToken($secret);
+
+    $this->validatorSchema[self::$CSRFFieldName] = new 
sfValidatorCSRFToken(array('token' => $token));
+    $this->widgetSchema[self::$CSRFFieldName] = new 
ExtjsWidgetFormInputHidden();
+    $this->setDefault(self::$CSRFFieldName, $token);
+
+    return $this;
+  }
 }

Modified: 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsForm/default/template/ExtjsFormGeneratedTemplate.php
===================================================================
--- 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsForm/default/template/ExtjsFormGeneratedTemplate.php
 2010-05-21 16:05:34 UTC (rev 29574)
+++ 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsForm/default/template/ExtjsFormGeneratedTemplate.php
 2010-05-21 17:11:05 UTC (rev 29575)
@@ -9,7 +9,7 @@
  * @subpackage form
  * @author     ##AUTHOR_NAME##
  */
-abstract class BaseExtjs<?php echo $this->table->getClassname() ?>Form extends 
BaseFormPropel
+abstract class BaseExtjs<?php echo $this->table->getClassname() ?>Form extends 
BaseExtjsFormPropel
 {
   public function setup()
   {

Modified: 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/configuration.php
===================================================================
--- 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/configuration.php
 2010-05-21 16:05:34 UTC (rev 29574)
+++ 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/configuration.php
 2010-05-21 17:11:05 UTC (rev 29575)
@@ -61,6 +61,12 @@
 <?php unset($this->config['filter']['class']) ?>
   }
 
+  public function getPrimaryKeys($firstOne = false)
+  {
+    $keys = <?php echo $this->asPhp($this->getPrimaryKeys()) ?>;
+    return $firstOne ? $keys[0] : $keys;
+  }
+
 <?php include dirname(__FILE__).'/paginationConfiguration.php' ?>
 
 <?php include dirname(__FILE__).'/sortingConfiguration.php' ?>
@@ -81,4 +87,6 @@
   {
     return '<?php echo isset($this->params['object_name']) ? 
$this->params['object_name'] : sfInflector::humanize($this->getModuleName()) 
?>';
   }
+
+
 }

Modified: 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/editAction.php
===================================================================
--- 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/editAction.php
    2010-05-21 16:05:34 UTC (rev 29574)
+++ 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/editAction.php
    2010-05-21 17:11:05 UTC (rev 29575)
@@ -2,5 +2,5 @@
   {
     $this-><?php echo $this->getSingularName() ?> = 
$this->getRoute()->getObject($this->configuration->getQueryMethods());
     $this->form = $this->configuration->getForm($this-><?php echo 
$this->getSingularName() ?>);
-<?php echo $this->getFormCustomization('edit') ?>    
+<?php echo $this->getFormCustomization('edit') ?>
   }

Modified: 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/filterpanelAction.php
===================================================================
--- 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/filterpanelAction.php
     2010-05-21 16:05:34 UTC (rev 29574)
+++ 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/parts/filterpanelAction.php
     2010-05-21 17:11:05 UTC (rev 29575)
@@ -1,5 +1,5 @@
   public function executeFilterpanel(sfWebRequest $request)
   {
-    $this->filters = $this->configuration->getFilterForm($this->getFilters()); 
 
+    $this->filters = $this->configuration->getFilterForm($this->getFilters());
     sfConfig::set('sf_escaping_strategy', false);
   }

Modified: 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/_filterpanel.js.php
===================================================================
--- 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/_filterpanel.js.php
  2010-05-21 16:05:34 UTC (rev 29574)
+++ 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/_filterpanel.js.php
  2010-05-21 17:11:05 UTC (rev 29575)
@@ -18,7 +18,7 @@
 $filterpanel->config_array['buttons'] = array(
   $sfExtjs3Plugin->Button(array
   (
-    'text'    => 'Filter',    
+    'text'    => 'Filter',
     'handler' => $sfExtjs3Plugin->asMethod("
       var params=this.form.getValues();
       this.fireEvent('filter_set', params, this);
@@ -44,7 +44,7 @@
     'help' => $field->getConfig('help'),
     'fieldLabel' => $field->getConfig('label', 
$form[$name]->getParent()->getWidget()->getFormFormatter()->generateLabelName($name)),
   );
-  
+
   eval($form[$name]->render(array_merge($attributes, 
$field->getConfig('attributes', array()))));
 }
 

Modified: 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/_formpanel.js.php
===================================================================
--- 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/_formpanel.js.php
    2010-05-21 16:05:34 UTC (rev 29574)
+++ 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/_formpanel.js.php
    2010-05-21 17:11:05 UTC (rev 29575)
@@ -33,104 +33,63 @@
 ?>
 <?php endif; ?>
 <?php if(in_array($name, array('_reload', '_save', '_savenew', '_delete', 
'_cancel'))): ?>
-include_partial('<?php echo 'editaction_'.$name ?>', array('sfExtjs3Plugin' => 
$sfExtjs3Plugin, 'formpanel' => $formpanel));
 
+include_partial('<?php echo 'editaction_'.$name ?>', array('sfExtjs3Plugin' => 
$sfExtjs3Plugin, 'formpanel' => $formpanel));
 <?php endif; ?>
 <?php echo $this->addCredentialCondition($this->getEditActionButton($name, 
$params), $params)."\n" ?>
 <?php endforeach; ?>
 <?php endif; ?>
 
 $readerFields = array();
+$fieldItems = array();
 <?php
 $form = $this->configuration->getForm();
-$key = sfInflector::underscore($this->getPrimaryKeys(true));
-$needsId = true;
 
-foreach ($this->configuration->getFormFields($form, $form->isNew() ? 'new' : 
'edit')  as $fieldset => $fields)
-{
+foreach ($this->configuration->getFormFields($form, $form->isNew() ? 'new' : 
'edit')  as $fieldset => $fields):
+       $fieldItems = array();
   foreach ($fields as $name => $field)
   {
-    if($name == $key) $needsId = false;
-    echo $this->addCredentialCondition((sprintf("%s;\n", 
$this->renderJsonReaderField($field, $form))), $field->getConfig());
-  }
-}
-if($needsId)
-{
-  $idField = $this->configuration->getFieldConfiguration('edit', $key);
-  echo sprintf("%s;\n", $this->renderJsonReaderField($idField, $form));
-}
-?>
+    echo $this->addCredentialCondition(sprintf("%s;\n\n", 
$this->renderJsonReaderField($field, $form)), $field->getConfig());
 
-$formpanel->config_array['reader'] = $sfExtjs3Plugin->JsonReader(array(
-  'root' => 'data',
-  'totalProperty' => 'totalCount',
-  'fields' => $readerFields,
-));
-
-foreach ($configuration->getFormFields($form, $form->isNew() ? 'new' : 'edit') 
 as $fieldset => $fields)
-{
-  $fieldItems = array();
-  $needsId = true;
-  
-  foreach ($fields as $name => $field)
-  {
-    //dirty hack till I figure out the real reason this is added or make a 
hidden field widget
-    if(strstr('_csrf_token', $name)) continue;
-    if($name == '<?php echo $key ?>') $needsId = false;
     $attributes = array(
       'help' => $field->getConfig('help'),
       'fieldLabel' => $field->getConfig('label', 
$form[$name]->getParent()->getWidget()->getFormFormatter()->generateLabelName($name)),
     );
-    
-    eval($form[$name]->render(array_merge($attributes, 
$field->getConfig('attributes', array()))));
-    //echo $form[$name]->render(array_merge($attributes, 
$field->getConfig('attributes', array())))."\n\n";
-  } 
-  
-  if($fieldset == 'NONE')
-  {
-    foreach($fieldItems as $fieldItem)
-    {
-      $formpanel->config_array['items'][] = $fieldItem;
-    }
+    echo $this->addCredentialCondition(sprintf("%s;\n\n", 
$form[$name]->render(array_merge($attributes, $field->getConfig('attributes', 
array())))), $field->getConfig());
   }
-  else
-  {     
-    $formpanel->config_array['items'][] = 
$sfExtjs3Plugin->FieldSet(array_merge(array(
-      'title' => __($fieldset, array(), '<?php echo $this->getI18nCatalogue() 
?>'),
-      'collapsible' => false,
-      'autoHeight' => true,
-      'style' => 'padding:10px;',
-      'bodyStyle' => 'padding:0px 0px;',
-      'style' => 'margin-left:5px;margin-right:10px',
-      'autoWidth' => true,
-      'defaults' => array(
-        'anchor' => '51%'
-      ),
-      'labelWidth' => $formpanel->config_array['labelWidth'] - 16, 
-      'items' => $fieldItems,
-    ), $configuration->getFormFieldsetParams('params_'.$fieldset)));
-  }
-}
 
-if($needsId)
-{
-  $formpanel->config_array['items'][] = 
$sfExtjs3Plugin->asCustomClass('Ext.form.Hidden', array(
-    'name' => sprintf($form->getWidgetSchema()->getNameFormat(), '<?php echo 
$key ?>'),
-  ));
-}
+  if($fieldset == 'NONE'): ?>
+foreach($fieldItems as $fieldItem) $formpanel->config_array['items'][] = 
$fieldItem;
+$fieldItems = array();
 
-if ($form->isCSRFProtected())
-{
-  //add csrf field
-  $formpanel->config_array['items'][] = 
$sfExtjs3Plugin->asCustomClass('Ext.form.Hidden', array(
-    'name' => sprintf($form->getWidgetSchema()->getNameFormat(), 
$form->getCSRFFieldName()),
-    'value' => $form->getCSRFToken(),
-  ));
-}
+<?php else: ?>
+$formpanel->config_array['items'][] = 
$sfExtjs3Plugin->FieldSet(array_merge(array(
+       'title' => __('<?php echo $fieldset ?>', array(), '<?php echo 
$this->getI18nCatalogue() ?>'),
+       'collapsible' => false,
+       'autoHeight' => true,
+       'style' => 'padding:10px;',
+       'bodyStyle' => 'padding:0px 0px;',
+       'style' => 'margin-left:5px;margin-right:10px',
+       'autoWidth' => true,
+       'defaults' => array(
+       'anchor' => '51%'
+       ),
+       'labelWidth' => $formpanel->config_array['labelWidth'] - 16,
+       'items' => $fieldItems,
+), $configuration->getFormFieldsetParams('params_<?php echo $fieldset ?>')));
+$fieldItems = array();
 
+<?php endif; ?>
+<?php endforeach; ?>
+
+$formpanel->config_array['reader'] = $sfExtjs3Plugin->JsonReader(array(
+  'root' => 'data',
+  'totalProperty' => 'totalCount',
+  'fields' => $readerFields,
+));
+
 //initComponent
 include_partial('formpanel_method_initComponent', array('sfExtjs3Plugin' => 
$sfExtjs3Plugin, 'formpanel' => $formpanel, 'className' => $className));
-
 <?php echo $this->getStandardPartials('formpanel', array('constructor',)) ?>
 <?php echo $this->getCustomPartials('formpanel'); ?>
 

Modified: 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/editSuccess.json.php
===================================================================
--- 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/editSuccess.json.php
 2010-05-21 16:05:34 UTC (rev 29574)
+++ 
plugins/ExtjsGeneratorPlugin/trunk/data/generator/ExtjsModule/admin/template/templates/editSuccess.json.php
 2010-05-21 17:11:05 UTC (rev 29575)
@@ -1,26 +1,19 @@
 [?php
 use_helper('I18N', 'Date');
 
-<?php 
+<?php
 $form = $this->configuration->getForm();
-$key = sfInflector::underscore($this->getPrimaryKeys(true));
-$needsId = true;
 foreach ($this->configuration->getFormFields($form, $form->isNew() ? 'new' : 
'edit')  as $fieldset => $fields)
 {
   foreach ($fields as $name => $field)
   {
-    if($name == $key) $needsId = false;
     echo $this->addCredentialCondition(sprintf("\$dataArray['%s'] = %s;\n", 
$name, "\$form->getDefault('$name')"));
   }
 }
-if($needsId)
-{
-  echo sprintf("\$dataArray['%s'] = %s;\n", $key, 
"\$form->getDefault('$key')");
-}
 ?>
 
 echo json_encode(array(
-  'totalCount' => 1, 
+  'totalCount' => 1,
   'data' => array($dataArray),
   'title' => <?php echo $this->getI18NString('edit.title', 'Edit 
'.$this->configuration->getObjectName(), false) ?>
 ));

Modified: 
plugins/ExtjsGeneratorPlugin/trunk/lib/generator/ExtjsModelGeneratorConfiguration.class.php
===================================================================
--- 
plugins/ExtjsGeneratorPlugin/trunk/lib/generator/ExtjsModelGeneratorConfiguration.class.php
 2010-05-21 16:05:34 UTC (rev 29574)
+++ 
plugins/ExtjsGeneratorPlugin/trunk/lib/generator/ExtjsModelGeneratorConfiguration.class.php
 2010-05-21 17:11:05 UTC (rev 29575)
@@ -80,7 +80,7 @@
       ),
       'gridpanel'   => array(
         'config'  => $this->getGridpanelConfig(),
-        'plugins' => $this->getGridpanelPlugins(),      
+        'plugins' => $this->getGridpanelPlugins(),
         'method'  => $this->getGridpanelPartials(),
       ),
       'formpanel'   => array(
@@ -191,7 +191,7 @@
     $this->configuration['credentials']['create'] = 
$this->configuration['credentials']['new'];
     $this->configuration['credentials']['update'] = 
$this->configuration['credentials']['edit'];
   }
-  
+
   /**
    * Gets the fields that represents the form.
    *
@@ -204,6 +204,10 @@
   public function getFormFields(sfForm $form, $context)
   {
     $config = $this->getConfig();
+    $key = sfInflector::underscore($this->getPrimaryKeys(true));
+               $csrfToken = $form->getCSRFFieldName();
+               $needsId = true;
+               $needsCsrf = true;
 
     $method = sprintf('get%sDisplay', ucfirst($context));
     if (!$fieldsets = $this->$method())
@@ -232,6 +236,9 @@
 
         foreach ($names as $name)
         {
+               if($name == $key) $needsId = false;
+          if($name == $csrfToken) $needsCsrf = false;
+
           list($name, $flag) = 
ExtjsModelGeneratorConfigurationField::splitFieldWithFlag($name);
           if (!isset($this->configuration[$context]['fields'][$name]))
           {
@@ -249,6 +256,28 @@
         }
       }
 
+      if($needsId)
+      {
+       $fields['NONE'][$key] = new ExtjsModelGeneratorConfigurationField($key, 
array_merge(
+               array('type' => 'Text'),
+               isset($config['default'][$key]) ? $config['default'][$key] : 
array(),
+               isset($config['form'][$key]) ? $config['form'][$key] : array(),
+               isset($config[$context][$key]) ? $config[$context][$key] : 
array(),
+               array('is_real' => false)
+             ));
+      }
+
+      if($needsCsrf)
+      {
+        $fields['NONE'][$csrfToken] = new 
ExtjsModelGeneratorConfigurationField($csrfToken, array_merge(
+          array('type' => 'Text'),
+          isset($config['default'][$csrfToken]) ? 
$config['default'][$csrfToken] : array(),
+          isset($config['form'][$csrfToken]) ? $config['form'][$csrfToken] : 
array(),
+          isset($config[$context][$csrfToken]) ? $config[$context][$csrfToken] 
: array(),
+          array('is_real' => false)
+        ));
+      }
+
       return $fields;
     }
 
@@ -266,7 +295,7 @@
 
     return array('NONE' => $fields);
   }
-  
+
   protected function parseVariables($context, $key)
   {
     preg_match_all('/%%([^%]+)%%/', $this->configuration[$context][$key], 
$matches, PREG_PATTERN_ORDER);

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