<script type="text/javascript">
{literal}
- function hideStatusAttachment( divName ) {
- cj( divName ).hide( );
- }
-
- function showDeleteAttachment( fileName, postURLData, fileID, divName, divFile ) {
- var confirmMsg = '{/literal}{ts escape="js"}Are you sure you want to delete attachment: {/ts}{literal}' + fileName + ' <a href="#" onclick="deleteAttachment( \'' + postURLData + '\',' + fileID + ',\'' + divName + '\', \'' + divFile + '\' ); return false;" style="text-decoration: underline;">{/literal}{ts escape='js'}Yes{/ts}{literal}</a> <a href="#" onclick="hideStatusAttachment( divName ); return false;" style="text-decoration: underline;">{/literal}{ts escape='js'}No{/ts}{literal}</a>';
- cj( divName ).show( ).html( confirmMsg );
- }
-
- function deleteAttachment( postURLData, fileID, divName, divFile ) {
- var postUrl = {/literal}"{crmURL p='civicrm/file/delete' h=0 }"{literal};
- cj.ajax({
- type: "GET",
- data: postURLData,
- url: postUrl,
- success: function(html){
- var resourceBase = {/literal}"{$config->resourceBase}"{literal};
- var successMsg = '{/literal}{ts escape="js"}The selected attachment has been deleted.{/ts}{literal} <a href="#" onclick="hideStatusAttachment( \'' + divName + '\'); return false;"><img title="{/literal}{ts escape='js'}close{/ts}{literal}" src="' +resourceBase+'i/close.png"/></a>';
- cj( divFile ).hide( );
- cj( divName ).show( ).html( successMsg );
- }
+ cj(function($) {
+ $('a.delete-attachment').click(function() {
+ var $el = $(this),
+ $row = $el.closest('.crm-attachment-wrapper'),
+ msg = '{/literal}{ts escape="js" 1="%1"}This will immediately delete the file %1. This action cannot be undone.{/ts}{literal}';
+ CRM.confirm(null, {
+ title: $el.attr('title'),
+ message: ts(msg, {1: '<em>' + $el.data('filename') + '</em>'})
+ }).on('crmConfirmYes', function() {
+ var postUrl = {/literal}"{crmURL p='civicrm/file/delete' h=0 }"{literal};
+ var request = $.post(postUrl, $el.data('args'));
+ CRM.status({success: '{/literal}{ts escape="js"}Removed{/ts}{literal}'}, request);
+ request.done(function() {
+ $row.remove();
+ });
+ });
+ return false;
});
- }
+ });
{/literal}
</script>