API CHANGE: Added targetFragment argument to GridFieldAddExistingAutocompleter, so that its location can be changed. Updated CSS and HTML to allow for this.

This commit is contained in:
Sam Minnee 2012-03-09 16:50:05 +13:00
parent d795a55bdb
commit 12618e2027
4 changed files with 25 additions and 5 deletions

View File

@ -2,6 +2,8 @@
.cms .ss-gridfield > div { margin-bottom: 35px; }
.cms .ss-gridfield[data-selectable] tr.ui-selected, .cms .ss-gridfield[data-selectable] tr.ui-selecting { background: #FFFAD6 !important; }
.cms .ss-gridfield[data-selectable] td { cursor: pointer; }
.cms .ss-gridfield .add-existing-autocompleter { width: 500px; }
.cms .ss-gridfield .add-existing-autocompleter input.relation-search { width: 380px; }
.cms table.ss-gridfield-table { display: table; box-shadow: none; padding: 0; border-collapse: separate; border-bottom: 0 none; width: 100%; }
.cms table.ss-gridfield-table thead { color: #1d2224; background: transparent; }
.cms table.ss-gridfield-table thead tr.filter-header .fieldgroup { max-width: 512px; }

View File

@ -15,7 +15,12 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
* @var string $itemClass
*/
protected $itemClass = 'GridFieldAddExistingAutocompleter';
/**
* The HTML fragment to write this component into
*/
protected $targetFragment;
/**
* Which columns that should be used for doing a "StartsWith" search.
* If multiple fields are provided, the filtering is performed non-exclusive.
@ -40,7 +45,8 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
*
* @param array $searchFields Which fields on the object in the list should be searched
*/
public function __construct($searchFields = null) {
public function __construct($targetFragment = 'before', $searchFields = null) {
$this->targetFragment = $targetFragment;
$this->searchFields = (array)$searchFields;
}
@ -67,7 +73,7 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
$findAction = new GridField_FormAction($gridField, 'gridfield_relationfind', _t('GridField.Find', "Find"), 'find', 'find');
$findAction->setAttribute('data-icon', 'relationfind');
$addAction = new GridField_FormAction($gridField, 'gridfield_relationadd', _t('GridField.LinkExisting', "Link Exisiting"), 'addto', 'addto');
$addAction = new GridField_FormAction($gridField, 'gridfield_relationadd', _t('GridField.LinkExisting', "Link Existing"), 'addto', 'addto');
$addAction->setAttribute('data-icon', 'chain--plus');
// If an object is not found, disable the action
@ -78,7 +84,10 @@ class GridFieldAddExistingAutocompleter implements GridField_HTMLProvider, GridF
$forTemplate->Fields->push($searchField);
$forTemplate->Fields->push($findAction);
$forTemplate->Fields->push($addAction);
return array('before' => $forTemplate->renderWith($this->itemClass));
return array(
$this->targetFragment => $forTemplate->renderWith($this->itemClass)
);
}
/**

View File

@ -53,6 +53,15 @@ $gf_grid_x: 16px;
}
}
}
.ss-gridfield {
.add-existing-autocompleter {
input.relation-search {
width: 380px;
}
width: 500px;
}
}
table.ss-gridfield-table {
display: table;

View File

@ -1,4 +1,4 @@
<div><% control Fields %>
<div class="add-existing-autocompleter"><% control Fields %>
<span>$Field</span>
<% end_control %>
</div>