Development

Changeset 5854

You must first sign up to be able to contribute.

Changeset 5854

Show
Ignore:
Timestamp:
11/04/07 17:35:57 (1 year ago)
Author:
Leon.van.der.Ree
Message:

Fixed preloading of foreign values in drop-down boxes

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_json_list_td.php

    r5793 r5854  
    99$hs = $this->getParameterValue('list.hide', array()); 
    1010$columns = $this->getColumns('list.display'); 
    11 //add PrimaryKey of class 
    12 $columns[] = $this->getAdminColumnForField($pk); 
    1311 
    1412// iterate through all columns of all class (inc. related) 
    1513$completeColumns= $this->getColumnsGroup($pk); 
    1614 
     15//add PrimaryKey of class 
     16$columns[] = $this->getAdminColumnForField($pk); 
    1717 
    18 //iterate through all columns of current class 
     18 
     19//add PrimaryKeys of foreign-classes 
     20foreach ($columns as $column)  
     21
     22  if ($foreign = (false !== strpos($column->getName(), '/')))  
     23  { 
     24    // construct foreign-id name 
     25    list($relatedClassName, $relatedColumn) = explode('/', $column->getName()); 
     26    $columnPk = $completeColumns['related'][$relatedClassName]['pk']; 
     27    $columnName = $relatedClassName."/".$columnPk->getName(); 
     28     
     29    // add column if not already in list 
     30    if (!in_array($columnName, $hs)) { 
     31      $columns[] = $this->getAdminColumnForField($columnName); 
     32    } 
     33  } 
     34
     35 
     36 
     37 
     38//iterate through all columns 
    1939$i = 0; 
    2040foreach ($columns as $column) : 
    2141 
    22   //set name 
     42  // set name 
    2343  $columnName = $column->getName(); 
    24   if (false !== strpos($column->getName(), '/')) 
     44  // add classname to json data for fields of current class  
     45  if (!$foreign = (false !== strpos($column->getName(), '/'))) 
    2546  { 
    26     list($relatedClassName, $relatedColumn) = explode('/', $column->getName()); 
    27     $columnName = $completeColumns['related'][$relatedClassName]['pk']->getName(); 
     47    $columnName = strtolower($this->getClassName())."/".$column->getName(); 
    2848  } 
    2949 
    3050  if (in_array($column->getName(), $hs)) continue; 
    3151 
    32     $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials'); 
     52  $credentials = $this->getParameterValue('list.fields.'.$column->getName().'.credentials'); 
    3353 
    3454?> 
     
    4363  } 
    4464 
    45   // set value 
    46   if ($column->getCreoleType() == CreoleTypes::BOOLEAN) 
    47   { 
    48     $value = $this->getColumnGetter($column, true); 
    49   } 
    50   else 
    51   { 
    52     if (false !== strpos($column->getName(), '/')) 
    53     { 
    54       list($relatedClassName, $relatedColumn) = explode('/', $column->getName()); 
    55       $value = $this->getColumnListTag($completeColumns['related'][$relatedClassName]['pk']); 
    56     } 
    57     else 
    58     { 
    59       $value = $this->getColumnListTag($column); 
    60     } 
    61   } 
     65//    // set value 
     66//    if ($column->getCreoleType() == CreoleTypes::BOOLEAN) 
     67//    { 
     68//      $value = $this->getColumnGetter($column, true); 
     69//    } 
     70   
     71  // value data, unfortunately we cannot use the '/' to distinquish the class and the field, because the name is used as variable in _list_ajax_layout.php 
     72  echo "\"".str_replace('/','_',$columnName)."\": \"[?php echo str_replace('\"', '\\\"', ".$this->getColumnListTag($column).") ?]\""; 
    6273 
    63   if (!in_array($columnName, $hs)) { 
    64     echo "\"".$columnName."\": \"[?php echo str_replace('\"', '\\\"', ".$value.") ?]\""; 
    65  
    66     //don't add it twice 
    67     $hs[] = $columnName; 
    68  
    69     if ($columnName != $column->getName()) echo ", "; 
    70   } 
    71   if ($columnName != $column->getName()) { 
    72     // value data 
    73     echo "\"".$column->getName()."\": \"[?php echo str_replace('\"', '\\\"', ".$this->getColumnListTag($column).") ?]\""; 
    74  
    75     //don't add it twice 
    76     $hs[] = $column->getName(); 
    77   } 
     74  //don't add it twice 
     75  $hs[] = $column->getName(); 
    7876 
    7977  $i++; 
  • plugins/sfExtjsThemePlugin/data/generator/sfPropelAdmin/extjs/template/templates/_list_ajax_layout.php

    r5798 r5854  
    3232$pk = $pks[0]->getPhpName(); 
    3333$pkn = $this->getAdminColumnForField($pk)->getName(); 
    34 $prefix = ""
     34$prefix = strtolower($this->getClassName())
    3535 
    3636$columns['pk'] = $this->getAdminColumnForField($pk); 
     
    4141 
    4242$group_field = $this->getParameterValue('list.grouping.field', null); 
    43 $group_field = $group_field ? $prefix.$group_field : null; 
     43$group_field = $group_field ? $prefix."_".$group_field : null; 
    4444 
    4545?> 
     
    8383 
    8484        // Always add the primary key 
    85         $listDisplay[0] = array('name' => $prefix.$columns['pk']->getName(), 
    86                                 'mapping' => $prefix.$columns['pk']->getName(), 
     85        $listDisplay[0] = array('name' => $prefix."_".$columns['pk']->getName(), 
     86                                'mapping' => $prefix."_".$columns['pk']->getName(), 
    8787                                'type' => extjs_convert_propel_type($columns['pk']->getType())); 
    8888 
     
    9393          { 
    9494            // Add id 
    95             $listDisplay[$i] = array('name' => $relatedClasses['pk']->getName(), // removed $class.'_'. 
    96                                      'mapping' => $relatedClasses['pk']->getName(), // removed $class.'_'. 
     95            $listDisplay[$i] = array('name' => $class."_".$relatedClasses['pk']->getName(), 
     96                                     'mapping' => $class."_".$relatedClasses['pk']->getName(), 
    9797                                     'type' => extjs_convert_propel_type($relatedClasses['pk']->getType())); 
    9898            $i++; 
     
    100100            foreach ($relatedClasses['columns'] as $relatedColumn => $col) 
    101101            { 
    102               $listDisplay[$i] = array('name' => $class.'/'.$relatedColumn, 
    103                                        'mapping' => $class.'/'.$relatedColumn, 
     102              $listDisplay[$i] = array('name' => $class.'_'.$relatedColumn, 
     103                                       'mapping' => $class.'_'.$relatedColumn, 
    104104                                       'type' => extjs_convert_propel_type($col->getType())); 
    105105              $i++; 
     
    111111        foreach ($columns['column'] as $column) 
    112112        { 
    113           $listDisplay[$i] = array('name' => $prefix.$column->getName(), 
    114                                    'mapping' => $prefix.$column->getName(), 
     113          $listDisplay[$i] = array('name' => $prefix."_".$column->getName(), 
     114                                   'mapping' => $prefix."_".$column->getName(), 
    115115                                   'type' => extjs_convert_propel_type($column->getType())); 
    116116 
     
    118118        } 
    119119 
    120         $options = array('id' => $prefix.$pkn, 
     120        $options = array('id' => $prefix."_".$pkn, 
    121121                         'root' => 'data', 
    122122                         'totalProperty' => 'totalCount'); 
     
    169169<?php 
    170170 
    171 //  $hs = $this->getParameterValue('list.hide', array()); 
     171  $hs = $this->getParameterValue('list.hide', array()); 
    172172//  $columns = $this->getColumns('list.display'); 
    173173 
     
    178178 
    179179    $pk = $relatedClasses['pk']->getName(); 
    180     $listDisplay = array(array('name' => $pk, 'mapping' => $pk)); 
     180    $listDisplay = array(array('name' => $class.'_'.$pk, 'mapping' => $class.'_'.$pk)); 
    181181 
    182182    // iterate through all requested columns of current class 
     
    191191<?php 
    192192      // add colum to array 
    193       $listDisplay[] = array('name' => $columnName, 'mapping' => $columnName); 
     193      $listDisplay[] = array('name' => $class.'_'.$columnName, 'mapping' => $class.'_'.$columnName); 
    194194?> 
    195195<?php 
     
    202202<?php endforeach; ?> 
    203203<?php 
    204     $options = array('id' => $pk, 
     204    $options = array('id' => $class.'_'.$pk, 
    205205                     'root' => 'data', 
    206206                     'totalProperty' => 'totalCount'); 
     
    214214    $options = array('url' => $url, 
    215215                     'reader' => $jsReader, 
    216                      'sortInfo' => array('field' => $columnName, 'direction' => 'asc'), 
     216                     'sortInfo' => array('field' => $class.'_'.$columnName, 'direction' => 'asc'), 
    217217                     'remoteSort' => 'true'); 
    218218    $jsDataStore = extjs_data_store($options); 
     
    221221    // disabled 
    222222    // <?php echo strtolower($class) ?>_ds.load({params:{start:0, limit:10000}}); // TODO: do I need to say more, this is a hack to preload everything, which probably isn't desired... (but when something isn't there, but it is requested by the renderer with its ID javascript breaks. Requesting the id would be ideal, but because it runs in a seperate thread I don't know how yet... 
     223 
     224    function <?php echo strtolower($class) ?>_ds_add_preloaded_from_index(index, value) { 
     225      <?php  
     226        $fields = $listDisplay; 
     227      ?> 
     228       
     229      var Record = Ext.data.Record.create(<?php echo _extjs_property_encode($fields) ?>); 
     230 
     231      var r = new Record({ 
     232        <?php echo $class.'_'.$pk ?>: value 
     233<?php 
     234    $hs = $this->getParameterValue('list.hide', array()); 
     235     
     236    // iterate through all requested columns of current class 
     237    foreach ($relatedClasses['columns'] as $relatedColumn => $column): 
     238      $columnName = $column->getName(); 
     239 
     240      $credentials = $this->getParameterValue('list.fields.'.$columnName.'.credentials'); 
     241?> 
     242<?php if ($credentials): $credentials = str_replace("\n", ' ', var_export($credentials, true)) ?> 
     243    [?php if ($sf_user->hasCredential(<?php echo $credentials ?>)): ?] 
     244<?php endif; ?> 
     245        <?php echo ", ".$class.'_'.$columnName ?>: ds.getAt(index).get('<?php echo $class.'_'.$columnName ?>') 
     246<?php 
     247  //don't add it twice 
     248  $hs[] = $column->getName(); 
     249?> 
     250<?php if ($credentials): ?> 
     251    [?php endif; ?] 
     252<?php endif; ?> 
     253<?php endforeach; ?> 
     254      }); 
     255       
     256      <?php echo strtolower($class) ?>_ds.add(r); 
     257    } 
     258 
     259 
    223260 
    224261  <?php endforeach; ?> 
     
    288325    if ($column->isPrimaryKey()) continue; 
    289326    if ($column->isForeignKey()) continue; 
    290     // OBSOLETE, ForeignKeyIDs 
    291 //    if ($column->isForeignKey()) 
    292 //    { 
    293 //      $relatedClassName = $this->getRelatedClassName($column); 
    294 //      $relatedColumn = 'name'; // TODO: This can be a default, but you should be able to set it. 
    295 //      $name = $column->getName(); 
    296 //    } 
     327 
    297328    // or are we looking for it? Columns defined as 'table/field' 
    298329    if (false !== strpos($column->getName(), '/')) 
    299330    { 
    300331      list($relatedClassName, $relatedColumn) = explode('/', $column->getName()); 
    301       $key = $completeColumns['related'][$relatedClassName]['pk']->getName(); // removed $relatedClassName.'_'. 
     332      $key = $relatedClassName."_".$completeColumns['related'][$relatedClassName]['pk']->getName(); // removed $relatedClassName.'_'. 
    302333    } 
    303334    else 
     
    323354          // if value in foreign datastore, return this value 
    324355          if (<?php echo $foreign_ds ?>.getById(value)) { 
    325             return <?php echo $foreign_ds ?>.getById(value).get('<?php echo $name ?>'); 
     356            return <?php echo $foreign_ds ?>.getById(value).get('<?php echo $relatedClassName."_".$name ?>'); 
    326357          // if not in foreign datastore, test if it is preloaded (this can be out-dated therefor do it after checking datastore) 
    327358          } else if ((index = ds.find('<?php echo $key ?>', value)) != -1)  { 
    328 // foreign-ID not known in foreign-store yet, add preloaded data to the main-store 
    329 // TODO: this should be done in a new function which is called when onLoad of the main-store is fired, for all foreign-columns (currently it works for only the first column of the foreign-table 
    330 var Record = Ext.data.Record.create([ 
    331   {name: '<?php echo $key ?>', mapping: 1}, 
    332   {name: '<?php echo $name ?>', mapping: 2} 
    333 ]); 
    334  
    335 var r = new Record({ 
    336   <?php echo $key ?>: value, 
    337   <?php echo $name ?>: ds.getAt(index).get('<?php echo $column->getName() ?>') 
    338 }); 
    339  
    340 <?php echo $foreign_ds ?>.add(r); 
    341  
    342             return ds.getAt(index).get('<?php echo $column->getName() ?>'); 
     359            // foreign-ID not known in foreign-store yet, add preloaded data from the main-store 
     360            <?php echo $foreign_ds ?>_add_preloaded_from_index(index, value); 
     361             
     362            return ds.getAt(index).get('<?php echo $relatedClassName.'_'.$name ?>'); 
    343363          } else { 
    344364            //TODO if value still not found the foreign-data-store should get it from the server! (but I don't think this will be necesarry occur) 
     
    374394  { 
    375395    list($relatedClassName, $relatedColumn) = explode('/', $column->getName()); 
    376     $dataIndex = $completeColumns['related'][$relatedClassName]['pk']->getName(); 
     396    $dataIndex = $relatedClassName."_".$completeColumns['related'][$relatedClassName]['pk']->getName(); 
    377397  } 
    378398  else 
    379399  { 
    380     $dataIndex = $column->getName(); 
     400    $dataIndex = strtolower($this->getClassName())."_".$column->getName(); 
    381401  } 
    382402 
     
    451471      list($relatedClassName, $relatedColumn) = explode('/', $column->getName()); 
    452472 
    453       $valueField = $completeColumns['related'][$relatedClassName]['pk']->getName(); 
     473      $valueField = $relatedClassName."_".$completeColumns['related'][$relatedClassName]['pk']->getName(); 
    454474      $options = array('valueField' => $valueField); 
    455475    } 
  • plugins/sfExtjsThemePlugin/lib/helper/ExtjsHelper.php

    r5783 r5854  
    3737function extjs_form_combobox($options) 
    3838{ 
    39   $defaultOptions = array('displayField' => 'name', 
     39  $defaultOptions = array('displayField' => 'REQUIRED', 
    4040                          'triggerAction' => 'all', 
    4141                          'typeAhead' => true, 
     
    4444                          'pageSize' => 15, 
    4545                          'lazyRender' => true, 
    46                           'queryParam' => 'filters[name]', 
     46                          'queryParam' => 'filters[REQUIRED]', 
    4747                          'listClass' => 'x-combo-list-small'); 
    4848 
  • plugins/sfExtjsThemePlugin/lib/sfExtjsPropelAdminGenerator.php

    r5793 r5854  
    189189    return $getter; 
    190190  } 
    191  
     191   
    192192  /** 
    193193   * Process the column name to check for foreign model peer classes 
     
    318318                         'name' => strtolower($relatedClassPhpName).'_'.$relatedColumn.'_combo', 
    319319                         'valueField' => $options['valueField'], 
    320                          'displayField' => $relatedColumn, 
    321                          'queryParam' => 'filters['.$relatedColumn.']', 
     320                         'displayField' => $relatedClassName."_".$relatedColumn, 
     321                         'queryParam' => 'filters['.$relatedClassName."_".$relatedColumn.']', 
    322322                         'store' => strtolower($relatedClassPhpName).'_ds' 
    323323                        );