Skip to content

Commit

Permalink
ENHANCEMENT: Files and images section warns if you are deleting a fil…
Browse files Browse the repository at this point in the history
…e that is linked to (from r96778)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@105678 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
chillu committed May 25, 2010
1 parent 8cea513 commit 1e51068
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
58 changes: 57 additions & 1 deletion javascript/AssetTableField.js
Expand Up @@ -111,4 +111,60 @@
}
});
});
}(jQuery));
}(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);
}
};
1 change: 1 addition & 0 deletions templates/Includes/AssetTableField_Item.ss
@@ -1,6 +1,7 @@
<tr id="record-$Parent.id-$ID"<% if HighlightClasses %> class="$HighlightClasses"<% end_if %>>
<td class="dragfile" id="drag-$Parent.Name-$ID">
<img id="drag-img-$Parent.Name-$ID" alt="Drag" title="<% _t('DRAGTOFOLDER','Drag to folder on left to move file') %>" src="sapphire/images/drag.gif" />
<span class="linkCount" style="display: none;">$BackLinkTrackingCount</span>
</div>
<% if Markable %><td class="markingcheckbox">$MarkingCheckbox</td><% end_if %>
<% control Fields %>
Expand Down

0 comments on commit 1e51068

Please sign in to comment.