Skip to content

Commit

Permalink
ENHANCEMENT Allow selection of items in GridField (via JavaScript only)
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Feb 8, 2012
1 parent 5a3242c commit 4126b95
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 10 deletions.
2 changes: 2 additions & 0 deletions css/GridField.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 54 additions & 8 deletions javascript/GridField.js
@@ -1,4 +1,16 @@
jQuery(function($){

$('fieldset.ss-gridfield').entwine({
getItems: function() {
return this.find('.ss-gridfield-item');
}
});

$('fieldset.ss-gridfield *').entwine({
getGridField: function() {
return this.parents('fieldset.ss-gridfield:first');
}
});

$('fieldset.ss-gridfield .action').entwine({
onclick: function(e){
Expand Down Expand Up @@ -26,13 +38,6 @@ jQuery(function($){
}
});

var removeFilterButtons = function() {
// Remove stuff
$('th').children('div').each(function(i,v) {
$(v).remove();
});
}

/*
* Upon focusing on a filter <input> element, move "filter" and "reset" buttons and display next to the current <input> element
* ToDo ensure filter-button state is maintained after filtering (see resetState param)
Expand All @@ -46,8 +51,10 @@ jQuery(function($){
return false;
}
var eleInput = $(this);

// Remove existing <div> and <button> elements in-lieu of cloning
removeFilterButtons();
this.getGridField().find('th > div').each(function(i,v) {$(v).remove();});

var eleButtonSetFilter = $('#action_filter');
var eleButtonResetFilter = $('#action_reset');
// Retain current widths to ensure <th>'s don't shift widths
Expand All @@ -71,4 +78,43 @@ jQuery(function($){
}
});

/**
* Allows selection of one or more rows in the grid field.
* Purely clientside at the moment.
*/
$('fieldset.ss-gridfield[data-selectable]').entwine({
/**
* @return {jQuery} Collection
*/
getSelectedItems: function() {
return this.find('.ss-gridfield-item.ui-selected');
},
/**
* @return {Array} Of record IDs
*/
getSelectedIDs: function() {
return $.map(this.getSelectedItems(), function(el) {return $(el).data('id');});
}
});
$('fieldset.ss-gridfield[data-selectable] .ss-gridfield-items').entwine({
onmatch: function() {
this._super();

// TODO Limit to single selection
this.selectable();
},
onunmatch: function() {
this._super();
this.selectable('destroy');
}

});

$('fieldset.ss-gridfield[data-multiselect] .ss-gridfield-item').entwine({
onclick: function() {
// this.siblings('selected');
this._super();
}
});

});
17 changes: 15 additions & 2 deletions scss/GridField.scss
Expand Up @@ -31,9 +31,22 @@ $gf_border_radius: 7px;
}

.cms {
fieldset.ss-gridfield>div {
margin-bottom: 35px;
fieldset.ss-gridfield {
& > div {
margin-bottom: 35px;
}

&[data-selectable] {
tr.ui-selected, tr.ui-selecting {
background: #FFFAD6 !important;
}

td {
cursor: pointer;
}
}
}

table.ss-gridfield.field {
box-shadow: none;
padding: 0;
Expand Down

0 comments on commit 4126b95

Please sign in to comment.