Browse files

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
  • Loading branch information...
1 parent 0b42282 commit 1c344db339e84d8a36e031b54202415a070e7641 @chillu chillu committed Mar 6, 2012
View
83 forms/gridfield/GridField.php
@@ -290,6 +290,17 @@ public function getState($getData=true) {
* @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();
@@ -670,13 +681,6 @@ class GridField_Action extends FormAction {
/**
*
- * @var string
- */
- protected $buttonLabel;
- protected $buttonIcon;
-
- /**
- *
* @var array
*/
protected $stateValues;
@@ -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 @@ public function nameEncode($val) {
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
13 forms/gridfield/GridFieldAction.php
@@ -163,16 +163,17 @@ public function getActions($gridField) {
* @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
2 forms/gridfield/GridFieldExporter.php
@@ -46,7 +46,7 @@ public function getHTMLFragments($gridField) {
'export',
null
);
- $button->setButtonIcon('exportlist');
+ $button->setAttribute('data-icon', 'exportlist');
$button->addExtraClass('no-ajax');
return array(
'after' => '<p>' . $button->Field() . '</p>',
View
12 forms/gridfield/GridFieldFilter.php
@@ -75,12 +75,14 @@ public function getHTMLFragments($gridField) {
$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
4 forms/gridfield/GridFieldPopupForms.php
@@ -224,9 +224,9 @@ function ItemEditForm() {
$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
4 forms/gridfield/GridFieldRelationAdd.php
@@ -66,9 +66,9 @@ public function getHTMLFragments($gridField) {
$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
10 forms/gridfield/GridFieldRelationDelete.php
@@ -73,15 +73,15 @@ public function getActions($gridField) {
* @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
6 forms/gridfield/GridFieldSortableHeader.php
@@ -28,9 +28,11 @@ public function getHTMLFragments($gridField) {
$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
4 templates/Includes/GridField_Action.ss
@@ -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>

0 comments on commit 1c344db

Please sign in to comment.