Permalink
Browse files

MDL-32867 Display a list of references pointing to the file in filema…

…nager
  • Loading branch information...
marinaglancy committed May 15, 2012
1 parent 420e7bb commit 9dbdf31f8c1569af0bead5bf47a58d74acd2fb64
View
@@ -322,13 +322,18 @@ private function fm_js_template_message() {
* disabled if they are not applicable for the particular file;
*
* There may be present elements with classes 'fp-original', 'fp-datemodified', 'fp-datecreated',
- * 'fp-size', 'fp-dimensions'. They will receive additional class 'fp-unknown' if information
- * is unavailable. If there is information available, the content of embedded element
- * with class 'fp-value' will be substituted with the value;
+ * 'fp-size', 'fp-dimensions', 'fp-reflist'. They will receive additional class 'fp-unknown' if
+ * information is unavailable. If there is information available, the content of embedded
+ * element with class 'fp-value' will be substituted with the value;
*
* The value of Original ('fp-original') is loaded in separate request. When it is applicable
* but not yet loaded the 'fp-original' element receives additional class 'fp-loading';
*
+ * The value of 'Aliases/Shortcuts' ('fp-reflist') is also loaded in separate request. When it
+ * is applicable but not yet loaded the 'fp-original' element receives additional class
+ * 'fp-loading'. The string explaining that XX references exist will replace content of element
+ * 'fp-refcount'. Inside '.fp-reflist .fp-value' each reference will be enclosed in <li>;
+ *
* Elements with classes 'fp-file-update', 'fp-file-download', 'fp-file-delete', 'fp-file-zip',
* 'fp-file-unzip', 'fp-file-setmain' and 'fp-file-cancel' will hold corresponding onclick
* events (there may be several elements with class 'fp-file-cancel');
@@ -371,6 +376,8 @@ private function fm_js_template_fileselectlayout() {
<td class="mdl-left"><select></select></td></tr>
<tr class="{!}fp-original"><td class="mdl-right"><label>'.get_string('original', 'repository').'</label>:</td>
<td class="mdl-left"><span class="fp-originloading">'.$icon_progress.' '.$strloading.'</span><span class="fp-value"/></td></tr>
+ <tr class="{!}fp-reflist"><td class="mdl-right"><label>'.get_string('referenceslist', 'repository').'</label>:</td>
+ <td class="mdl-left"><p class="{!}fp-refcount"/><span class="fp-reflistloading">'.$icon_progress.' '.$strloading.'</span><ul class="fp-value"/></td></tr>
</table>
</form>
<p class="{!}fp-thumbnail"></p>
View
@@ -168,6 +168,8 @@
$string['popupblockeddownload'] = 'The downloading window is blocked, please allow the popup window, and try again.';
$string['preview'] = 'Preview';
$string['readonlyinstance'] = 'You cannot edit/delete a read-only instance';
+$string['referencesexist'] = 'There are {$a} alias/shortcut files that use this file as their source';
+$string['referenceslist'] = 'Aliases/Shortcuts';
$string['refresh'] = 'Refresh';
$string['refreshnonjsfilepicker'] = 'Please close this window and refresh non-javascript file picker';
$string['removed'] = 'Repository removed';
@@ -199,6 +201,7 @@
$string['upload'] = 'Upload this file';
$string['uploading'] = 'Uploading...';
$string['uploadsucc'] = 'The file has been uploaded successfully';
+$string['undisclosedreference'] = '(Undisclosed)';
$string['uselatestfile'] = 'Use latest file';
$string['usercontextrepositorydisabled'] = 'You cannot edit this repository in user context';
$string['usenonjsfilemanager'] = 'Open file manager in new window';
@@ -226,6 +226,20 @@ public function get_sortorder() {
return 0;
}
+ /**
+ * Returns the localised human-readable name of the file together with
+ * virtual path
+ *
+ * @return string
+ */
+ public function get_readable_fullname() {
+ $fpath = array();
+ for ($parent = $this; $parent; $parent = $parent->get_parent()) {
+ array_unshift($fpath, $parent->get_visible_name());
+ }
+ return join('/', $fpath);
+ }
+
/**
* Create new directory, may throw exception - make sure
* params are valid.
View
@@ -831,7 +831,7 @@ M.form_filemanager.init = function(Y, options) {
});
selectnode.all('.fp-author input, .fp-license select').set('disabled',(node.type == 'folder')?'disabled':'');
// display static information about a file (when known)
- var attrs = ['datemodified','datecreated','size','dimensions','original'];
+ var attrs = ['datemodified','datecreated','size','dimensions','original','reflist'];
for (var i in attrs) {
if (selectnode.one('.fp-'+attrs[i])) {
var value = (node[attrs[i]+'_f']) ? node[attrs[i]+'_f'] : (node[attrs[i]] ? node[attrs[i]] : '');
@@ -853,7 +853,7 @@ M.form_filemanager.init = function(Y, options) {
scope: this,
params: {'filepath':node.filepath,'filename':node.fullname},
callback: function(id, obj, args) {
- // check if we did not select another file yet
+ // check if we did not select another file meanwhile
var scope = args.scope;
if (scope.selectui.fileinfo && node &&
scope.selectui.fileinfo.filepath == node.filepath &&
@@ -869,6 +869,34 @@ M.form_filemanager.init = function(Y, options) {
}
}, false);
}
+ // load references list if applicable
+ selectnode.one('.fp-refcount').setContent(node.refcount ? M.util.get_string('referencesexist', 'repository', node.refcount) : '');
+ if (node.refcount && !node.reflist) {
+ selectnode.one('.fp-reflist').removeClass('fp-unknown').addClass('fp-loading');
+ this.request({
+ action: 'getreferences',
+ scope: this,
+ params: {'filepath':node.filepath,'filename':node.fullname},
+ callback: function(id, obj, args) {
+ // check if we did not select another file meanwhile
+ var scope = args.scope;
+ if (scope.selectui.fileinfo && node &&
+ scope.selectui.fileinfo.filepath == node.filepath &&
+ scope.selectui.fileinfo.fullname == node.fullname) {
+ selectnode.one('.fp-reflist').removeClass('fp-loading');
+ if (obj.references) {
+ node.reflist = '';
+ for (var i in obj.references) {
+ node.reflist += '<li>'+obj.references[i]+'</li>';
+ }
+ selectnode.one('.fp-reflist .fp-value').setContent(node.reflist);
+ } else {
+ selectnode.one('.fp-reflist .fp-value').setContent('');
+ }
+ }
+ }
+ }, false);
+ }
// show panel
this.selectui.show();
},
@@ -445,7 +445,8 @@ protected function find_module($component) {
array('nofilesattached', 'repository'), array('filepicker', 'repository'), array('logout', 'repository'),
array('nofilesavailable', 'repository'), array('norepositoriesavailable', 'repository'),
array('fileexistsdialogheader', 'repository'), array('fileexistsdialog_editor', 'repository'),
- array('fileexistsdialog_filemanager', 'repository'), array('renameto', 'repository')
+ array('fileexistsdialog_filemanager', 'repository'), array('renameto', 'repository'),
+ array('referencesexist', 'repository')
));
break;
case 'core_comment':
@@ -395,6 +395,34 @@
}
die;
+ case 'getreferences':
+ $filename = required_param('filename', PARAM_FILE);
+ $filepath = required_param('filepath', PARAM_PATH);
+
+ $fs = get_file_storage();
+ $file = $fs->get_file($user_context->id, 'user', 'draft', $draftid, $filepath, $filename);
+ if (!$file) {
+ echo json_encode(false);
+ } else {
+ $source = unserialize($file->get_source());
+ $return = array('filename' => $filename, 'filepath' => $filepath, 'references' => array());
+ $browser = get_file_browser();
+ if (isset($source->original)) {
+ $reffiles = $fs->search_references($source->original);
+ foreach ($reffiles as $reffile) {
+ $refcontext = get_context_instance_by_id($reffile->get_contextid());
+ $fileinfo = $browser->get_file_info($refcontext, $reffile->get_component(), $reffile->get_filearea(), $reffile->get_itemid(), $reffile->get_filepath(), $reffile->get_filename());
+ if (empty($fileinfo)) {
+ $return['references'][] = get_string('undisclosedreference', 'repository');
+ } else {
+ $return['references'][] = $fileinfo->get_readable_fullname();
+ }
+ }
+ }
+ echo json_encode((object)$return);
+ }
+ die;
+
default:
// no/unknown action?
echo json_encode(false);
@@ -291,6 +291,11 @@ a.ygtvspacer:hover {color: transparent;text-decoration: none;}
.filemanager.fp-select .fp-original .fp-originloading {display:none;}
.filemanager.fp-select .fp-original.fp-loading .fp-originloading {display:inline;}
+.filemanager.fp-select .fp-reflist.fp-unknown {display:none;}
+.filemanager.fp-select .fp-reflist .fp-reflistloading {display:none;}
+.filemanager.fp-select .fp-reflist.fp-loading .fp-reflistloading {display:inline;}
+.filemanager.fp-select .fp-reflist .fp-value {max-width:400px;max-height:50px;overflow:auto;}
+
/*
* Create folder dialogue (File Manager only)
*/

0 comments on commit 9dbdf31

Please sign in to comment.