Skip to content

Commit

Permalink
Merge branch '3'
Browse files Browse the repository at this point in the history
  • Loading branch information
robbieaverill committed Feb 11, 2018
2 parents 37a206c + ed51125 commit b192551
Show file tree
Hide file tree
Showing 11 changed files with 233 additions and 98 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ matrix:
env: DB=PGSQL PHPUNIT_TEST=1
- php: 7.1
env: DB=MYSQL PHPUNIT_COVERAGE_TEST=1
- php: 7.2
env: DB=MYSQL PHPUNIT_TEST=1

before_script:
- phpenv rehash
Expand All @@ -25,7 +27,7 @@ before_script:
script:
- if [[ $PHPUNIT_TEST ]]; then vendor/bin/phpunit tests/; fi
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then phpdbg -qrr vendor/bin/phpunit --coverage-clover=coverage.xml; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs --standard=vendor/silverstripe/framework/phpcs.xml.dist src/ tests/ ; fi
- if [[ $PHPCS_TEST ]]; then vendor/bin/phpcs src/ tests/ *.php; fi

after_success:
- if [[ $PHPUNIT_COVERAGE_TEST ]]; then bash <(curl -s https://codecov.io/bash) -f coverage.xml; fi
35 changes: 4 additions & 31 deletions css/GridFieldExtensions.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,46 +14,20 @@
}

.add-existing-search-dialog .add-existing-search-form .field label {
padding-bottom: 4px;
padding: 4px 0;
}

.add-existing-search-dialog .add-existing-search-form .Actions {
margin-top: 10px;
padding: 0;
}

.add-existing-search-dialog .add-existing-search-items li a {
background: #FFF;
border: solid #CCC;
border-right-width: 1px;
border-bottom-width: 1px;
border-left-width: 1px;
display: block;
padding: 6px;
.add-existing-search-dialog .list-group-item {
min-height: 32px;
}

.add-existing-search-dialog .add-existing-search-items li:first-child a {
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border-top-width: 1px;
}

.add-existing-search-dialog .add-existing-search-items li:last-child a {
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
}

.add-existing-search-dialog .add-existing-search-items li a:hover {
background: #F4F4F4;
}

.add-existing-search-dialog .add-existing-search-pagination li {
background: #FFF;
display: block;
float: left;
margin-right: 2px;
.add-existing-search-dialog .btn-toolbar {
margin-top: 12px;
padding: 6px;
}

/**
Expand Down Expand Up @@ -97,7 +71,6 @@
display: inline-block;
margin: 0;
min-width: 150px;
width: calc(100% - 20px);
}

.ss-gridfield-add-new-multi-class .form-group:after {
Expand Down
87 changes: 86 additions & 1 deletion javascript/GridFieldExtensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
}
});

// Allow the list item to be clickable as well as the anchor
$('.add-existing-search-dialog .add-existing-search-items .list-group-item-action').entwine({
onclick: function() {
if (this.children('a').length > 0) {
this.children('a').first().trigger('click');
}
}
});

$(".add-existing-search-dialog .add-existing-search-items a").entwine({
onclick: function() {
var link = this.closest(".add-existing-search-items").data("add-link");
Expand Down Expand Up @@ -264,6 +273,82 @@
*/

$(".ss-gridfield-orderable tbody").entwine({
// reload the gridfield without triggering the change event
// this is because the change has already been saved by reorder action
reload: function (ajaxOpts, successCallback) {
var self = this.getGridField(), form = this.closest('form'),
focusedElName = this.find(':input:focus').attr('name'), // Save focused element for restoring after refresh
data = form.find(':input').serializeArray();

if (!ajaxOpts) {
ajaxOpts = {};
}
if (!ajaxOpts.data) {
ajaxOpts.data = [];
}
ajaxOpts.data = ajaxOpts.data.concat(data);

// Include any GET parameters from the current URL, as the view state might depend on it.
// For example, a list prefiltered through external search criteria might be passed to GridField.
if (window.location.search) {
ajaxOpts.data = window.location.search.replace(/^\?/, '') + '&' + $.param(ajaxOpts.data);
}

form.addClass('loading');

$.ajax($.extend({}, {
headers: {"X-Pjax": 'CurrentField'},
type: "POST",
url: this.data('url'),
dataType: 'html',
success: function (data) {
// Replace the grid field with response, not the form.
// TODO Only replaces all its children, to avoid replacing the current scope
// of the executing method. Means that it doesn't retrigger the onmatch() on the main container.
self.empty().append($(data).children());

// Refocus previously focused element. Useful e.g. for finding+adding
// multiple relationships via keyboard.
if (focusedElName) self.find(':input[name="' + focusedElName + '"]').focus();

// Update filter
if (self.find('.grid-field__filter-header').length) {
var content;
if (ajaxOpts.data[0].filter == "show") {
content = '<span class="non-sortable"></span>';
self.addClass('show-filter').find('.grid-field__filter-header').show();
} else {
content = '<button type="button" title="Open search and filter" name="showFilter" class="btn btn-secondary font-icon-search btn--no-text btn--icon-large grid-field__filter-open"></button>';
self.removeClass('show-filter').find('.grid-field__filter-header').hide();
}

self.find('.sortable-header th:last').html(content);
}

form.removeClass('loading');
if (successCallback) {
successCallback.apply(this, arguments);
}
self.trigger('reload', self);

// update publish button if necessary
const publish = $('#Form_EditForm_action_publish');

// button needs to be updated only if it's in published state
if (publish.length > 0 && publish.hasClass('btn-outline-primary')) {
publish.removeClass('btn-outline-primary');
publish.removeClass('font-icon-tick');
publish.addClass('btn-primary');
publish.addClass('font-icon-rocket');
publish.find('.btn__title').html('Save & publish');
}
},
error: function (e) {
alert(i18n._t('Admin.ERRORINTRANSACTION'));
form.removeClass('loading');
}
}, ajaxOpts));
},
rebuildSort: function() {
var grid = this.getGridField();

Expand Down Expand Up @@ -320,7 +405,7 @@
var grid = self.getGridField();
if (grid.data("immediate-update") && postback)
{
grid.reload({
self.reload({
url: grid.data("url-reorder")
});
}
Expand Down
14 changes: 14 additions & 0 deletions lang/en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
en:
GridFieldExtensions:
ADD: Add
ADDEXISTING: 'Add Existing'
BACK: Back
CURRENT: (current)
NOITEMS: 'There are no items.'
Next: Next
PREVIOUS: Previous
RESULTS: Results
SEARCH: Search
SELECTTYPETOCREATE: '(Select type to create)'
Symbiote\GridFieldExtensions\GridFieldConfigurablePaginator:
SHOW: Show
9 changes: 9 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="SilverStripe">
<description>CodeSniffer ruleset for SilverStripe coding conventions.</description>

<rule ref="PSR2" >
<!-- Current exclusions -->
<exclude name="PSR1.Methods.CamelCapsMethodName" />
</rule>
</ruleset>
13 changes: 7 additions & 6 deletions src/GridFieldAddExistingSearchButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,15 @@ public function getHTMLFragments($grid)
{
GridFieldExtensions::include_requirements();

$data = new ArrayData(array(
$data = ArrayData::create([
'Title' => $this->getTitle(),
'Link' => $grid->Link('add-existing-search')
));
'Classes' => 'action btn btn-primary font-icon-search add-existing-search',
'Link' => $grid->Link('add-existing-search'),
]);

return array(
$this->fragment => $data->renderWith('Symbiote\\GridFieldExtensions\\GridFieldAddExistingSearchButton'),
);
return [
$this->fragment => $data->renderWith(__CLASS__),
];
}

public function getURLHandlers($grid)
Expand Down
13 changes: 7 additions & 6 deletions src/GridFieldAddExistingSearchHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\ORM\DataList;
use SilverStripe\ORM\PaginatedList;
use SilverStripe\ORM\Search\SearchContext;

/**
* Used by {@link GridFieldAddExistingSearchButton} to provide the searching
Expand Down Expand Up @@ -49,7 +51,7 @@ public function __construct($grid, $button)

public function index()
{
return $this->renderWith('Symbiote\\GridFieldExtensions\\GridFieldAddExistingSearchHandler');
return $this->renderWith(__CLASS__);
}

public function add($request)
Expand All @@ -73,19 +75,18 @@ public function add($request)
*/
public function SearchForm()
{
$form = new Form(
$form = Form::create(
$this,
'SearchForm',
$this->context->getFields(),
new FieldList(
FieldList::create(
FormAction::create('doSearch', _t('GridFieldExtensions.SEARCH', 'Search'))
->setUseButtonTag(true)
->addExtraClass('ss-ui-button')
->setAttribute('data-icon', 'magnifier')
->addExtraClass('btn btn-primary font-icon-search')
)
);

$form->addExtraClass('stacked add-existing-search-form');
$form->addExtraClass('stacked add-existing-search-form form--no-dividers');
$form->setFormMethod('GET');

return $form;
Expand Down
15 changes: 9 additions & 6 deletions src/GridFieldConfigurablePaginator.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use Exception;
use SilverStripe\Core\Config\Configurable;
use SilverStripe\Forms\GridField\GridField;
use SilverStripe\Forms\GridField\GridFieldPaginator;
use SilverStripe\Forms\GridField\GridField_FormAction;
use SilverStripe\Forms\GridField\GridFieldPaginator;
use SilverStripe\Forms\GridField\GridState_Data;
use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\Limitable;
Expand Down Expand Up @@ -269,7 +269,7 @@ public function getManipulatedData(GridField $gridField, SS_List $dataList)
* {@inheritDoc}
*
* @param GridField $gridField
* @return ArrayList|null
* @return ArrayData|null
*/
public function getTemplateParameters(GridField $gridField)
{
Expand All @@ -281,21 +281,23 @@ public function getTemplateParameters(GridField $gridField)

// Figure out which page and record range we're on
if (!$arguments['total-rows']) {
return;
return null;
}

// Define a list of the FormActions that should be generated for pager controls (see getPagerActions())
$controls = array(
'first' => array(
'title' => 'First',
'args' => array('first-shown' => 1),
'extra-class' => 'btn btn-secondary btn--hide-text btn-sm font-icon-angle-double-left ss-gridfield-firstpage',
'extra-class' => 'btn btn-secondary btn--hide-text btn-sm font-icon-angle-double-left '
. 'ss-gridfield-firstpage',
'disable-previous' => ($this->getCurrentPage() == 1)
),
'prev' => array(
'title' => 'Previous',
'args' => array('first-shown' => $arguments['first-shown'] - $this->getItemsPerPage()),
'extra-class' => 'btn btn-secondary btn--hide-text btn-sm font-icon-angle-left ss-gridfield-previouspage',
'extra-class' => 'btn btn-secondary btn--hide-text btn-sm font-icon-angle-left '
. 'ss-gridfield-previouspage',
'disable-previous' => ($this->getCurrentPage() == 1)
),
'next' => array(
Expand All @@ -307,7 +309,8 @@ public function getTemplateParameters(GridField $gridField)
'last' => array(
'title' => 'Last',
'args' => array('first-shown' => ($this->getTotalPages() - 1) * $this->getItemsPerPage() + 1),
'extra-class' => 'btn btn-secondary btn--hide-text btn-sm font-icon-angle-double-right ss-gridfield-lastpage',
'extra-class' => 'btn btn-secondary btn--hide-text btn-sm font-icon-angle-double-right '
. 'ss-gridfield-lastpage',
'disable-next' => ($this->getCurrentPage() == $arguments['total-pages'])
),
'pagesize' => array(
Expand Down
Loading

0 comments on commit b192551

Please sign in to comment.