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.createWithFilesSkin(M.form_filemanager.templates.fileselectlayout);
104 this.selectnode.generateID();
105 this.selectui = new Y.Panel({
106 srcNode : this.selectnode,
113 this.selectui.plug(Y.Plugin.Drag,{handles:['#'+this.selectnode.get('id')+' .yui3-widget-hd']});
114 this.selectui.hide();
115 this.setup_select_file();
116 // setup buttons onclick events
117 this.setup_buttons();
118 // set event handler for lazy loading of thumbnails
119 this.filemanager.one('.fp-content').on(['scroll','resize'], this.content_scrolled, this);
121 this.viewmode = 1; // TODO take from cookies?
122 this.filemanager.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').removeClass('checked')
123 this.filemanager.all('.fp-vb-icons').addClass('checked')
124 this.refresh(this.currentpath); // MDL-31113 get latest list from server
128 this.filemanager.addClass('fm-updating');
130 request: function(args, redraw) {
131 var api = this.api + '?action='+args.action;
135 scope = args['scope'];
137 params['sesskey'] = M.cfg.sesskey;
138 params['client_id'] = this.client_id;
139 params['filepath'] = this.currentpath;
140 params['itemid'] = this.options.itemid?this.options.itemid:0;
141 if (args['params']) {
142 for (i in args['params']) {
143 params[i] = args['params'][i];
149 complete: function(id,o,p) {
156 data = Y.JSON.parse(o.responseText);
158 scope.print_msg(M.str.repository.invalidjson, 'error');
159 Y.error(M.str.repository.invalidjson+":\n"+o.responseText);
162 if (data && data.tree && scope.set_current_tree) {
163 scope.set_current_tree(data.tree);
165 args.callback(id,data,p);
172 'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
173 'User-Agent': 'MoodleFileManager/3.0'
175 data: build_querystring(params)
178 cfg.form = args.form;
185 filepicker_callback: function(obj) {
187 this.check_buttons();
188 this.refresh(this.currentpath);
189 if (typeof M.core_formchangechecker != 'undefined') {
190 M.core_formchangechecker.set_form_changed();
193 check_buttons: function() {
194 if (this.filecount>0) {
195 this.filemanager.removeClass('fm-nofiles');
197 this.filemanager.addClass('fm-nofiles');
199 if (this.filecount >= this.maxfiles && this.maxfiles!=-1) {
200 this.filemanager.addClass('fm-maxfiles');
203 this.filemanager.removeClass('fm-maxfiles');
206 refresh: function(filepath) {
208 this.currentpath = filepath;
210 filepath = this.currentpath;
212 this.currentpath = filepath;
217 params: {'filepath':filepath},
218 callback: function(id, obj, args) {
219 scope.filecount = obj.filecount;
220 scope.check_buttons();
222 scope.lazyloading = {};
227 /** displays message in a popup */
228 print_msg: function(msg, type) {
229 var header = M.str.moodle.error;
230 if (type != 'error') {
231 type = 'info'; // one of only two types excepted
232 header = M.str.moodle.info;
235 this.msg_dlg_node = Y.Node.createWithFilesSkin(M.form_filemanager.templates.message);
236 var nodeid = this.msg_dlg_node.generateID();
238 this.msg_dlg = new Y.Panel({
239 srcNode : this.msg_dlg_node,
246 this.msg_dlg.plug(Y.Plugin.Drag,{handles:['#'+nodeid+' .yui3-widget-hd']});
247 this.msg_dlg_node.one('.fp-msg-butok').on('click', function(e) {
253 this.msg_dlg.set('headerContent', header);
254 this.msg_dlg_node.removeClass('fp-msg-info').removeClass('fp-msg-error').addClass('fp-msg-'+type)
255 this.msg_dlg_node.one('.fp-msg-text').setContent(msg);
258 setup_buttons: function() {
259 var button_download = this.filemanager.one('.fp-btn-download');
260 var button_create = this.filemanager.one('.fp-btn-mkdir');
261 var button_addfile = this.filemanager.one('.fp-btn-add');
263 // setup 'add file' button
264 button_addfile.on('click', this.show_filepicker, this);
266 var dndarrow = this.filemanager.one('.dndupload-arrow');
268 dndarrow.on('click', this.show_filepicker, this);
271 // setup 'make a folder' button
272 if (this.options.subdirs) {
273 button_create.on('click',function(e) {
276 // a function used to perform an ajax request
277 var perform_action = function(e) {
279 var foldername = Y.one('#fm-newname-'+scope.client_id).get('value');
281 scope.mkdir_dialog.hide();
286 params: {filepath:scope.currentpath, newdirname:foldername},
287 callback: function(id, obj, args) {
288 var filepath = obj.filepath;
289 scope.mkdir_dialog.hide();
290 scope.refresh(filepath);
291 Y.one('#fm-newname-'+scope.client_id).set('value', '');
292 if (typeof M.core_formchangechecker != 'undefined') {
293 M.core_formchangechecker.set_form_changed();
298 if (!this.mkdir_dialog) {
299 var node = Y.Node.createWithFilesSkin(M.form_filemanager.templates.mkdir);
300 this.mkdir_dialog = new Y.Panel({
308 this.mkdir_dialog.plug(Y.Plugin.Drag,{handles:['.yui3-widget-hd']});
309 node.one('.fp-dlg-butcreate').on('click', perform_action, this);
310 node.one('input').set('id', 'fm-newname-'+this.client_id).
311 on('keydown', function(e){
312 if (e.keyCode == 13) {Y.bind(perform_action, this)(e);}
314 node.all('.fp-dlg-butcancel').on('click', function(e){e.preventDefault();this.mkdir_dialog.hide();}, this);
315 node.all('.fp-dlg-curpath').set('id', 'fm-curpath-'+this.client_id);
317 this.mkdir_dialog.show();
318 Y.one('#fm-newname-'+scope.client_id).focus();
319 Y.all('#fm-curpath-'+scope.client_id).setContent(this.currentpath)
322 this.filemanager.addClass('fm-nomkdir');
325 // setup 'download this folder' button
326 button_download.on('click',function(e) {
329 // perform downloaddir ajax request
331 action: 'downloaddir',
333 callback: function(id, obj, args) {
335 scope.refresh(obj.filepath);
336 node = Y.Node.create('<iframe></iframe>').setStyles({
337 visibility : 'hidden',
341 node.set('src', obj.fileurl);
342 Y.one('body').appendChild(node);
344 scope.print_msg(M.str.repository.draftareanofiles, 'error');
350 this.filemanager.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').
351 on('click', function(e) {
353 var viewbar = this.filemanager.one('.fp-viewbar')
354 if (!viewbar || !viewbar.hasClass('disabled')) {
355 this.filemanager.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').removeClass('checked')
356 if (e.currentTarget.hasClass('fp-vb-tree')) {
358 } else if (e.currentTarget.hasClass('fp-vb-details')) {
363 e.currentTarget.addClass('checked')
369 show_filepicker: function (e) {
370 // if maxfiles == -1, the no limit
372 var options = this.filepicker_options;
373 options.formcallback = this.filepicker_callback;
374 // XXX: magic here, to let filepicker use filemanager scope
375 options.magicscope = this;
376 options.savepath = this.currentpath;
377 M.core_filepicker.show(Y, options);
380 print_path: function() {
381 var p = this.options.path;
382 this.pathbar.setContent('').addClass('empty');
383 if (p && p.length!=0 && this.viewmode != 2) {
384 for(var i = 0; i < p.length; i++) {
385 var el = this.pathnode.cloneNode(true);
386 this.pathbar.appendChild(el);
389 el.addClass('first');
391 if (i == p.length-1) {
400 el.one('.fp-path-folder-name').setContent(p[i].name).
401 on('click', function(e, path) {
406 this.pathbar.removeClass('empty');
409 get_filepath: function(obj) {
410 if (obj.path && obj.path.length) {
411 return obj.path[obj.path.length-1].path;
415 treeview_dynload: function(node, cb) {
416 var retrieved_children = {};
418 for (var i in node.children) {
419 retrieved_children[node.children[i].path] = node.children[i];
422 if (!node.path || node.path == '/') {
423 // this is a root pseudo folder
424 node.fileinfo.filepath = '/';
425 node.fileinfo.type = 'folder';
426 node.fileinfo.fullname = node.fileinfo.title;
427 node.fileinfo.filename = '.';
431 params: {filepath:node.path?node.path:''},
433 callback: function(id, obj, args) {
435 var scope = args.scope;
436 // check that user did not leave the view mode before recieving this response
437 if (!(scope.viewmode == 2 && node && node.getChildrenEl())) {
440 if (cb != null) { // (in manual mode do not update current path)
442 scope.currentpath = node.path?node.path:'/';
444 node.highlight(false);
445 node.origlist = obj.list ? obj.list : null;
446 node.origpath = obj.path ? obj.path : null;
449 if (list[k].type == 'folder' && retrieved_children[list[k].filepath]) {
450 // if this child is a folder and has already been retrieved
451 retrieved_children[list[k].filepath].fileinfo = list[k];
452 node.children[node.children.length] = retrieved_children[list[k].filepath];
454 // append new file to the list
455 scope.view_files([list[k]]);
461 // invoke callback requested by TreeView component
464 scope.content_scrolled();
468 content_scrolled: function(e) {
469 setTimeout(Y.bind(function() {
470 if (this.processingimages) {return;}
471 this.processingimages = true;
473 fpcontent = this.filemanager.one('.fp-content'),
474 fpcontenty = fpcontent.getY(),
475 fpcontentheight = fpcontent.getStylePx('height'),
476 is_node_visible = function(node) {
477 var offset = node.getY()-fpcontenty;
478 if (offset <= fpcontentheight && (offset >=0 || offset+node.getStylePx('height')>=0)) {
483 // replace src for visible images that need to be lazy-loaded
484 if (scope.lazyloading) {
485 fpcontent.all('img').each( function(node) {
486 if (node.get('id') && scope.lazyloading[node.get('id')] && is_node_visible(node)) {
487 node.setImgRealSrc(scope.lazyloading);
491 this.processingimages = false;
494 view_files: function(appendfiles) {
495 this.filemanager.removeClass('fm-updating').removeClass('fm-noitems');
496 if ((appendfiles == null) && (!this.options.list || this.options.list.length == 0) && this.viewmode != 2) {
497 this.filemanager.addClass('fm-noitems');
500 var list = (appendfiles != null) ? appendfiles : this.options.list;
501 var element_template;
502 if (this.viewmode == 2 || this.viewmode == 3) {
503 element_template = Y.Node.create(M.form_filemanager.templates.listfilename);
506 element_template = Y.Node.create(M.form_filemanager.templates.iconfilename);
509 viewmode : this.viewmode,
510 appendonly : appendfiles != null,
511 filenode : element_template,
512 callbackcontext : this,
513 callback : function(e, node) {
514 if (e.preventDefault) { e.preventDefault(); }
515 if (node.type == 'folder') {
516 this.refresh(node.filepath);
518 this.select_file(node);
521 rightclickcallback : function(e, node) {
522 if (e.preventDefault) { e.preventDefault(); }
523 this.select_file(node);
525 classnamecallback : function(node) {
527 if (node.type == 'folder' || (!node.type && !node.filename)) {
528 classname = classname + ' fp-folder';
530 if (node.filename || node.filepath || (node.path && node.path != '/')) {
531 classname = classname + ' fp-hascontextmenu';
534 classname = classname + ' fp-isreference';
537 classname = classname + ' fp-hasreferences';
539 if (node.originalmissing) {
540 classname = classname + ' fp-originalmissing';
542 if (node.sortorder == 1) { classname = classname + ' fp-mainfile';}
543 return Y.Lang.trim(classname);
546 if (this.viewmode == 2) {
547 options.dynload = true;
548 options.filepath = this.options.path;
549 options.treeview_dynload = this.treeview_dynload;
550 options.norootrightclick = true;
551 options.callback = function(e, node) {
552 // TODO MDL-32736 e is not an event here but an object with properties 'event' and 'node'
553 if (!node.fullname) {return;}
554 if (node.type != 'folder') {
555 if (e.node.parent && e.node.parent.origpath) {
556 // set the current path
557 this.options.path = e.node.parent.origpath;
558 this.options.list = e.node.parent.origlist;
561 this.currentpath = node.filepath;
562 this.select_file(node);
564 // save current path and filelist (in case we want to jump to other viewmode)
565 this.options.path = e.node.origpath;
566 this.options.list = e.node.origlist;
567 this.currentpath = node.filepath;
569 //this.content_scrolled();
573 if (!this.lazyloading) {
576 this.filemanager.one('.fp-content').fp_display_filelist(options, list, this.lazyloading);
577 this.content_scrolled();
579 populate_licenses_select: function(node) {
584 var licenses = this.options.licenses;
585 for (var i in licenses) {
586 var option = Y.Node.create('<option/>').
587 set('value', licenses[i].shortname).
588 setContent(licenses[i].fullname);
589 node.appendChild(option)
592 set_current_tree: function(tree) {
593 var appendfilepaths = function(list, node) {
594 if (!node || !node.children || !node.children.length) {return;}
595 for (var i in node.children) {
596 list[list.length] = node.children[i].filepath;
597 appendfilepaths(list, node.children[i]);
601 appendfilepaths(list, tree);
602 var selectnode = this.selectnode;
603 node = selectnode.one('.fp-path select');
605 for (var i in list) {
606 node.appendChild(Y.Node.create('<option/>').
607 set('value', list[i]).setContent(list[i]))
610 update_file: function(confirmed) {
611 var selectnode = this.selectnode;
612 var fileinfo = this.selectui.fileinfo;
614 var newfilename = Y.Lang.trim(selectnode.one('.fp-saveas input').get('value'));
615 var filenamechanged = (newfilename && newfilename != fileinfo.fullname);
616 var pathselect = selectnode.one('.fp-path select'),
617 pathindex = pathselect.get('selectedIndex'),
618 targetpath = pathselect.get("options").item(pathindex).get('value');
619 var filepathchanged = (targetpath != this.get_parent_folder_name(fileinfo));
620 var newauthor = Y.Lang.trim(selectnode.one('.fp-author input').get('value'));
621 var authorchanged = (newauthor != Y.Lang.trim(fileinfo.author));
622 var licenseselect = selectnode.one('.fp-license select'),
623 licenseindex = licenseselect.get('selectedIndex'),
624 newlicense = licenseselect.get("options").item(licenseindex).get('value');
625 var licensechanged = (newlicense != fileinfo.license);
628 var dialog_options = {callback:this.update_file, callbackargs:[true], scope:this};
629 if (fileinfo.type == 'folder') {
631 this.print_msg(M.str.repository.entername, 'error');
634 if (filenamechanged || filepathchanged) {
636 dialog_options.message = M.str.repository.confirmrenamefolder;
637 this.show_confirm_dialog(dialog_options);
640 params = {filepath:fileinfo.filepath, newdirname:newfilename, newfilepath:targetpath};
641 action = 'updatedir';
645 this.print_msg(M.str.repository.enternewname, 'error');
648 if ((filenamechanged || filepathchanged) && !confirmed && fileinfo.refcount) {
649 dialog_options.message = M.util.get_string('confirmrenamefile', 'repository', fileinfo.refcount);
650 this.show_confirm_dialog(dialog_options);
653 if (filenamechanged || filepathchanged || licensechanged || authorchanged) {
654 params = {filepath:fileinfo.filepath, filename:fileinfo.fullname,
655 newfilename:newfilename, newfilepath:targetpath,
656 newlicense:newlicense, newauthor:newauthor};
657 action = 'updatefile';
662 this.selectui.hide();
665 selectnode.addClass('loading');
670 callback: function(id, obj, args) {
672 selectnode.removeClass('loading');
673 args.scope.print_msg(obj.error, 'error');
675 args.scope.selectui.hide();
676 args.scope.refresh((obj && obj.filepath) ? obj.filepath : '/');
677 if (typeof M.core_formchangechecker != 'undefined') {
678 M.core_formchangechecker.set_form_changed();
685 * Displays a confirmation dialog
686 * Expected attributes in dialog_options: message, callback, callbackargs(optional), scope(optional)
688 show_confirm_dialog: function(dialog_options) {
689 // instead of M.util.show_confirm_dialog(e, dialog_options);
690 if (!this.confirm_dlg) {
691 this.confirm_dlg_node = Y.Node.createWithFilesSkin(M.form_filemanager.templates.confirmdialog);
692 var node = this.confirm_dlg_node;
694 this.confirm_dlg = new Y.Panel({
703 this.confirm_dlg.plug(Y.Plugin.Drag,{handles:['#'+node.get('id')+' .yui3-widget-hd']});
704 var handle_confirm = function(ev) {
705 var dlgopt = this.confirm_dlg.dlgopt;
707 this.confirm_dlg.hide();
708 if (dlgopt.callback) {
709 if (dlgopt.callbackargs) {
710 dlgopt.callback.apply(dlgopt.scope || this, dlgopt.callbackargs);
712 dlgopt.callback.apply(dlgopt.scope || this);
716 var handle_cancel = function(ev) {
718 this.confirm_dlg.hide();
720 node.one('.fp-dlg-butconfirm').on('click', handle_confirm, this);
721 node.one('.fp-dlg-butcancel').on('click', handle_cancel, this);
723 this.confirm_dlg.dlgopt = dialog_options;
724 this.confirm_dlg_node.one('.fp-dlg-text').setContent(dialog_options.message);
725 this.confirm_dlg.show();
727 setup_select_file: function() {
728 var selectnode = this.selectnode;
729 // bind labels with corresponding inputs
730 selectnode.all('.fp-saveas,.fp-path,.fp-author,.fp-license').each(function (node) {
731 node.all('label').set('for', node.one('input,select').generateID());
733 this.populate_licenses_select(selectnode.one('.fp-license select'));
734 // register event on clicking buttons
735 selectnode.one('.fp-file-update').on('click', function(e) {
739 selectnode.one('.fp-file-download').on('click', function(e) {
741 if (this.selectui.fileinfo.type != 'folder') {
742 node = Y.Node.create('<iframe></iframe>').setStyles({
743 visibility : 'hidden',
747 node.set('src', this.selectui.fileinfo.url);
748 Y.one('body').appendChild(node);
751 selectnode.one('.fp-file-delete').on('click', function(e) {
753 var dialog_options = {};
755 var fileinfo = this.selectui.fileinfo;
756 dialog_options.scope = this;
757 params.filepath = fileinfo.filepath;
758 if (fileinfo.type == 'folder') {
759 params.filename = '.';
760 dialog_options.message = M.str.repository.confirmdeletefolder;
762 params.filename = fileinfo.fullname;
763 if (fileinfo.refcount) {
764 dialog_options.message = M.util.get_string('confirmdeletefilewithhref', 'repository', fileinfo.refcount);
766 dialog_options.message = M.str.repository.confirmdeletefile;
769 dialog_options.callbackargs = [params];
770 dialog_options.callback = function(params) {
771 //selectnode.addClass('loading');
776 callback: function(id, obj, args) {
777 //args.scope.selectui.hide();
778 args.scope.filecount--;
779 args.scope.refresh(obj.filepath);
780 if (typeof M.core_formchangechecker != 'undefined') {
781 M.core_formchangechecker.set_form_changed();
786 this.selectui.hide(); // TODO remove this after confirm dialog is replaced with YUI3
787 this.show_confirm_dialog(dialog_options);
789 selectnode.one('.fp-file-zip').on('click', function(e) {
792 var fileinfo = this.selectui.fileinfo;
793 if (fileinfo.type != 'folder') {
794 // this button should not even be shown
797 params['filepath'] = fileinfo.filepath;
798 params['filename'] = '.';
799 selectnode.addClass('loading');
804 callback: function(id, obj, args) {
805 args.scope.selectui.hide();
806 args.scope.refresh(obj.filepath);
810 selectnode.one('.fp-file-unzip').on('click', function(e) {
813 var fileinfo = this.selectui.fileinfo;
814 if (fileinfo.type != 'zip') {
815 // this button should not even be shown
818 params['filepath'] = fileinfo.filepath;
819 params['filename'] = fileinfo.fullname;
820 selectnode.addClass('loading');
825 callback: function(id, obj, args) {
826 args.scope.selectui.hide();
827 args.scope.refresh(obj.filepath);
831 selectnode.one('.fp-file-setmain').on('click', function(e) {
834 var fileinfo = this.selectui.fileinfo;
835 if (!this.enablemainfile || fileinfo.type == 'folder') {
836 // this button should not even be shown for folders or when mainfile is disabled
839 params['filepath'] = fileinfo.filepath;
840 params['filename'] = fileinfo.fullname;
841 selectnode.addClass('loading');
843 action: 'setmainfile',
846 callback: function(id, obj, args) {
847 args.scope.selectui.hide();
848 args.scope.refresh(fileinfo.filepath);
852 selectnode.all('.fp-file-cancel').on('click', function(e) {
854 // TODO if changed asked to confirm, the same with close button
855 this.selectui.hide();
858 get_parent_folder_name: function(node) {
859 if (node.type != 'folder' || node.filepath.length < node.fullname.length+1) {
860 return node.filepath;
862 var basedir = node.filepath.substr(0, node.filepath.length - node.fullname.length - 1);
863 var lastdir = node.filepath.substr(node.filepath.length - node.fullname.length - 2);
864 if (lastdir == '/' + node.fullname + '/') {
867 return node.filepath;
869 select_file: function(node) {
870 var selectnode = this.selectnode;
871 selectnode.removeClass('loading').removeClass('fp-folder').
872 removeClass('fp-file').removeClass('fp-zip').removeClass('fp-cansetmain');
873 if (node.type == 'folder' || node.type == 'zip') {
874 selectnode.addClass('fp-'+node.type);
876 selectnode.addClass('fp-file');
878 if (this.enablemainfile && (node.sortorder != 1) && node.type == 'file') {
879 selectnode.addClass('fp-cansetmain');
881 this.selectui.fileinfo = node;
882 selectnode.one('.fp-saveas input').set('value', node.fullname);
883 var foldername = this.get_parent_folder_name(node);
884 selectnode.all('.fp-author input').set('value', node.author ? node.author : '');
885 selectnode.all('.fp-license select option[selected]').set('selected', false);
886 selectnode.all('.fp-license select option[value='+node.license+']').set('selected', true);
887 selectnode.all('.fp-path select option[selected]').set('selected', false);
888 selectnode.all('.fp-path select option').each(function(el){
889 if (el.get('value') == foldername) {
890 el.set('selected', true);
893 selectnode.all('.fp-author input, .fp-license select').set('disabled',(node.type == 'folder')?'disabled':'');
894 // display static information about a file (when known)
895 var attrs = ['datemodified','datecreated','size','dimensions','original','reflist'];
896 for (var i in attrs) {
897 if (selectnode.one('.fp-'+attrs[i])) {
898 var value = (node[attrs[i]+'_f']) ? node[attrs[i]+'_f'] : (node[attrs[i]] ? node[attrs[i]] : '');
899 selectnode.one('.fp-'+attrs[i]).addClassIf('fp-unknown', ''+value == '')
900 .one('.fp-value').setContent(value);
904 var imgnode = Y.Node.create('<img/>').
905 set('src', node.realthumbnail ? node.realthumbnail : node.thumbnail).
906 setStyle('maxHeight', ''+(node.thumbnail_height ? node.thumbnail_height : 90)+'px').
907 setStyle('maxWidth', ''+(node.thumbnail_width ? node.thumbnail_width : 90)+'px');
908 selectnode.one('.fp-thumbnail').setContent('').appendChild(imgnode);
909 // load original location if applicable
910 if (node.isref && !node.original) {
911 selectnode.one('.fp-original').removeClass('fp-unknown').addClass('fp-loading');
913 action: 'getoriginal',
915 params: {'filepath':node.filepath,'filename':node.fullname},
916 callback: function(id, obj, args) {
917 // check if we did not select another file meanwhile
918 var scope = args.scope;
919 if (scope.selectui.fileinfo && node &&
920 scope.selectui.fileinfo.filepath == node.filepath &&
921 scope.selectui.fileinfo.fullname == node.fullname) {
922 selectnode.one('.fp-original').removeClass('fp-loading');
924 node.original = obj.original;
925 selectnode.one('.fp-original .fp-value').setContent(node.original);
927 selectnode.one('.fp-original .fp-value').setContent(M.str.repository.unknownsource);
933 // load references list if applicable
934 selectnode.one('.fp-refcount').setContent(node.refcount ? M.util.get_string('referencesexist', 'repository', node.refcount) : '');
935 if (node.refcount && !node.reflist) {
936 selectnode.one('.fp-reflist').removeClass('fp-unknown').addClass('fp-loading');
938 action: 'getreferences',
940 params: {'filepath':node.filepath,'filename':node.fullname},
941 callback: function(id, obj, args) {
942 // check if we did not select another file meanwhile
943 var scope = args.scope;
944 if (scope.selectui.fileinfo && node &&
945 scope.selectui.fileinfo.filepath == node.filepath &&
946 scope.selectui.fileinfo.fullname == node.fullname) {
947 selectnode.one('.fp-reflist').removeClass('fp-loading');
948 if (obj.references) {
950 for (var i in obj.references) {
951 node.reflist += '<li>'+obj.references[i]+'</li>';
953 selectnode.one('.fp-reflist .fp-value').setContent(node.reflist);
955 selectnode.one('.fp-reflist .fp-value').setContent('');
962 this.selectui.show();
970 // finally init everything needed
971 // hide loading picture, display filemanager interface
972 var filemanager = Y.one('#filemanager-'+options.client_id);
973 filemanager.removeClass('fm-loading').addClass('fm-loaded');
975 var manager = new FileManagerHelper(options);
977 filemanager: manager,
978 acceptedtypes: options.accepted_types,
979 clientid: options.client_id,
980 author: options.author,
981 maxfiles: options.maxfiles,
982 maxbytes: options.maxbytes,
983 itemid: options.itemid,
984 repositories: manager.filepicker_options.repositories,
985 containerid: manager.dndcontainer.get('id')
987 M.form_dndupload.init(Y, dndoptions);