From a415034d0af04bee922c0f2934c449e607fcd3f2 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 1 Mar 2012 00:19:22 +0100 Subject: [PATCH] MINOR Changed GridField.js edit click behaviour from event-based to an (subclassable) method class, which means it works outside of the CMS by default. Making the whole row active in case an edit link is present --- admin/javascript/LeftAndMain.js | 10 ++++++++++ javascript/GridField.js | 27 ++++++++++++++++++++++++--- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/admin/javascript/LeftAndMain.js b/admin/javascript/LeftAndMain.js index 7622ec2c2..c1eee5bfe 100644 --- a/admin/javascript/LeftAndMain.js +++ b/admin/javascript/LeftAndMain.js @@ -381,6 +381,16 @@ jQuery.noConflict(); }); }); + /** + * Overload the default GridField behaviour (open a new URL in the browser) + * with the CMS-specific ajax loading. + */ + $('.cms .ss-gridfield').entwine({ + showDetailView: function(url) { + $('.cms-container').entwine('ss').loadPanel(url); + } + }); + $('.cms-filter-form').entwine({ GridField: null, diff --git a/javascript/GridField.js b/javascript/GridField.js index 2c474324e..b0e57b9fd 100644 --- a/javascript/GridField.js +++ b/javascript/GridField.js @@ -34,6 +34,9 @@ } }, ajaxOpts)); }, + showDetailView: function(url) { + window.location.href = url; + }, getItems: function() { return this.find('.ss-gridfield-item'); }, @@ -59,6 +62,24 @@ return this.closest('.ss-gridfield'); } }); + + $('.ss-gridfield .ss-gridfield-item').entwine({ + onclick: function(e) { + if($(e.target).is('.action')) { + this._super(e); + return; + } + + var editLink = this.find('.edit-link'); + if(editLink.length) this.getGridField().showDetailView(editLink.prop('href')); + }, + onmouseover: function() { + if(this.find('.edit-link').length) this.css('cursor', 'pointer'); + }, + onmouseout: function() { + this.css('cursor', 'default'); + } + }); $('.ss-gridfield .action').entwine({ onclick: function(e){ @@ -67,7 +88,7 @@ } }); - $('.ss-gridfield .action-deleterecord').entwine({ + $('.ss-gridfield .gridfield-button-delete').entwine({ onclick: function(e){ if(!confirm(ss.i18n._t('TABLEFIELD.DELETECONFIRMMESSAGE'))) return false; else this._super(e); @@ -76,14 +97,14 @@ $('fieldset.ss-gridfield .new-link').entwine({ onclick: function(e) { - $(this).trigger('opennewview', $(this).prop('href')); + this.getGridField().showDetailView($(this).prop('href')); return false; } }); $('fieldset.ss-gridfield .edit-link').entwine({ onclick: function(e) { - $(this).trigger('openeditview', $(this).prop('href')); + this.getGridField().showDetailView($(this).prop('href')); return false; } });