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) {this.filemanager.removeClass('fm-nofiles');}
197 else {this.filemanager.addClass('fm-nofiles');}
198 if (this.filecount >= this.maxfiles && this.maxfiles!=-1)
199 {this.filemanager.addClass('fm-maxfiles');}
200 else {this.filemanager.removeClass('fm-maxfiles');}
202 refresh: function(filepath) {
204 this.currentpath = filepath;
206 filepath = this.currentpath;
208 this.currentpath = filepath;
213 params: {'filepath':filepath},
214 callback: function(id, obj, args) {
215 scope.filecount = obj.filecount;
216 scope.check_buttons();
218 scope.lazyloading = {};
223 /** displays message in a popup */
224 print_msg: function(msg, type) {
225 var header = M.str.moodle.error;
226 if (type != 'error') {
227 type = 'info'; // one of only two types excepted
228 header = M.str.moodle.info;
231 var node = Y.Node.create(M.form_filemanager.templates.message);
232 this.filemanager.appendChild(node);
234 this.msg_dlg = new Y.Panel({
242 this.msg_dlg.plug(Y.Plugin.Drag,{handles:['.yui3-widget-hd']});
243 node.one('.fp-msg-butok').on('click', function(e) {
249 this.msg_dlg.set('headerContent', header);
250 this.filemanager.one('.fp-msg').removeClass('fp-msg-info').removeClass('fp-msg-error').addClass('fp-msg-'+type)
251 this.filemanager.one('.fp-msg .fp-msg-text').setContent(msg);
254 setup_buttons: function() {
255 var button_download = this.filemanager.one('.fp-btn-download');
256 var button_create = this.filemanager.one('.fp-btn-mkdir');
257 var button_addfile = this.filemanager.one('.fp-btn-add');
259 // setup 'add file' button
260 // if maxfiles == -1, the no limit
261 button_addfile.on('click', function(e) {
263 var options = this.filepicker_options;
264 options.formcallback = this.filepicker_callback;
265 // XXX: magic here, to let filepicker use filemanager scope
266 options.magicscope = this;
267 options.savepath = this.currentpath;
268 M.core_filepicker.show(Y, options);
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.create(M.form_filemanager.templates.mkdir);
300 this.filemanager.appendChild(node);
301 this.mkdir_dialog = new Y.Panel({
309 this.mkdir_dialog.plug(Y.Plugin.Drag,{handles:['.yui3-widget-hd']});
310 node.one('.fp-dlg-butcreate').on('click', perform_action, this);
311 node.one('input').set('id', 'fm-newname-'+this.client_id).
312 on('keydown', function(e){
313 if (e.keyCode == 13) {Y.bind(perform_action, this)(e);}
315 node.all('.fp-dlg-butcancel').on('click', function(e){e.preventDefault();this.mkdir_dialog.hide();}, this);
316 node.all('.fp-dlg-curpath').set('id', 'fm-curpath-'+this.client_id);
318 this.mkdir_dialog.show();
319 Y.one('#fm-newname-'+scope.client_id).focus();
320 Y.all('#fm-curpath-'+scope.client_id).setContent(this.currentpath)
323 this.filemanager.addClass('fm-nomkdir');
326 // setup 'download this folder' button
327 // NOTE: popup window must be enabled to perform download process
328 button_download.on('click',function(e) {
331 // perform downloaddir ajax request
333 action: 'downloaddir',
335 callback: function(id, obj, args) {
337 scope.refresh(obj.filepath);
338 var win = window.open(obj.fileurl, 'fm-download-folder');
340 scope.print_msg(M.str.repository.popupblockeddownload, 'error');
343 scope.print_msg(M.str.repository.draftareanofiles, 'error');
349 this.filemanager.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').
350 on('click', function(e) {
352 var viewbar = this.filemanager.one('.fp-viewbar')
353 if (!viewbar || !viewbar.hasClass('disabled')) {
354 this.filemanager.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').removeClass('checked')
355 if (e.currentTarget.hasClass('fp-vb-tree')) {
357 } else if (e.currentTarget.hasClass('fp-vb-details')) {
362 e.currentTarget.addClass('checked')
364 //Y.Cookie.set('recentviewmode', this.viewmode);
368 print_path: function() {
369 var p = this.options.path;
370 this.pathbar.setContent('').addClass('empty');
371 if (p && p.length!=0 && this.viewmode != 2) {
372 for(var i = 0; i < p.length; i++) {
373 var el = this.pathnode.cloneNode(true);
374 this.pathbar.appendChild(el);
375 if (i == 0) {el.addClass('first');}
376 if (i == p.length-1) {el.addClass('last');}
377 if (i%2) {el.addClass('even');} else {el.addClass('odd');}
378 el.one('.fp-path-folder-name').setContent(p[i].name).
379 on('click', function(e, path) {
384 this.pathbar.removeClass('empty');
387 get_filepath: function(obj) {
388 if (obj.path && obj.path.length) {
389 return obj.path[obj.path.length-1].path;
393 treeview_dynload: function(node, cb) {
394 var retrieved_children = {};
396 for (var i in node.children) {
397 retrieved_children[node.children[i].path] = node.children[i];
400 if (!node.path || node.path == '/') {
401 // this is a root pseudo folder
402 node.fileinfo.filepath = '/';
403 node.fileinfo.type = 'folder';
404 node.fileinfo.fullname = node.fileinfo.title;
405 node.fileinfo.filename = '.';
409 params: {filepath:node.path?node.path:''},
411 callback: function(id, obj, args) {
413 var scope = args.scope;
414 // check that user did not leave the view mode before recieving this response
415 if (!(scope.viewmode == 2 && node && node.getChildrenEl())) {
418 if (cb != null) { // (in manual mode do not update current path)
420 scope.currentpath = node.path?node.path:'/';
422 node.highlight(false);
423 node.origlist = obj.list?obj.list:null;
424 node.origpath = obj.path?obj.path:null;
427 if (list[k].type == 'folder' && retrieved_children[list[k].filepath]) {
428 // if this child is a folder and has already been retrieved
429 retrieved_children[list[k].filepath].fileinfo = list[k];
430 node.children[node.children.length] = retrieved_children[list[k].filepath];
432 // append new file to the list
433 scope.view_files([list[k]]);
439 // invoke callback requested by TreeView component
442 scope.content_scrolled();
446 content_scrolled: function(e) {
447 setTimeout(Y.bind(function() {
448 if (this.processingimages) {return;}
449 this.processingimages = true;
451 fpcontent = this.filemanager.one('.fp-content'),
452 fpcontenty = fpcontent.getY(),
453 fpcontentheight = fpcontent.getStylePx('height'),
454 is_node_visible = function(node) {
455 var offset = node.getY()-fpcontenty;
456 if (offset <= fpcontentheight && (offset >=0 || offset+node.getStylePx('height')>=0)) {
461 // replace src for visible images that need to be lazy-loaded
462 if (scope.lazyloading) {
463 fpcontent.all('img').each( function(node) {
464 if (node.get('id') && scope.lazyloading[node.get('id')] && is_node_visible(node)) {
465 node.set('src', scope.lazyloading[node.get('id')]);
466 delete scope.lazyloading[node.get('id')];
470 this.processingimages = false;
473 view_files: function(appendfiles) {
474 this.filemanager.removeClass('fm-updating').removeClass('fm-noitems');
475 if ((appendfiles == null) && (!this.options.list || this.options.list.length == 0) && this.viewmode != 2) {
476 this.filemanager.addClass('fm-noitems');
479 var list = (appendfiles != null) ? appendfiles : this.options.list;
480 var element_template;
481 if (this.viewmode == 2 || this.viewmode == 3) {
482 element_template = Y.Node.create(M.form_filemanager.templates.listfilename);
485 element_template = Y.Node.create(M.form_filemanager.templates.iconfilename);
488 viewmode : this.viewmode,
489 appendonly : appendfiles != null,
490 filenode : element_template,
491 callbackcontext : this,
492 callback : function(e, node) {
493 if (e.preventDefault) { e.preventDefault(); }
494 if (node.type == 'folder') {
495 this.refresh(node.filepath);
497 this.select_file(node);
500 rightclickcallback : function(e, node) {
501 if (e.preventDefault) { e.preventDefault(); }
502 this.select_file(node);
504 classnamecallback : function(node) {
506 if (node.type == 'folder' || (!node.type && !node.filename)) {
507 classname = classname + ' fp-folder';
509 if (node.filename || node.filepath || (node.path && node.path != '/')) {
510 classname = classname + ' fp-hascontextmenu';
513 classname = classname + ' fp-isreference';
516 classname = classname + ' fp-hasreferences';
518 if (node.sortorder == 1) { classname = classname + ' fp-mainfile';}
519 return Y.Lang.trim(classname);
522 if (this.viewmode == 2) {
523 options.dynload = true;
524 options.filepath = this.options.path;
525 options.treeview_dynload = this.treeview_dynload;
526 options.norootrightclick = true;
527 options.callback = function(e, node) {
528 // TODO MDL-32736 e is not an event here but an object with properties 'event' and 'node'
529 if (!node.fullname) {return;}
530 if (node.type != 'folder') {
531 if (e.node.parent && e.node.parent.origpath) {
532 // set the current path
533 this.options.path = e.node.parent.origpath;
534 this.options.list = e.node.parent.origlist;
537 this.currentpath = node.filepath;
538 this.select_file(node);
540 // save current path and filelist (in case we want to jump to other viewmode)
541 this.options.path = e.node.origpath;
542 this.options.list = e.node.origlist;
543 this.currentpath = node.filepath;
545 //this.content_scrolled();
549 if (!this.lazyloading) {this.lazyloading={};}
550 this.filemanager.one('.fp-content').fp_display_filelist(options, list, this.lazyloading);
551 this.content_scrolled();
553 populate_licenses_select: function(node) {
556 var licenses = this.options.licenses;
557 for (var i in licenses) {
558 var option = Y.Node.create('<option/>').
559 set('value', licenses[i].shortname).
560 setContent(licenses[i].fullname);
561 node.appendChild(option)
564 set_current_tree: function(tree) {
565 var appendfilepaths = function(list, node) {
566 if (!node || !node.children || !node.children.length) {return;}
567 for (var i in node.children) {
568 list[list.length] = node.children[i].filepath;
569 appendfilepaths(list, node.children[i]);
573 appendfilepaths(list, tree);
574 var selectnode = this.selectnode;
575 node = selectnode.one('.fp-path select');
577 for (var i in list) {
578 node.appendChild(Y.Node.create('<option/>').
579 set('value', list[i]).setContent(list[i]))
582 update_file: function(confirmed) {
583 var selectnode = this.selectnode;
584 var fileinfo = this.selectui.fileinfo;
586 var newfilename = Y.Lang.trim(selectnode.one('.fp-saveas input').get('value'));
587 var filenamechanged = (newfilename && newfilename != fileinfo.fullname);
588 var pathselect = selectnode.one('.fp-path select'),
589 pathindex = pathselect.get('selectedIndex'),
590 targetpath = pathselect.get("options").item(pathindex).get('value');
591 var filepathchanged = (targetpath != this.get_parent_folder_name(fileinfo));
592 var newauthor = Y.Lang.trim(selectnode.one('.fp-author input').get('value'));
593 var authorchanged = (newauthor != Y.Lang.trim(fileinfo.author));
594 var licenseselect = selectnode.one('.fp-license select'),
595 licenseindex = licenseselect.get('selectedIndex'),
596 newlicense = licenseselect.get("options").item(licenseindex).get('value');
597 var licensechanged = (newlicense != fileinfo.license);
600 var dialog_options = {callback:this.update_file, callbackargs:[true], scope:this};
601 if (fileinfo.type == 'folder') {
603 this.print_msg(M.str.repository.entername, 'error');
606 if (filenamechanged || filepathchanged) {
608 dialog_options.message = M.str.repository.confirmrenamefolder;
609 this.show_confirm_dialog(dialog_options);
612 params = {filepath:fileinfo.filepath, newdirname:newfilename, newfilepath:targetpath};
613 action = 'updatedir';
617 this.print_msg(M.str.repository.enternewname, 'error');
620 if ((filenamechanged || filepathchanged) && !confirmed && fileinfo.refcount) {
621 dialog_options.message = M.util.get_string('confirmrenamefile', 'repository', fileinfo.refcount);
622 this.show_confirm_dialog(dialog_options);
625 if (filenamechanged || filepathchanged || licensechanged || authorchanged) {
626 params = {filepath:fileinfo.filepath, filename:fileinfo.fullname,
627 newfilename:newfilename, newfilepath:targetpath,
628 newlicense:newlicense, newauthor:newauthor};
629 action = 'updatefile';
634 this.selectui.hide();
637 selectnode.addClass('loading');
642 callback: function(id, obj, args) {
644 selectnode.removeClass('loading');
645 args.scope.print_msg(obj.error, 'error');
647 args.scope.selectui.hide();
648 args.scope.refresh((obj && obj.filepath) ? obj.filepath : '/');
649 if (typeof M.core_formchangechecker != 'undefined') {
650 M.core_formchangechecker.set_form_changed();
657 * Displays a confirmation dialog
658 * Expected attributes in dialog_options: message, callback, callbackargs(optional), scope(optional)
660 show_confirm_dialog: function(dialog_options) {
661 // instead of M.util.show_confirm_dialog(e, dialog_options);
662 if (!this.confirm_dlg) {
663 this.confirm_dlg_node = Y.Node.create(M.form_filemanager.templates.confirmdialog);
664 var node = this.confirm_dlg_node;
666 Y.one(document.body).appendChild(node);
667 this.confirm_dlg = new Y.Panel({
676 this.confirm_dlg.plug(Y.Plugin.Drag,{handles:['#'+node.get('id')+' .yui3-widget-hd']});
677 var handleConfirm = function(ev) {
678 var dlgopt = this.confirm_dlg.dlgopt;
680 this.confirm_dlg.hide();
681 if (dlgopt.callback) {
682 if (dlgopt.callbackargs) {
683 dlgopt.callback.apply(dlgopt.scope || this, dlgopt.callbackargs);
685 dlgopt.callback.apply(dlgopt.scope || this);
689 var handleCancel = function(ev) {
691 this.confirm_dlg.hide();
693 node.one('.fp-dlg-butconfirm').on('click', handleConfirm, this);
694 node.one('.fp-dlg-butcancel').on('click', handleCancel, this);
696 this.confirm_dlg.dlgopt = dialog_options;
697 this.confirm_dlg_node.one('.fp-dlg-text').setContent(dialog_options.message);
698 this.confirm_dlg.show();
700 setup_select_file: function() {
701 var selectnode = this.selectnode;
702 // bind labels with corresponding inputs
703 selectnode.all('.fp-saveas,.fp-path,.fp-author,.fp-license').each(function (node) {
704 node.all('label').set('for', node.one('input,select').generateID());
706 this.populate_licenses_select(selectnode.one('.fp-license select'));
707 // register event on clicking buttons
708 selectnode.one('.fp-file-update').on('click', function(e) {
712 selectnode.one('.fp-file-download').on('click', function(e) {
714 if (this.selectui.fileinfo.type != 'folder') {
715 window.open(this.selectui.fileinfo.url, 'fm-download-file');
718 selectnode.one('.fp-file-delete').on('click', function(e) {
720 var dialog_options = {};
722 var fileinfo = this.selectui.fileinfo;
723 dialog_options.scope = this;
724 params.filepath = fileinfo.filepath;
725 if (fileinfo.type == 'folder') {
726 params.filename = '.';
727 dialog_options.message = M.str.repository.confirmdeletefolder;
729 params.filename = fileinfo.fullname;
730 if (fileinfo.refcount) {
731 dialog_options.message = M.util.get_string('confirmdeletefilewithhref', 'repository', fileinfo.refcount);
733 dialog_options.message = M.str.repository.confirmdeletefile;
736 dialog_options.callbackargs = [params];
737 dialog_options.callback = function(params) {
738 //selectnode.addClass('loading');
743 callback: function(id, obj, args) {
744 //args.scope.selectui.hide();
745 args.scope.filecount--;
746 args.scope.refresh(obj.filepath);
747 if (typeof M.core_formchangechecker != 'undefined') {
748 M.core_formchangechecker.set_form_changed();
753 this.selectui.hide(); // TODO remove this after confirm dialog is replaced with YUI3
754 this.show_confirm_dialog(dialog_options);
756 selectnode.one('.fp-file-zip').on('click', function(e) {
759 var fileinfo = this.selectui.fileinfo;
760 if (fileinfo.type != 'folder') {
761 // this button should not even be shown
764 params['filepath'] = fileinfo.filepath;
765 params['filename'] = '.';
766 selectnode.addClass('loading');
771 callback: function(id, obj, args) {
772 args.scope.selectui.hide();
773 args.scope.refresh(obj.filepath);
777 selectnode.one('.fp-file-unzip').on('click', function(e) {
780 var fileinfo = this.selectui.fileinfo;
781 if (fileinfo.type != 'zip') {
782 // this button should not even be shown
785 params['filepath'] = fileinfo.filepath;
786 params['filename'] = fileinfo.fullname;
787 selectnode.addClass('loading');
792 callback: function(id, obj, args) {
793 args.scope.selectui.hide();
794 args.scope.refresh(obj.filepath);
798 selectnode.one('.fp-file-setmain').on('click', function(e) {
801 var fileinfo = this.selectui.fileinfo;
802 if (fileinfo.type == 'folder') {
803 // this button should not even be shown for folders
806 params['filepath'] = fileinfo.filepath;
807 params['filename'] = fileinfo.fullname;
808 selectnode.addClass('loading');
810 action: 'setmainfile',
813 callback: function(id, obj, args) {
814 args.scope.selectui.hide();
815 args.scope.refresh(fileinfo.filepath);
819 selectnode.all('.fp-file-cancel').on('click', function(e) {
821 // TODO if changed asked to confirm, the same with close button
822 this.selectui.hide();
825 get_parent_folder_name: function(node) {
826 if (node.type != 'folder' || node.filepath.length < node.fullname.length+1) { return node.filepath; }
827 var basedir = node.filepath.substr(0, node.filepath.length - node.fullname.length - 1);
828 var lastdir = node.filepath.substr(node.filepath.length - node.fullname.length - 2);
829 if (lastdir == '/' + node.fullname + '/') { return basedir; }
830 return node.filepath;
832 select_file: function(node) {
833 var selectnode = this.selectnode;
834 selectnode.removeClass('loading').removeClass('fp-folder').
835 removeClass('fp-file').removeClass('fp-zip').removeClass('fp-cansetmain');
836 if (node.type == 'folder' || node.type == 'zip') {selectnode.addClass('fp-'+node.type);}
837 else {selectnode.addClass('fp-file');}
838 if (this.enablemainfile && (node.sortorder != 1) && node.type == 'file') {
839 selectnode.addClass('fp-cansetmain');
841 this.selectui.fileinfo = node;
842 selectnode.one('.fp-saveas input').set('value', node.fullname);
843 var foldername = this.get_parent_folder_name(node);
844 selectnode.all('.fp-author input').set('value', node.author);
845 selectnode.all('.fp-license select option[selected]').set('selected', false);
846 selectnode.all('.fp-license select option[value='+node.license+']').set('selected', true);
847 selectnode.all('.fp-path select option[selected]').set('selected', false);
848 selectnode.all('.fp-path select option').each(function(el){
849 if (el.get('value') == foldername) {el.set('selected', true);}
851 selectnode.all('.fp-author input, .fp-license select').set('disabled',(node.type == 'folder')?'disabled':'');
852 // display static information about a file (when known)
853 var attrs = ['datemodified','datecreated','size','dimensions','original','reflist'];
854 for (var i in attrs) {
855 if (selectnode.one('.fp-'+attrs[i])) {
856 var value = (node[attrs[i]+'_f']) ? node[attrs[i]+'_f'] : (node[attrs[i]] ? node[attrs[i]] : '');
857 selectnode.one('.fp-'+attrs[i]).addClassIf('fp-unknown', ''+value == '')
858 .one('.fp-value').setContent(value);
862 var imgnode = Y.Node.create('<img/>').
863 set('src', node.realthumbnail ? node.realthumbnail : node.thumbnail).
864 setStyle('maxHeight', ''+(node.thumbnail_height ? node.thumbnail_height : 90)+'px').
865 setStyle('maxWidth', ''+(node.thumbnail_width ? node.thumbnail_width : 90)+'px');
866 selectnode.one('.fp-thumbnail').setContent('').appendChild(imgnode);
867 // load original location if applicable
868 if (node.isref && !node.original) {
869 selectnode.one('.fp-original').removeClass('fp-unknown').addClass('fp-loading');
871 action: 'getoriginal',
873 params: {'filepath':node.filepath,'filename':node.fullname},
874 callback: function(id, obj, args) {
875 // check if we did not select another file meanwhile
876 var scope = args.scope;
877 if (scope.selectui.fileinfo && node &&
878 scope.selectui.fileinfo.filepath == node.filepath &&
879 scope.selectui.fileinfo.fullname == node.fullname) {
880 selectnode.one('.fp-original').removeClass('fp-loading');
882 node.original = obj.original;
883 selectnode.one('.fp-original .fp-value').setContent(node.original);
885 selectnode.one('.fp-original .fp-value').setContent(M.str.repository.unknownsource);
891 // load references list if applicable
892 selectnode.one('.fp-refcount').setContent(node.refcount ? M.util.get_string('referencesexist', 'repository', node.refcount) : '');
893 if (node.refcount && !node.reflist) {
894 selectnode.one('.fp-reflist').removeClass('fp-unknown').addClass('fp-loading');
896 action: 'getreferences',
898 params: {'filepath':node.filepath,'filename':node.fullname},
899 callback: function(id, obj, args) {
900 // check if we did not select another file meanwhile
901 var scope = args.scope;
902 if (scope.selectui.fileinfo && node &&
903 scope.selectui.fileinfo.filepath == node.filepath &&
904 scope.selectui.fileinfo.fullname == node.fullname) {
905 selectnode.one('.fp-reflist').removeClass('fp-loading');
906 if (obj.references) {
908 for (var i in obj.references) {
909 node.reflist += '<li>'+obj.references[i]+'</li>';
911 selectnode.one('.fp-reflist .fp-value').setContent(node.reflist);
913 selectnode.one('.fp-reflist .fp-value').setContent('');
920 this.selectui.show();
928 // finally init everything needed
929 // hide loading picture, display filemanager interface
930 var filemanager = Y.one('#filemanager-'+options.client_id);
931 filemanager.removeClass('fm-loading').addClass('fm-loaded');
933 var manager = new FileManagerHelper(options);
935 filemanager: manager,
936 acceptedtypes: options.accepted_types,
937 clientid: options.client_id,
938 maxfiles: options.maxfiles,
939 maxbytes: options.maxbytes,
940 itemid: options.itemid,
941 repositories: manager.filepicker_options.repositories,
942 containerid: manager.dndcontainer.get('id')
944 M.form_dndupload.init(Y, dndoptions);