1 // This file is part of Moodle - http://moodle.org/
3 // Moodle is free software: you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation, either version 3 of the License, or
6 // (at your option) any later version.
8 // Moodle is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * this.api, stores the URL to make ajax request
21 * this.filepicker_options
22 * this.movefile_dialog
26 * this.filecount, how many files in this filemanager
29 * this.filemanager, contains reference to filemanager Node
30 * this.selectnode, contains referenct to select-file Node
31 * this.selectui, YUI Panel to select the file
33 * FileManager options:
35 * this.options.currentpath
40 M.form_filemanager = {templates:{}};
42 M.form_filemanager.set_templates = function(Y, templates) {
43 M.form_filemanager.templates = templates;
47 * This fucntion is called for each file picker on page.
49 M.form_filemanager.init = function(Y, options) {
50 var FileManagerHelper = function(options) {
51 FileManagerHelper.superclass.constructor.apply(this, arguments);
53 FileManagerHelper.NAME = "FileManager";
54 FileManagerHelper.ATTRS = {
59 Y.extend(FileManagerHelper, Y.Base, {
60 api: M.cfg.wwwroot+'/repository/draftfiles_ajax.php',
62 initializer: function(options) {
63 this.options = options;
64 if (options.mainfile) {
65 this.enablemainfile = options.mainfile;
67 this.client_id = options.client_id;
68 this.currentpath = '/';
69 this.maxfiles = options.maxfiles;
70 this.maxbytes = options.maxbytes;
71 this.emptycallback = null; // Used by drag and drop upload
73 this.filepicker_options = options.filepicker?options.filepicker:{};
74 this.filepicker_options.client_id = this.client_id;
75 this.filepicker_options.context = options.context;
76 this.filepicker_options.maxfiles = this.maxfiles;
77 this.filepicker_options.maxbytes = this.maxbytes;
78 this.filepicker_options.env = 'filemanager';
79 this.filepicker_options.itemid = options.itemid;
81 if (options.filecount) {
82 this.filecount = options.filecount;
86 // prepare filemanager for drag-and-drop upload
87 this.filemanager = Y.one('#filemanager-'+options.client_id);
88 if (this.filemanager.hasClass('filemanager-container') || !this.filemanager.one('.filemanager-container')) {
89 this.dndcontainer = this.filemanager;
91 this.dndcontainer = this.filemanager.one('.filemanager-container');
92 if (!this.dndcontainer.get('id')) {
93 this.dndcontainer.generateID();
96 // save template for one path element and location of path bar
97 if (this.filemanager.one('.fp-path-folder')) {
98 this.pathnode = this.filemanager.one('.fp-path-folder');
99 this.pathbar = this.pathnode.get('parentNode');
100 this.pathbar.removeChild(this.pathnode);
102 // initialize 'select file' panel
103 this.selectnode = Y.Node.create(M.form_filemanager.templates.fileselectlayout);
104 this.selectnode.generateID();
105 Y.one(document.body).appendChild(this.selectnode);
106 this.selectui = new Y.Panel({
107 srcNode : this.selectnode,
114 this.selectui.plug(Y.Plugin.Drag,{handles:['#'+this.selectnode.get('id')+' .yui3-widget-hd']});
115 this.selectui.hide();
116 this.setup_select_file();
117 // setup buttons onclick events
118 this.setup_buttons();
119 // set event handler for lazy loading of thumbnails
120 this.filemanager.one('.fp-content').on(['scroll','resize'], this.content_scrolled, this);
122 this.viewmode = 1; // TODO take from cookies?
123 this.filemanager.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').removeClass('checked')
124 this.filemanager.all('.fp-vb-icons').addClass('checked')
125 this.refresh(this.currentpath); // MDL-31113 get latest list from server
129 this.filemanager.addClass('fm-updating');
131 request: function(args, redraw) {
132 var api = this.api + '?action='+args.action;
136 scope = args['scope'];
138 params['sesskey'] = M.cfg.sesskey;
139 params['client_id'] = this.client_id;
140 params['filepath'] = this.currentpath;
141 params['itemid'] = this.options.itemid?this.options.itemid:0;
142 if (args['params']) {
143 for (i in args['params']) {
144 params[i] = args['params'][i];
150 complete: function(id,o,p) {
157 data = Y.JSON.parse(o.responseText);
159 // TODO display error
160 scope.print_msg(M.str.repository.invalidjson, 'error');
161 //scope.display_error(M.str.repository.invalidjson+'<pre>'+stripHTML(o.responseText)+'</pre>', 'invalidjson')
164 if (data && data.tree && scope.set_current_tree) {
165 scope.set_current_tree(data.tree);
167 args.callback(id,data,p);
174 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
175 'User-Agent': 'MoodleFileManager/3.0'
177 data: build_querystring(params)
180 cfg.form = args.form;
187 filepicker_callback: function(obj) {
189 this.check_buttons();
190 this.refresh(this.currentpath);
191 if (typeof M.core_formchangechecker != 'undefined') {
192 M.core_formchangechecker.set_form_changed();
195 check_buttons: function() {
196 if (this.filecount>0) {
197 this.filemanager.removeClass('fm-nofiles');
199 this.filemanager.addClass('fm-nofiles');
201 if (this.filecount >= this.maxfiles && this.maxfiles!=-1) {
202 this.filemanager.addClass('fm-maxfiles');
205 this.filemanager.removeClass('fm-maxfiles');
208 refresh: function(filepath) {
210 this.currentpath = filepath;
212 filepath = this.currentpath;
214 this.currentpath = filepath;
219 params: {'filepath':filepath},
220 callback: function(id, obj, args) {
221 scope.filecount = obj.filecount;
222 scope.check_buttons();
224 scope.lazyloading = {};
229 /** displays message in a popup */
230 print_msg: function(msg, type) {
231 var header = M.str.moodle.error;
232 if (type != 'error') {
233 type = 'info'; // one of only two types excepted
234 header = M.str.moodle.info;
237 var node = Y.Node.create(M.form_filemanager.templates.message);
238 this.filemanager.appendChild(node);
240 this.msg_dlg = new Y.Panel({
248 this.msg_dlg.plug(Y.Plugin.Drag,{handles:['.yui3-widget-hd']});
249 node.one('.fp-msg-butok').on('click', function(e) {
255 this.msg_dlg.set('headerContent', header);
256 this.filemanager.one('.fp-msg').removeClass('fp-msg-info').removeClass('fp-msg-error').addClass('fp-msg-'+type)
257 this.filemanager.one('.fp-msg .fp-msg-text').setContent(msg);
260 setup_buttons: function() {
261 var button_download = this.filemanager.one('.fp-btn-download');
262 var button_create = this.filemanager.one('.fp-btn-mkdir');
263 var button_addfile = this.filemanager.one('.fp-btn-add');
265 // setup 'add file' button
266 // if maxfiles == -1, the no limit
267 button_addfile.on('click', function(e) {
269 var options = this.filepicker_options;
270 options.formcallback = this.filepicker_callback;
271 // XXX: magic here, to let filepicker use filemanager scope
272 options.magicscope = this;
273 options.savepath = this.currentpath;
274 M.core_filepicker.show(Y, options);
277 // setup 'make a folder' button
278 if (this.options.subdirs) {
279 button_create.on('click',function(e) {
282 // a function used to perform an ajax request
283 var perform_action = function(e) {
285 var foldername = Y.one('#fm-newname-'+scope.client_id).get('value');
287 scope.mkdir_dialog.hide();
292 params: {filepath:scope.currentpath, newdirname:foldername},
293 callback: function(id, obj, args) {
294 var filepath = obj.filepath;
295 scope.mkdir_dialog.hide();
296 scope.refresh(filepath);
297 Y.one('#fm-newname-'+scope.client_id).set('value', '');
298 if (typeof M.core_formchangechecker != 'undefined') {
299 M.core_formchangechecker.set_form_changed();
304 if (!this.mkdir_dialog) {
305 var node = Y.Node.create(M.form_filemanager.templates.mkdir);
306 this.filemanager.appendChild(node);
307 this.mkdir_dialog = new Y.Panel({
315 this.mkdir_dialog.plug(Y.Plugin.Drag,{handles:['.yui3-widget-hd']});
316 node.one('.fp-dlg-butcreate').on('click', perform_action, this);
317 node.one('input').set('id', 'fm-newname-'+this.client_id).
318 on('keydown', function(e){
319 if (e.keyCode == 13) {Y.bind(perform_action, this)(e);}
321 node.all('.fp-dlg-butcancel').on('click', function(e){e.preventDefault();this.mkdir_dialog.hide();}, this);
322 node.all('.fp-dlg-curpath').set('id', 'fm-curpath-'+this.client_id);
324 this.mkdir_dialog.show();
325 Y.one('#fm-newname-'+scope.client_id).focus();
326 Y.all('#fm-curpath-'+scope.client_id).setContent(this.currentpath)
329 this.filemanager.addClass('fm-nomkdir');
332 // setup 'download this folder' button
333 // NOTE: popup window must be enabled to perform download process
334 button_download.on('click',function(e) {
337 // perform downloaddir ajax request
339 action: 'downloaddir',
341 callback: function(id, obj, args) {
343 scope.refresh(obj.filepath);
344 var win = window.open(obj.fileurl, 'fm-download-folder');
346 scope.print_msg(M.str.repository.popupblockeddownload, 'error');
349 scope.print_msg(M.str.repository.draftareanofiles, 'error');
355 this.filemanager.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').
356 on('click', function(e) {
358 var viewbar = this.filemanager.one('.fp-viewbar')
359 if (!viewbar || !viewbar.hasClass('disabled')) {
360 this.filemanager.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').removeClass('checked')
361 if (e.currentTarget.hasClass('fp-vb-tree')) {
363 } else if (e.currentTarget.hasClass('fp-vb-details')) {
368 e.currentTarget.addClass('checked')
370 //Y.Cookie.set('recentviewmode', this.viewmode);
374 print_path: function() {
375 var p = this.options.path;
376 this.pathbar.setContent('').addClass('empty');
377 if (p && p.length!=0 && this.viewmode != 2) {
378 for(var i = 0; i < p.length; i++) {
379 var el = this.pathnode.cloneNode(true);
380 this.pathbar.appendChild(el);
383 el.addClass('first');
385 if (i == p.length-1) {
394 el.one('.fp-path-folder-name').setContent(p[i].name).
395 on('click', function(e, path) {
400 this.pathbar.removeClass('empty');
403 get_filepath: function(obj) {
404 if (obj.path && obj.path.length) {
405 return obj.path[obj.path.length-1].path;
409 treeview_dynload: function(node, cb) {
410 var retrieved_children = {};
412 for (var i in node.children) {
413 retrieved_children[node.children[i].path] = node.children[i];
416 if (!node.path || node.path == '/') {
417 // this is a root pseudo folder
418 node.fileinfo.filepath = '/';
419 node.fileinfo.type = 'folder';
420 node.fileinfo.fullname = node.fileinfo.title;
421 node.fileinfo.filename = '.';
425 params: {filepath:node.path?node.path:''},
427 callback: function(id, obj, args) {
429 var scope = args.scope;
430 // check that user did not leave the view mode before recieving this response
431 if (!(scope.viewmode == 2 && node && node.getChildrenEl())) {
434 if (cb != null) { // (in manual mode do not update current path)
436 scope.currentpath = node.path?node.path:'/';
438 node.highlight(false);
439 node.origlist = obj.list ? obj.list : null;
440 node.origpath = obj.path ? obj.path : null;
443 if (list[k].type == 'folder' && retrieved_children[list[k].filepath]) {
444 // if this child is a folder and has already been retrieved
445 retrieved_children[list[k].filepath].fileinfo = list[k];
446 node.children[node.children.length] = retrieved_children[list[k].filepath];
448 // append new file to the list
449 scope.view_files([list[k]]);
455 // invoke callback requested by TreeView component
458 scope.content_scrolled();
462 content_scrolled: function(e) {
463 setTimeout(Y.bind(function() {
464 if (this.processingimages) {return;}
465 this.processingimages = true;
467 fpcontent = this.filemanager.one('.fp-content'),
468 fpcontenty = fpcontent.getY(),
469 fpcontentheight = fpcontent.getStylePx('height'),
470 is_node_visible = function(node) {
471 var offset = node.getY()-fpcontenty;
472 if (offset <= fpcontentheight && (offset >=0 || offset+node.getStylePx('height')>=0)) {
477 // replace src for visible images that need to be lazy-loaded
478 if (scope.lazyloading) {
479 fpcontent.all('img').each( function(node) {
480 if (node.get('id') && scope.lazyloading[node.get('id')] && is_node_visible(node)) {
481 node.set('src', scope.lazyloading[node.get('id')]);
482 delete scope.lazyloading[node.get('id')];
486 this.processingimages = false;
489 view_files: function(appendfiles) {
490 this.filemanager.removeClass('fm-updating').removeClass('fm-noitems');
491 if ((appendfiles == null) && (!this.options.list || this.options.list.length == 0) && this.viewmode != 2) {
492 this.filemanager.addClass('fm-noitems');
495 var list = (appendfiles != null) ? appendfiles : this.options.list;
496 var element_template;
497 if (this.viewmode == 2 || this.viewmode == 3) {
498 element_template = Y.Node.create(M.form_filemanager.templates.listfilename);
501 element_template = Y.Node.create(M.form_filemanager.templates.iconfilename);
504 viewmode : this.viewmode,
505 appendonly : appendfiles != null,
506 filenode : element_template,
507 callbackcontext : this,
508 callback : function(e, node) {
509 if (e.preventDefault) { e.preventDefault(); }
510 if (node.type == 'folder') {
511 this.refresh(node.filepath);
513 this.select_file(node);
516 rightclickcallback : function(e, node) {
517 if (e.preventDefault) { e.preventDefault(); }
518 this.select_file(node);
520 classnamecallback : function(node) {
522 if (node.type == 'folder' || (!node.type && !node.filename)) {
523 classname = classname + ' fp-folder';
525 if (node.filename || node.filepath || (node.path && node.path != '/')) {
526 classname = classname + ' fp-hascontextmenu';
529 classname = classname + ' fp-isreference';
532 classname = classname + ' fp-hasreferences';
534 if (node.sortorder == 1) { classname = classname + ' fp-mainfile';}
535 return Y.Lang.trim(classname);
538 if (this.viewmode == 2) {
539 options.dynload = true;
540 options.filepath = this.options.path;
541 options.treeview_dynload = this.treeview_dynload;
542 options.norootrightclick = true;
543 options.callback = function(e, node) {
544 // TODO MDL-32736 e is not an event here but an object with properties 'event' and 'node'
545 if (!node.fullname) {return;}
546 if (node.type != 'folder') {
547 if (e.node.parent && e.node.parent.origpath) {
548 // set the current path
549 this.options.path = e.node.parent.origpath;
550 this.options.list = e.node.parent.origlist;
553 this.currentpath = node.filepath;
554 this.select_file(node);
556 // save current path and filelist (in case we want to jump to other viewmode)
557 this.options.path = e.node.origpath;
558 this.options.list = e.node.origlist;
559 this.currentpath = node.filepath;
561 //this.content_scrolled();
565 if (!this.lazyloading) {
568 this.filemanager.one('.fp-content').fp_display_filelist(options, list, this.lazyloading);
569 this.content_scrolled();
571 populate_licenses_select: function(node) {
576 var licenses = this.options.licenses;
577 for (var i in licenses) {
578 var option = Y.Node.create('<option/>').
579 set('value', licenses[i].shortname).
580 setContent(licenses[i].fullname);
581 node.appendChild(option)
584 set_current_tree: function(tree) {
585 var appendfilepaths = function(list, node) {
586 if (!node || !node.children || !node.children.length) {return;}
587 for (var i in node.children) {
588 list[list.length] = node.children[i].filepath;
589 appendfilepaths(list, node.children[i]);
593 appendfilepaths(list, tree);
594 var selectnode = this.selectnode;
595 node = selectnode.one('.fp-path select');
597 for (var i in list) {
598 node.appendChild(Y.Node.create('<option/>').
599 set('value', list[i]).setContent(list[i]))
602 update_file: function(confirmed) {
603 var selectnode = this.selectnode;
604 var fileinfo = this.selectui.fileinfo;
606 var newfilename = Y.Lang.trim(selectnode.one('.fp-saveas input').get('value'));
607 var filenamechanged = (newfilename && newfilename != fileinfo.fullname);
608 var pathselect = selectnode.one('.fp-path select'),
609 pathindex = pathselect.get('selectedIndex'),
610 targetpath = pathselect.get("options").item(pathindex).get('value');
611 var filepathchanged = (targetpath != this.get_parent_folder_name(fileinfo));
612 var newauthor = Y.Lang.trim(selectnode.one('.fp-author input').get('value'));
613 var authorchanged = (newauthor != Y.Lang.trim(fileinfo.author));
614 var licenseselect = selectnode.one('.fp-license select'),
615 licenseindex = licenseselect.get('selectedIndex'),
616 newlicense = licenseselect.get("options").item(licenseindex).get('value');
617 var licensechanged = (newlicense != fileinfo.license);
620 var dialog_options = {callback:this.update_file, callbackargs:[true], scope:this};
621 if (fileinfo.type == 'folder') {
623 this.print_msg(M.str.repository.entername, 'error');
626 if (filenamechanged || filepathchanged) {
628 dialog_options.message = M.str.repository.confirmrenamefolder;
629 this.show_confirm_dialog(dialog_options);
632 params = {filepath:fileinfo.filepath, newdirname:newfilename, newfilepath:targetpath};
633 action = 'updatedir';
637 this.print_msg(M.str.repository.enternewname, 'error');
640 if ((filenamechanged || filepathchanged) && !confirmed && fileinfo.refcount) {
641 dialog_options.message = M.util.get_string('confirmrenamefile', 'repository', fileinfo.refcount);
642 this.show_confirm_dialog(dialog_options);
645 if (filenamechanged || filepathchanged || licensechanged || authorchanged) {
646 params = {filepath:fileinfo.filepath, filename:fileinfo.fullname,
647 newfilename:newfilename, newfilepath:targetpath,
648 newlicense:newlicense, newauthor:newauthor};
649 action = 'updatefile';
654 this.selectui.hide();
657 selectnode.addClass('loading');
662 callback: function(id, obj, args) {
664 selectnode.removeClass('loading');
665 args.scope.print_msg(obj.error, 'error');
667 args.scope.selectui.hide();
668 args.scope.refresh((obj && obj.filepath) ? obj.filepath : '/');
669 if (typeof M.core_formchangechecker != 'undefined') {
670 M.core_formchangechecker.set_form_changed();
677 * Displays a confirmation dialog
678 * Expected attributes in dialog_options: message, callback, callbackargs(optional), scope(optional)
680 show_confirm_dialog: function(dialog_options) {
681 // instead of M.util.show_confirm_dialog(e, dialog_options);
682 if (!this.confirm_dlg) {
683 this.confirm_dlg_node = Y.Node.create(M.form_filemanager.templates.confirmdialog);
684 var node = this.confirm_dlg_node;
686 Y.one(document.body).appendChild(node);
687 this.confirm_dlg = new Y.Panel({
696 this.confirm_dlg.plug(Y.Plugin.Drag,{handles:['#'+node.get('id')+' .yui3-widget-hd']});
697 var handle_confirm = function(ev) {
698 var dlgopt = this.confirm_dlg.dlgopt;
700 this.confirm_dlg.hide();
701 if (dlgopt.callback) {
702 if (dlgopt.callbackargs) {
703 dlgopt.callback.apply(dlgopt.scope || this, dlgopt.callbackargs);
705 dlgopt.callback.apply(dlgopt.scope || this);
709 var handle_cancel = function(ev) {
711 this.confirm_dlg.hide();
713 node.one('.fp-dlg-butconfirm').on('click', handle_confirm, this);
714 node.one('.fp-dlg-butcancel').on('click', handle_cancel, this);
716 this.confirm_dlg.dlgopt = dialog_options;
717 this.confirm_dlg_node.one('.fp-dlg-text').setContent(dialog_options.message);
718 this.confirm_dlg.show();
720 setup_select_file: function() {
721 var selectnode = this.selectnode;
722 // bind labels with corresponding inputs
723 selectnode.all('.fp-saveas,.fp-path,.fp-author,.fp-license').each(function (node) {
724 node.all('label').set('for', node.one('input,select').generateID());
726 this.populate_licenses_select(selectnode.one('.fp-license select'));
727 // register event on clicking buttons
728 selectnode.one('.fp-file-update').on('click', function(e) {
732 selectnode.one('.fp-file-download').on('click', function(e) {
734 if (this.selectui.fileinfo.type != 'folder') {
735 window.open(this.selectui.fileinfo.url, 'fm-download-file');
738 selectnode.one('.fp-file-delete').on('click', function(e) {
740 var dialog_options = {};
742 var fileinfo = this.selectui.fileinfo;
743 dialog_options.scope = this;
744 params.filepath = fileinfo.filepath;
745 if (fileinfo.type == 'folder') {
746 params.filename = '.';
747 dialog_options.message = M.str.repository.confirmdeletefolder;
749 params.filename = fileinfo.fullname;
750 if (fileinfo.refcount) {
751 dialog_options.message = M.util.get_string('confirmdeletefilewithhref', 'repository', fileinfo.refcount);
753 dialog_options.message = M.str.repository.confirmdeletefile;
756 dialog_options.callbackargs = [params];
757 dialog_options.callback = function(params) {
758 //selectnode.addClass('loading');
763 callback: function(id, obj, args) {
764 //args.scope.selectui.hide();
765 args.scope.filecount--;
766 args.scope.refresh(obj.filepath);
767 if (typeof M.core_formchangechecker != 'undefined') {
768 M.core_formchangechecker.set_form_changed();
773 this.selectui.hide(); // TODO remove this after confirm dialog is replaced with YUI3
774 this.show_confirm_dialog(dialog_options);
776 selectnode.one('.fp-file-zip').on('click', function(e) {
779 var fileinfo = this.selectui.fileinfo;
780 if (fileinfo.type != 'folder') {
781 // this button should not even be shown
784 params['filepath'] = fileinfo.filepath;
785 params['filename'] = '.';
786 selectnode.addClass('loading');
791 callback: function(id, obj, args) {
792 args.scope.selectui.hide();
793 args.scope.refresh(obj.filepath);
797 selectnode.one('.fp-file-unzip').on('click', function(e) {
800 var fileinfo = this.selectui.fileinfo;
801 if (fileinfo.type != 'zip') {
802 // this button should not even be shown
805 params['filepath'] = fileinfo.filepath;
806 params['filename'] = fileinfo.fullname;
807 selectnode.addClass('loading');
812 callback: function(id, obj, args) {
813 args.scope.selectui.hide();
814 args.scope.refresh(obj.filepath);
818 selectnode.one('.fp-file-setmain').on('click', function(e) {
821 var fileinfo = this.selectui.fileinfo;
822 if (fileinfo.type == 'folder') {
823 // this button should not even be shown for folders
826 params['filepath'] = fileinfo.filepath;
827 params['filename'] = fileinfo.fullname;
828 selectnode.addClass('loading');
830 action: 'setmainfile',
833 callback: function(id, obj, args) {
834 args.scope.selectui.hide();
835 args.scope.refresh(fileinfo.filepath);
839 selectnode.all('.fp-file-cancel').on('click', function(e) {
841 // TODO if changed asked to confirm, the same with close button
842 this.selectui.hide();
845 get_parent_folder_name: function(node) {
846 if (node.type != 'folder' || node.filepath.length < node.fullname.length+1) {
847 return node.filepath;
849 var basedir = node.filepath.substr(0, node.filepath.length - node.fullname.length - 1);
850 var lastdir = node.filepath.substr(node.filepath.length - node.fullname.length - 2);
851 if (lastdir == '/' + node.fullname + '/') {
854 return node.filepath;
856 select_file: function(node) {
857 var selectnode = this.selectnode;
858 selectnode.removeClass('loading').removeClass('fp-folder').
859 removeClass('fp-file').removeClass('fp-zip').removeClass('fp-cansetmain');
860 if (node.type == 'folder' || node.type == 'zip') {
861 selectnode.addClass('fp-'+node.type);
863 selectnode.addClass('fp-file');
865 if (this.enablemainfile && (node.sortorder != 1) && node.type == 'file') {
866 selectnode.addClass('fp-cansetmain');
868 this.selectui.fileinfo = node;
869 selectnode.one('.fp-saveas input').set('value', node.fullname);
870 var foldername = this.get_parent_folder_name(node);
871 selectnode.all('.fp-author input').set('value', node.author);
872 selectnode.all('.fp-license select option[selected]').set('selected', false);
873 selectnode.all('.fp-license select option[value='+node.license+']').set('selected', true);
874 selectnode.all('.fp-path select option[selected]').set('selected', false);
875 selectnode.all('.fp-path select option').each(function(el){
876 if (el.get('value') == foldername) {
877 el.set('selected', true);
880 selectnode.all('.fp-author input, .fp-license select').set('disabled',(node.type == 'folder')?'disabled':'');
881 // display static information about a file (when known)
882 var attrs = ['datemodified','datecreated','size','dimensions','original','reflist'];
883 for (var i in attrs) {
884 if (selectnode.one('.fp-'+attrs[i])) {
885 var value = (node[attrs[i]+'_f']) ? node[attrs[i]+'_f'] : (node[attrs[i]] ? node[attrs[i]] : '');
886 selectnode.one('.fp-'+attrs[i]).addClassIf('fp-unknown', ''+value == '')
887 .one('.fp-value').setContent(value);
891 var imgnode = Y.Node.create('<img/>').
892 set('src', node.realthumbnail ? node.realthumbnail : node.thumbnail).
893 setStyle('maxHeight', ''+(node.thumbnail_height ? node.thumbnail_height : 90)+'px').
894 setStyle('maxWidth', ''+(node.thumbnail_width ? node.thumbnail_width : 90)+'px');
895 selectnode.one('.fp-thumbnail').setContent('').appendChild(imgnode);
896 // load original location if applicable
897 if (node.isref && !node.original) {
898 selectnode.one('.fp-original').removeClass('fp-unknown').addClass('fp-loading');
900 action: 'getoriginal',
902 params: {'filepath':node.filepath,'filename':node.fullname},
903 callback: function(id, obj, args) {
904 // check if we did not select another file meanwhile
905 var scope = args.scope;
906 if (scope.selectui.fileinfo && node &&
907 scope.selectui.fileinfo.filepath == node.filepath &&
908 scope.selectui.fileinfo.fullname == node.fullname) {
909 selectnode.one('.fp-original').removeClass('fp-loading');
911 node.original = obj.original;
912 selectnode.one('.fp-original .fp-value').setContent(node.original);
914 selectnode.one('.fp-original .fp-value').setContent(M.str.repository.unknownsource);
920 // load references list if applicable
921 selectnode.one('.fp-refcount').setContent(node.refcount ? M.util.get_string('referencesexist', 'repository', node.refcount) : '');
922 if (node.refcount && !node.reflist) {
923 selectnode.one('.fp-reflist').removeClass('fp-unknown').addClass('fp-loading');
925 action: 'getreferences',
927 params: {'filepath':node.filepath,'filename':node.fullname},
928 callback: function(id, obj, args) {
929 // check if we did not select another file meanwhile
930 var scope = args.scope;
931 if (scope.selectui.fileinfo && node &&
932 scope.selectui.fileinfo.filepath == node.filepath &&
933 scope.selectui.fileinfo.fullname == node.fullname) {
934 selectnode.one('.fp-reflist').removeClass('fp-loading');
935 if (obj.references) {
937 for (var i in obj.references) {
938 node.reflist += '<li>'+obj.references[i]+'</li>';
940 selectnode.one('.fp-reflist .fp-value').setContent(node.reflist);
942 selectnode.one('.fp-reflist .fp-value').setContent('');
949 this.selectui.show();
957 // finally init everything needed
958 // hide loading picture, display filemanager interface
959 var filemanager = Y.one('#filemanager-'+options.client_id);
960 filemanager.removeClass('fm-loading').addClass('fm-loaded');
962 var manager = new FileManagerHelper(options);
964 filemanager: manager,
965 acceptedtypes: options.accepted_types,
966 clientid: options.client_id,
967 maxfiles: options.maxfiles,
968 maxbytes: options.maxbytes,
969 itemid: options.itemid,
970 repositories: manager.filepicker_options.repositories,
971 containerid: manager.dndcontainer.get('id')
973 M.form_dndupload.init(Y, dndoptions);