Skip to content

Commit

Permalink
MINOR Move gridfield actions HTML to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewandante committed Feb 22, 2012
1 parent 0acaf39 commit b389138
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
21 changes: 8 additions & 13 deletions forms/gridfield/GridField.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,22 +709,17 @@ public function Field() {
$actionData['StateID'] = $id;

// And generate field
$attributes = array(
'class' => 'action' . ($this->extraClass() ? $this->extraClass() : ''),
'id' => $this->id(),
'type' => 'submit',
$data = new ArrayData(array(
'Class' => 'action' . ($this->extraClass() ? $this->extraClass() : '') . ($this->isReadonly() ? ' disabled' : ''),
'ID' => $this->id(),
// Note: This field needs to be less than 65 chars, otherwise Suhosin security patch
// will strip it from the requests
'name' => 'action_gridFieldAlterAction'. '?' . http_build_query($actionData),
'tabindex' => $this->getTabIndex(),
);
'Name' => 'action_gridFieldAlterAction'. '?' . http_build_query($actionData),
'Disabled' => $this->isReadonly(),
'Label' => $this->buttonLabel
));

if($this->isReadonly()) {
$attributes['disabled'] = 'disabled';
$attributes['class'] = $attributes['class'] . ' disabled';
}

return $this->createTag('button', $attributes, $this->buttonLabel);
return $data->renderWith('GridField_Action');
}

/**
Expand Down
6 changes: 5 additions & 1 deletion forms/gridfield/GridFieldAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ public function getActions($gridField) {
* @return string - the HTML for the column
*/
public function getColumnContent($gridField, $record, $columnName) {
return sprintf('<a class="action-edit" href="%s">%s</a> ', Controller::join_links($gridField->Link('item'), $record->ID, 'edit'), _t('GridAction.Edit', 'edit'));
$data = new ArrayData(array(
'Link' => Controller::join_links($gridField->Link('item'), $record->ID, 'edit')
));

return $data->renderWith('GridFieldAction_Edit');
}

/**
Expand Down
1 change: 1 addition & 0 deletions templates/Includes/GridFieldAction_Edit.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<a class="action-edit" href="$Link">edit</a>
1 change: 1 addition & 0 deletions templates/Includes/GridField_Action.ss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<button id="$ID" class="$Class" name="$Name" type="submit"<% if Disabled %> disabled="disabled"<% end_if %>>$Label</button>

0 comments on commit b389138

Please sign in to comment.