Updating scaffold templates to use post forms for delete buttons. Updating test case.

This commit is contained in:
mark_story 2010-12-12 13:13:00 -05:00
parent 495061537f
commit 11df32148f
3 changed files with 29 additions and 20 deletions

View file

@ -27,10 +27,15 @@
<div class="actions"> <div class="actions">
<h3><?php echo __('Actions'); ?></h3> <h3><?php echo __('Actions'); ?></h3>
<ul> <ul>
<?php if ($this->action != 'add'):?> <?php if ($this->request->action != 'add'): ?>
<li><?php echo $this->Html->link(__('Delete'), array('action' => 'delete', $this->Form->value($modelClass.'.'.$primaryKey)), null, __('Are you sure you want to delete').' #' . $this->Form->value($modelClass.'.'.$primaryKey)); ?></li> <li><?php echo $this->Form->postLink(
__('Delete'),
array('action' => 'delete', $this->Form->value($modelClass . '.' . $primaryKey)),
null,
__('Are you sure you want to delete # %s?', $this->Form->value($modelClass . '.' . $primaryKey)));
?></li>
<?php endif;?> <?php endif;?>
<li><?php echo $this->Html->link(__('List').' '.$pluralHumanName, array('action' => 'index'));?></li> <li><?php echo $this->Html->link(__('List') . ' ' . $pluralHumanName, array('action' => 'index'));?></li>
<?php <?php
$done = array(); $done = array();
foreach ($associations as $_type => $_data) { foreach ($associations as $_type => $_data) {

View file

@ -33,33 +33,37 @@ foreach (${$pluralVar} as ${$singularVar}):
if ($i++ % 2 == 0) { if ($i++ % 2 == 0) {
$class = ' class="altrow"'; $class = ' class="altrow"';
} }
echo "\n"; echo "<tr{$class}>";
echo "\t<tr{$class}>\n";
foreach ($scaffoldFields as $_field) { foreach ($scaffoldFields as $_field) {
$isKey = false; $isKey = false;
if (!empty($associations['belongsTo'])) { if (!empty($associations['belongsTo'])) {
foreach ($associations['belongsTo'] as $_alias => $_details) { foreach ($associations['belongsTo'] as $_alias => $_details) {
if ($_field === $_details['foreignKey']) { if ($_field === $_details['foreignKey']) {
$isKey = true; $isKey = true;
echo "\t\t<td>\n\t\t\t" . $this->Html->link(${$singularVar}[$_alias][$_details['displayField']], array('controller' => $_details['controller'], 'action' => 'view', ${$singularVar}[$_alias][$_details['primaryKey']])) . "\n\t\t</td>\n"; echo "<td>" . $this->Html->link(${$singularVar}[$_alias][$_details['displayField']], array('controller' => $_details['controller'], 'action' => 'view', ${$singularVar}[$_alias][$_details['primaryKey']])) . "</td>";
break; break;
} }
} }
} }
if ($isKey !== true) { if ($isKey !== true) {
echo "\t\t<td>" . h(${$singularVar}[$modelClass][$_field]) . "</td>\n"; echo "<td>" . h(${$singularVar}[$modelClass][$_field]) . "</td>";
} }
} }
echo "\t\t<td class=\"actions\">\n"; echo '<td class="actions">';
echo "\t\t\t" . $this->Html->link(__('View'), array('action' => 'view', ${$singularVar}[$modelClass][$primaryKey])) . "\n"; echo $this->Html->link(__('View'), array('action' => 'view', ${$singularVar}[$modelClass][$primaryKey]));
echo "\t\t\t" . $this->Html->link(__('Edit'), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey])) . "\n"; echo $this->Html->link(__('Edit'), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey]));
echo "\t\t\t" . $this->Html->link(__('Delete'), array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]), null, __('Are you sure you want to delete').' #' . ${$singularVar}[$modelClass][$primaryKey]) . "\n"; echo $this->Form->postLink(
echo "\t\t</td>\n"; __('Delete'),
echo "\t</tr>\n"; array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]),
null,
__('Are you sure you want to delete').' #' . ${$singularVar}[$modelClass][$primaryKey]
);
echo '</td>';
echo '</tr>';
endforeach; endforeach;
echo "\n";
?> ?>
</table> </table>
<p><?php <p><?php
@ -68,9 +72,9 @@ echo "\n";
)); ));
?></p> ?></p>
<div class="paging"> <div class="paging">
<?php echo "\t" . $this->Paginator->prev('<< ' . __('previous'), array(), null, array('class' => 'disabled')) . "\n";?> <?php echo $this->Paginator->prev('<< ' . __('previous'), array(), null, array('class' => 'disabled')); ?>
| <?php echo $this->Paginator->numbers() . "\n"?> | <?php echo $this->Paginator->numbers(); ?>
<?php echo "\t ". $this->Paginator->next(__('next') .' >>', array(), null, array('class' => 'disabled')) . "\n";?> <?php echo $this->Paginator->next(__('next') .' >>', array(), null, array('class' => 'disabled')); ?>
</div> </div>
</div> </div>
<div class="actions"> <div class="actions">
@ -82,8 +86,8 @@ echo "\n";
foreach ($associations as $_type => $_data) { foreach ($associations as $_type => $_data) {
foreach ($_data as $_alias => $_details) { foreach ($_data as $_alias => $_details) {
if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) { if ($_details['controller'] != $this->name && !in_array($_details['controller'], $done)) {
echo "\t\t<li>" . $this->Html->link(__('List %s', Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "</li>\n"; echo "<li>" . $this->Html->link(__('List %s', Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "</li>";
echo "\t\t<li>" . $this->Html->link(__('New %s', Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "</li>\n"; echo "<li>" . $this->Html->link(__('New %s', Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "</li>";
$done[] = $_details['controller']; $done[] = $_details['controller'];
} }
} }

View file

@ -524,7 +524,7 @@ class ScaffoldViewTest extends CakeTestCase {
$this->assertContains('input name="data[ScaffoldMock][title]" maxlength="255" type="text" value="First Article" id="ScaffoldMockTitle"', $result); $this->assertContains('input name="data[ScaffoldMock][title]" maxlength="255" type="text" value="First Article" id="ScaffoldMockTitle"', $result);
$this->assertContains('input name="data[ScaffoldMock][published]" maxlength="1" type="text" value="Y" id="ScaffoldMockPublished"', $result); $this->assertContains('input name="data[ScaffoldMock][published]" maxlength="1" type="text" value="Y" id="ScaffoldMockPublished"', $result);
$this->assertContains('textarea name="data[ScaffoldMock][body]" cols="30" rows="6" id="ScaffoldMockBody"', $result); $this->assertContains('textarea name="data[ScaffoldMock][body]" cols="30" rows="6" id="ScaffoldMockBody"', $result);
$this->assertPattern('/<li><a href="\/scaffold_mock\/delete\/1"[^>]*>Delete<\/a>\s*<\/li>/', $result); $this->assertPattern('/<a href="\#" onclick="if[^>]*>Delete<\/a><\/li>/', $result);
} }
/** /**