MDL-39888 mnet: Removal of an old sql statement invloving the mdl_log table.
[moodle.git] / lib / form / filepicker.js
blobe3632e2f07ee791372f08a23775e592af8fd6496
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');
17 /**
18  * This fucntion is called for each file picker on page.
19  */
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);
33     }
34     Y.on('click', function(e, client_id) {
35         e.preventDefault();
36         if (this.ancestor('.fitem.disabled') == null) {
37             M.core_filepicker.instances[client_id].show();
38         }
39     }, '#filepicker-button-'+options.client_id, null, options.client_id);
41     var item = document.getElementById('nonjs-filepicker-'+options.client_id);
42     if (item) {
43         item.parentNode.removeChild(item);
44     }
45     item = document.getElementById('filepicker-wrapper-'+options.client_id);
46     if (item) {
47         item.style.display = '';
48     }
50     var dndoptions = {
51         clientid: options.client_id,
52         acceptedtypes: options.accepted_types,
53         author: options.author,
54         maxfiles: -1,
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     };
62     M.form_dndupload.init(Y, dndoptions);