Commit eff245b8 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Warn before deleting files attached to other artefacts

parent f23c29f9
......@@ -61,7 +61,9 @@ function pieform_element_filebrowser(Pieform $form, $element) {
$smarty->assign('path', array_reverse($path));
$smarty->assign('highlight', $element['highlight'][0]);
$smarty->assign('edit', !empty($element['edit']) ? $element['edit'] : -1);
$smarty->assign('browse', (int) $element['browse']);
if (isset($element['browse'])) {
$smarty->assign('browse', (int) $element['browse']);
}
$config = array_map('intval', $element['config']);
$smarty->assign('config', $config);
if ($config['select']) {
......@@ -157,8 +159,6 @@ function pieform_element_filebrowser_build_filelist($form, $element, $folder, $h
function pieform_element_filebrowser_get_value(Pieform $form, $element) {
log_debug($_POST);
// Check if the user tried to make a change to the filebrowser element
if ($form->is_submitted()) {
......@@ -640,6 +640,7 @@ function pieform_element_filebrowser_get_headdata($element) {
'editfolder',
'filewithnameexists',
'namefieldisrequired',
'detachfilewarning',
),
);
}
......
......@@ -204,9 +204,21 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
this.browse_init = function () {
if (self.config.edit) {
forEach(getElementsByTagAndClassName('button', null, 'filelist'), function (elem) {
if (getNodeAttribute(elem, 'name').match(/^edit\[\d+\]$/)) {
var name = getNodeAttribute(elem, 'name');
if (name.match(/^edit\[\d+\]$/)) {
connect(elem, 'onclick', self.edit_form);
}
else if (name.match(/^delete\[\d+\]$/)) {
var id = name.replace(/^delete\[(\d+)\]$/, '$1');
if (self.filedata[id].attachcount > 0) {
connect(elem, 'onclick', function (e) {
if (!confirm(get_string('detachfilewarning', self.filedata[id].attachcount))) {
e.stop();
return false;
}
});
}
}
});
connect(self.id + '_edit_cancel', 'onclick', function (e) {
e.stop();
......
......@@ -46,6 +46,7 @@ $string['deletefile?'] = 'Are you sure you want to delete this file?';
$string['deletefolder?'] = 'Are you sure you want to delete this folder?';
$string['Description'] = 'Description';
$string['destination'] = 'Destination';
$string['detachfilewarning'] = 'If you delete this file, it will be detached from %s other item(s) in your portfolio.';
$string['Download'] = 'Download';
$string['downloadfile'] = 'Download %s';
$string['downloadoriginalversion'] = 'Download the original version';
......@@ -97,7 +98,6 @@ $string['timeouterror'] = 'File upload failed: try uploading the file again';
$string['title'] = 'Name';
$string['titlefieldisrequired'] = 'The name field is required';
$string['Type'] = 'Type';
$string['unlinkthisfilefromblogposts?'] = 'This file is attached to one or more blog posts. If you delete the file, it will be removed from these posts.';
$string['upload'] = 'Upload';
$string['uploadagreement'] = 'Upload Agreement';
$string['uploadagreementdescription'] = 'Enable this option if you would like to force users to agree to the text below before they can upload a file to the site.';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment