mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
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:
parent
0b4228231c
commit
1c344db339
@ -290,6 +290,17 @@ class GridField extends FormField {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function FieldHolder() {
|
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
|
// Get columns
|
||||||
$columns = $this->getColumns();
|
$columns = $this->getColumns();
|
||||||
|
|
||||||
@ -668,13 +679,6 @@ class GridField_Action extends FormAction {
|
|||||||
*/
|
*/
|
||||||
protected $gridField;
|
protected $gridField;
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $buttonLabel;
|
|
||||||
protected $buttonIcon;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @var array
|
* @var array
|
||||||
@ -688,8 +692,11 @@ class GridField_Action extends FormAction {
|
|||||||
//protected $stateFields = array();
|
//protected $stateFields = array();
|
||||||
|
|
||||||
protected $actionName;
|
protected $actionName;
|
||||||
|
|
||||||
protected $args = array();
|
protected $args = array();
|
||||||
|
|
||||||
|
public $useButtonTag = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param GridField $gridField
|
* @param GridField $gridField
|
||||||
@ -698,12 +705,11 @@ class GridField_Action extends FormAction {
|
|||||||
* @param type $actionName
|
* @param type $actionName
|
||||||
* @param type $args
|
* @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->gridField = $gridField;
|
||||||
$this->buttonLabel = $label;
|
|
||||||
$this->actionName = $actionName;
|
$this->actionName = $actionName;
|
||||||
$this->args = $args;
|
$this->args = $args;
|
||||||
parent::__construct($name);
|
parent::__construct($name, $title);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -723,64 +729,27 @@ class GridField_Action extends FormAction {
|
|||||||
public function _nameEncode($match) {
|
public function _nameEncode($match) {
|
||||||
return '%'.dechex(ord($match[0]));
|
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
|
// Store state in session, and pass ID to client side
|
||||||
$state = array(
|
$state = array(
|
||||||
'grid' => $this->getNameFromParent(),
|
'grid' => $this->getNameFromParent(),
|
||||||
'actionName' => $this->actionName,
|
'actionName' => $this->actionName,
|
||||||
'args' => $this->args,
|
'args' => $this->args,
|
||||||
);
|
);
|
||||||
|
|
||||||
$id = preg_replace('/[^\w]+/', '_', uniqid('', true));
|
$id = preg_replace('/[^\w]+/', '_', uniqid('', true));
|
||||||
Session::set($id, $state);
|
Session::set($id, $state);
|
||||||
|
|
||||||
$actionData['StateID'] = $id;
|
$actionData['StateID'] = $id;
|
||||||
|
|
||||||
// And generate field
|
return array_merge(
|
||||||
$data = new ArrayData(array(
|
parent::getAttributes(),
|
||||||
'Class' => ($this->extraClass() ? $this->extraClass() : '') . ($this->isReadonly() ? ' disabled' : ''),
|
array(
|
||||||
'ID' => $this->id(),
|
// Note: This field needs to be less than 65 chars, otherwise Suhosin security patch
|
||||||
// Note: This field needs to be less than 65 chars, otherwise Suhosin security patch
|
// will strip it from the requests
|
||||||
// will strip it from the requests
|
'name' => 'action_gridFieldAlterAction'. '?' . http_build_query($actionData),
|
||||||
'Name' => 'action_gridFieldAlterAction'. '?' . http_build_query($actionData),
|
'data-url' => $this->gridField->Link(),
|
||||||
'Disabled' => $this->isReadonly(),
|
)
|
||||||
'Label' => $this->buttonLabel,
|
);
|
||||||
'Icon' => $this->buttonIcon,
|
|
||||||
'DataURL' => $this->gridField->Link(),
|
|
||||||
));
|
|
||||||
|
|
||||||
return $data->renderWith('GridField_Action');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,16 +163,17 @@ class GridFieldAction_Delete implements GridField_ColumnProvider, GridField_Acti
|
|||||||
* @return string - the HTML for the column
|
* @return string - the HTML for the column
|
||||||
*/
|
*/
|
||||||
public function getColumnContent($gridField, $record, $columnName) {
|
public function getColumnContent($gridField, $record, $columnName) {
|
||||||
$field = new GridField_Action(
|
$field = Object::create('GridField_Action',
|
||||||
$gridField,
|
$gridField,
|
||||||
'DeleteRecord'.$record->ID,
|
'DeleteRecord'.$record->ID,
|
||||||
_t('GridAction.Delete', "delete"),
|
false,
|
||||||
"deleterecord",
|
"deleterecord",
|
||||||
array('RecordID' => $record->ID)
|
array('RecordID' => $record->ID)
|
||||||
);
|
)
|
||||||
$field->addExtraClass('gridfield-button-delete');
|
->addExtraClass('gridfield-button-delete')
|
||||||
$output = $field->Field();
|
->setAttribute('title', _t('GridAction.Delete', "delete"))
|
||||||
return $output;
|
->setAttribute('data-icon', 'decline');
|
||||||
|
return $field->Field();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -46,7 +46,7 @@ class GridFieldExporter implements GridField_HTMLProvider, GridField_ActionProvi
|
|||||||
'export',
|
'export',
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
$button->setButtonIcon('exportlist');
|
$button->setAttribute('data-icon', 'exportlist');
|
||||||
$button->addExtraClass('no-ajax');
|
$button->addExtraClass('no-ajax');
|
||||||
return array(
|
return array(
|
||||||
'after' => '<p>' . $button->Field() . '</p>',
|
'after' => '<p>' . $button->Field() . '</p>',
|
||||||
|
@ -75,12 +75,14 @@ class GridFieldFilter implements GridField_HTMLProvider, GridField_DataManipulat
|
|||||||
|
|
||||||
$field = new FieldGroup(
|
$field = new FieldGroup(
|
||||||
$field,
|
$field,
|
||||||
$filterbutton = new GridField_Action($gridField, 'filter', _t('GridField.Filter', "Filter"), 'filter', null),
|
Object::create('GridField_Action', $gridField, 'filter', false, 'filter', null)
|
||||||
$resetbutton = new GridField_Action($gridField, 'reset', _t('GridField.ResetFilter', "Reset"), 'reset', 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 {
|
} else {
|
||||||
$field = new LiteralField('', '');
|
$field = new LiteralField('', '');
|
||||||
}
|
}
|
||||||
|
@ -224,9 +224,9 @@ class GridFieldPopupForm_ItemRequest extends RequestHandler {
|
|||||||
$this->record->getCMSFields($this->popupController, $this->popupFormName),
|
$this->record->getCMSFields($this->popupController, $this->popupFormName),
|
||||||
new FieldList(
|
new FieldList(
|
||||||
FormAction::create('doSave', _t('GridFieldDetailsForm.Save', 'Save'))
|
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'))
|
FormAction::create('doDelete', _t('GridFieldDetailsForm.Delete', 'Delete'))
|
||||||
->setUseButtonTag(true)->addExtraClass('ss-ui-action-destructive')
|
->addExtraClass('ss-ui-action-destructive')
|
||||||
),
|
),
|
||||||
$this->component->getValidator()
|
$this->component->getValidator()
|
||||||
);
|
);
|
||||||
|
@ -66,9 +66,9 @@ class GridFieldRelationAdd implements GridField_HTMLProvider, GridField_ActionPr
|
|||||||
$searchField->addExtraClass('relation-search');
|
$searchField->addExtraClass('relation-search');
|
||||||
|
|
||||||
$findAction = new GridField_Action($gridField, 'gridfield_relationfind', _t('GridField.Find', "Find"), 'find', 'find');
|
$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 = 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 an object is not found, disable the action
|
||||||
if(!is_int($gridField->State->GridFieldAddRelation)) {
|
if(!is_int($gridField->State->GridFieldAddRelation)) {
|
||||||
|
@ -73,15 +73,15 @@ class GridFieldRelationDelete implements GridField_ColumnProvider, GridField_Act
|
|||||||
* @return string - the HTML for the column
|
* @return string - the HTML for the column
|
||||||
*/
|
*/
|
||||||
public function getColumnContent($gridField, $record, $columnName) {
|
public function getColumnContent($gridField, $record, $columnName) {
|
||||||
$field = new GridField_Action(
|
$field = Object::create('GridField_Action',
|
||||||
$gridField,
|
$gridField,
|
||||||
'UnlinkRelation'.$record->ID,
|
'UnlinkRelation'.$record->ID,
|
||||||
_t('GridAction.UnlinkRelation', "Unlink"),
|
false,
|
||||||
"unlinkrelation",
|
"unlinkrelation",
|
||||||
array('RecordID' => $record->ID)
|
array('RecordID' => $record->ID)
|
||||||
);
|
)
|
||||||
$output = $field->Field();
|
->setAttribute('title', _t('GridAction.UnlinkRelation', "Unlink"));
|
||||||
return $output;
|
return $field->Field();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -28,9 +28,11 @@ class GridFieldSortableHeader implements GridField_HTMLProvider, GridField_DataM
|
|||||||
$dir = 'desc';
|
$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){
|
if($state->SortColumn == $columnField){
|
||||||
$field->addExtraClass('ss-gridfield-sorted');
|
$field->addExtraClass('ss-gridfield-sorted');
|
||||||
|
|
||||||
|
@ -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 %>>
|
<button $AttributesHTML>
|
||||||
$Label
|
<% if ButtonContent %>$ButtonContent<% else %>$Title<% end_if %>
|
||||||
</button>
|
</button>
|
Loading…
Reference in New Issue
Block a user