1 |
efrain |
1 |
|
|
|
2 |
M.form_filepicker = {};
|
|
|
3 |
M.form_filepicker.Y = null;
|
|
|
4 |
M.form_filepicker.instances = [];
|
|
|
5 |
|
|
|
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 elementid = M.core_filepicker.instances[params['client_id']].options.elementid;
|
|
|
12 |
M.form_filepicker.instances[elementid].fileadded = true;
|
|
|
13 |
//generate event to indicate changes which will be used by disable if or validation code
|
|
|
14 |
M.form_filepicker.Y.one('#'+elementid).simulate('change');
|
|
|
15 |
};
|
|
|
16 |
|
|
|
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;
|
|
|
23 |
|
|
|
24 |
//For client side validation, initialize file status for this filepicker
|
|
|
25 |
M.form_filepicker.instances[options.elementid] = {};
|
|
|
26 |
M.form_filepicker.instances[options.elementid].fileadded = false;
|
|
|
27 |
|
|
|
28 |
//Set filepicker callback
|
|
|
29 |
options.formcallback = M.form_filepicker.callback;
|
|
|
30 |
|
|
|
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);
|
|
|
40 |
|
|
|
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 |
}
|
|
|
49 |
|
|
|
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 |
contextid: options.context.id
|
|
|
62 |
};
|
|
|
63 |
M.form_dndupload.init(Y, dndoptions);
|
|
|
64 |
};
|