From 1e510684a3c949311e1d2d611035932a296e2c0e Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 25 May 2010 23:38:34 +0000 Subject: [PATCH] ENHANCEMENT: Files and images section warns if you are deleting a file that is linked to (from r96778) git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@105678 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- javascript/AssetTableField.js | 58 +++++++++++++++++++++- templates/Includes/AssetTableField_Item.ss | 1 + 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/javascript/AssetTableField.js b/javascript/AssetTableField.js index 025a9b23..4966ea6c 100644 --- a/javascript/AssetTableField.js +++ b/javascript/AssetTableField.js @@ -111,4 +111,60 @@ } }); }); -}(jQuery)); \ No newline at end of file +}(jQuery)); + +// TODO Implementation in Behaviour instead of entwine is necessary to overload TableListField +var AssetTableField = Class.create(); +AssetTableField.applyTo('#Form_EditForm_Files'); +AssetTableField.prototype = { + initialize: function() { + var rules = {}; + rules['#'+this.id+' table.data a.deletelink'] = {onclick: this.deleteRecord.bind(this)}; + Behaviour.register('ComplexTableField_'+this.id,rules); + }, + + deleteRecord: function(e) { + var img = Event.element(e); + var link = Event.findElement(e,"a"); + var row = Event.findElement(e,"tr"); + + var linkCount = row.getElementsByClassName('linkCount')[0]; + if(linkCount) linkCount = linkCount.innerHTML; + + var confirmMessage = ss.i18n._t('TABLEFIELD.DELETECONFIRMMESSAGE', 'Are you sure you want to delete this record?'); + if(linkCount && linkCount > 0) confirmMessage += '\nThere are ' + linkCount + ' page(s) that use this file, please review the list of pages on the Links tab of the file before continuing.'; + + // TODO ajaxErrorHandler and loading-image are dependent on cms, but formfield is in sapphire + var confirmed = confirm(confirmMessage); + if(confirmed) + { + img.setAttribute("src",'cms/images/network-save.gif'); // TODO doesn't work + new Ajax.Request( + link.getAttribute("href"), + { + method: 'post', + postBody: 'forceajax=1' + ($('SecurityID') ? '&SecurityID=' + $('SecurityID').value : ''), + onComplete: function(){ + Effect.Fade( + row, + { + afterFinish: function(obj) { + // remove row from DOM + obj.element.parentNode.removeChild(obj.element); + // recalculate summary if needed (assumes that TableListField.js is present) + // TODO Proper inheritance + if(this._summarise) this._summarise(); + // custom callback + if(this.callback_deleteRecord) this.callback_deleteRecord(e); + }.bind(this) + } + ); + }.bind(this), + onFailure: this.ajaxErrorHandler + } + ); + } + + Event.stop(e); + } +}; \ No newline at end of file diff --git a/templates/Includes/AssetTableField_Item.ss b/templates/Includes/AssetTableField_Item.ss index e90ecc9e..4a65b629 100644 --- a/templates/Includes/AssetTableField_Item.ss +++ b/templates/Includes/AssetTableField_Item.ss @@ -1,6 +1,7 @@ class="$HighlightClasses"<% end_if %>> Drag + <% if Markable %>$MarkingCheckbox<% end_if %> <% control Fields %>