2 M.form_filepicker = {};
3 M.form_filepicker.Y = null;
4 M.form_filepicker.instances = [];
6 M.form_filepicker.callback = function(params) {
7 var html = '<a href="'+params['url']+'">'+params['file']+'</a>';
8 html += '<div class="dndupload-progressbars"></div>';
9 M.form_filepicker.Y.one('#file_info_'+params['client_id'] + ' .filepicker-filename').setContent(html);
10 //When file is added then set status of global variable to true
11 var elementname = M.core_filepicker.instances[params['client_id']].options.elementname;
12 M.form_filepicker.instances[elementname].fileadded = true;
13 //generate event to indicate changes which will be used by disable if or validation code
14 M.form_filepicker.Y.one('#id_'+elementname).simulate('change');
18 * This fucntion is called for each file picker on page.
20 M.form_filepicker.init = function(Y, options) {
21 //Keep reference of YUI, so that it can be used in callback.
22 M.form_filepicker.Y = Y;
24 //For client side validation, initialize file status for this filepicker
25 M.form_filepicker.instances[options.elementname] = {};
26 M.form_filepicker.instances[options.elementname].fileadded = false;
28 //Set filepicker callback
29 options.formcallback = M.form_filepicker.callback;
31 if (!M.core_filepicker.instances[options.client_id]) {
32 M.core_filepicker.init(Y, options);
34 Y.on('click', function(e, client_id) {
36 if (this.ancestor('.fitem.disabled') == null) {
37 M.core_filepicker.instances[client_id].show();
39 }, '#filepicker-button-'+options.client_id, null, options.client_id);
41 var item = document.getElementById('nonjs-filepicker-'+options.client_id);
43 item.parentNode.removeChild(item);
45 item = document.getElementById('filepicker-wrapper-'+options.client_id);
47 item.style.display = '';
51 clientid: options.client_id,
52 acceptedtypes: options.accepted_types,
53 author: options.author,
55 maxbytes: options.maxbytes,
56 itemid: options.itemid,
57 repositories: options.repositories,
58 formcallback: options.formcallback,
59 containerprefix: '#file_info_',
60 containerid: 'file_info_'+options.client_id,
61 contextid: options.context.id
63 M.form_dndupload.init(Y, dndoptions);