Permalink
Browse files

MINOR JS interactions for pagination, sortable headers, and filtering

  • Loading branch information...
1 parent bff3220 commit 9fc948f7896b39e4b46e88134b1f3c4bc69452b1 Jean-Fabien committed Dec 15, 2011
View
3 forms/gridfield/GridFieldFilter.php
@@ -20,7 +20,6 @@ public function __construct(GridField $gridField) {
$cols = $gridField->DisplayFields;
foreach ($cols as $col) {
$this->filterFields[] = $field = new TextField('SetFilter'.$col, $col);
- $field->addExtraClass('ss-gridfield-button');
$this->push($field);
}
}
@@ -49,11 +48,13 @@ function getChildContent() {
}
$setFilter = new GridField_AlterAction($grid, 'SetFilter', 'Filter');
+ $setFilter->addExtraClass('ss-gridfield-button');
$setFilter->stateChangeOnTrigger(array('Filter.SetFilter'=>1));
$setFilter->applyStateFromFieldsOnTrigger('Filter.Criteria', $this->filterFields);
$resetFilter = new GridField_AlterAction($grid, 'ResetFilter', 'Reset');
$resetFilter->stateChangeOnTrigger(array('Filter.ResetFilter'=>1));
+ $resetFilter->addExtraClass('ss-gridfield-button');
$filterFields.= '<tr><th colspan="'.max(1, count($grid->DisplayFields) - 2).'"></th>';
$filterFields.= '<th>'.$setFilter->forTemplate().'</th>';
$filterFields.= '<th>'.$resetFilter->forTemplate().'</th>';
View
8 forms/gridfield/GridFieldPaginator.php
@@ -11,12 +11,10 @@
class GridFieldPaginator extends GridFieldElement {
static $location = 'foot';
- /** @var string */
- protected $template = 'GridFieldPaginator';
-
/** @param GridField $gridField */
public function __construct(GridField $gridField) {
- Requirements::javascript('sapphire/javascript/GridFieldPaginator.js');
+ Requirements::javascript(SAPPHIRE_DIR.'/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
+ Requirements::javascript(SAPPHIRE_DIR.'/javascript/GridField.js');
parent::__construct($gridField, 'GridFieldPaginator');
}
@@ -30,7 +28,7 @@ function generateChildren() {
$field->stateChangeOnTrigger(array(
'Pagination.Page' => $idx
));
-
+ $field->addExtraClass('ss-gridfield-button');
$this->push($field);
}
}
View
4 forms/gridfield/GridFieldSortableHeader.php
@@ -4,6 +4,8 @@ class GridFieldSortableHeader extends GridFieldElement {
static $location = 'head';
function __construct($gridField) {
+ Requirements::javascript(SAPPHIRE_DIR.'/thirdparty/jquery-entwine/dist/jquery.entwine-dist.js');
+ Requirements::javascript(SAPPHIRE_DIR.'/javascript/GridField.js');
parent::__construct($gridField, 'GridFieldSortableHeader');
}
@@ -17,7 +19,7 @@ function generateChildren() {
$field->stateChangeOnTrigger(array(
'Sorting.Order' => array($col => $state->Sorting->getToggledOrder($col))
));
-
+ $field->addExtraClass('ss-gridfield-button');
$this->push($field);
}
}
View
25 javascript/GridField.js
@@ -0,0 +1,25 @@
+jQuery(function($){
+
+ $('.ss-gridfield-button').entwine({
+ onclick: function(e){
+ button = this;
+ e.preventDefault();
+ var form = $(this).closest("form");
+ form.addClass('loading');
+ $.ajax({
+ type: "POST",
+ url: form.attr('action'),
+ data: form.serialize()+'&'+escape(button.attr('name'))+'='+escape(button.val()),
+ dataType: 'html',
+ success: function(data) {
+ form.replaceWith(data);
+ form.removeClass('loading');
+ },
+ error: function(e) {
+ alert(ss.i18n._t('GRIDFIELD.ERRORINTRANSACTION', 'An error occured while fecthing data from the server\n Please try again later.'));
+ form.removeClass('loading');
+ }
+ });
+ }
+ });
+});
View
30 javascript/GridFieldPaginator.js
@@ -1,30 +0,0 @@
-jQuery(function($){
-
- var onGridClick = function(){
- var form = $(this).closest("form");
- var gridField = $(this).closest(".ss-gridfield");
- $(this).addClass('loading');
- $.ajax({
- type: "POST",
- url: form.attr('action')+'/field/'+gridField.attr('id'),
- data: form.serialize()+"&page="+$(this).attr('value'),
- success: function(data) {
- $(gridField).replaceWith(data);
- gridInit();
- },
- error: function() {
- alert('There seems like there where some failure when trying to fetch the page, please reload and try again.');
- }
-
- });
-
- return false;
- }
-
- var gridInit = function() {
- $('.ss-gridfield-pagination-button').click(onGridClick);
- }
-
- gridInit();
-
-});
View
3 javascript/lang/en_US.js
@@ -15,6 +15,7 @@ if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
'FILEIFRAMEFIELD.UNATTACHFILE': 'Un-Attach File',
'FILEIFRAMEFIELD.DELETEIMAGE': 'Delete Image',
'FILEIFRAMEFIELD.CONFIRMDELETE': 'Are you sure you want to delete this file?',
- 'LeftAndMain.IncompatBrowserWarning': 'Your browser is not compatible with the CMS interface. Please use Internet Explorer 7+, Google Chrome 10+ or Mozilla Firefox 3.5+.'
+ 'LeftAndMain.IncompatBrowserWarning': 'Your browser is not compatible with the CMS interface. Please use Internet Explorer 7+, Google Chrome 10+ or Mozilla Firefox 3.5+.',
+ 'GRIDFIELD.ERRORINTRANSACTION': 'An error occured while fecthing data from the server\n Please try again later.'
});
}
View
3 javascript/lang/fr_FR.js
@@ -10,6 +10,7 @@ if(typeof(ss) == 'undefined' || typeof(ss.i18n) == 'undefined') {
'UNIQUEFIELD.ENTERNEWVALUE': 'You devez saisir une nouvelle valeur pou ce champ',
'UNIQUEFIELD.CANNOTLEAVEEMPTY': 'Ce champ ne peut être laissé vide',
'RESTRICTEDTEXTFIELD.CHARCANTBEUSED': "Le character '%s' ne peut être utilisé dans ce champ",
- 'UPDATEURL.CONFIRM': 'Voulez-vous que je change l\'URL en:\n\n%s/\n\nCliquez Ok pour changer l\'URL, cliquez Annuler pour la laisser à:\n\n%s'
+ 'UPDATEURL.CONFIRM': 'Voulez-vous que je change l\'URL en:\n\n%s/\n\nCliquez Ok pour changer l\'URL, cliquez Annuler pour la laisser à:\n\n%s',
+ 'GRIDFIELD.ERRORINTRANSACTION': 'Une erreur est survenue durant la transaction avec le serveur\n Merci de reesayer plus tard.'
});
}

0 comments on commit 9fc948f

Please sign in to comment.