1 |
efrain |
1 |
// YUI3 File Picker module for moodle
|
|
|
2 |
// Author: Dongsheng Cai <dongsheng@moodle.com>
|
|
|
3 |
|
|
|
4 |
/**
|
|
|
5 |
*
|
|
|
6 |
* File Picker UI
|
|
|
7 |
* =====
|
|
|
8 |
* this.fpnode, contains reference to filepicker Node, non-empty if and only if rendered
|
|
|
9 |
* this.api, stores the URL to make ajax request
|
|
|
10 |
* this.mainui, YUI Panel
|
|
|
11 |
* this.selectnode, contains reference to select-file Node
|
|
|
12 |
* this.selectui, YUI Panel for selecting particular file
|
|
|
13 |
* this.msg_dlg, YUI Panel for error or info message
|
|
|
14 |
* this.process_dlg, YUI Panel for processing existing filename
|
|
|
15 |
* this.treeview, YUI Treeview
|
|
|
16 |
* this.viewmode, store current view mode
|
|
|
17 |
* this.pathbar, reference to the Node with path bar
|
|
|
18 |
* this.pathnode, a Node element representing one folder in a path bar (not attached anywhere, just used for template)
|
|
|
19 |
* this.currentpath, the current path in the repository (or last requested path)
|
|
|
20 |
*
|
|
|
21 |
* Filepicker options:
|
|
|
22 |
* =====
|
|
|
23 |
* this.options.client_id, the instance id
|
|
|
24 |
* this.options.contextid
|
|
|
25 |
* this.options.itemid
|
|
|
26 |
* this.options.repositories, stores all repositories displayed in file picker
|
|
|
27 |
* this.options.formcallback
|
|
|
28 |
*
|
|
|
29 |
* Active repository options
|
|
|
30 |
* =====
|
|
|
31 |
* this.active_repo.id
|
|
|
32 |
* this.active_repo.defaultreturntype
|
|
|
33 |
* this.active_repo.nosearch
|
|
|
34 |
* this.active_repo.norefresh
|
|
|
35 |
* this.active_repo.nologin
|
|
|
36 |
* this.active_repo.help
|
|
|
37 |
* this.active_repo.manage
|
|
|
38 |
*
|
|
|
39 |
* Server responses
|
|
|
40 |
* =====
|
|
|
41 |
* this.filelist, cached filelist
|
|
|
42 |
* this.pages
|
|
|
43 |
* this.page
|
|
|
44 |
* this.filepath, current path (each element of the array is a part of the breadcrumb)
|
|
|
45 |
* this.logindata, cached login form
|
|
|
46 |
*/
|
|
|
47 |
|
|
|
48 |
YUI.add('moodle-core_filepicker', function(Y) {
|
|
|
49 |
/** help function to extract width/height style as a number, not as a string */
|
|
|
50 |
Y.Node.prototype.getStylePx = function(attr) {
|
|
|
51 |
var style = this.getStyle(attr);
|
|
|
52 |
if (''+style == '0' || ''+style == '0px') {
|
|
|
53 |
return 0;
|
|
|
54 |
}
|
|
|
55 |
var matches = style.match(/^([\d\.]+)px$/)
|
|
|
56 |
if (matches && parseFloat(matches[1])) {
|
|
|
57 |
return parseFloat(matches[1]);
|
|
|
58 |
}
|
|
|
59 |
return null;
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
/** if condition is met, the class is added to the node, otherwise - removed */
|
|
|
63 |
Y.Node.prototype.addClassIf = function(className, condition) {
|
|
|
64 |
if (condition) {
|
|
|
65 |
this.addClass(className);
|
|
|
66 |
} else {
|
|
|
67 |
this.removeClass(className);
|
|
|
68 |
}
|
|
|
69 |
return this;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
/** sets the width(height) of the node considering existing minWidth(minHeight) */
|
|
|
73 |
Y.Node.prototype.setStyleAdv = function(stylename, value) {
|
|
|
74 |
var stylenameCap = stylename.substr(0,1).toUpperCase() + stylename.substr(1, stylename.length-1).toLowerCase();
|
|
|
75 |
this.setStyle(stylename, '' + Math.max(value, this.getStylePx('min'+stylenameCap)) + 'px')
|
|
|
76 |
return this;
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
/** set image source to src, if there is preview, remember it in lazyloading.
|
|
|
80 |
* If there is a preview and it was already loaded, use it. */
|
|
|
81 |
Y.Node.prototype.setImgSrc = function(src, realsrc, lazyloading) {
|
|
|
82 |
if (realsrc) {
|
|
|
83 |
if (M.core_filepicker.loadedpreviews[realsrc]) {
|
|
|
84 |
this.set('src', realsrc).addClass('realpreview');
|
|
|
85 |
return this;
|
|
|
86 |
} else {
|
|
|
87 |
if (!this.get('id')) {
|
|
|
88 |
this.generateID();
|
|
|
89 |
}
|
|
|
90 |
lazyloading[this.get('id')] = realsrc;
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
this.set('src', src);
|
|
|
94 |
return this;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
/**
|
|
|
98 |
* Replaces the image source with preview. If the image is inside the treeview, we need
|
|
|
99 |
* also to update the html property of corresponding YAHOO.widget.HTMLNode
|
|
|
100 |
* @param array lazyloading array containing associations of imgnodeid->realsrc
|
|
|
101 |
*/
|
|
|
102 |
Y.Node.prototype.setImgRealSrc = function(lazyloading) {
|
|
|
103 |
if (this.get('id') && lazyloading[this.get('id')]) {
|
|
|
104 |
var newsrc = lazyloading[this.get('id')];
|
|
|
105 |
M.core_filepicker.loadedpreviews[newsrc] = true;
|
|
|
106 |
this.set('src', newsrc).addClass('realpreview');
|
|
|
107 |
delete lazyloading[this.get('id')];
|
|
|
108 |
var treenode = this.ancestor('.fp-treeview')
|
|
|
109 |
if (treenode && treenode.get('parentNode').treeview) {
|
|
|
110 |
treenode.get('parentNode').treeview.getRoot().refreshPreviews(this.get('id'), newsrc);
|
|
|
111 |
}
|
|
|
112 |
}
|
|
|
113 |
return this;
|
|
|
114 |
}
|
|
|
115 |
|
|
|
116 |
/** scan TreeView to find which node contains image with id=imgid and replace it's html
|
|
|
117 |
* with the new image source. */
|
|
|
118 |
Y.YUI2.widget.Node.prototype.refreshPreviews = function(imgid, newsrc, regex) {
|
|
|
119 |
if (!regex) {
|
|
|
120 |
regex = new RegExp("<img\\s[^>]*id=\""+imgid+"\"[^>]*?(/?)>", "im");
|
|
|
121 |
}
|
|
|
122 |
if (this.expanded || this.isLeaf) {
|
|
|
123 |
var html = this.getContentHtml();
|
|
|
124 |
if (html && this.setHtml && regex.test(html)) {
|
|
|
125 |
var newhtml = this.html.replace(regex, "<img id=\""+imgid+"\" src=\""+newsrc+"\" class=\"realpreview\"$1>", html);
|
|
|
126 |
this.setHtml(newhtml);
|
|
|
127 |
return true;
|
|
|
128 |
}
|
|
|
129 |
if (!this.isLeaf && this.children) {
|
|
|
130 |
for(var c in this.children) {
|
|
|
131 |
if (this.children[c].refreshPreviews(imgid, newsrc, regex)) {
|
|
|
132 |
return true;
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
return false;
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
/**
|
|
|
141 |
* Displays a list of files (used by filepicker, filemanager) inside the Node
|
|
|
142 |
*
|
|
|
143 |
* @param array options
|
|
|
144 |
* viewmode : 1 - icons, 2 - tree, 3 - table
|
|
|
145 |
* appendonly : whether fileslist need to be appended instead of replacing the existing content
|
|
|
146 |
* filenode : Node element that contains template for displaying one file
|
|
|
147 |
* callback : On click callback. The element of the fileslist array will be passed as argument
|
|
|
148 |
* rightclickcallback : On right click callback (optional).
|
|
|
149 |
* callbackcontext : context where callbacks are executed
|
|
|
150 |
* sortable : whether content may be sortable (in table mode)
|
|
|
151 |
* dynload : allow dynamic load for tree view
|
|
|
152 |
* filepath : for pre-building of tree view - the path to the current directory in filepicker format
|
|
|
153 |
* treeview_dynload : callback to function to dynamically load the folder in tree view
|
|
|
154 |
* classnamecallback : callback to function that returns the class name for an element
|
|
|
155 |
* @param array fileslist array of files to show, each array element may have attributes:
|
|
|
156 |
* title or fullname : file name
|
|
|
157 |
* shorttitle (optional) : display file name
|
|
|
158 |
* thumbnail : url of image
|
|
|
159 |
* icon : url of icon image
|
|
|
160 |
* thumbnail_width : width of thumbnail, default 90
|
|
|
161 |
* thumbnail_height : height of thumbnail, default 90
|
|
|
162 |
* thumbnail_alt : TODO not needed!
|
|
|
163 |
* description or thumbnail_title : alt text
|
|
|
164 |
* @param array lazyloading : reference to the array with lazy loading images
|
|
|
165 |
*/
|
|
|
166 |
Y.Node.prototype.fp_display_filelist = function(options, fileslist, lazyloading) {
|
|
|
167 |
var viewmodeclassnames = {1:'fp-iconview', 2:'fp-treeview', 3:'fp-tableview'};
|
|
|
168 |
var classname = viewmodeclassnames[options.viewmode];
|
|
|
169 |
var scope = this;
|
|
|
170 |
/** return whether file is a folder (different attributes in FileManager and FilePicker) */
|
|
|
171 |
var file_is_folder = function(node) {
|
|
|
172 |
if (node.children) {return true;}
|
|
|
173 |
if (node.type && node.type == 'folder') {return true;}
|
|
|
174 |
return false;
|
|
|
175 |
};
|
|
|
176 |
/** return the name of the file (different attributes in FileManager and FilePicker) */
|
|
|
177 |
var file_get_filename = function(node) {
|
|
|
178 |
return node.title ? node.title : node.fullname;
|
|
|
179 |
};
|
|
|
180 |
/** return display name of the file (different attributes in FileManager and FilePicker) */
|
|
|
181 |
var file_get_displayname = function(node) {
|
|
|
182 |
var displayname = node.shorttitle ? node.shorttitle : file_get_filename(node);
|
|
|
183 |
return Y.Escape.html(displayname);
|
|
|
184 |
};
|
|
|
185 |
/** return file description (different attributes in FileManager and FilePicker) */
|
|
|
186 |
var file_get_description = function(node) {
|
|
|
187 |
var description = '';
|
|
|
188 |
if (node.description) {
|
|
|
189 |
description = node.description;
|
|
|
190 |
} else if (node.thumbnail_title) {
|
|
|
191 |
description = node.thumbnail_title;
|
|
|
192 |
} else {
|
|
|
193 |
description = file_get_filename(node);
|
|
|
194 |
}
|
|
|
195 |
return Y.Escape.html(description);
|
|
|
196 |
};
|
|
|
197 |
/** help funciton for tree view */
|
|
|
198 |
var build_tree = function(node, level) {
|
|
|
199 |
// prepare file name with icon
|
|
|
200 |
var el = Y.Node.create('<div/>');
|
|
|
201 |
el.appendChild(options.filenode.cloneNode(true));
|
|
|
202 |
|
|
|
203 |
el.one('.fp-filename').setContent(file_get_displayname(node));
|
|
|
204 |
// TODO add tooltip with node.title or node.thumbnail_title
|
|
|
205 |
var tmpnodedata = {className:options.classnamecallback(node)};
|
|
|
206 |
el.get('children').addClass(tmpnodedata.className);
|
|
|
207 |
if (node.icon) {
|
|
|
208 |
el.one('.fp-icon').appendChild(Y.Node.create('<img/>'));
|
|
|
209 |
el.one('.fp-icon img').setImgSrc(node.icon, node.realicon, lazyloading);
|
|
|
210 |
}
|
|
|
211 |
// create node
|
|
|
212 |
tmpnodedata.html = el.getContent();
|
|
|
213 |
var tmpNode = new Y.YUI2.widget.HTMLNode(tmpnodedata, level, false);
|
|
|
214 |
if (node.dynamicLoadComplete) {
|
|
|
215 |
tmpNode.dynamicLoadComplete = true;
|
|
|
216 |
}
|
|
|
217 |
tmpNode.fileinfo = node;
|
|
|
218 |
tmpNode.isLeaf = !file_is_folder(node);
|
|
|
219 |
if (!tmpNode.isLeaf) {
|
|
|
220 |
if(node.expanded) {
|
|
|
221 |
tmpNode.expand();
|
|
|
222 |
}
|
|
|
223 |
tmpNode.path = node.path ? node.path : (node.filepath ? node.filepath : '');
|
|
|
224 |
for(var c in node.children) {
|
|
|
225 |
build_tree(node.children[c], tmpNode);
|
|
|
226 |
}
|
|
|
227 |
}
|
|
|
228 |
};
|
|
|
229 |
/** initialize tree view */
|
|
|
230 |
var initialize_tree_view = function() {
|
|
|
231 |
var parentid = scope.one('.'+classname).get('id');
|
|
|
232 |
// TODO MDL-32736 use YUI3 gallery TreeView
|
|
|
233 |
scope.treeview = new Y.YUI2.widget.TreeView(parentid);
|
|
|
234 |
if (options.dynload) {
|
|
|
235 |
scope.treeview.setDynamicLoad(Y.bind(options.treeview_dynload, options.callbackcontext), 1);
|
|
|
236 |
}
|
|
|
237 |
scope.treeview.singleNodeHighlight = true;
|
|
|
238 |
if (options.filepath && options.filepath.length) {
|
|
|
239 |
// we just jumped from icon/details view, we need to show all parents
|
|
|
240 |
// we extract as much information as possible from filepath and filelist
|
|
|
241 |
// and send additional requests to retrieve siblings for parent folders
|
|
|
242 |
var mytree = {};
|
|
|
243 |
var mytreeel = null;
|
|
|
244 |
for (var i in options.filepath) {
|
|
|
245 |
if (mytreeel == null) {
|
|
|
246 |
mytreeel = mytree;
|
|
|
247 |
} else {
|
|
|
248 |
mytreeel.children = [{}];
|
|
|
249 |
mytreeel = mytreeel.children[0];
|
|
|
250 |
}
|
|
|
251 |
var pathelement = options.filepath[i];
|
|
|
252 |
mytreeel.path = pathelement.path;
|
|
|
253 |
mytreeel.title = pathelement.name;
|
|
|
254 |
mytreeel.icon = pathelement.icon;
|
|
|
255 |
mytreeel.dynamicLoadComplete = true; // we will call it manually
|
|
|
256 |
mytreeel.expanded = true;
|
|
|
257 |
}
|
|
|
258 |
mytreeel.children = fileslist;
|
|
|
259 |
build_tree(mytree, scope.treeview.getRoot());
|
|
|
260 |
// manually call dynload for parent elements in the tree so we can load other siblings
|
|
|
261 |
if (options.dynload) {
|
|
|
262 |
var root = scope.treeview.getRoot();
|
|
|
263 |
// Whether search results are currently displayed in the active repository in the filepicker.
|
|
|
264 |
// We do not want to load siblings of parent elements when displaying search tree results.
|
|
|
265 |
var isSearchResult = typeof options.callbackcontext.active_repo !== 'undefined' &&
|
|
|
266 |
options.callbackcontext.active_repo.issearchresult;
|
|
|
267 |
while (root && root.children && root.children.length) {
|
|
|
268 |
root = root.children[0];
|
|
|
269 |
if (root.path == mytreeel.path) {
|
|
|
270 |
root.origpath = options.filepath;
|
|
|
271 |
root.origlist = fileslist;
|
|
|
272 |
} else if (!root.isLeaf && root.expanded && !isSearchResult) {
|
|
|
273 |
Y.bind(options.treeview_dynload, options.callbackcontext)(root, null);
|
|
|
274 |
}
|
|
|
275 |
}
|
|
|
276 |
}
|
|
|
277 |
} else {
|
|
|
278 |
// there is no path information, just display all elements as a list, without hierarchy
|
|
|
279 |
for(k in fileslist) {
|
|
|
280 |
build_tree(fileslist[k], scope.treeview.getRoot());
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
scope.treeview.subscribe('clickEvent', function(e){
|
|
|
284 |
e.node.highlight(false);
|
|
|
285 |
var callback = options.callback;
|
|
|
286 |
if (options.rightclickcallback && e.event.target &&
|
|
|
287 |
Y.Node(e.event.target).ancestor('.fp-treeview .fp-contextmenu', true)) {
|
|
|
288 |
callback = options.rightclickcallback;
|
|
|
289 |
}
|
|
|
290 |
Y.bind(callback, options.callbackcontext)(e, e.node.fileinfo);
|
|
|
291 |
Y.YUI2.util.Event.stopEvent(e.event)
|
|
|
292 |
});
|
|
|
293 |
// Simulate click on file not folder.
|
|
|
294 |
scope.treeview.subscribe('enterKeyPressed', function(node) {
|
|
|
295 |
if (node.children.length === 0) {
|
|
|
296 |
Y.one(node.getContentEl()).one('a').simulate('click');
|
|
|
297 |
}
|
|
|
298 |
});
|
|
|
299 |
// TODO MDL-32736 support right click
|
|
|
300 |
/*if (options.rightclickcallback) {
|
|
|
301 |
scope.treeview.subscribe('dblClickEvent', function(e){
|
|
|
302 |
e.node.highlight(false);
|
|
|
303 |
Y.bind(options.rightclickcallback, options.callbackcontext)(e, e.node.fileinfo);
|
|
|
304 |
});
|
|
|
305 |
}*/
|
|
|
306 |
scope.treeview.draw();
|
|
|
307 |
};
|
|
|
308 |
/** formatting function for table view */
|
|
|
309 |
var formatValue = function (o){
|
|
|
310 |
if (o.data[''+o.column.key+'_f_s']) {return o.data[''+o.column.key+'_f_s'];}
|
|
|
311 |
else if (o.data[''+o.column.key+'_f']) {return o.data[''+o.column.key+'_f'];}
|
|
|
312 |
else if (o.value) {return o.value;}
|
|
|
313 |
else {return '';}
|
|
|
314 |
};
|
|
|
315 |
/** formatting function for table view */
|
|
|
316 |
var formatTitle = function(o) {
|
|
|
317 |
var el = Y.Node.create('<div/>');
|
|
|
318 |
el.appendChild(options.filenode.cloneNode(true)); // TODO not node but string!
|
|
|
319 |
el.get('children').addClass(o.data['classname']);
|
|
|
320 |
el.one('.fp-filename').setContent(o.value);
|
|
|
321 |
if (o.data['icon']) {
|
|
|
322 |
el.one('.fp-icon').appendChild(Y.Node.create('<img/>'));
|
|
|
323 |
el.one('.fp-icon img').setImgSrc(o.data['icon'], o.data['realicon'], lazyloading);
|
|
|
324 |
}
|
|
|
325 |
if (options.rightclickcallback) {
|
|
|
326 |
el.get('children').addClass('fp-hascontextmenu');
|
|
|
327 |
}
|
|
|
328 |
// TODO add tooltip with o.data['title'] (o.value) or o.data['thumbnail_title']
|
|
|
329 |
return el.getContent();
|
|
|
330 |
}
|
|
|
331 |
|
|
|
332 |
/**
|
|
|
333 |
* Generate slave checkboxes based on toggleall's specification
|
|
|
334 |
* @param {object} o An object reprsenting the record for the current row.
|
|
|
335 |
* @return {html} The checkbox html
|
|
|
336 |
*/
|
|
|
337 |
var formatCheckbox = function(o) {
|
|
|
338 |
var el = Y.Node.create('<div/>');
|
|
|
339 |
var parentid = scope.one('.' + classname).get('id');
|
|
|
340 |
var checkbox = Y.Node.create('<input/>')
|
|
|
341 |
.setAttribute('type', 'checkbox')
|
|
|
342 |
.setAttribute('data-fieldtype', 'checkbox')
|
|
|
343 |
.setAttribute('data-fullname', o.data.fullname)
|
|
|
344 |
.setAttribute('data-action', 'toggle')
|
|
|
345 |
.setAttribute('data-toggle', 'slave')
|
|
|
346 |
.setAttribute('data-togglegroup', 'file-selections-' + parentid);
|
|
|
347 |
|
|
|
348 |
var checkboxLabel = Y.Node.create('<label>')
|
|
|
349 |
.setHTML("Select file '" + o.data.fullname + "'")
|
|
|
350 |
.addClass('sr-only')
|
|
|
351 |
.setAttrs({
|
|
|
352 |
for: checkbox.generateID(),
|
|
|
353 |
});
|
|
|
354 |
|
|
|
355 |
el.appendChild(checkbox);
|
|
|
356 |
el.appendChild(checkboxLabel);
|
|
|
357 |
return el.getContent();
|
|
|
358 |
};
|
|
|
359 |
/** sorting function for table view */
|
|
|
360 |
var sortFoldersFirst = function(a, b, desc) {
|
|
|
361 |
if (a.get('isfolder') && !b.get('isfolder')) {
|
|
|
362 |
return -1;
|
|
|
363 |
}
|
|
|
364 |
if (!a.get('isfolder') && b.get('isfolder')) {
|
|
|
365 |
return 1;
|
|
|
366 |
}
|
|
|
367 |
var aa = a.get(this.key), bb = b.get(this.key), dir = desc ? -1 : 1;
|
|
|
368 |
return (aa > bb) ? dir : ((aa < bb) ? -dir : 0);
|
|
|
369 |
}
|
|
|
370 |
/** initialize table view */
|
|
|
371 |
var initialize_table_view = function() {
|
|
|
372 |
var cols = [
|
|
|
373 |
{key: "displayname", label: M.util.get_string('name', 'moodle'), allowHTML: true, formatter: formatTitle,
|
|
|
374 |
sortable: true, sortFn: sortFoldersFirst},
|
|
|
375 |
{key: "datemodified", label: M.util.get_string('lastmodified', 'moodle'), allowHTML: true, formatter: formatValue,
|
|
|
376 |
sortable: true, sortFn: sortFoldersFirst},
|
|
|
377 |
{key: "size", label: M.util.get_string('size', 'repository'), allowHTML: true, formatter: formatValue,
|
|
|
378 |
sortable: true, sortFn: sortFoldersFirst},
|
|
|
379 |
{key: "mimetype", label: M.util.get_string('type', 'repository'), allowHTML: true,
|
|
|
380 |
sortable: true, sortFn: sortFoldersFirst}
|
|
|
381 |
];
|
|
|
382 |
|
|
|
383 |
// Generate a checkbox based on toggleall's specification
|
|
|
384 |
var div = Y.Node.create('<div/>');
|
|
|
385 |
var parentid = scope.one('.' + classname).get('id');
|
|
|
386 |
var checkbox = Y.Node.create('<input/>')
|
|
|
387 |
.setAttribute('type', 'checkbox')
|
|
|
388 |
// .setAttribute('title', M.util.get_string('selectallornone', 'form'))
|
|
|
389 |
.setAttribute('data-action', 'toggle')
|
|
|
390 |
.setAttribute('data-toggle', 'master')
|
|
|
391 |
.setAttribute('data-togglegroup', 'file-selections-' + parentid);
|
|
|
392 |
|
|
|
393 |
var checkboxLabel = Y.Node.create('<label>')
|
|
|
394 |
.setHTML(M.util.get_string('selectallornone', 'form'))
|
|
|
395 |
.addClass('sr-only')
|
|
|
396 |
.setAttrs({
|
|
|
397 |
for: checkbox.generateID(),
|
|
|
398 |
});
|
|
|
399 |
|
|
|
400 |
div.appendChild(checkboxLabel);
|
|
|
401 |
div.appendChild(checkbox);
|
|
|
402 |
|
|
|
403 |
// Define the selector for the click event handler.
|
|
|
404 |
var clickEventSelector = 'tr';
|
|
|
405 |
// Enable the selectable checkboxes
|
|
|
406 |
if (options.disablecheckboxes != undefined && !options.disablecheckboxes) {
|
|
|
407 |
clickEventSelector = 'tr td:not(:first-child)';
|
|
|
408 |
cols.unshift({
|
|
|
409 |
key: "",
|
|
|
410 |
label: div.getContent(),
|
|
|
411 |
allowHTML: true,
|
|
|
412 |
formatter: formatCheckbox,
|
|
|
413 |
sortable: false
|
|
|
414 |
});
|
|
|
415 |
}
|
|
|
416 |
scope.tableview = new Y.DataTable({columns: cols, data: fileslist});
|
|
|
417 |
scope.tableview.delegate('click', function (e, tableview) {
|
|
|
418 |
var record = tableview.getRecord(e.currentTarget.get('id'));
|
|
|
419 |
if (record) {
|
|
|
420 |
var callback = options.callback;
|
|
|
421 |
if (options.rightclickcallback && e.target.ancestor('.fp-tableview .fp-contextmenu', true)) {
|
|
|
422 |
callback = options.rightclickcallback;
|
|
|
423 |
}
|
|
|
424 |
Y.bind(callback, this)(e, record.getAttrs());
|
|
|
425 |
}
|
|
|
426 |
}, clickEventSelector, options.callbackcontext, scope.tableview);
|
|
|
427 |
|
|
|
428 |
if (options.rightclickcallback) {
|
|
|
429 |
scope.tableview.delegate('contextmenu', function (e, tableview) {
|
|
|
430 |
var record = tableview.getRecord(e.currentTarget.get('id'));
|
|
|
431 |
if (record) { Y.bind(options.rightclickcallback, this)(e, record.getAttrs()); }
|
|
|
432 |
}, 'tr', options.callbackcontext, scope.tableview);
|
|
|
433 |
}
|
|
|
434 |
}
|
|
|
435 |
/** append items in table view mode */
|
|
|
436 |
var append_files_table = function() {
|
|
|
437 |
if (options.appendonly) {
|
|
|
438 |
fileslist.forEach(function(el) {
|
|
|
439 |
this.tableview.data.add(el);
|
|
|
440 |
},scope);
|
|
|
441 |
}
|
|
|
442 |
scope.tableview.render(scope.one('.'+classname));
|
|
|
443 |
scope.tableview.sortable = options.sortable ? true : false;
|
|
|
444 |
};
|
|
|
445 |
/** append items in tree view mode */
|
|
|
446 |
var append_files_tree = function() {
|
|
|
447 |
if (options.appendonly) {
|
|
|
448 |
var parentnode = scope.treeview.getRoot();
|
|
|
449 |
if (scope.treeview.getHighlightedNode()) {
|
|
|
450 |
parentnode = scope.treeview.getHighlightedNode();
|
|
|
451 |
if (parentnode.isLeaf) {parentnode = parentnode.parent;}
|
|
|
452 |
}
|
|
|
453 |
for (var k in fileslist) {
|
|
|
454 |
build_tree(fileslist[k], parentnode);
|
|
|
455 |
}
|
|
|
456 |
scope.treeview.draw();
|
|
|
457 |
} else {
|
|
|
458 |
// otherwise files were already added in initialize_tree_view()
|
|
|
459 |
}
|
|
|
460 |
}
|
|
|
461 |
/** append items in icon view mode */
|
|
|
462 |
var append_files_icons = function() {
|
|
|
463 |
parent = scope.one('.'+classname);
|
|
|
464 |
for (var k in fileslist) {
|
|
|
465 |
var node = fileslist[k];
|
|
|
466 |
var element = options.filenode.cloneNode(true);
|
|
|
467 |
parent.appendChild(element);
|
|
|
468 |
element.addClass(options.classnamecallback(node));
|
|
|
469 |
var filenamediv = element.one('.fp-filename');
|
|
|
470 |
filenamediv.setContent(file_get_displayname(node));
|
|
|
471 |
var imgdiv = element.one('.fp-thumbnail'), width, height, src;
|
|
|
472 |
if (node.thumbnail) {
|
|
|
473 |
width = node.thumbnail_width ? node.thumbnail_width : 90;
|
|
|
474 |
height = node.thumbnail_height ? node.thumbnail_height : 90;
|
|
|
475 |
src = node.thumbnail;
|
|
|
476 |
} else {
|
|
|
477 |
width = 16;
|
|
|
478 |
height = 16;
|
|
|
479 |
src = node.icon;
|
|
|
480 |
}
|
|
|
481 |
filenamediv.setStyleAdv('width', width);
|
|
|
482 |
imgdiv.setStyleAdv('width', width).setStyleAdv('height', height);
|
|
|
483 |
var img = Y.Node.create('<img/>').setAttrs({
|
|
|
484 |
title: file_get_description(node),
|
|
|
485 |
alt: Y.Escape.html(node.thumbnail_alt ? node.thumbnail_alt : file_get_filename(node))}).
|
|
|
486 |
setStyle('maxWidth', ''+width+'px').
|
|
|
487 |
setStyle('maxHeight', ''+height+'px');
|
|
|
488 |
img.setImgSrc(src, node.realthumbnail, lazyloading);
|
|
|
489 |
imgdiv.appendChild(img);
|
|
|
490 |
element.on('click', function(e, nd) {
|
|
|
491 |
if (options.rightclickcallback && e.target.ancestor('.fp-iconview .fp-contextmenu', true)) {
|
|
|
492 |
Y.bind(options.rightclickcallback, this)(e, nd);
|
|
|
493 |
} else {
|
|
|
494 |
Y.bind(options.callback, this)(e, nd);
|
|
|
495 |
}
|
|
|
496 |
}, options.callbackcontext, node);
|
|
|
497 |
if (options.rightclickcallback) {
|
|
|
498 |
element.on('contextmenu', options.rightclickcallback, options.callbackcontext, node);
|
|
|
499 |
}
|
|
|
500 |
}
|
|
|
501 |
}
|
|
|
502 |
|
|
|
503 |
// Notify the user if any of the files has a problem status.
|
|
|
504 |
var problemFiles = [];
|
|
|
505 |
fileslist.forEach(function(file) {
|
|
|
506 |
if (!file_is_folder(file) && file.hasOwnProperty('status') && file.status != 0) {
|
|
|
507 |
problemFiles.push(file);
|
|
|
508 |
}
|
|
|
509 |
});
|
|
|
510 |
if (problemFiles.length > 0) {
|
|
|
511 |
require(["core/notification", "core/str"], function(Notification, Str) {
|
|
|
512 |
problemFiles.forEach(function(problemFile) {
|
|
|
513 |
Str.get_string('storedfilecannotreadfile', 'error', problemFile.fullname).then(function(string) {
|
|
|
514 |
Notification.addNotification({
|
|
|
515 |
message: string,
|
|
|
516 |
type: "error"
|
|
|
517 |
});
|
|
|
518 |
return;
|
|
|
519 |
}).catch(Notification.exception);
|
|
|
520 |
});
|
|
|
521 |
});
|
|
|
522 |
}
|
|
|
523 |
|
|
|
524 |
// If table view, need some additional properties
|
|
|
525 |
// before passing fileslist to the YUI tableview
|
|
|
526 |
if (options.viewmode == 3) {
|
|
|
527 |
fileslist.forEach(function(el) {
|
|
|
528 |
el.displayname = file_get_displayname(el);
|
|
|
529 |
el.isfolder = file_is_folder(el);
|
|
|
530 |
el.classname = options.classnamecallback(el);
|
|
|
531 |
}, scope);
|
|
|
532 |
}
|
|
|
533 |
|
|
|
534 |
// initialize files view
|
|
|
535 |
if (!options.appendonly) {
|
|
|
536 |
var parent = Y.Node.create('<div/>').addClass(classname);
|
|
|
537 |
this.setContent('').appendChild(parent);
|
|
|
538 |
parent.generateID();
|
|
|
539 |
if (options.viewmode == 2) {
|
|
|
540 |
initialize_tree_view();
|
|
|
541 |
} else if (options.viewmode == 3) {
|
|
|
542 |
initialize_table_view();
|
|
|
543 |
} else {
|
|
|
544 |
// nothing to initialize for icon view
|
|
|
545 |
}
|
|
|
546 |
}
|
|
|
547 |
|
|
|
548 |
// append files to the list
|
|
|
549 |
if (options.viewmode == 2) {
|
|
|
550 |
append_files_tree();
|
|
|
551 |
} else if (options.viewmode == 3) {
|
|
|
552 |
append_files_table();
|
|
|
553 |
} else {
|
|
|
554 |
append_files_icons();
|
|
|
555 |
}
|
|
|
556 |
|
|
|
557 |
}
|
|
|
558 |
}, '@VERSION@', {
|
|
|
559 |
requires:['base', 'node', 'yui2-treeview', 'panel', 'cookie', 'datatable', 'datatable-sort']
|
|
|
560 |
});
|
|
|
561 |
|
|
|
562 |
M.core_filepicker = M.core_filepicker || {};
|
|
|
563 |
|
|
|
564 |
/**
|
|
|
565 |
* instances of file pickers used on page
|
|
|
566 |
*/
|
|
|
567 |
M.core_filepicker.instances = M.core_filepicker.instances || {};
|
|
|
568 |
M.core_filepicker.active_filepicker = null;
|
|
|
569 |
|
|
|
570 |
/**
|
|
|
571 |
* HTML Templates to use in FilePicker
|
|
|
572 |
*/
|
|
|
573 |
M.core_filepicker.templates = M.core_filepicker.templates || {};
|
|
|
574 |
|
|
|
575 |
/**
|
|
|
576 |
* Array of image sources for real previews (realicon or realthumbnail) that are already loaded
|
|
|
577 |
*/
|
|
|
578 |
M.core_filepicker.loadedpreviews = M.core_filepicker.loadedpreviews || {};
|
|
|
579 |
|
|
|
580 |
/**
|
|
|
581 |
* Set selected file info
|
|
|
582 |
*
|
|
|
583 |
* @param object file info
|
|
|
584 |
*/
|
|
|
585 |
M.core_filepicker.select_file = function(file) {
|
|
|
586 |
M.core_filepicker.active_filepicker.select_file(file);
|
|
|
587 |
}
|
|
|
588 |
|
|
|
589 |
/**
|
|
|
590 |
* Init and show file picker
|
|
|
591 |
*/
|
|
|
592 |
M.core_filepicker.show = function(Y, options) {
|
|
|
593 |
if (!M.core_filepicker.instances[options.client_id]) {
|
|
|
594 |
M.core_filepicker.init(Y, options);
|
|
|
595 |
}
|
|
|
596 |
M.core_filepicker.instances[options.client_id].options.formcallback = options.formcallback;
|
|
|
597 |
M.core_filepicker.instances[options.client_id].show();
|
|
|
598 |
};
|
|
|
599 |
|
|
|
600 |
M.core_filepicker.set_templates = function(Y, templates) {
|
|
|
601 |
for (var templid in templates) {
|
|
|
602 |
M.core_filepicker.templates[templid] = templates[templid];
|
|
|
603 |
}
|
|
|
604 |
}
|
|
|
605 |
|
|
|
606 |
/**
|
|
|
607 |
* Add new file picker to current instances
|
|
|
608 |
*/
|
|
|
609 |
M.core_filepicker.init = function(Y, options) {
|
|
|
610 |
var FilePickerHelper = function(options) {
|
|
|
611 |
FilePickerHelper.superclass.constructor.apply(this, arguments);
|
|
|
612 |
};
|
|
|
613 |
|
|
|
614 |
FilePickerHelper.NAME = "FilePickerHelper";
|
|
|
615 |
FilePickerHelper.ATTRS = {
|
|
|
616 |
options: {},
|
|
|
617 |
lang: {}
|
|
|
618 |
};
|
|
|
619 |
|
|
|
620 |
Y.extend(FilePickerHelper, Y.Base, {
|
|
|
621 |
api: M.cfg.wwwroot+'/repository/repository_ajax.php',
|
|
|
622 |
cached_responses: {},
|
|
|
623 |
waitinterval : null, // When the loading template is being displayed and its animation is running this will be an interval instance.
|
|
|
624 |
initializer: function(options) {
|
|
|
625 |
this.options = options;
|
|
|
626 |
if (!this.options.savepath) {
|
|
|
627 |
this.options.savepath = '/';
|
|
|
628 |
}
|
|
|
629 |
},
|
|
|
630 |
|
|
|
631 |
destructor: function() {
|
|
|
632 |
},
|
|
|
633 |
|
|
|
634 |
request: function(args, redraw) {
|
|
|
635 |
var api = (args.api ? args.api : this.api) + '?action='+args.action;
|
|
|
636 |
var params = {};
|
|
|
637 |
var scope = args['scope'] ? args['scope'] : this;
|
|
|
638 |
params['repo_id']=args.repository_id;
|
|
|
639 |
params['p'] = args.path?args.path:'';
|
|
|
640 |
params['page'] = args.page?args.page:'';
|
|
|
641 |
params['env']=this.options.env;
|
|
|
642 |
// the form element only accept certain file types
|
|
|
643 |
params['accepted_types']=this.options.accepted_types;
|
|
|
644 |
params['sesskey'] = M.cfg.sesskey;
|
|
|
645 |
params['client_id'] = args.client_id;
|
|
|
646 |
params['itemid'] = this.options.itemid?this.options.itemid:0;
|
|
|
647 |
params['maxbytes'] = this.options.maxbytes?this.options.maxbytes:-1;
|
|
|
648 |
// The unlimited value of areamaxbytes is -1, it is defined by FILE_AREA_MAX_BYTES_UNLIMITED.
|
|
|
649 |
params['areamaxbytes'] = this.options.areamaxbytes ? this.options.areamaxbytes : -1;
|
|
|
650 |
if (this.options.context && this.options.context.id) {
|
|
|
651 |
params['ctx_id'] = this.options.context.id;
|
|
|
652 |
}
|
|
|
653 |
if (args['params']) {
|
|
|
654 |
for (i in args['params']) {
|
|
|
655 |
params[i] = args['params'][i];
|
|
|
656 |
}
|
|
|
657 |
}
|
|
|
658 |
if (args.action == 'upload') {
|
|
|
659 |
var list = [];
|
|
|
660 |
for(var k in params) {
|
|
|
661 |
var value = params[k];
|
|
|
662 |
if(value instanceof Array) {
|
|
|
663 |
for(var i in value) {
|
|
|
664 |
list.push(k+'[]='+value[i]);
|
|
|
665 |
}
|
|
|
666 |
} else {
|
|
|
667 |
list.push(k+'='+value);
|
|
|
668 |
}
|
|
|
669 |
}
|
|
|
670 |
params = list.join('&');
|
|
|
671 |
} else {
|
|
|
672 |
params = build_querystring(params);
|
|
|
673 |
}
|
|
|
674 |
var cfg = {
|
|
|
675 |
method: 'POST',
|
|
|
676 |
on: {
|
|
|
677 |
complete: function(id,o,p) {
|
|
|
678 |
var data = null;
|
|
|
679 |
try {
|
|
|
680 |
data = Y.JSON.parse(o.responseText);
|
|
|
681 |
} catch(e) {
|
|
|
682 |
if (o && o.status && o.status > 0) {
|
|
|
683 |
Y.use('moodle-core-notification-exception', function() {
|
|
|
684 |
return new M.core.exception(e);
|
|
|
685 |
});
|
|
|
686 |
return;
|
|
|
687 |
}
|
|
|
688 |
}
|
|
|
689 |
// error checking
|
|
|
690 |
if (data && data.error) {
|
|
|
691 |
Y.use('moodle-core-notification-ajaxexception', function () {
|
|
|
692 |
return new M.core.ajaxException(data);
|
|
|
693 |
});
|
|
|
694 |
this.fpnode.one('.fp-content').setContent('');
|
|
|
695 |
return;
|
|
|
696 |
} else {
|
|
|
697 |
if (data.msg) {
|
|
|
698 |
scope.print_msg(data.msg, 'info');
|
|
|
699 |
}
|
|
|
700 |
// cache result if applicable
|
|
|
701 |
if (args.action != 'upload' && data.allowcaching) {
|
|
|
702 |
scope.cached_responses[params] = data;
|
|
|
703 |
}
|
|
|
704 |
// invoke callback
|
|
|
705 |
args.callback(id,data,p);
|
|
|
706 |
}
|
|
|
707 |
}
|
|
|
708 |
},
|
|
|
709 |
arguments: {
|
|
|
710 |
scope: scope
|
|
|
711 |
},
|
|
|
712 |
headers: {
|
|
|
713 |
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
|
|
714 |
},
|
|
|
715 |
data: params,
|
|
|
716 |
context: this
|
|
|
717 |
};
|
|
|
718 |
if (args.form) {
|
|
|
719 |
cfg.form = args.form;
|
|
|
720 |
}
|
|
|
721 |
// check if result of the same request has been already cached. If not, request it
|
|
|
722 |
// (never applicable in case of form submission and/or upload action):
|
|
|
723 |
if (!args.form && args.action != 'upload' && scope.cached_responses[params]) {
|
|
|
724 |
args.callback(null, scope.cached_responses[params], {scope: scope})
|
|
|
725 |
} else {
|
|
|
726 |
Y.io(api, cfg);
|
|
|
727 |
if (redraw) {
|
|
|
728 |
this.wait();
|
|
|
729 |
}
|
|
|
730 |
}
|
|
|
731 |
},
|
|
|
732 |
/** displays the dialog and processes rename/overwrite if there is a file with the same name in the same filearea*/
|
|
|
733 |
process_existing_file: function(data) {
|
|
|
734 |
var scope = this;
|
|
|
735 |
var handleOverwrite = function(e) {
|
|
|
736 |
// overwrite
|
|
|
737 |
e.preventDefault();
|
|
|
738 |
var data = this.process_dlg.dialogdata;
|
|
|
739 |
var params = {}
|
|
|
740 |
params['existingfilename'] = data.existingfile.filename;
|
|
|
741 |
params['existingfilepath'] = data.existingfile.filepath;
|
|
|
742 |
params['newfilename'] = data.newfile.filename;
|
|
|
743 |
params['newfilepath'] = data.newfile.filepath;
|
|
|
744 |
this.hide_header();
|
|
|
745 |
this.request({
|
|
|
746 |
'params': params,
|
|
|
747 |
'scope': this,
|
|
|
748 |
'action':'overwrite',
|
|
|
749 |
'path': '',
|
|
|
750 |
'client_id': this.options.client_id,
|
|
|
751 |
'repository_id': this.active_repo.id,
|
|
|
752 |
'callback': function(id, o, args) {
|
|
|
753 |
scope.hide();
|
|
|
754 |
// Add an arbitrary parameter to the URL to force browsers to re-load the new image even
|
|
|
755 |
// if the file name has not changed.
|
|
|
756 |
var urlimage = data.existingfile.url + "?time=" + (new Date()).getTime();
|
|
|
757 |
if (scope.options.editor_target && scope.options.env == 'editor') {
|
|
|
758 |
// editor needs to update url
|
|
|
759 |
scope.options.editor_target.value = urlimage;
|
|
|
760 |
scope.options.editor_target.dispatchEvent(new Event('change'), {'bubbles': true});
|
|
|
761 |
}
|
|
|
762 |
var fileinfo = {'client_id':scope.options.client_id,
|
|
|
763 |
'url': urlimage,
|
|
|
764 |
'file': data.existingfile.filename};
|
|
|
765 |
var formcallback_scope = scope.options.magicscope ? scope.options.magicscope : scope;
|
|
|
766 |
scope.options.formcallback.apply(formcallback_scope, [fileinfo]);
|
|
|
767 |
}
|
|
|
768 |
}, true);
|
|
|
769 |
}
|
|
|
770 |
var handleRename = function(e) {
|
|
|
771 |
// inserts file with the new name
|
|
|
772 |
e.preventDefault();
|
|
|
773 |
var scope = this;
|
|
|
774 |
var data = this.process_dlg.dialogdata;
|
|
|
775 |
if (scope.options.editor_target && scope.options.env == 'editor') {
|
|
|
776 |
scope.options.editor_target.value = data.newfile.url;
|
|
|
777 |
scope.options.editor_target.dispatchEvent(new Event('change'), {'bubbles': true});
|
|
|
778 |
}
|
|
|
779 |
scope.hide();
|
|
|
780 |
var formcallback_scope = scope.options.magicscope ? scope.options.magicscope : scope;
|
|
|
781 |
var fileinfo = {'client_id':scope.options.client_id,
|
|
|
782 |
'url':data.newfile.url,
|
|
|
783 |
'file':data.newfile.filename};
|
|
|
784 |
scope.options.formcallback.apply(formcallback_scope, [fileinfo]);
|
|
|
785 |
}
|
|
|
786 |
var handleCancel = function(e) {
|
|
|
787 |
// Delete tmp file
|
|
|
788 |
e.preventDefault();
|
|
|
789 |
var params = {};
|
|
|
790 |
params['newfilename'] = this.process_dlg.dialogdata.newfile.filename;
|
|
|
791 |
params['newfilepath'] = this.process_dlg.dialogdata.newfile.filepath;
|
|
|
792 |
this.request({
|
|
|
793 |
'params': params,
|
|
|
794 |
'scope': this,
|
|
|
795 |
'action':'deletetmpfile',
|
|
|
796 |
'path': '',
|
|
|
797 |
'client_id': this.options.client_id,
|
|
|
798 |
'repository_id': this.active_repo.id,
|
|
|
799 |
'callback': function(id, o, args) {
|
|
|
800 |
// let it be in background, from user point of view nothing is happenning
|
|
|
801 |
}
|
|
|
802 |
}, false);
|
|
|
803 |
this.process_dlg.hide();
|
|
|
804 |
this.selectui.hide();
|
|
|
805 |
}
|
|
|
806 |
if (!this.process_dlg) {
|
|
|
807 |
this.process_dlg_node = Y.Node.create(M.core_filepicker.templates.processexistingfile);
|
|
|
808 |
var node = this.process_dlg_node;
|
|
|
809 |
node.generateID();
|
|
|
810 |
this.process_dlg = new M.core.dialogue({
|
|
|
811 |
draggable : true,
|
|
|
812 |
bodyContent : node,
|
|
|
813 |
headerContent: M.util.get_string('fileexistsdialogheader', 'repository'),
|
|
|
814 |
centered : true,
|
|
|
815 |
modal : true,
|
|
|
816 |
visible : false,
|
|
|
817 |
zIndex : this.options.zIndex
|
|
|
818 |
});
|
|
|
819 |
node.one('.fp-dlg-butoverwrite').on('click', handleOverwrite, this);
|
|
|
820 |
node.one('.fp-dlg-butrename').on('click', handleRename, this);
|
|
|
821 |
node.one('.fp-dlg-butcancel').on('click', handleCancel, this);
|
|
|
822 |
if (this.options.env == 'editor') {
|
|
|
823 |
node.one('.fp-dlg-text').setContent(M.util.get_string('fileexistsdialog_editor', 'repository'));
|
|
|
824 |
} else {
|
|
|
825 |
node.one('.fp-dlg-text').setContent(M.util.get_string('fileexistsdialog_filemanager', 'repository'));
|
|
|
826 |
}
|
|
|
827 |
}
|
|
|
828 |
this.selectnode.removeClass('loading');
|
|
|
829 |
this.process_dlg.dialogdata = data;
|
|
|
830 |
this.process_dlg_node.one('.fp-dlg-butrename').setContent(M.util.get_string('renameto', 'repository', data.newfile.filename));
|
|
|
831 |
this.process_dlg.show();
|
|
|
832 |
},
|
|
|
833 |
/** displays error instead of filepicker contents */
|
|
|
834 |
display_error: function(errortext, errorcode) {
|
|
|
835 |
this.fpnode.one('.fp-content').setContent(M.core_filepicker.templates.error);
|
|
|
836 |
this.fpnode.one('.fp-content .fp-error').
|
|
|
837 |
addClass(errorcode).
|
|
|
838 |
setContent(Y.Escape.html(errortext));
|
|
|
839 |
},
|
|
|
840 |
/** displays message in a popup */
|
|
|
841 |
print_msg: function(msg, type) {
|
|
|
842 |
var header = M.util.get_string('error', 'moodle');
|
|
|
843 |
if (type != 'error') {
|
|
|
844 |
type = 'info'; // one of only two types excepted
|
|
|
845 |
header = M.util.get_string('info', 'moodle');
|
|
|
846 |
}
|
|
|
847 |
if (!this.msg_dlg) {
|
|
|
848 |
this.msg_dlg_node = Y.Node.create(M.core_filepicker.templates.message);
|
|
|
849 |
this.msg_dlg_node.generateID();
|
|
|
850 |
|
|
|
851 |
this.msg_dlg = new M.core.dialogue({
|
|
|
852 |
draggable : true,
|
|
|
853 |
bodyContent : this.msg_dlg_node,
|
|
|
854 |
centered : true,
|
|
|
855 |
modal : true,
|
|
|
856 |
visible : false,
|
|
|
857 |
zIndex : this.options.zIndex
|
|
|
858 |
});
|
|
|
859 |
this.msg_dlg_node.one('.fp-msg-butok').on('click', function(e) {
|
|
|
860 |
e.preventDefault();
|
|
|
861 |
this.msg_dlg.hide();
|
|
|
862 |
}, this);
|
|
|
863 |
}
|
|
|
864 |
|
|
|
865 |
this.msg_dlg.set('headerContent', header);
|
|
|
866 |
this.msg_dlg_node.removeClass('fp-msg-info').removeClass('fp-msg-error').addClass('fp-msg-'+type)
|
|
|
867 |
this.msg_dlg_node.one('.fp-msg-text').setContent(Y.Escape.html(msg));
|
|
|
868 |
this.msg_dlg.show();
|
|
|
869 |
},
|
|
|
870 |
view_files: function(appenditems) {
|
|
|
871 |
this.viewbar_set_enabled(true);
|
|
|
872 |
this.print_path();
|
|
|
873 |
/*if ((appenditems == null) && (!this.filelist || !this.filelist.length) && !this.active_repo.hasmorepages) {
|
|
|
874 |
// TODO do it via classes and adjust for each view mode!
|
|
|
875 |
// If there are no items and no next page, just display status message and quit
|
|
|
876 |
this.display_error(M.util.get_string('nofilesavailable', 'repository'), 'nofilesavailable');
|
|
|
877 |
return;
|
|
|
878 |
}*/
|
|
|
879 |
if (this.viewmode == 2) {
|
|
|
880 |
this.view_as_list(appenditems);
|
|
|
881 |
} else if (this.viewmode == 3) {
|
|
|
882 |
this.view_as_table(appenditems);
|
|
|
883 |
} else {
|
|
|
884 |
this.view_as_icons(appenditems);
|
|
|
885 |
}
|
|
|
886 |
this.fpnode.one('.fp-content').setAttribute('tabindex', '0');
|
|
|
887 |
this.fpnode.one('.fp-content').focus();
|
|
|
888 |
// display/hide the link for requesting next page
|
|
|
889 |
if (!appenditems && this.active_repo.hasmorepages) {
|
|
|
890 |
if (!this.fpnode.one('.fp-content .fp-nextpage')) {
|
|
|
891 |
this.fpnode.one('.fp-content').append(M.core_filepicker.templates.nextpage);
|
|
|
892 |
}
|
|
|
893 |
this.fpnode.one('.fp-content .fp-nextpage').one('a,button').on('click', function(e) {
|
|
|
894 |
e.preventDefault();
|
|
|
895 |
this.fpnode.one('.fp-content .fp-nextpage').addClass('loading');
|
|
|
896 |
this.request_next_page();
|
|
|
897 |
}, this);
|
|
|
898 |
}
|
|
|
899 |
if (!this.active_repo.hasmorepages && this.fpnode.one('.fp-content .fp-nextpage')) {
|
|
|
900 |
this.fpnode.one('.fp-content .fp-nextpage').remove();
|
|
|
901 |
}
|
|
|
902 |
if (this.fpnode.one('.fp-content .fp-nextpage')) {
|
|
|
903 |
this.fpnode.one('.fp-content .fp-nextpage').removeClass('loading');
|
|
|
904 |
}
|
|
|
905 |
this.content_scrolled();
|
|
|
906 |
},
|
|
|
907 |
content_scrolled: function(e) {
|
|
|
908 |
setTimeout(Y.bind(function() {
|
|
|
909 |
if (this.processingimages) {
|
|
|
910 |
return;
|
|
|
911 |
}
|
|
|
912 |
this.processingimages = true;
|
|
|
913 |
var scope = this,
|
|
|
914 |
fpcontent = this.fpnode.one('.fp-content'),
|
|
|
915 |
fpcontenty = fpcontent.getY(),
|
|
|
916 |
fpcontentheight = fpcontent.getStylePx('height'),
|
|
|
917 |
nextpage = fpcontent.one('.fp-nextpage'),
|
|
|
918 |
is_node_visible = function(node) {
|
|
|
919 |
var offset = node.getY()-fpcontenty;
|
|
|
920 |
if (offset <= fpcontentheight && (offset >=0 || offset+node.getStylePx('height')>=0)) {
|
|
|
921 |
return true;
|
|
|
922 |
}
|
|
|
923 |
return false;
|
|
|
924 |
};
|
|
|
925 |
// automatically load next page when 'more' link becomes visible
|
|
|
926 |
if (nextpage && !nextpage.hasClass('loading') && is_node_visible(nextpage)) {
|
|
|
927 |
nextpage.one('a,button').simulate('click');
|
|
|
928 |
}
|
|
|
929 |
// replace src for visible images that need to be lazy-loaded
|
|
|
930 |
if (scope.lazyloading) {
|
|
|
931 |
fpcontent.all('img').each( function(node) {
|
|
|
932 |
if (node.get('id') && scope.lazyloading[node.get('id')] && is_node_visible(node)) {
|
|
|
933 |
node.setImgRealSrc(scope.lazyloading);
|
|
|
934 |
}
|
|
|
935 |
});
|
|
|
936 |
}
|
|
|
937 |
this.processingimages = false;
|
|
|
938 |
}, this), 200)
|
|
|
939 |
},
|
|
|
940 |
treeview_dynload: function(node, cb) {
|
|
|
941 |
var retrieved_children = {};
|
|
|
942 |
if (node.children) {
|
|
|
943 |
for (var i in node.children) {
|
|
|
944 |
retrieved_children[node.children[i].path] = node.children[i];
|
|
|
945 |
}
|
|
|
946 |
}
|
|
|
947 |
this.request({
|
|
|
948 |
action:'list',
|
|
|
949 |
client_id: this.options.client_id,
|
|
|
950 |
repository_id: this.active_repo.id,
|
|
|
951 |
path:node.path?node.path:'',
|
|
|
952 |
page:node.page?args.page:'',
|
|
|
953 |
scope:this,
|
|
|
954 |
callback: function(id, obj, args) {
|
|
|
955 |
var list = obj.list;
|
|
|
956 |
var scope = args.scope;
|
|
|
957 |
// check that user did not leave the view mode before recieving this response
|
|
|
958 |
if (!(scope.active_repo.id == obj.repo_id && scope.viewmode == 2 && node && node.getChildrenEl())) {
|
|
|
959 |
return;
|
|
|
960 |
}
|
|
|
961 |
if (cb != null) { // (in manual mode do not update current path)
|
|
|
962 |
scope.viewbar_set_enabled(true);
|
|
|
963 |
scope.parse_repository_options(obj);
|
|
|
964 |
}
|
|
|
965 |
node.highlight(false);
|
|
|
966 |
node.origlist = obj.list ? obj.list : null;
|
|
|
967 |
node.origpath = obj.path ? obj.path : null;
|
|
|
968 |
node.children = [];
|
|
|
969 |
for(k in list) {
|
|
|
970 |
if (list[k].children && retrieved_children[list[k].path]) {
|
|
|
971 |
// if this child is a folder and has already been retrieved
|
|
|
972 |
node.children[node.children.length] = retrieved_children[list[k].path];
|
|
|
973 |
} else {
|
|
|
974 |
// append new file to the list
|
|
|
975 |
scope.view_as_list([list[k]]);
|
|
|
976 |
}
|
|
|
977 |
}
|
|
|
978 |
if (cb == null) {
|
|
|
979 |
node.refresh();
|
|
|
980 |
} else {
|
|
|
981 |
// invoke callback requested by TreeView component
|
|
|
982 |
cb();
|
|
|
983 |
}
|
|
|
984 |
scope.content_scrolled();
|
|
|
985 |
}
|
|
|
986 |
}, false);
|
|
|
987 |
},
|
|
|
988 |
classnamecallback : function(node) {
|
|
|
989 |
var classname = '';
|
|
|
990 |
if (node.children) {
|
|
|
991 |
classname = classname + ' fp-folder';
|
|
|
992 |
}
|
|
|
993 |
if (node.isref) {
|
|
|
994 |
classname = classname + ' fp-isreference';
|
|
|
995 |
}
|
|
|
996 |
if (node.iscontrolledlink) {
|
|
|
997 |
classname = classname + ' fp-iscontrolledlink';
|
|
|
998 |
}
|
|
|
999 |
if (node.refcount) {
|
|
|
1000 |
classname = classname + ' fp-hasreferences';
|
|
|
1001 |
}
|
|
|
1002 |
if (node.originalmissing) {
|
|
|
1003 |
classname = classname + ' fp-originalmissing';
|
|
|
1004 |
}
|
|
|
1005 |
return Y.Lang.trim(classname);
|
|
|
1006 |
},
|
|
|
1007 |
/** displays list of files in tree (list) view mode. If param appenditems is specified,
|
|
|
1008 |
* appends those items to the end of the list. Otherwise (default behaviour)
|
|
|
1009 |
* clears the contents and displays the items from this.filelist */
|
|
|
1010 |
view_as_list: function(appenditems) {
|
|
|
1011 |
var list = (appenditems != null) ? appenditems : this.filelist;
|
|
|
1012 |
this.viewmode = 2;
|
|
|
1013 |
if (!this.filelist || this.filelist.length==0 && (!this.filepath || !this.filepath.length)) {
|
|
|
1014 |
this.display_error(M.util.get_string('nofilesavailable', 'repository'), 'nofilesavailable');
|
|
|
1015 |
return;
|
|
|
1016 |
}
|
|
|
1017 |
|
|
|
1018 |
var element_template = Y.Node.create(M.core_filepicker.templates.listfilename);
|
|
|
1019 |
var options = {
|
|
|
1020 |
viewmode : this.viewmode,
|
|
|
1021 |
appendonly : (appenditems != null),
|
|
|
1022 |
filenode : element_template,
|
|
|
1023 |
callbackcontext : this,
|
|
|
1024 |
callback : function(e, node) {
|
|
|
1025 |
// TODO MDL-32736 e is not an event here but an object with properties 'event' and 'node'
|
|
|
1026 |
if (!node.children) {
|
|
|
1027 |
if (e.node.parent && e.node.parent.origpath) {
|
|
|
1028 |
// set the current path
|
|
|
1029 |
this.filepath = e.node.parent.origpath;
|
|
|
1030 |
this.filelist = e.node.parent.origlist;
|
|
|
1031 |
this.print_path();
|
|
|
1032 |
}
|
|
|
1033 |
this.select_file(node);
|
|
|
1034 |
} else {
|
|
|
1035 |
// save current path and filelist (in case we want to jump to other viewmode)
|
|
|
1036 |
this.filepath = e.node.origpath;
|
|
|
1037 |
this.filelist = e.node.origlist;
|
|
|
1038 |
this.currentpath = e.node.path;
|
|
|
1039 |
this.print_path();
|
|
|
1040 |
this.content_scrolled();
|
|
|
1041 |
}
|
|
|
1042 |
},
|
|
|
1043 |
classnamecallback : this.classnamecallback,
|
|
|
1044 |
dynload : this.active_repo.dynload,
|
|
|
1045 |
filepath : this.filepath,
|
|
|
1046 |
treeview_dynload : this.treeview_dynload
|
|
|
1047 |
};
|
|
|
1048 |
this.fpnode.one('.fp-content').fp_display_filelist(options, list, this.lazyloading);
|
|
|
1049 |
},
|
|
|
1050 |
/** displays list of files in icon view mode. If param appenditems is specified,
|
|
|
1051 |
* appends those items to the end of the list. Otherwise (default behaviour)
|
|
|
1052 |
* clears the contents and displays the items from this.filelist */
|
|
|
1053 |
view_as_icons: function(appenditems) {
|
|
|
1054 |
this.viewmode = 1;
|
|
|
1055 |
var list = (appenditems != null) ? appenditems : this.filelist;
|
|
|
1056 |
var element_template = Y.Node.create(M.core_filepicker.templates.iconfilename);
|
|
|
1057 |
if ((appenditems == null) && (!this.filelist || !this.filelist.length)) {
|
|
|
1058 |
this.display_error(M.util.get_string('nofilesavailable', 'repository'), 'nofilesavailable');
|
|
|
1059 |
return;
|
|
|
1060 |
}
|
|
|
1061 |
var options = {
|
|
|
1062 |
viewmode : this.viewmode,
|
|
|
1063 |
appendonly : (appenditems != null),
|
|
|
1064 |
filenode : element_template,
|
|
|
1065 |
callbackcontext : this,
|
|
|
1066 |
callback : function(e, node) {
|
|
|
1067 |
if (e.preventDefault) {
|
|
|
1068 |
e.preventDefault();
|
|
|
1069 |
}
|
|
|
1070 |
if(node.children) {
|
|
|
1071 |
if (this.active_repo.dynload) {
|
|
|
1072 |
this.list({'path':node.path});
|
|
|
1073 |
} else {
|
|
|
1074 |
this.filelist = node.children;
|
|
|
1075 |
this.view_files();
|
|
|
1076 |
}
|
|
|
1077 |
} else {
|
|
|
1078 |
this.select_file(node);
|
|
|
1079 |
}
|
|
|
1080 |
},
|
|
|
1081 |
classnamecallback : this.classnamecallback
|
|
|
1082 |
};
|
|
|
1083 |
this.fpnode.one('.fp-content').fp_display_filelist(options, list, this.lazyloading);
|
|
|
1084 |
},
|
|
|
1085 |
/** displays list of files in table view mode. If param appenditems is specified,
|
|
|
1086 |
* appends those items to the end of the list. Otherwise (default behaviour)
|
|
|
1087 |
* clears the contents and displays the items from this.filelist */
|
|
|
1088 |
view_as_table: function(appenditems) {
|
|
|
1089 |
this.viewmode = 3;
|
|
|
1090 |
var list = (appenditems != null) ? appenditems : this.filelist;
|
|
|
1091 |
if (!appenditems && (!this.filelist || this.filelist.length==0) && !this.active_repo.hasmorepages) {
|
|
|
1092 |
this.display_error(M.util.get_string('nofilesavailable', 'repository'), 'nofilesavailable');
|
|
|
1093 |
return;
|
|
|
1094 |
}
|
|
|
1095 |
var element_template = Y.Node.create(M.core_filepicker.templates.listfilename);
|
|
|
1096 |
var options = {
|
|
|
1097 |
viewmode : this.viewmode,
|
|
|
1098 |
appendonly : (appenditems != null),
|
|
|
1099 |
filenode : element_template,
|
|
|
1100 |
callbackcontext : this,
|
|
|
1101 |
sortable : !this.active_repo.hasmorepages,
|
|
|
1102 |
callback : function(e, node) {
|
|
|
1103 |
if (e.preventDefault) {e.preventDefault();}
|
|
|
1104 |
if (node.children) {
|
|
|
1105 |
if (this.active_repo.dynload) {
|
|
|
1106 |
this.list({'path':node.path});
|
|
|
1107 |
} else {
|
|
|
1108 |
this.filelist = node.children;
|
|
|
1109 |
this.view_files();
|
|
|
1110 |
}
|
|
|
1111 |
} else {
|
|
|
1112 |
this.select_file(node);
|
|
|
1113 |
}
|
|
|
1114 |
},
|
|
|
1115 |
classnamecallback : this.classnamecallback
|
|
|
1116 |
};
|
|
|
1117 |
this.fpnode.one('.fp-content').fp_display_filelist(options, list, this.lazyloading);
|
|
|
1118 |
},
|
|
|
1119 |
/** If more than one page available, requests and displays the files from the next page */
|
|
|
1120 |
request_next_page: function() {
|
|
|
1121 |
if (!this.active_repo.hasmorepages || this.active_repo.nextpagerequested) {
|
|
|
1122 |
// nothing to load
|
|
|
1123 |
return;
|
|
|
1124 |
}
|
|
|
1125 |
this.active_repo.nextpagerequested = true;
|
|
|
1126 |
var nextpage = this.active_repo.page+1;
|
|
|
1127 |
var args = {
|
|
|
1128 |
page: nextpage,
|
|
|
1129 |
repo_id: this.active_repo.id
|
|
|
1130 |
};
|
|
|
1131 |
var action = this.active_repo.issearchresult ? 'search' : 'list';
|
|
|
1132 |
this.request({
|
|
|
1133 |
path: this.currentpath,
|
|
|
1134 |
scope: this,
|
|
|
1135 |
action: action,
|
|
|
1136 |
client_id: this.options.client_id,
|
|
|
1137 |
repository_id: args.repo_id,
|
|
|
1138 |
params: args,
|
|
|
1139 |
callback: function(id, obj, args) {
|
|
|
1140 |
var scope = args.scope;
|
|
|
1141 |
// Check that we are still in the same repository and are expecting this page. We have no way
|
|
|
1142 |
// to compare the requested page and the one returned, so we assume that if the last chunk
|
|
|
1143 |
// of the breadcrumb is similar, then we probably are on the same page.
|
|
|
1144 |
var samepage = true;
|
|
|
1145 |
if (obj.path && scope.filepath) {
|
|
|
1146 |
var pathbefore = scope.filepath[scope.filepath.length-1];
|
|
|
1147 |
var pathafter = obj.path[obj.path.length-1];
|
|
|
1148 |
if (pathbefore.path != pathafter.path) {
|
|
|
1149 |
samepage = false;
|
|
|
1150 |
}
|
|
|
1151 |
}
|
|
|
1152 |
if (scope.active_repo.hasmorepages && obj.list && obj.page &&
|
|
|
1153 |
obj.repo_id == scope.active_repo.id &&
|
|
|
1154 |
obj.page == scope.active_repo.page+1 && samepage) {
|
|
|
1155 |
scope.parse_repository_options(obj, true);
|
|
|
1156 |
scope.view_files(obj.list)
|
|
|
1157 |
}
|
|
|
1158 |
}
|
|
|
1159 |
}, false);
|
|
|
1160 |
},
|
|
|
1161 |
select_file: function(args) {
|
|
|
1162 |
var argstitle = args.shorttitle ? args.shorttitle : args.title;
|
|
|
1163 |
// Limit the string length so it fits nicely on mobile devices
|
|
|
1164 |
var titlelength = 30;
|
|
|
1165 |
if (argstitle.length > titlelength) {
|
|
|
1166 |
argstitle = argstitle.substring(0, titlelength) + '...';
|
|
|
1167 |
}
|
|
|
1168 |
Y.one('#fp-file_label_'+this.options.client_id).setContent(Y.Escape.html(M.util.get_string('select', 'repository')+' '+argstitle));
|
|
|
1169 |
this.selectui.show();
|
|
|
1170 |
Y.one('#'+this.selectnode.get('id')).focus();
|
|
|
1171 |
var client_id = this.options.client_id;
|
|
|
1172 |
var selectnode = this.selectnode;
|
|
|
1173 |
var return_types = this.options.repositories[this.active_repo.id].return_types;
|
|
|
1174 |
selectnode.removeClass('loading');
|
|
|
1175 |
selectnode.one('.fp-saveas input').set('value', args.title);
|
|
|
1176 |
|
|
|
1177 |
var imgnode = Y.Node.create('<img/>').
|
|
|
1178 |
set('src', args.realthumbnail ? args.realthumbnail : args.thumbnail).
|
|
|
1179 |
setStyle('maxHeight', ''+(args.thumbnail_height ? args.thumbnail_height : 90)+'px').
|
|
|
1180 |
setStyle('maxWidth', ''+(args.thumbnail_width ? args.thumbnail_width : 90)+'px');
|
|
|
1181 |
selectnode.one('.fp-thumbnail').setContent('').appendChild(imgnode);
|
|
|
1182 |
|
|
|
1183 |
// filelink is the array of file-link-types available for this repository in this env
|
|
|
1184 |
var filelinktypes = [2/*FILE_INTERNAL*/,1/*FILE_EXTERNAL*/,4/*FILE_REFERENCE*/,8/*FILE_CONTROLLED_LINK*/];
|
|
|
1185 |
var filelink = {}, firstfilelink = null, filelinkcount = 0;
|
|
|
1186 |
for (var i in filelinktypes) {
|
|
|
1187 |
var allowed = (return_types & filelinktypes[i]) &&
|
|
|
1188 |
(this.options.return_types & filelinktypes[i]);
|
|
|
1189 |
if (filelinktypes[i] == 1/*FILE_EXTERNAL*/ && !this.options.externallink && this.options.env == 'editor') {
|
|
|
1190 |
// special configuration setting 'repositoryallowexternallinks' may prevent
|
|
|
1191 |
// using external links in editor environment
|
|
|
1192 |
allowed = false;
|
|
|
1193 |
}
|
|
|
1194 |
filelink[filelinktypes[i]] = allowed;
|
|
|
1195 |
firstfilelink = (firstfilelink==null && allowed) ? filelinktypes[i] : firstfilelink;
|
|
|
1196 |
filelinkcount += allowed ? 1 : 0;
|
|
|
1197 |
}
|
|
|
1198 |
var defaultreturntype = this.options.repositories[this.active_repo.id].defaultreturntype;
|
|
|
1199 |
if (defaultreturntype) {
|
|
|
1200 |
if (filelink[defaultreturntype]) {
|
|
|
1201 |
firstfilelink = defaultreturntype;
|
|
|
1202 |
}
|
|
|
1203 |
}
|
|
|
1204 |
// make radio buttons enabled if this file-link-type is available and only if there are more than one file-link-type option
|
|
|
1205 |
// check the first available file-link-type option
|
|
|
1206 |
for (var linktype in filelink) {
|
|
|
1207 |
var el = selectnode.one('.fp-linktype-'+linktype);
|
|
|
1208 |
el.addClassIf('uneditable', !(filelink[linktype] && filelinkcount>1));
|
|
|
1209 |
el.one('input').set('checked', (firstfilelink == linktype) ? 'checked' : '').simulate('change');
|
|
|
1210 |
}
|
|
|
1211 |
|
|
|
1212 |
// TODO MDL-32532: attributes 'hasauthor' and 'haslicense' need to be obsolete,
|
|
|
1213 |
selectnode.one('.fp-setauthor input').set('value', args.author ? args.author : this.options.author);
|
|
|
1214 |
this.populateLicensesSelect(selectnode.one('.fp-setlicense select'), args);
|
|
|
1215 |
selectnode.one('form #filesource-'+client_id).set('value', args.source);
|
|
|
1216 |
selectnode.one('form #filesourcekey-'+client_id).set('value', args.sourcekey);
|
|
|
1217 |
|
|
|
1218 |
// display static information about a file (when known)
|
|
|
1219 |
var attrs = ['datemodified','datecreated','size','license','author','dimensions'];
|
|
|
1220 |
for (var i in attrs) {
|
|
|
1221 |
if (selectnode.one('.fp-'+attrs[i])) {
|
|
|
1222 |
var value = (args[attrs[i]+'_f']) ? args[attrs[i]+'_f'] : (args[attrs[i]] ? args[attrs[i]] : '');
|
|
|
1223 |
selectnode.one('.fp-'+attrs[i]).addClassIf('fp-unknown', ''+value == '')
|
|
|
1224 |
.one('.fp-value').setContent(Y.Escape.html(value));
|
|
|
1225 |
}
|
|
|
1226 |
}
|
|
|
1227 |
},
|
|
|
1228 |
setup_select_file: function() {
|
|
|
1229 |
var client_id = this.options.client_id;
|
|
|
1230 |
var selectnode = this.selectnode;
|
|
|
1231 |
var getfile = selectnode.one('.fp-select-confirm');
|
|
|
1232 |
var filePickerHelper = this;
|
|
|
1233 |
// bind labels with corresponding inputs
|
|
|
1234 |
selectnode.all('.fp-saveas,.fp-linktype-2,.fp-linktype-1,.fp-linktype-4,fp-linktype-8,.fp-setauthor,.fp-setlicense').each(function (node) {
|
|
|
1235 |
node.all('label').set('for', node.one('input,select').generateID());
|
|
|
1236 |
});
|
|
|
1237 |
selectnode.one('.fp-linktype-2 input').setAttrs({value: 2, name: 'linktype'});
|
|
|
1238 |
selectnode.one('.fp-linktype-1 input').setAttrs({value: 1, name: 'linktype'});
|
|
|
1239 |
selectnode.one('.fp-linktype-4 input').setAttrs({value: 4, name: 'linktype'});
|
|
|
1240 |
selectnode.one('.fp-linktype-8 input').setAttrs({value: 8, name: 'linktype'});
|
|
|
1241 |
var changelinktype = function(e) {
|
|
|
1242 |
if (e.currentTarget.get('checked')) {
|
|
|
1243 |
var allowinputs = e.currentTarget.get('value') != 1/*FILE_EXTERNAL*/;
|
|
|
1244 |
selectnode.all('.fp-setauthor,.fp-setlicense,.fp-saveas').each(function(node){
|
|
|
1245 |
node.addClassIf('uneditable', !allowinputs);
|
|
|
1246 |
node.all('input,select').set('disabled', allowinputs?'':'disabled');
|
|
|
1247 |
});
|
|
|
1248 |
|
|
|
1249 |
// If the link to the file is selected, only then.
|
|
|
1250 |
// Remember: this is not to be done for all repos.
|
|
|
1251 |
// Only for those repos where the filereferencewarning is set.
|
|
|
1252 |
// The value 4 represents FILE_REFERENCE here.
|
|
|
1253 |
if (e.currentTarget.get('value') === '4') {
|
|
|
1254 |
var filereferencewarning = filePickerHelper.active_repo.filereferencewarning;
|
|
|
1255 |
if (filereferencewarning) {
|
|
|
1256 |
var fileReferenceNode = e.currentTarget.ancestor('.fp-linktype-4');
|
|
|
1257 |
var fileReferenceWarningNode = Y.Node.create('<div/>').
|
|
|
1258 |
addClass('alert alert-warning px-3 py-1 my-1 small').
|
|
|
1259 |
setAttrs({role: 'alert'}).
|
|
|
1260 |
setContent(filereferencewarning);
|
|
|
1261 |
fileReferenceNode.append(fileReferenceWarningNode);
|
|
|
1262 |
}
|
|
|
1263 |
} else {
|
|
|
1264 |
var fileReferenceInput = selectnode.one('.fp-linktype-4 input');
|
|
|
1265 |
var fileReferenceWarningNode = fileReferenceInput.ancestor('.fp-linktype-4').one('.alert-warning');
|
|
|
1266 |
if (fileReferenceWarningNode) {
|
|
|
1267 |
fileReferenceWarningNode.remove();
|
|
|
1268 |
}
|
|
|
1269 |
}
|
|
|
1270 |
}
|
|
|
1271 |
};
|
|
|
1272 |
selectnode.all('.fp-linktype-2,.fp-linktype-1,.fp-linktype-4,.fp-linktype-8').each(function (node) {
|
|
|
1273 |
node.one('input').on('change', changelinktype, this);
|
|
|
1274 |
});
|
|
|
1275 |
// register event on clicking submit button
|
|
|
1276 |
getfile.on('click', function(e) {
|
|
|
1277 |
e.preventDefault();
|
|
|
1278 |
var client_id = this.options.client_id;
|
|
|
1279 |
var scope = this;
|
|
|
1280 |
var repository_id = this.active_repo.id;
|
|
|
1281 |
var title = selectnode.one('.fp-saveas input').get('value');
|
|
|
1282 |
var filesource = selectnode.one('form #filesource-'+client_id).get('value');
|
|
|
1283 |
var filesourcekey = selectnode.one('form #filesourcekey-'+client_id).get('value');
|
11 |
efrain |
1284 |
var params = {
|
|
|
1285 |
'title': title,
|
|
|
1286 |
'source': filesource,
|
|
|
1287 |
'savepath': this.options.savepath || '/',
|
|
|
1288 |
'sourcekey': filesourcekey,
|
|
|
1289 |
};
|
1 |
efrain |
1290 |
var license = selectnode.one('.fp-setlicense select');
|
|
|
1291 |
if (license) {
|
|
|
1292 |
params['license'] = license.get('value');
|
|
|
1293 |
var origlicense = selectnode.one('.fp-license .fp-value');
|
|
|
1294 |
if (origlicense) {
|
|
|
1295 |
origlicense = origlicense.getContent();
|
|
|
1296 |
}
|
|
|
1297 |
if (this.options.rememberuserlicensepref) {
|
|
|
1298 |
this.set_preference('recentlicense', license.get('value'));
|
|
|
1299 |
}
|
|
|
1300 |
}
|
|
|
1301 |
params['author'] = selectnode.one('.fp-setauthor input').get('value');
|
|
|
1302 |
|
|
|
1303 |
var return_types = this.options.repositories[this.active_repo.id].return_types;
|
|
|
1304 |
if (this.options.env == 'editor') {
|
|
|
1305 |
// in editor, images are stored in '/' only
|
|
|
1306 |
params.savepath = '/';
|
|
|
1307 |
}
|
|
|
1308 |
if ((this.options.externallink || this.options.env != 'editor') &&
|
|
|
1309 |
(return_types & 1/*FILE_EXTERNAL*/) &&
|
|
|
1310 |
(this.options.return_types & 1/*FILE_EXTERNAL*/) &&
|
|
|
1311 |
selectnode.one('.fp-linktype-1 input').get('checked')) {
|
|
|
1312 |
params['linkexternal'] = 'yes';
|
|
|
1313 |
} else if ((return_types & 4/*FILE_REFERENCE*/) &&
|
|
|
1314 |
(this.options.return_types & 4/*FILE_REFERENCE*/) &&
|
|
|
1315 |
selectnode.one('.fp-linktype-4 input').get('checked')) {
|
|
|
1316 |
params['usefilereference'] = '1';
|
|
|
1317 |
} else if ((return_types & 8/*FILE_CONTROLLED_LINK*/) &&
|
|
|
1318 |
(this.options.return_types & 8/*FILE_CONTROLLED_LINK*/) &&
|
|
|
1319 |
selectnode.one('.fp-linktype-8 input').get('checked')) {
|
|
|
1320 |
params['usecontrolledlink'] = '1';
|
|
|
1321 |
}
|
|
|
1322 |
|
|
|
1323 |
selectnode.addClass('loading');
|
|
|
1324 |
this.request({
|
|
|
1325 |
action:'download',
|
|
|
1326 |
client_id: client_id,
|
|
|
1327 |
repository_id: repository_id,
|
|
|
1328 |
'params': params,
|
|
|
1329 |
onerror: function(id, obj, args) {
|
|
|
1330 |
selectnode.removeClass('loading');
|
|
|
1331 |
scope.selectui.hide();
|
|
|
1332 |
},
|
|
|
1333 |
callback: function(id, obj, args) {
|
|
|
1334 |
selectnode.removeClass('loading');
|
|
|
1335 |
if (obj.event == 'fileexists') {
|
|
|
1336 |
scope.process_existing_file(obj);
|
|
|
1337 |
return;
|
|
|
1338 |
}
|
|
|
1339 |
if (scope.options.editor_target && scope.options.env=='editor') {
|
|
|
1340 |
scope.options.editor_target.value=obj.url;
|
|
|
1341 |
scope.options.editor_target.dispatchEvent(new Event('change'), {'bubbles': true});
|
|
|
1342 |
}
|
|
|
1343 |
scope.hide();
|
|
|
1344 |
obj.client_id = client_id;
|
|
|
1345 |
var formcallback_scope = args.scope.options.magicscope ? args.scope.options.magicscope : args.scope;
|
|
|
1346 |
scope.options.formcallback.apply(formcallback_scope, [obj]);
|
|
|
1347 |
}
|
|
|
1348 |
}, false);
|
|
|
1349 |
}, this);
|
|
|
1350 |
var elform = selectnode.one('form');
|
|
|
1351 |
elform.appendChild(Y.Node.create('<input/>').
|
|
|
1352 |
setAttrs({type:'hidden',id:'filesource-'+client_id}));
|
|
|
1353 |
elform.appendChild(Y.Node.create('<input/>').
|
|
|
1354 |
setAttrs({type:'hidden',id:'filesourcekey-'+client_id}));
|
|
|
1355 |
elform.on('keydown', function(e) {
|
|
|
1356 |
if (e.keyCode == 13) {
|
|
|
1357 |
getfile.simulate('click');
|
|
|
1358 |
e.preventDefault();
|
|
|
1359 |
}
|
|
|
1360 |
}, this);
|
|
|
1361 |
var cancel = selectnode.one('.fp-select-cancel');
|
|
|
1362 |
cancel.on('click', function(e) {
|
|
|
1363 |
e.preventDefault();
|
|
|
1364 |
this.selectui.hide();
|
|
|
1365 |
}, this);
|
|
|
1366 |
},
|
|
|
1367 |
wait: function() {
|
|
|
1368 |
// First check there isn't already an interval in play, and if there is kill it now.
|
|
|
1369 |
if (this.waitinterval != null) {
|
|
|
1370 |
clearInterval(this.waitinterval);
|
|
|
1371 |
}
|
|
|
1372 |
// Prepare the root node we will set content for and the loading template we want to display as a YUI node.
|
|
|
1373 |
var root = this.fpnode.one('.fp-content');
|
|
|
1374 |
var content = Y.Node.create(M.core_filepicker.templates.loading).addClass('fp-content-hidden').setStyle('opacity', 0);
|
|
|
1375 |
var count = 0;
|
|
|
1376 |
// Initiate an interval, we will have a count which will increment every 100 milliseconds.
|
|
|
1377 |
// Count 0 - the loading icon will have visibility set to hidden (invisible) and have an opacity of 0 (invisible also)
|
|
|
1378 |
// Count 5 - the visiblity will be switched to visible but opacity will still be at 0 (inivisible)
|
|
|
1379 |
// Counts 6 - 15 opacity will be increased by 0.1 making the loading icon visible over the period of a second
|
|
|
1380 |
// Count 16 - The interval will be cancelled.
|
|
|
1381 |
var interval = setInterval(function(){
|
|
|
1382 |
if (!content || !root.contains(content) || count >= 15) {
|
|
|
1383 |
clearInterval(interval);
|
|
|
1384 |
return true;
|
|
|
1385 |
}
|
|
|
1386 |
if (count == 5) {
|
|
|
1387 |
content.removeClass('fp-content-hidden');
|
|
|
1388 |
} else if (count > 5) {
|
|
|
1389 |
var opacity = parseFloat(content.getStyle('opacity'));
|
|
|
1390 |
content.setStyle('opacity', opacity + 0.1);
|
|
|
1391 |
}
|
|
|
1392 |
count++;
|
|
|
1393 |
return false;
|
|
|
1394 |
}, 100);
|
|
|
1395 |
// Store the wait interval so that we can check it in the future.
|
|
|
1396 |
this.waitinterval = interval;
|
|
|
1397 |
// Set the content to the loading template.
|
|
|
1398 |
root.setContent(content);
|
|
|
1399 |
},
|
|
|
1400 |
viewbar_set_enabled: function(mode) {
|
|
|
1401 |
var viewbar = this.fpnode.one('.fp-viewbar')
|
|
|
1402 |
if (viewbar) {
|
|
|
1403 |
if (mode) {
|
|
|
1404 |
viewbar.addClass('enabled').removeClass('disabled');
|
|
|
1405 |
this.fpnode.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').setAttribute("aria-disabled", "false");
|
|
|
1406 |
this.fpnode.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').setAttribute("tabindex", "");
|
|
|
1407 |
} else {
|
|
|
1408 |
viewbar.removeClass('enabled').addClass('disabled');
|
|
|
1409 |
this.fpnode.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').setAttribute("aria-disabled", "true");
|
|
|
1410 |
this.fpnode.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').setAttribute("tabindex", "-1");
|
|
|
1411 |
}
|
|
|
1412 |
}
|
|
|
1413 |
this.fpnode.all('.fp-vb-icons,.fp-vb-tree,.fp-vb-details').removeClass('checked');
|
|
|
1414 |
var modes = {1:'icons', 2:'tree', 3:'details'};
|
|
|
1415 |
this.fpnode.all('.fp-vb-'+modes[this.viewmode]).addClass('checked');
|
|
|
1416 |
},
|
|
|
1417 |
viewbar_clicked: function(e) {
|
|
|
1418 |
e.preventDefault();
|
|
|
1419 |
var viewbar = this.fpnode.one('.fp-viewbar')
|
|
|
1420 |
if (!viewbar || !viewbar.hasClass('disabled')) {
|
|
|
1421 |
if (e.currentTarget.hasClass('fp-vb-tree')) {
|
|
|
1422 |
this.viewmode = 2;
|
|
|
1423 |
} else if (e.currentTarget.hasClass('fp-vb-details')) {
|
|
|
1424 |
this.viewmode = 3;
|
|
|
1425 |
} else {
|
|
|
1426 |
this.viewmode = 1;
|
|
|
1427 |
}
|
|
|
1428 |
this.viewbar_set_enabled(true)
|
|
|
1429 |
this.view_files();
|
|
|
1430 |
this.set_preference('recentviewmode', this.viewmode);
|
|
|
1431 |
}
|
|
|
1432 |
},
|
|
|
1433 |
render: function() {
|
|
|
1434 |
var client_id = this.options.client_id;
|
|
|
1435 |
var fpid = "filepicker-"+ client_id;
|
|
|
1436 |
var labelid = 'fp-dialog-label_'+ client_id;
|
|
|
1437 |
var width = 873;
|
|
|
1438 |
var draggable = true;
|
|
|
1439 |
this.fpnode = Y.Node.create(M.core_filepicker.templates.generallayout).
|
|
|
1440 |
set('id', 'filepicker-'+client_id).set('aria-labelledby', labelid);
|
|
|
1441 |
|
|
|
1442 |
if (this.in_iframe()) {
|
|
|
1443 |
width = Math.floor(window.innerWidth * 0.95);
|
|
|
1444 |
draggable = false;
|
|
|
1445 |
}
|
|
|
1446 |
|
|
|
1447 |
this.mainui = new M.core.dialogue({
|
|
|
1448 |
extraClasses : ['filepicker'],
|
|
|
1449 |
draggable : draggable,
|
|
|
1450 |
bodyContent : this.fpnode,
|
|
|
1451 |
headerContent: '<h3 id="'+ labelid +'">'+ M.util.get_string('filepicker', 'repository') +'</h3>',
|
|
|
1452 |
centered : true,
|
|
|
1453 |
modal : true,
|
|
|
1454 |
visible : false,
|
|
|
1455 |
width : width+'px',
|
|
|
1456 |
responsiveWidth : 768,
|
|
|
1457 |
height : '558px',
|
|
|
1458 |
zIndex : this.options.zIndex,
|
|
|
1459 |
focusOnPreviousTargetAfterHide: true,
|
|
|
1460 |
focusAfterHide: this.options.previousActiveElement
|
|
|
1461 |
});
|
|
|
1462 |
|
|
|
1463 |
// create panel for selecting a file (initially hidden)
|
|
|
1464 |
this.selectnode = Y.Node.create(M.core_filepicker.templates.selectlayout).
|
|
|
1465 |
set('id', 'filepicker-select-'+client_id).
|
|
|
1466 |
set('aria-live', 'assertive').
|
|
|
1467 |
set('role', 'dialog');
|
|
|
1468 |
|
|
|
1469 |
var fplabel = 'fp-file_label_'+ client_id;
|
|
|
1470 |
this.selectui = new M.core.dialogue({
|
|
|
1471 |
headerContent: '<h3 id="' + fplabel +'">'+M.util.get_string('select', 'repository')+'</h3>',
|
|
|
1472 |
draggable : true,
|
|
|
1473 |
width : '450px',
|
|
|
1474 |
bodyContent : this.selectnode,
|
|
|
1475 |
centered : true,
|
|
|
1476 |
modal : true,
|
|
|
1477 |
visible : false,
|
|
|
1478 |
zIndex : this.options.zIndex
|
|
|
1479 |
});
|
|
|
1480 |
Y.one('#'+this.selectnode.get('id')).setAttribute('aria-labelledby', fplabel);
|
|
|
1481 |
// event handler for lazy loading of thumbnails and next page
|
|
|
1482 |
this.fpnode.one('.fp-content').on(['scroll','resize'], this.content_scrolled, this);
|
|
|
1483 |
// save template for one path element and location of path bar
|
|
|
1484 |
if (this.fpnode.one('.fp-path-folder')) {
|
|
|
1485 |
this.pathnode = this.fpnode.one('.fp-path-folder');
|
|
|
1486 |
this.pathbar = this.pathnode.get('parentNode');
|
|
|
1487 |
this.pathbar.removeChild(this.pathnode);
|
|
|
1488 |
}
|
|
|
1489 |
// assign callbacks for view mode switch buttons
|
|
|
1490 |
this.fpnode.one('.fp-vb-icons').on('click', this.viewbar_clicked, this);
|
|
|
1491 |
this.fpnode.one('.fp-vb-tree').on('click', this.viewbar_clicked, this);
|
|
|
1492 |
this.fpnode.one('.fp-vb-details').on('click', this.viewbar_clicked, this);
|
|
|
1493 |
|
|
|
1494 |
// assign callbacks for toolbar links
|
|
|
1495 |
this.setup_toolbar();
|
|
|
1496 |
this.setup_select_file();
|
|
|
1497 |
this.hide_header();
|
|
|
1498 |
|
|
|
1499 |
// processing repository listing
|
|
|
1500 |
// Resort the repositories by sortorder
|
|
|
1501 |
var sorted_repositories = [];
|
|
|
1502 |
var i;
|
|
|
1503 |
for (i in this.options.repositories) {
|
|
|
1504 |
sorted_repositories[i] = this.options.repositories[i];
|
|
|
1505 |
}
|
|
|
1506 |
sorted_repositories.sort(function(a,b){return a.sortorder-b.sortorder});
|
|
|
1507 |
// extract one repository template and repeat it for all repositories available,
|
|
|
1508 |
// set name and icon and assign callbacks
|
|
|
1509 |
var reponode = this.fpnode.one('.fp-repo');
|
|
|
1510 |
if (reponode) {
|
|
|
1511 |
var list = reponode.get('parentNode');
|
|
|
1512 |
list.removeChild(reponode);
|
|
|
1513 |
for (i in sorted_repositories) {
|
|
|
1514 |
var repository = sorted_repositories[i];
|
|
|
1515 |
var h = (parseInt(i) == 0) ? parseInt(i) : parseInt(i) - 1,
|
|
|
1516 |
j = (parseInt(i) == Object.keys(sorted_repositories).length - 1) ? parseInt(i) : parseInt(i) + 1;
|
|
|
1517 |
var previousrepository = sorted_repositories[h];
|
|
|
1518 |
var nextrepository = sorted_repositories[j];
|
|
|
1519 |
var node = reponode.cloneNode(true);
|
|
|
1520 |
list.appendChild(node);
|
|
|
1521 |
node.
|
|
|
1522 |
set('id', 'fp-repo-'+client_id+'-'+repository.id).
|
|
|
1523 |
on('click', function(e, repository_id) {
|
|
|
1524 |
e.preventDefault();
|
|
|
1525 |
this.set_preference('recentrepository', repository_id);
|
|
|
1526 |
this.hide_header();
|
|
|
1527 |
this.list({'repo_id':repository_id});
|
|
|
1528 |
}, this /*handler running scope*/, repository.id/*second argument of handler*/);
|
|
|
1529 |
node.on('key', function(e, previousrepositoryid, nextrepositoryid, clientid, repositoryid) {
|
|
|
1530 |
this.changeHighlightedRepository(e, clientid, repositoryid, previousrepositoryid, nextrepositoryid);
|
|
|
1531 |
}, 'down:38,40', this, previousrepository.id, nextrepository.id, client_id, repository.id);
|
|
|
1532 |
node.on('key', function(e, repositoryid) {
|
|
|
1533 |
e.preventDefault();
|
|
|
1534 |
this.set_preference('recentrepository', repositoryid);
|
|
|
1535 |
this.hide_header();
|
|
|
1536 |
this.list({'repo_id': repositoryid});
|
|
|
1537 |
}, 'enter', this, repository.id);
|
|
|
1538 |
node.one('.fp-repo-name').setContent(Y.Escape.html(repository.name));
|
|
|
1539 |
node.one('.fp-repo-icon').set('src', repository.icon);
|
|
|
1540 |
if (i==0) {
|
|
|
1541 |
node.addClass('first');
|
|
|
1542 |
}
|
|
|
1543 |
if (i==sorted_repositories.length-1) {
|
|
|
1544 |
node.addClass('last');
|
|
|
1545 |
}
|
|
|
1546 |
if (i%2) {
|
|
|
1547 |
node.addClass('even');
|
|
|
1548 |
} else {
|
|
|
1549 |
node.addClass('odd');
|
|
|
1550 |
}
|
|
|
1551 |
}
|
|
|
1552 |
}
|
|
|
1553 |
// display error if no repositories found
|
|
|
1554 |
if (sorted_repositories.length==0) {
|
|
|
1555 |
this.display_error(M.util.get_string('norepositoriesavailable', 'repository'), 'norepositoriesavailable')
|
|
|
1556 |
}
|
|
|
1557 |
// display repository that was used last time
|
|
|
1558 |
this.mainui.show();
|
|
|
1559 |
this.show_recent_repository();
|
|
|
1560 |
},
|
|
|
1561 |
/**
|
|
|
1562 |
* Change the highlighted repository to a new one.
|
|
|
1563 |
*
|
|
|
1564 |
* @param {object} event The key event
|
|
|
1565 |
* @param {integer} clientid The client id to identify the repo class.
|
|
|
1566 |
* @param {integer} oldrepositoryid The repository id that we are removing the highlight for
|
|
|
1567 |
* @param {integer} previousrepositoryid The previous repository id.
|
|
|
1568 |
* @param {integer} nextrepositoryid The next repository id.
|
|
|
1569 |
*/
|
|
|
1570 |
changeHighlightedRepository: function(event, clientid, oldrepositoryid, previousrepositoryid, nextrepositoryid) {
|
|
|
1571 |
event.preventDefault();
|
|
|
1572 |
var newrepositoryid = (event.keyCode == '40') ? nextrepositoryid : previousrepositoryid;
|
|
|
1573 |
this.fpnode.one('#fp-repo-' + clientid + '-' + oldrepositoryid).setAttribute('tabindex', '-1');
|
|
|
1574 |
this.fpnode.one('#fp-repo-' + clientid + '-' + newrepositoryid)
|
|
|
1575 |
.setAttribute('tabindex', '0')
|
|
|
1576 |
.focus();
|
|
|
1577 |
},
|
|
|
1578 |
parse_repository_options: function(data, appendtolist) {
|
|
|
1579 |
if (appendtolist) {
|
|
|
1580 |
if (data.list) {
|
|
|
1581 |
if (!this.filelist) {
|
|
|
1582 |
this.filelist = [];
|
|
|
1583 |
}
|
|
|
1584 |
for (var i in data.list) {
|
|
|
1585 |
this.filelist[this.filelist.length] = data.list[i];
|
|
|
1586 |
}
|
|
|
1587 |
}
|
|
|
1588 |
} else {
|
|
|
1589 |
this.filelist = data.list?data.list:null;
|
|
|
1590 |
this.lazyloading = {};
|
|
|
1591 |
}
|
|
|
1592 |
this.filepath = data.path?data.path:null;
|
|
|
1593 |
this.objecttag = data.object?data.object:null;
|
|
|
1594 |
this.active_repo = {};
|
|
|
1595 |
this.active_repo.issearchresult = data.issearchresult ? true : false;
|
|
|
1596 |
this.active_repo.defaultreturntype = data.defaultreturntype?data.defaultreturntype:null;
|
|
|
1597 |
this.active_repo.dynload = data.dynload?data.dynload:false;
|
|
|
1598 |
this.active_repo.pages = Number(data.pages?data.pages:null);
|
|
|
1599 |
this.active_repo.page = Number(data.page?data.page:null);
|
|
|
1600 |
this.active_repo.hasmorepages = (this.active_repo.pages && this.active_repo.page && (this.active_repo.page < this.active_repo.pages || this.active_repo.pages == -1))
|
|
|
1601 |
this.active_repo.id = data.repo_id?data.repo_id:null;
|
|
|
1602 |
this.active_repo.nosearch = (data.login || data.nosearch); // this is either login form or 'nosearch' attribute set
|
|
|
1603 |
this.active_repo.norefresh = (data.login || data.norefresh); // this is either login form or 'norefresh' attribute set
|
|
|
1604 |
this.active_repo.nologin = (data.login || data.nologin); // this is either login form or 'nologin' attribute is set
|
|
|
1605 |
this.active_repo.logouttext = data.logouttext?data.logouttext:null;
|
|
|
1606 |
this.active_repo.logouturl = (data.logouturl || '');
|
|
|
1607 |
this.active_repo.message = (data.message || '');
|
|
|
1608 |
this.active_repo.help = data.help?data.help:null;
|
|
|
1609 |
this.active_repo.manage = data.manage?data.manage:null;
|
|
|
1610 |
// Warning message related to the file reference option, if applicable to the given repository.
|
|
|
1611 |
this.active_repo.filereferencewarning = data.filereferencewarning ? data.filereferencewarning : null;
|
|
|
1612 |
this.print_header();
|
|
|
1613 |
},
|
|
|
1614 |
print_login: function(data) {
|
|
|
1615 |
this.parse_repository_options(data);
|
|
|
1616 |
var client_id = this.options.client_id;
|
|
|
1617 |
var repository_id = data.repo_id;
|
|
|
1618 |
var l = this.logindata = data.login;
|
|
|
1619 |
var loginurl = '';
|
|
|
1620 |
var action = data['login_btn_action'] ? data['login_btn_action'] : 'login';
|
|
|
1621 |
var form_id = 'fp-form-'+client_id;
|
|
|
1622 |
|
|
|
1623 |
var loginform_node = Y.Node.create(M.core_filepicker.templates.loginform);
|
|
|
1624 |
loginform_node.one('form').set('id', form_id);
|
|
|
1625 |
this.fpnode.one('.fp-content').setContent('').appendChild(loginform_node);
|
|
|
1626 |
var templates = {
|
|
|
1627 |
'popup' : loginform_node.one('.fp-login-popup'),
|
|
|
1628 |
'textarea' : loginform_node.one('.fp-login-textarea'),
|
|
|
1629 |
'select' : loginform_node.one('.fp-login-select'),
|
|
|
1630 |
'text' : loginform_node.one('.fp-login-text'),
|
|
|
1631 |
'radio' : loginform_node.one('.fp-login-radiogroup'),
|
|
|
1632 |
'checkbox' : loginform_node.one('.fp-login-checkbox'),
|
|
|
1633 |
'input' : loginform_node.one('.fp-login-input')
|
|
|
1634 |
};
|
|
|
1635 |
var container;
|
|
|
1636 |
for (var i in templates) {
|
|
|
1637 |
if (templates[i]) {
|
|
|
1638 |
container = templates[i].get('parentNode');
|
|
|
1639 |
container.removeChild(templates[i]);
|
|
|
1640 |
}
|
|
|
1641 |
}
|
|
|
1642 |
|
|
|
1643 |
for(var k in l) {
|
|
|
1644 |
if (templates[l[k].type]) {
|
|
|
1645 |
var node = templates[l[k].type].cloneNode(true);
|
|
|
1646 |
} else {
|
|
|
1647 |
node = templates['input'].cloneNode(true);
|
|
|
1648 |
}
|
|
|
1649 |
if (l[k].type == 'popup') {
|
|
|
1650 |
// submit button
|
|
|
1651 |
loginurl = l[k].url;
|
|
|
1652 |
var popupbutton = node.one('button');
|
|
|
1653 |
popupbutton.on('click', function(e){
|
|
|
1654 |
M.core_filepicker.active_filepicker = this;
|
|
|
1655 |
window.open(loginurl, 'repo_auth', 'location=0,status=0,width=500,height=300,scrollbars=yes');
|
|
|
1656 |
e.preventDefault();
|
|
|
1657 |
}, this);
|
|
|
1658 |
loginform_node.one('form').on('keydown', function(e) {
|
|
|
1659 |
if (e.keyCode == 13) {
|
|
|
1660 |
popupbutton.simulate('click');
|
|
|
1661 |
e.preventDefault();
|
|
|
1662 |
}
|
|
|
1663 |
}, this);
|
|
|
1664 |
loginform_node.all('.fp-login-submit').remove();
|
|
|
1665 |
action = 'popup';
|
|
|
1666 |
} else if(l[k].type=='textarea') {
|
|
|
1667 |
// textarea element
|
|
|
1668 |
if (node.one('label')) {
|
|
|
1669 |
node.one('label').set('for', l[k].id).setContent(l[k].label);
|
|
|
1670 |
}
|
|
|
1671 |
node.one('textarea').setAttrs({id:l[k].id, name:l[k].name});
|
|
|
1672 |
} else if(l[k].type=='select') {
|
|
|
1673 |
// select element
|
|
|
1674 |
if (node.one('label')) {
|
|
|
1675 |
node.one('label').set('for', l[k].id).setContent(l[k].label);
|
|
|
1676 |
}
|
|
|
1677 |
node.one('select').setAttrs({id:l[k].id, name:l[k].name}).setContent('');
|
|
|
1678 |
for (i in l[k].options) {
|
|
|
1679 |
node.one('select').appendChild(
|
|
|
1680 |
Y.Node.create('<option/>').
|
|
|
1681 |
set('value', l[k].options[i].value).
|
|
|
1682 |
setContent(l[k].options[i].label));
|
|
|
1683 |
}
|
|
|
1684 |
} else if(l[k].type=='radio') {
|
|
|
1685 |
// radio input element
|
|
|
1686 |
node.all('label').setContent(l[k].label);
|
|
|
1687 |
var list = l[k].value.split('|');
|
|
|
1688 |
var labels = l[k].value_label.split('|');
|
|
|
1689 |
var radionode = null;
|
|
|
1690 |
for(var item in list) {
|
|
|
1691 |
if (radionode == null) {
|
|
|
1692 |
radionode = node.one('.fp-login-radio');
|
|
|
1693 |
radionode.one('input').set('checked', 'checked');
|
|
|
1694 |
} else {
|
|
|
1695 |
var x = radionode.cloneNode(true);
|
|
|
1696 |
radionode.insert(x, 'after');
|
|
|
1697 |
radionode = x;
|
|
|
1698 |
radionode.one('input').set('checked', '');
|
|
|
1699 |
}
|
|
|
1700 |
radionode.one('input').setAttrs({id:''+l[k].id+item, name:l[k].name,
|
|
|
1701 |
type:l[k].type, value:list[item]});
|
|
|
1702 |
radionode.all('label').setContent(labels[item]).set('for', ''+l[k].id+item)
|
|
|
1703 |
}
|
|
|
1704 |
if (radionode == null) {
|
|
|
1705 |
node.one('.fp-login-radio').remove();
|
|
|
1706 |
}
|
|
|
1707 |
} else {
|
|
|
1708 |
// input element
|
|
|
1709 |
if (node.one('label')) { node.one('label').set('for', l[k].id).setContent(l[k].label) }
|
|
|
1710 |
node.one('input').
|
|
|
1711 |
set('type', l[k].type).
|
|
|
1712 |
set('id', l[k].id).
|
|
|
1713 |
set('name', l[k].name).
|
|
|
1714 |
set('value', l[k].value?l[k].value:'')
|
|
|
1715 |
}
|
|
|
1716 |
container.appendChild(node);
|
|
|
1717 |
}
|
|
|
1718 |
// custom label text for submit button
|
|
|
1719 |
if (data['login_btn_label']) {
|
|
|
1720 |
loginform_node.all('.fp-login-submit').setContent(data['login_btn_label'])
|
|
|
1721 |
}
|
|
|
1722 |
// register button action for login and search
|
|
|
1723 |
if (action == 'login' || action == 'search') {
|
|
|
1724 |
loginform_node.one('.fp-login-submit').on('click', function(e){
|
|
|
1725 |
e.preventDefault();
|
|
|
1726 |
this.hide_header();
|
|
|
1727 |
this.request({
|
|
|
1728 |
'scope': this,
|
|
|
1729 |
'action':(action == 'search') ? 'search' : 'signin',
|
|
|
1730 |
'path': '',
|
|
|
1731 |
'client_id': client_id,
|
|
|
1732 |
'repository_id': repository_id,
|
|
|
1733 |
'form': {id:form_id, upload:false, useDisabled:true},
|
|
|
1734 |
'callback': this.display_response
|
|
|
1735 |
}, true);
|
|
|
1736 |
}, this);
|
|
|
1737 |
}
|
|
|
1738 |
// if 'Enter' is pressed in the form, simulate the button click
|
|
|
1739 |
if (loginform_node.one('.fp-login-submit')) {
|
|
|
1740 |
loginform_node.one('form').on('keydown', function(e) {
|
|
|
1741 |
if (e.keyCode == 13) {
|
|
|
1742 |
loginform_node.one('.fp-login-submit').simulate('click')
|
|
|
1743 |
e.preventDefault();
|
|
|
1744 |
}
|
|
|
1745 |
}, this);
|
|
|
1746 |
}
|
|
|
1747 |
},
|
|
|
1748 |
display_response: function(id, obj, args) {
|
|
|
1749 |
var scope = args.scope;
|
|
|
1750 |
// highlight the current repository in repositories list
|
|
|
1751 |
scope.fpnode.all('.fp-repo.active')
|
|
|
1752 |
.removeClass('active')
|
|
|
1753 |
.setAttribute('aria-selected', 'false')
|
|
|
1754 |
.setAttribute('tabindex', '-1');
|
|
|
1755 |
scope.fpnode.all('.nav-link')
|
|
|
1756 |
.removeClass('active')
|
|
|
1757 |
.setAttribute('aria-selected', 'false')
|
|
|
1758 |
.setAttribute('tabindex', '-1');
|
|
|
1759 |
var activenode = scope.fpnode.one('#fp-repo-' + scope.options.client_id + '-' + obj.repo_id);
|
|
|
1760 |
activenode.addClass('active')
|
|
|
1761 |
.setAttribute('aria-selected', 'true')
|
|
|
1762 |
.setAttribute('tabindex', '0');
|
|
|
1763 |
activenode.all('.nav-link').addClass('active');
|
|
|
1764 |
// add class repository_REPTYPE to the filepicker (for repository-specific styles)
|
|
|
1765 |
for (var i in scope.options.repositories) {
|
|
|
1766 |
scope.fpnode.removeClass('repository_'+scope.options.repositories[i].type)
|
|
|
1767 |
}
|
|
|
1768 |
if (obj.repo_id && scope.options.repositories[obj.repo_id]) {
|
|
|
1769 |
scope.fpnode.addClass('repository_'+scope.options.repositories[obj.repo_id].type)
|
|
|
1770 |
}
|
|
|
1771 |
Y.one('.file-picker .fp-repo-items').focus();
|
|
|
1772 |
|
|
|
1773 |
// display response
|
|
|
1774 |
if (obj.login) {
|
|
|
1775 |
scope.viewbar_set_enabled(false);
|
|
|
1776 |
scope.print_login(obj);
|
|
|
1777 |
} else if (obj.upload) {
|
|
|
1778 |
scope.viewbar_set_enabled(false);
|
|
|
1779 |
scope.parse_repository_options(obj);
|
|
|
1780 |
scope.create_upload_form(obj);
|
|
|
1781 |
} else if (obj.object) {
|
|
|
1782 |
M.core_filepicker.active_filepicker = scope;
|
|
|
1783 |
scope.viewbar_set_enabled(false);
|
|
|
1784 |
scope.parse_repository_options(obj);
|
|
|
1785 |
scope.create_object_container(obj.object);
|
|
|
1786 |
} else if (obj.list) {
|
|
|
1787 |
scope.viewbar_set_enabled(true);
|
|
|
1788 |
scope.parse_repository_options(obj);
|
|
|
1789 |
scope.view_files();
|
|
|
1790 |
}
|
|
|
1791 |
},
|
|
|
1792 |
list: function(args) {
|
|
|
1793 |
if (!args) {
|
|
|
1794 |
args = {};
|
|
|
1795 |
}
|
|
|
1796 |
if (!args.repo_id) {
|
|
|
1797 |
args.repo_id = this.active_repo.id;
|
|
|
1798 |
}
|
|
|
1799 |
if (!args.path) {
|
|
|
1800 |
args.path = '';
|
|
|
1801 |
}
|
|
|
1802 |
this.currentpath = args.path;
|
|
|
1803 |
this.request({
|
|
|
1804 |
action: 'list',
|
|
|
1805 |
client_id: this.options.client_id,
|
|
|
1806 |
repository_id: args.repo_id,
|
|
|
1807 |
path: args.path,
|
|
|
1808 |
page: args.page,
|
|
|
1809 |
scope: this,
|
|
|
1810 |
callback: this.display_response
|
|
|
1811 |
}, true);
|
|
|
1812 |
},
|
|
|
1813 |
populateLicensesSelect: function(licensenode, filenode) {
|
|
|
1814 |
if (!licensenode) {
|
|
|
1815 |
return;
|
|
|
1816 |
}
|
|
|
1817 |
licensenode.setContent('');
|
|
|
1818 |
var selectedlicense = this.options.defaultlicense;
|
|
|
1819 |
if (filenode) {
|
|
|
1820 |
// File has a license already, use it.
|
|
|
1821 |
selectedlicense = filenode.license;
|
|
|
1822 |
} else if (this.options.rememberuserlicensepref && this.get_preference('recentlicense')) {
|
|
|
1823 |
// When 'Remember user licence preference' is enabled use the last license selected by the user, if any.
|
|
|
1824 |
selectedlicense = this.get_preference('recentlicense');
|
|
|
1825 |
}
|
|
|
1826 |
var licenses = this.options.licenses;
|
|
|
1827 |
for (var i in licenses) {
|
|
|
1828 |
// Include the file's current license, even if not enabled, to prevent displaying
|
|
|
1829 |
// misleading information about which license the file currently has assigned to it.
|
|
|
1830 |
if (licenses[i].enabled == true || (filenode !== undefined && licenses[i].shortname === filenode.license)) {
|
|
|
1831 |
var option = Y.Node.create('<option/>').
|
|
|
1832 |
set('selected', (licenses[i].shortname == selectedlicense)).
|
|
|
1833 |
set('value', licenses[i].shortname).
|
|
|
1834 |
setContent(Y.Escape.html(licenses[i].fullname));
|
|
|
1835 |
licensenode.appendChild(option);
|
|
|
1836 |
}
|
|
|
1837 |
}
|
|
|
1838 |
},
|
|
|
1839 |
create_object_container: function(data) {
|
|
|
1840 |
var content = this.fpnode.one('.fp-content');
|
|
|
1841 |
content.setContent('');
|
|
|
1842 |
//var str = '<object data="'+data.src+'" type="'+data.type+'" width="98%" height="98%" id="container_object" class="fp-object-container mdl-align"></object>';
|
|
|
1843 |
var container = Y.Node.create('<object/>').
|
|
|
1844 |
setAttrs({data:data.src, type:data.type, id:'container_object'}).
|
|
|
1845 |
addClass('fp-object-container');
|
|
|
1846 |
content.setContent('').appendChild(container);
|
|
|
1847 |
},
|
|
|
1848 |
create_upload_form: function(data) {
|
|
|
1849 |
var client_id = this.options.client_id;
|
|
|
1850 |
var id = data.upload.id+'_'+client_id;
|
|
|
1851 |
var content = this.fpnode.one('.fp-content');
|
|
|
1852 |
var template_name = 'uploadform_'+this.options.repositories[data.repo_id].type;
|
|
|
1853 |
var template = M.core_filepicker.templates[template_name] || M.core_filepicker.templates['uploadform'];
|
|
|
1854 |
content.setContent(template);
|
|
|
1855 |
|
|
|
1856 |
content.all('.fp-file,.fp-saveas,.fp-setauthor,.fp-setlicense').each(function (node) {
|
|
|
1857 |
node.all('label').set('for', node.one('input,select').generateID());
|
|
|
1858 |
});
|
|
|
1859 |
content.one('form').set('id', id);
|
|
|
1860 |
content.one('.fp-file input').set('name', 'repo_upload_file');
|
|
|
1861 |
if (data.upload.label && content.one('.fp-file label')) {
|
|
|
1862 |
content.one('.fp-file label').setContent(data.upload.label);
|
|
|
1863 |
}
|
|
|
1864 |
content.one('.fp-saveas input').set('name', 'title');
|
|
|
1865 |
content.one('.fp-setauthor input').setAttrs({name:'author', value:this.options.author});
|
|
|
1866 |
content.one('.fp-setlicense select').set('name', 'license');
|
|
|
1867 |
this.populateLicensesSelect(content.one('.fp-setlicense select'));
|
|
|
1868 |
// append hidden inputs to the upload form
|
|
|
1869 |
content.one('form').appendChild(Y.Node.create('<input/>').
|
|
|
1870 |
setAttrs({type:'hidden',name:'itemid',value:this.options.itemid}));
|
|
|
1871 |
var types = this.options.accepted_types;
|
|
|
1872 |
for (var i in types) {
|
|
|
1873 |
content.one('form').appendChild(Y.Node.create('<input/>').
|
|
|
1874 |
setAttrs({type:'hidden',name:'accepted_types[]',value:types[i]}));
|
|
|
1875 |
}
|
|
|
1876 |
|
|
|
1877 |
var scope = this;
|
|
|
1878 |
content.one('.fp-upload-btn').on('click', function(e) {
|
|
|
1879 |
e.preventDefault();
|
|
|
1880 |
var license = content.one('.fp-setlicense select');
|
|
|
1881 |
|
|
|
1882 |
if (this.options.rememberuserlicensepref) {
|
|
|
1883 |
this.set_preference('recentlicense', license.get('value'));
|
|
|
1884 |
}
|
|
|
1885 |
if (!content.one('.fp-file input').get('value')) {
|
|
|
1886 |
scope.print_msg(M.util.get_string('nofilesattached', 'repository'), 'error');
|
|
|
1887 |
return false;
|
|
|
1888 |
}
|
|
|
1889 |
this.hide_header();
|
|
|
1890 |
scope.request({
|
|
|
1891 |
scope: scope,
|
|
|
1892 |
action:'upload',
|
|
|
1893 |
client_id: client_id,
|
11 |
efrain |
1894 |
params: {'savepath': scope.options.savepath || '/'},
|
1 |
efrain |
1895 |
repository_id: scope.active_repo.id,
|
|
|
1896 |
form: {id: id, upload:true},
|
|
|
1897 |
onerror: function(id, o, args) {
|
|
|
1898 |
scope.create_upload_form(data);
|
|
|
1899 |
},
|
|
|
1900 |
callback: function(id, o, args) {
|
|
|
1901 |
if (o.event == 'fileexists') {
|
|
|
1902 |
scope.create_upload_form(data);
|
|
|
1903 |
scope.process_existing_file(o);
|
|
|
1904 |
return;
|
|
|
1905 |
}
|
|
|
1906 |
if (scope.options.editor_target&&scope.options.env=='editor') {
|
|
|
1907 |
scope.options.editor_target.value=o.url;
|
|
|
1908 |
scope.options.editor_target.dispatchEvent(new Event('change'), {'bubbles': true});
|
|
|
1909 |
}
|
|
|
1910 |
scope.hide();
|
|
|
1911 |
o.client_id = client_id;
|
|
|
1912 |
var formcallback_scope = args.scope.options.magicscope ? args.scope.options.magicscope : args.scope;
|
|
|
1913 |
scope.options.formcallback.apply(formcallback_scope, [o]);
|
|
|
1914 |
}
|
|
|
1915 |
}, true);
|
|
|
1916 |
}, this);
|
|
|
1917 |
},
|
|
|
1918 |
/** setting handlers and labels for elements in toolbar. Called once during the initial render of filepicker */
|
|
|
1919 |
setup_toolbar: function() {
|
|
|
1920 |
var client_id = this.options.client_id;
|
|
|
1921 |
var toolbar = this.fpnode.one('.fp-toolbar');
|
|
|
1922 |
toolbar.one('.fp-tb-logout').one('a,button').on('click', function(e) {
|
|
|
1923 |
e.preventDefault();
|
|
|
1924 |
if (!this.active_repo.nologin) {
|
|
|
1925 |
this.hide_header();
|
|
|
1926 |
this.request({
|
|
|
1927 |
action:'logout',
|
|
|
1928 |
client_id: this.options.client_id,
|
|
|
1929 |
repository_id: this.active_repo.id,
|
|
|
1930 |
path:'',
|
|
|
1931 |
callback: this.display_response
|
|
|
1932 |
}, true);
|
|
|
1933 |
}
|
|
|
1934 |
if (this.active_repo.logouturl) {
|
|
|
1935 |
window.open(this.active_repo.logouturl, 'repo_auth', 'location=0,status=0,width=500,height=300,scrollbars=yes');
|
|
|
1936 |
}
|
|
|
1937 |
}, this);
|
|
|
1938 |
toolbar.one('.fp-tb-refresh').one('a,button').on('click', function(e) {
|
|
|
1939 |
e.preventDefault();
|
|
|
1940 |
if (!this.active_repo.norefresh) {
|
|
|
1941 |
this.list({ path: this.currentpath });
|
|
|
1942 |
}
|
|
|
1943 |
}, this);
|
|
|
1944 |
toolbar.one('.fp-tb-search form').
|
|
|
1945 |
set('method', 'POST').
|
|
|
1946 |
set('id', 'fp-tb-search-'+client_id).
|
|
|
1947 |
on('submit', function(e) {
|
|
|
1948 |
e.preventDefault();
|
|
|
1949 |
if (!this.active_repo.nosearch) {
|
|
|
1950 |
this.request({
|
|
|
1951 |
scope: this,
|
|
|
1952 |
action:'search',
|
|
|
1953 |
client_id: this.options.client_id,
|
|
|
1954 |
repository_id: this.active_repo.id,
|
|
|
1955 |
form: {id: 'fp-tb-search-'+client_id, upload:false, useDisabled:true},
|
|
|
1956 |
callback: this.display_response
|
|
|
1957 |
}, true);
|
|
|
1958 |
}
|
|
|
1959 |
}, this);
|
|
|
1960 |
|
|
|
1961 |
// it does not matter what kind of element is .fp-tb-manage, we create a dummy <a>
|
|
|
1962 |
// element and use it to open url on click event
|
|
|
1963 |
var managelnk = Y.Node.create('<a/>').
|
|
|
1964 |
setAttrs({id:'fp-tb-manage-'+client_id+'-link', target:'_blank'}).
|
|
|
1965 |
setStyle('display', 'none');
|
|
|
1966 |
toolbar.append(managelnk);
|
|
|
1967 |
toolbar.one('.fp-tb-manage').one('a,button').
|
|
|
1968 |
on('click', function(e) {
|
|
|
1969 |
e.preventDefault();
|
|
|
1970 |
managelnk.simulate('click')
|
|
|
1971 |
});
|
|
|
1972 |
|
|
|
1973 |
// same with .fp-tb-help
|
|
|
1974 |
var helplnk = Y.Node.create('<a/>').
|
|
|
1975 |
setAttrs({id:'fp-tb-help-'+client_id+'-link', target:'_blank'}).
|
|
|
1976 |
setStyle('display', 'none');
|
|
|
1977 |
toolbar.append(helplnk);
|
|
|
1978 |
toolbar.one('.fp-tb-help').one('a,button').
|
|
|
1979 |
on('click', function(e) {
|
|
|
1980 |
e.preventDefault();
|
|
|
1981 |
helplnk.simulate('click')
|
|
|
1982 |
});
|
|
|
1983 |
},
|
|
|
1984 |
hide_header: function() {
|
|
|
1985 |
if (this.fpnode.one('.fp-toolbar')) {
|
|
|
1986 |
this.fpnode.one('.fp-toolbar').addClass('empty');
|
|
|
1987 |
}
|
|
|
1988 |
if (this.pathbar) {
|
|
|
1989 |
this.pathbar.setContent('').addClass('empty');
|
|
|
1990 |
}
|
|
|
1991 |
},
|
|
|
1992 |
print_header: function() {
|
|
|
1993 |
var r = this.active_repo;
|
|
|
1994 |
var scope = this;
|
|
|
1995 |
var client_id = this.options.client_id;
|
|
|
1996 |
this.hide_header();
|
|
|
1997 |
this.print_path();
|
|
|
1998 |
var toolbar = this.fpnode.one('.fp-toolbar');
|
|
|
1999 |
if (!toolbar) { return; }
|
|
|
2000 |
|
|
|
2001 |
var enable_tb_control = function(node, enabled) {
|
|
|
2002 |
if (!node) { return; }
|
|
|
2003 |
node.addClassIf('disabled', !enabled).addClassIf('enabled', enabled)
|
|
|
2004 |
if (enabled) {
|
|
|
2005 |
toolbar.removeClass('empty');
|
|
|
2006 |
}
|
|
|
2007 |
}
|
|
|
2008 |
|
|
|
2009 |
// TODO 'back' permanently disabled for now. Note, flickr_public uses 'Logout' for it!
|
|
|
2010 |
enable_tb_control(toolbar.one('.fp-tb-back'), false);
|
|
|
2011 |
|
|
|
2012 |
// search form
|
|
|
2013 |
enable_tb_control(toolbar.one('.fp-tb-search'), !r.nosearch);
|
|
|
2014 |
if(!r.nosearch) {
|
|
|
2015 |
var searchform = toolbar.one('.fp-tb-search form');
|
|
|
2016 |
searchform.setContent('');
|
|
|
2017 |
this.request({
|
|
|
2018 |
scope: this,
|
|
|
2019 |
action:'searchform',
|
|
|
2020 |
repository_id: this.active_repo.id,
|
|
|
2021 |
callback: function(id, obj, args) {
|
|
|
2022 |
if (obj.repo_id == scope.active_repo.id && obj.form) {
|
|
|
2023 |
// if we did not jump to another repository meanwhile
|
|
|
2024 |
searchform.setContent(obj.form);
|
|
|
2025 |
// Highlight search text when user click for search.
|
|
|
2026 |
var searchnode = searchform.one('input[name="s"]');
|
|
|
2027 |
if (searchnode) {
|
|
|
2028 |
searchnode.once('click', function(e) {
|
|
|
2029 |
e.preventDefault();
|
|
|
2030 |
this.select();
|
|
|
2031 |
});
|
|
|
2032 |
}
|
|
|
2033 |
}
|
|
|
2034 |
}
|
|
|
2035 |
}, false);
|
|
|
2036 |
}
|
|
|
2037 |
|
|
|
2038 |
// refresh button
|
|
|
2039 |
// weather we use cache for this instance, this button will reload listing anyway
|
|
|
2040 |
enable_tb_control(toolbar.one('.fp-tb-refresh'), !r.norefresh);
|
|
|
2041 |
|
|
|
2042 |
// login button
|
|
|
2043 |
enable_tb_control(toolbar.one('.fp-tb-logout'), !r.nologin);
|
|
|
2044 |
|
|
|
2045 |
// manage url
|
|
|
2046 |
enable_tb_control(toolbar.one('.fp-tb-manage'), r.manage);
|
|
|
2047 |
Y.one('#fp-tb-manage-'+client_id+'-link').set('href', r.manage);
|
|
|
2048 |
|
|
|
2049 |
// help url
|
|
|
2050 |
enable_tb_control(toolbar.one('.fp-tb-help'), r.help);
|
|
|
2051 |
Y.one('#fp-tb-help-'+client_id+'-link').set('href', r.help);
|
|
|
2052 |
|
|
|
2053 |
// message
|
|
|
2054 |
enable_tb_control(toolbar.one('.fp-tb-message'), r.message);
|
|
|
2055 |
toolbar.one('.fp-tb-message').setContent(r.message);
|
|
|
2056 |
},
|
|
|
2057 |
print_path: function() {
|
|
|
2058 |
if (!this.pathbar) {
|
|
|
2059 |
return;
|
|
|
2060 |
}
|
|
|
2061 |
this.pathbar.setContent('').addClass('empty');
|
|
|
2062 |
var p = this.filepath;
|
|
|
2063 |
if (p && p.length!=0 && this.viewmode != 2) {
|
|
|
2064 |
for(var i = 0; i < p.length; i++) {
|
|
|
2065 |
var el = this.pathnode.cloneNode(true);
|
|
|
2066 |
this.pathbar.appendChild(el);
|
|
|
2067 |
if (i == 0) {
|
|
|
2068 |
el.addClass('first');
|
|
|
2069 |
}
|
|
|
2070 |
if (i == p.length-1) {
|
|
|
2071 |
el.addClass('last');
|
|
|
2072 |
}
|
|
|
2073 |
if (i%2) {
|
|
|
2074 |
el.addClass('even');
|
|
|
2075 |
} else {
|
|
|
2076 |
el.addClass('odd');
|
|
|
2077 |
}
|
|
|
2078 |
el.all('.fp-path-folder-name').setContent(Y.Escape.html(p[i].name));
|
|
|
2079 |
el.on('click',
|
|
|
2080 |
function(e, path) {
|
|
|
2081 |
e.preventDefault();
|
|
|
2082 |
this.list({'path':path});
|
|
|
2083 |
},
|
|
|
2084 |
this, p[i].path);
|
|
|
2085 |
}
|
|
|
2086 |
this.pathbar.removeClass('empty');
|
|
|
2087 |
}
|
|
|
2088 |
},
|
|
|
2089 |
hide: function() {
|
|
|
2090 |
this.selectui.hide();
|
|
|
2091 |
if (this.process_dlg) {
|
|
|
2092 |
this.process_dlg.hide();
|
|
|
2093 |
}
|
|
|
2094 |
if (this.msg_dlg) {
|
|
|
2095 |
this.msg_dlg.hide();
|
|
|
2096 |
}
|
|
|
2097 |
this.mainui.hide();
|
|
|
2098 |
},
|
|
|
2099 |
show: function() {
|
|
|
2100 |
if (this.fpnode) {
|
|
|
2101 |
this.hide();
|
|
|
2102 |
this.mainui.show();
|
|
|
2103 |
this.show_recent_repository();
|
|
|
2104 |
} else {
|
|
|
2105 |
this.launch();
|
|
|
2106 |
}
|
|
|
2107 |
},
|
|
|
2108 |
launch: function() {
|
|
|
2109 |
this.render();
|
|
|
2110 |
},
|
|
|
2111 |
show_recent_repository: function() {
|
|
|
2112 |
this.hide_header();
|
|
|
2113 |
this.viewbar_set_enabled(false);
|
|
|
2114 |
var repository_id = this.get_preference('recentrepository');
|
|
|
2115 |
this.viewmode = this.get_preference('recentviewmode');
|
|
|
2116 |
if (this.viewmode != 2 && this.viewmode != 3) {
|
|
|
2117 |
this.viewmode = 1;
|
|
|
2118 |
}
|
|
|
2119 |
if (this.options.repositories[repository_id]) {
|
|
|
2120 |
this.list({'repo_id':repository_id});
|
|
|
2121 |
}
|
|
|
2122 |
},
|
|
|
2123 |
get_preference: function (name) {
|
|
|
2124 |
if (this.options.userprefs[name]) {
|
|
|
2125 |
return this.options.userprefs[name];
|
|
|
2126 |
} else {
|
|
|
2127 |
return false;
|
|
|
2128 |
}
|
|
|
2129 |
},
|
|
|
2130 |
set_preference: function(name, value) {
|
|
|
2131 |
if (this.options.userprefs[name] != value) {
|
|
|
2132 |
require(['core_user/repository'], function(UserRepository) {
|
|
|
2133 |
UserRepository.setUserPreference('filepicker_' + name, value);
|
|
|
2134 |
this.options.userprefs[name] = value;
|
|
|
2135 |
}.bind(this));
|
|
|
2136 |
}
|
|
|
2137 |
},
|
|
|
2138 |
in_iframe: function () {
|
|
|
2139 |
// If we're not the top window then we're in an iFrame
|
|
|
2140 |
return window.self !== window.top;
|
|
|
2141 |
}
|
|
|
2142 |
});
|
|
|
2143 |
var loading = Y.one('#filepicker-loading-'+options.client_id);
|
|
|
2144 |
if (loading) {
|
|
|
2145 |
loading.setStyle('display', 'none');
|
|
|
2146 |
}
|
|
|
2147 |
M.core_filepicker.instances[options.client_id] = new FilePickerHelper(options);
|
|
|
2148 |
};
|