Commit 03f77081 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Warn when deleting files attached to views; initial support for deleting non-empty folders


Signed-off-by: default avatarRichard Mansfield <richardm@catalyst.net.nz>
parent 0da65864
......@@ -248,9 +248,29 @@ function FileBrowser(idprefix, folderid, config, globalconfig) {
}
else if (name[1] == 'delete') {
var id = name[2];
var warn = '';
if (self.filedata[id].attachcount > 0) {
warn += get_string('fileattached', self.filedata[id].attachcount);
}
if (self.filedata[id].viewcount > 0) {
warn += ' ' + get_string('itemappearsinviews', self.filedata[id].viewcount);
}
if (self.filedata[id].artefacttype == 'folder') {
if (self.filedata[id].childcount > 0) {
warn += ' ' + get_string('foldernotempty');
warn += ' ' + get_string('confirmdeletefolderandcontents');
}
else if (warn != '') {
warn += ' ' + get_string('confirmdeletefolder');
}
}
else if (warn != '') {
warn += ' ' + get_string('confirmdeletefile');
}
if (warn != '') {
connect(elem, 'onclick', function (e) {
if (!confirm(get_string('detachfilewarning', self.filedata[id].attachcount))) {
if (!confirm(warn)) {
e.stop();
return false;
}
......
......@@ -40,6 +40,9 @@ $string['copyrightnotice'] = 'Copyright notice';
$string['create'] = 'Create';
$string['Created'] = 'Created';
$string['createfolder'] = 'Create folder';
$string['confirmdeletefile'] = 'Are you sure you want to delete this file?';
$string['confirmdeletefolder'] = 'Are you sure you want to delete this folder?';
$string['confirmdeletefolderandcontents'] = 'Are you sure you want to delete this folder and all its contents?';
$string['customagreement'] = 'Custom Agreement';
$string['Date'] = 'Date';
$string['defaultagreement'] = 'Default Agreement';
......@@ -49,7 +52,6 @@ $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';
......@@ -59,6 +61,7 @@ $string['emptyfolder'] = 'Empty folder';
$string['file'] = 'File'; // Capitalised to be consistent with names of all the other artefact types
$string['File'] = 'File';
$string['filealreadyindestination'] = 'The file you moved is already in that folder';
$string['fileattached'] = 'This file is attached to %s other item(s) in your portfolio.';
$string['files'] = 'files';
$string['Files'] = 'Files';
$string['fileexists'] = 'File exists';
......@@ -72,6 +75,7 @@ $string['filewithnameexists'] = 'A file or folder with the name "%s" already exi
$string['folder'] = 'Folder';
$string['Folder'] = 'Folder';
$string['Folders'] = 'Folders';
$string['foldernotempty'] = 'This folder is not empty.';
$string['foldercreated'] = 'Folder created';
$string['foldernamerequired'] = 'Please provide a name for the new folder.';
$string['gotofolder'] = 'Go to %s';
......@@ -80,6 +84,7 @@ $string['home'] = 'Home';
$string['htmlremovedmessage'] = 'You are viewing <strong>%s</strong> by <a href="%s">%s</a>. The file displayed below has been filtered to remove malicious content, and is only a rough representation of the original.';
$string['htmlremovedmessagenoowner'] = 'You are viewing <strong>%s</strong>. The file displayed below has been filtered to remove malicious content, and is only a rough representation of the original.';
$string['image'] = 'Image';
$string['itemappearsinviews'] = 'This item appears in %s of your views.';
$string['lastmodified'] = 'Last Modified';
$string['myfiles'] = 'My Files';
$string['Name'] = 'Name';
......
......@@ -118,11 +118,16 @@ class PluginArtefactFile extends PluginArtefact {
'remove',
),
'artefact.file' => array(
'detachfilewarning',
'confirmdeletefile',
'confirmdeletefolder',
'confirmdeletefolderandcontents',
'editfile',
'editfolder',
'fileattached',
'filewithnameexists',
'foldernamerequired',
'foldernotempty',
'itemappearsinviews',
'nametoolong',
'namefieldisrequired',
'uploadingfiletofolder',
......@@ -276,11 +281,12 @@ abstract class ArtefactTypeFileBase extends ArtefactType {
$select = '
SELECT
a.id, a.artefacttype, a.mtime, f.size, a.title, a.description,
COUNT(c.id) AS childcount, COUNT (aa.artefact) AS attachcount';
COUNT(DISTINCT c.id) AS childcount, COUNT (DISTINCT aa.artefact) AS attachcount, COUNT(DISTINCT va.view) AS viewcount';
$from = '
FROM {artefact} a
LEFT OUTER JOIN {artefact_file_files} f ON f.artefact = a.id
LEFT OUTER JOIN {artefact} c ON c.parent = a.id
LEFT OUTER JOIN {view_artefact} va ON va.artefact = a.id
LEFT OUTER JOIN {artefact_attachment} aa ON aa.attachment = a.id';
if (!empty($filters['artefacttype'])) {
......
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