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 M.form_filepicker.Y.one('#file_info_'+params['client_id'] + ' .filepicker-filename').setContent(html);
9 //When file is added then set status of global variable to true
10 var elementname = M.core_filepicker.instances[params['client_id']].options.elementname;
11 M.form_filepicker.instances[elementname].fileadded = true;
12 //generate event to indicate changes which will be used by disable if or validation code
13 M.form_filepicker.Y.one('#id_'+elementname).simulate('change');
17 * This fucntion is called for each file picker on page.
19 M.form_filepicker.init = function(Y, options) {
20 //Keep reference of YUI, so that it can be used in callback.
21 M.form_filepicker.Y = Y;
23 //For client side validation, initialize file status for this filepicker
24 M.form_filepicker.instances[options.elementname] = {};
25 M.form_filepicker.instances[options.elementname].fileadded = false;
27 //Set filepicker callback
28 options.formcallback = M.form_filepicker.callback;
30 if (!M.core_filepicker.instances[options.client_id]) {
31 M.core_filepicker.init(Y, options);
33 Y.on('click', function(e, client_id) {
35 if (this.ancestor('.fitem.disabled') == null) {
36 M.core_filepicker.instances[client_id].show();
38 }, '#filepicker-button-'+options.client_id, null, options.client_id);
40 var item = document.getElementById('nonjs-filepicker-'+options.client_id);
42 item.parentNode.removeChild(item);
44 item = document.getElementById('filepicker-wrapper-'+options.client_id);
46 item.style.display = '';
50 clientid: options.client_id,
51 acceptedtypes: options.accepted_types,
52 author: options.author,
54 maxbytes: options.maxbytes,
55 itemid: options.itemid,
56 repositories: options.repositories,
57 formcallback: options.formcallback,
58 containerprefix: '#file_info_',
59 containerid: 'file_info_'+options.client_id
61 M.form_dndupload.init(Y, dndoptions);