MINOR More consistent overloading in GridField_Action, using standard getAttributes() method rather than custom template placeholders, removing setButtonIcon() and setButtonLabel() as those features already exist in the base implementation

This commit is contained in:
Ingo Schommer 2012-03-06 16:58:13 +01:00
parent 0b4228231c
commit 1c344db339
9 changed files with 56 additions and 82 deletions

View File

@ -290,6 +290,17 @@ class GridField extends FormField {
* @return string
*/
public function FieldHolder() {
Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
Requirements::css(SAPPHIRE_DIR . '/css/GridField.css');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js');
Requirements::javascript(THIRDPARTY_DIR . '/json-js/json2.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/i18n.js');
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/GridField.js');
// Get columns
$columns = $this->getColumns();
@ -668,13 +679,6 @@ class GridField_Action extends FormAction {
*/
protected $gridField;
/**
*
* @var string
*/
protected $buttonLabel;
protected $buttonIcon;
/**
*
* @var array
@ -688,8 +692,11 @@ class GridField_Action extends FormAction {
//protected $stateFields = array();
protected $actionName;
protected $args = array();
public $useButtonTag = true;
/**
*
* @param GridField $gridField
@ -698,12 +705,11 @@ class GridField_Action extends FormAction {
* @param type $actionName
* @param type $args
*/
public function __construct(GridField $gridField, $name, $label, $actionName, $args) {
public function __construct(GridField $gridField, $name, $title, $actionName, $args) {
$this->gridField = $gridField;
$this->buttonLabel = $label;
$this->actionName = $actionName;
$this->args = $args;
parent::__construct($name);
parent::__construct($name, $title);
}
/**
@ -723,64 +729,27 @@ class GridField_Action extends FormAction {
public function _nameEncode($match) {
return '%'.dechex(ord($match[0]));
}
/**
* buttonIcon setter
*/
public function setButtonIcon($iconName) {
$this->buttonIcon = $iconName;
}
/**
* buttonIcon getter
*/
public function getButtonIcon(){
return $this->buttonIcon;
}
/**
* Default method used by Templates to render the form
*
* @return string HTML tag
*/
public function Field() {
Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
Requirements::css(SAPPHIRE_DIR . '/css/GridField.css');
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
Requirements::javascript(SAPPHIRE_DIR . '/thirdparty/jquery-ui/jquery-ui.js');
Requirements::javascript(THIRDPARTY_DIR . '/json-js/json2.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/i18n.js');
Requirements::add_i18n_javascript(SAPPHIRE_DIR . '/javascript/lang');
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript(SAPPHIRE_DIR . '/javascript/GridField.js');
public function getAttributes() {
// Store state in session, and pass ID to client side
$state = array(
'grid' => $this->getNameFromParent(),
'actionName' => $this->actionName,
'args' => $this->args,
);
$id = preg_replace('/[^\w]+/', '_', uniqid('', true));
Session::set($id, $state);
$actionData['StateID'] = $id;
// And generate field
$data = new ArrayData(array(
'Class' => ($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),
'Disabled' => $this->isReadonly(),
'Label' => $this->buttonLabel,
'Icon' => $this->buttonIcon,
'DataURL' => $this->gridField->Link(),
));
return $data->renderWith('GridField_Action');
return array_merge(
parent::getAttributes(),
array(
// 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),
'data-url' => $this->gridField->Link(),
)
);
}
/**

View File

@ -163,16 +163,17 @@ class GridFieldAction_Delete implements GridField_ColumnProvider, GridField_Acti
* @return string - the HTML for the column
*/
public function getColumnContent($gridField, $record, $columnName) {
$field = new GridField_Action(
$field = Object::create('GridField_Action',
$gridField,
'DeleteRecord'.$record->ID,
_t('GridAction.Delete', "delete"),
false,
"deleterecord",
array('RecordID' => $record->ID)
);
$field->addExtraClass('gridfield-button-delete');
$output = $field->Field();
return $output;
)
->addExtraClass('gridfield-button-delete')
->setAttribute('title', _t('GridAction.Delete', "delete"))
->setAttribute('data-icon', 'decline');
return $field->Field();
}
/**

View File

@ -46,7 +46,7 @@ class GridFieldExporter implements GridField_HTMLProvider, GridField_ActionProvi
'export',
null
);
$button->setButtonIcon('exportlist');
$button->setAttribute('data-icon', 'exportlist');
$button->addExtraClass('no-ajax');
return array(
'after' => '<p>' . $button->Field() . '</p>',

View File

@ -75,12 +75,14 @@ class GridFieldFilter implements GridField_HTMLProvider, GridField_DataManipulat
$field = new FieldGroup(
$field,
$filterbutton = new GridField_Action($gridField, 'filter', _t('GridField.Filter', "Filter"), 'filter', null),
$resetbutton = new GridField_Action($gridField, 'reset', _t('GridField.ResetFilter', "Reset"), 'reset', null)
Object::create('GridField_Action', $gridField, 'filter', false, 'filter', null)
->addExtraClass('ss-gridfield-button-filter')
->setAttribute('title', _t('GridField.Filter', "Filter"))
,
Object::create('GridField_Action', $gridField, 'reset', false, 'reset', null)
->addExtraClass('ss-gridfield-button-reset')
->setAttribute('title', _t('GridField.ResetFilter', "Reset"))
);
$filterbutton->addExtraClass('ss-gridfield-button-filter');
$resetbutton->addExtraClass('ss-gridfield-button-reset');
} else {
$field = new LiteralField('', '');
}

View File

@ -224,9 +224,9 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler {
$this->record->getCMSFields($this->popupController, $this->popupFormName),
new FieldList(
FormAction::create('doSave', _t('GridFieldDetailsForm.Save', 'Save'))
->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'),
->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'),
FormAction::create('doDelete', _t('GridFieldDetailsForm.Delete', 'Delete'))
->setUseButtonTag(true)->addExtraClass('ss-ui-action-destructive')
->addExtraClass('ss-ui-action-destructive')
),
$this->component->getValidator()
);

View File

@ -66,9 +66,9 @@ class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionPr
$searchField->addExtraClass('relation-search');
$findAction = new GridField_Action($gridField, 'gridfield_relationfind', _t('GridField.Find', "Find"), 'find', 'find');
$findAction->setButtonIcon('relationfind');
$findAction->setAttribute('data-icon', 'relationfind');
$addAction = new GridField_Action($gridField, 'gridfield_relationadd', _t('GridField.LinkExisting', "Link Exisiting"), 'addto', 'addto');
$addAction->setButtonIcon('linkexisting');
$addAction->setAttribute('data-icon', 'linkexisting');
// If an object is not found, disable the action
if(!is_int($gridField->State->GridFieldAddRelation)) {

View File

@ -73,15 +73,15 @@ class GridFieldRelationDelete implements GridField_ColumnProvider, GridField_Act
* @return string - the HTML for the column
*/
public function getColumnContent($gridField, $record, $columnName) {
$field = new GridField_Action(
$field = Object::create('GridField_Action',
$gridField,
'UnlinkRelation'.$record->ID,
_t('GridAction.UnlinkRelation', "Unlink"),
false,
"unlinkrelation",
array('RecordID' => $record->ID)
);
$output = $field->Field();
return $output;
)
->setAttribute('title', _t('GridAction.UnlinkRelation', "Unlink"));
return $field->Field();
}
/**

View File

@ -28,9 +28,11 @@ class GridFieldSortableHeader implements GridField_HTMLProvider, GridField_DataM
$dir = 'desc';
}
$field = new GridField_Action($gridField, 'SetOrder'.$columnField, $title, "sort$dir", array('SortColumn' => $columnField));
$field = Object::create(
'GridField_Action', $gridField, 'SetOrder'.$columnField, $title,
"sort$dir", array('SortColumn' => $columnField)
)->addExtraClass('ss-gridfield-sort');
$field->addExtraClass('ss-gridfield-sort');
if($state->SortColumn == $columnField){
$field->addExtraClass('ss-gridfield-sorted');

View File

@ -1,3 +1,3 @@
<button id="$ID" class="$Class" name="$Name" type="submit" data-url="$DataURL"<% if Disabled %> disabled="disabled"<% end_if %><% if Icon %> data-icon="$Icon"<% end_if %>>
$Label
<button $AttributesHTML>
<% if ButtonContent %>$ButtonContent<% else %>$Title<% end_if %>
</button>