Skip to content

Commit

Permalink
Updating scaffold templates to use post forms for delete buttons. Upd…
Browse files Browse the repository at this point in the history
…ating test case.
  • Loading branch information
markstory committed Dec 12, 2010
1 parent 4950615 commit 11df321
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 20 deletions.
11 changes: 8 additions & 3 deletions cake/libs/view/scaffolds/edit.ctp
Expand Up @@ -27,10 +27,15 @@
<div class="actions">
<h3><?php echo __('Actions'); ?></h3>
<ul>
<?php if ($this->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>
<?php if ($this->request->action != 'add'): ?>
<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;?>
<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
$done = array();
foreach ($associations as $_type => $_data) {
Expand Down
36 changes: 20 additions & 16 deletions cake/libs/view/scaffolds/index.ctp
Expand Up @@ -33,33 +33,37 @@ foreach (${$pluralVar} as ${$singularVar}):
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
echo "\n";
echo "\t<tr{$class}>\n";
echo "<tr{$class}>";
foreach ($scaffoldFields as $_field) {
$isKey = false;
if (!empty($associations['belongsTo'])) {
foreach ($associations['belongsTo'] as $_alias => $_details) {
if ($_field === $_details['foreignKey']) {
$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;
}
}
}
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 "\t\t\t" . $this->Html->link(__('View'), array('action' => 'view', ${$singularVar}[$modelClass][$primaryKey])) . "\n";
echo "\t\t\t" . $this->Html->link(__('Edit'), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey])) . "\n";
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 "\t\t</td>\n";
echo "\t</tr>\n";
echo '<td class="actions">';
echo $this->Html->link(__('View'), array('action' => 'view', ${$singularVar}[$modelClass][$primaryKey]));
echo $this->Html->link(__('Edit'), array('action' => 'edit', ${$singularVar}[$modelClass][$primaryKey]));
echo $this->Form->postLink(
__('Delete'),
array('action' => 'delete', ${$singularVar}[$modelClass][$primaryKey]),
null,
__('Are you sure you want to delete').' #' . ${$singularVar}[$modelClass][$primaryKey]
);
echo '</td>';
echo '</tr>';

endforeach;
echo "\n";

?>
</table>
<p><?php
Expand All @@ -68,9 +72,9 @@ echo "\n";
));
?></p>
<div class="paging">
<?php echo "\t" . $this->Paginator->prev('<< ' . __('previous'), array(), null, array('class' => 'disabled')) . "\n";?>
| <?php echo $this->Paginator->numbers() . "\n"?>
<?php echo "\t ". $this->Paginator->next(__('next') .' >>', array(), null, array('class' => 'disabled')) . "\n";?>
<?php echo $this->Paginator->prev('<< ' . __('previous'), array(), null, array('class' => 'disabled')); ?>
| <?php echo $this->Paginator->numbers(); ?>
<?php echo $this->Paginator->next(__('next') .' >>', array(), null, array('class' => 'disabled')); ?>
</div>
</div>
<div class="actions">
Expand All @@ -82,8 +86,8 @@ echo "\n";
foreach ($associations as $_type => $_data) {
foreach ($_data as $_alias => $_details) {
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 "\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(__('List %s', Inflector::humanize($_details['controller'])), array('controller' => $_details['controller'], 'action' => 'index')) . "</li>";
echo "<li>" . $this->Html->link(__('New %s', Inflector::humanize(Inflector::underscore($_alias))), array('controller' => $_details['controller'], 'action' => 'add')) . "</li>";
$done[] = $_details['controller'];
}
}
Expand Down
2 changes: 1 addition & 1 deletion cake/tests/cases/libs/controller/scaffold.test.php
Expand Up @@ -524,7 +524,7 @@ function testEditScaffold() {
$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('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);
}

/**
Expand Down

0 comments on commit 11df321

Please sign in to comment.