2012-12-23 12:37:59 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* A modal search dialog which uses search context to search for and add
|
|
|
|
* existing records to a grid field.
|
|
|
|
*/
|
|
|
|
class GridFieldAddExistingSearchButton implements
|
|
|
|
GridField_HTMLProvider,
|
|
|
|
GridField_URLHandler {
|
|
|
|
|
2013-02-16 12:59:29 +01:00
|
|
|
protected $title;
|
2012-12-23 12:37:59 +01:00
|
|
|
protected $fragment;
|
2013-03-28 10:43:17 +01:00
|
|
|
protected $searchList;
|
2012-12-23 12:37:59 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $fragment
|
|
|
|
*/
|
2013-02-16 12:56:43 +01:00
|
|
|
public function __construct($fragment = 'buttons-before-left') {
|
2012-12-23 12:37:59 +01:00
|
|
|
$this->fragment = $fragment;
|
2013-02-16 12:59:29 +01:00
|
|
|
$this->title = _t('GridFieldExtensions.ADDEXISTING', 'Add Existing');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getTitle() {
|
|
|
|
return $this->title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $title
|
|
|
|
*/
|
|
|
|
public function setTitle($title) {
|
|
|
|
$this->title = $title;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getFragment() {
|
|
|
|
return $this->fragment;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param string $fragment
|
|
|
|
*/
|
|
|
|
public function setFragment($fragment) {
|
|
|
|
$this->fragment = $fragment;
|
2012-12-23 12:37:59 +01:00
|
|
|
}
|
|
|
|
|
2013-03-28 10:43:17 +01:00
|
|
|
/**
|
|
|
|
* Sets a custom list to use to provide the searchable items.
|
|
|
|
*
|
|
|
|
* @param SS_List $list
|
|
|
|
*/
|
|
|
|
public function setSearchList(SS_List $list) {
|
|
|
|
$this->searchList = $list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return SS_List|null
|
|
|
|
*/
|
|
|
|
public function getSearchList() {
|
|
|
|
return $this->searchList;
|
|
|
|
}
|
|
|
|
|
2012-12-23 12:37:59 +01:00
|
|
|
public function getHTMLFragments($grid) {
|
2013-02-08 15:42:48 +01:00
|
|
|
GridFieldExtensions::include_requirements();
|
2012-12-23 12:37:59 +01:00
|
|
|
|
|
|
|
$data = new ArrayData(array(
|
2013-02-16 12:59:29 +01:00
|
|
|
'Title' => $this->getTitle(),
|
2012-12-23 12:37:59 +01:00
|
|
|
'Link' => $grid->Link('add-existing-search')
|
|
|
|
));
|
|
|
|
|
|
|
|
return array(
|
|
|
|
$this->fragment => $data->renderWith('GridFieldAddExistingSearchButton'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURLHandlers($grid) {
|
|
|
|
return array(
|
|
|
|
'add-existing-search' => 'handleSearch'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handleSearch($grid, $request) {
|
|
|
|
return new GridFieldAddExistingSearchHandler($grid, $this);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|