"REPOSITORY/MDL-13766, 1. support help option 2. make breadcrumb clickable"
[moodle.git] / repository / javascript.php
CommitLineData
9bdd9eee 1<?php // $Id$
9bdd9eee 2///////////////////////////////////////////////////////////////////////////
3// //
4// Don't modify this file unless you know how it works //
5// //
6///////////////////////////////////////////////////////////////////////////
7983d5e7 7
8require_once(dirname(dirname(__FILE__)).'/config.php');
9$yui = optional_param('yui', 0, PARAM_RAW); // page or path
10if (!empty($yui)) {
11 repository_get_yui();
12}
13function repository_get_yui() {
14 global $CFG;
4de94541 15
16 $lifetime = '86400';
17
18 @header('Content-type: text/javascript');
19 @header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
20 @header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .'GMT');
21 @header('Cache-control: max-age='.$lifetime);
22 @header('Pragma: ');
23
7983d5e7 24 $jslist = array(
25 'yahoo-dom-event/yahoo-dom-event.js',
26 'element/element-beta-min.js',
27 'treeview/treeview-min.js',
28 'dragdrop/dragdrop-min.js',
1e285d0a 29 'container/container-min.js',
7983d5e7 30 'resize/resize-min.js',
31 'layout/layout-min.js',
32 'connection/connection-min.js',
33 'json/json-min.js',
34 'button/button-min.js',
35 'selector/selector-beta-min.js'
36 );
37 foreach ($jslist as $js) {
4de94541 38 echo "/* Included from lib/yui/$js */\n";
1e285d0a 39 readfile($CFG->dirroot.'/lib/yui/'.$js);
4de94541 40 echo "\n\n";
7983d5e7 41 }
42 exit();
43}
9bdd9eee 44/**
45 * Return javascript to create file picker to browse repositories
46 * @global object $CFG
47 * @global object $USER
48 * @param object $context the context
49 * @return array
50 */
c167aa26 51function repository_get_client($context, $accepted_filetypes = '*', $returnvalue = '*') {
9bdd9eee 52 global $CFG, $USER;
53 $suffix = uniqid();
54 $sesskey = sesskey();
8d419e59 55 // language string
56 $stradd = get_string('add', 'repository');
9bdd9eee 57 $strback = get_string('back', 'repository');
58 $strcancel = get_string('cancel');
59 $strclose = get_string('close', 'repository');
60 $strccache = get_string('cleancache', 'repository');
61 $strcopying = get_string('copying', 'repository');
62 $strdownbtn = get_string('getfile', 'repository');
63 $strdownload = get_string('downloadsucc', 'repository');
64 $strdate = get_string('date', 'repository').': ';
65 $strerror = get_string('error', 'repository');
66 $strfilenotnull = get_string('filenotnull', 'repository');
f823a796 67 $strfederatedsearch = get_string('federatedsearch', 'repository');
70920df7 68 $strhelp = get_string('help');
9bdd9eee 69 $strrefresh = get_string('refresh', 'repository');
70 $strinvalidjson = get_string('invalidjson', 'repository');
71 $strlistview = get_string('listview', 'repository');
c196505b 72 $strlogin = get_string('login', 'repository');
9bdd9eee 73 $strlogout = get_string('logout', 'repository');
74 $strloading = get_string('loading', 'repository');
75 $strthumbview = get_string('thumbview', 'repository');
76 $strtitle = get_string('title', 'repository');
00045af9 77 $strnoresult = get_string('noresult', 'repository');
9bdd9eee 78 $strmgr = get_string('manageurl', 'repository');
79 $strnoenter = get_string('noenter', 'repository');
80 $strsave = get_string('save', 'repository');
8d419e59 81 $strsaveas = get_string('saveas', 'repository').': ';
9bdd9eee 82 $strsaved = get_string('saved', 'repository');
83 $strsaving = get_string('saving', 'repository');
84 $strsize = get_string('size', 'repository').': ';
85 $strsync = get_string('sync', 'repository');
86 $strsearch = get_string('search', 'repository');
87 $strsearching = get_string('searching', 'repository');
88 $strsubmit = get_string('submit', 'repository');
89 $strpreview = get_string('preview', 'repository');
90 $strpopup = get_string('popup', 'repository');
cdf083f9 91 $strupload = get_string('upload', 'repository').'...';
9bdd9eee 92 $struploading = get_string('uploading', 'repository');
93 $css = '';
94 if (!isset($CFG->repo_yui_loaded)) {
95 $css .= <<<EOD
96<style type="text/css">
97@import "$CFG->httpswwwroot/lib/yui/resize/assets/skins/sam/resize.css";
98@import "$CFG->httpswwwroot/lib/yui/container/assets/skins/sam/container.css";
99@import "$CFG->httpswwwroot/lib/yui/layout/assets/skins/sam/layout.css";
100@import "$CFG->httpswwwroot/lib/yui/button/assets/skins/sam/button.css";
101@import "$CFG->httpswwwroot/lib/yui/assets/skins/sam/treeview.css";
102</style>
103<style type="text/css">
104.file-picker{font-size:12px;}
105.file-picker strong{background:#FFFFCC}
106.file-picker a{color: #336699}
107.file-picker a:hover{background:#003366;color:white}
108.fp-panel{padding:0;margin:0; text-align:left;}
4572588a 109.fp-login-form{text-align:center}
9bdd9eee 110.fp-searchbar{float:right}
111.fp-viewbar{width:300px;float:left}
112.fp-toolbar{padding: .8em;background: #FFFFCC;color:white;text-align:center}
113.fp-toolbar a{padding: 0 .5em}
68f63143 114.fp-list{list-style-type:none;padding:0;float:left;width:100%;margin:0;}
9bdd9eee 115.fp-list li{border-bottom:1px dotted gray;margin-bottom: 1em;}
116.fp-repo-name{display:block;padding: .5em;margin-bottom: .5em}
117.fp-pathbar{margin: .4em;border-bottom: 1px dotted gray;}
118.fp-pathbar a{padding: .4em;}
119.fp-rename-form{text-align:center}
120.fp-rename-form p{margin: 1em;}
121.fp-upload-form{margin: 2em 0;text-align:center}
cdf083f9 122.fp-upload-btn a{cursor: default;background: white;border:1px solid gray;color:black;padding: .5em}
9bdd9eee 123.fp-upload-btn a:hover {background: grey;color:white}
124.fp-paging{margin:1em .5em; clear:both;text-align:center;line-height: 2.5em;}
125.fp-paging a{padding: .5em;border: 1px solid #CCC}
4a7108a3 126.fp-paging a.cur_page{border: 1px solid blue}
9bdd9eee 127.fp-popup{text-align:center}
45a5c8a5 128.fp-grid{float:left;text-align:center;}
129.fp-grid div{overflow: hidden}
9bdd9eee 130.fp-grid p{margin:0;padding:0;background: #FFFFCC}
45a5c8a5 131.fp-grid .label{height:48px;text-align:center}
b23b4638 132.fp-grid span{color:gray}
9bdd9eee 133</style>
dbc01944 134
135<!--[if IE 6]>
136 <style type="text/css">
137 /* Fix for IE6 */
138 .yui-skin-sam .yui-panel .hd{
139
140 }
141 </style>
142<![endif]-->
9bdd9eee 143EOD;
144
7983d5e7 145 $js = '<script type="text/javascript" src="'.$CFG->httpswwwroot.'/repository/javascript.php?yui=1"></script>';
9bdd9eee 146 $CFG->repo_yui_loaded = true;
147 } else {
148 $js = '';
149 }
150
151 $js .= <<<EOD
152<script type="text/javascript">
153//<![CDATA[
fc11edbf 154//
20efad8b 155var mdl_in_array = function(el, arr) {
156 for(var i = 0, l = arr.length; i < l; i++) {
157 if(arr[i] == el) {
fc11edbf 158 return true;
159 }
160 }
161 return false;
162}
163
9bdd9eee 164var active_instance = null;
165function repository_callback(id) {
5fa358d1 166 active_instance.req(id, '');
9bdd9eee 167}
168var repository_client_$suffix = (function() {
169// private static field
170var dver = '1.0';
171// private static methods
77b57b29 172function version() {
9bdd9eee 173 alert(dver);
174}
175function _client() {
176// public varible
177this.name = 'repository_client_$suffix';
178// private varible
179var Dom = YAHOO.util.Dom, Event = YAHOO.util.Event, layout = null, resize = null;
180var IE_QUIRKS = (YAHOO.env.ua.ie && document.compatMode == "BackCompat");
181var IE_SYNC = (YAHOO.env.ua.ie == 6 || (YAHOO.env.ua.ie == 7 && IE_QUIRKS));
182var PANEL_BODY_PADDING = (10*2);
183var btn_list = {label: '$strlistview', value: 'l', checked: true, onclick: {fn: _client.viewlist}};
184var btn_thumb = {label: '$strthumbview', value: 't', onclick: {fn: _client.viewthumb}};
185var repo_list = null;
186var resize = null;
187var filepicker = new YAHOO.widget.Panel('file-picker-$suffix', {
188 draggable: true,
189 close: true,
9bdd9eee 190 underlay: 'none',
191 zindex: 666666,
192 xy: [50, Dom.getDocumentScrollTop()+20]
193});
194// construct code section
195{
196 filepicker.setHeader('$strtitle');
197 filepicker.setBody('<div id="layout-$suffix"></div>');
198 filepicker.beforeRenderEvent.subscribe(function() {
199 Event.onAvailable('layout-$suffix', function() {
200 layout = new YAHOO.widget.Layout('layout-$suffix', {
77b57b29 201 height: 480, width: 700,
9bdd9eee 202 units: [
203 {position: 'top', height: 32, resize: false,
204 body:'<div class="yui-buttongroup fp-viewbar" id="repo-viewbar-$suffix"></div><div class="fp-searchbar" id="search-div-$suffix"></div>', gutter: '2'},
422639d4 205 {position: 'left', width: 200, resize: true, scroll:true,
9bdd9eee 206 body:'<ul class="fp-list" id="repo-list-$suffix"></ul>', gutter: '0 5 0 2', minWidth: 150, maxWidth: 300 },
207 {position: 'center', body: '<div class="fp-panel" id="panel-$suffix"></div>',
208 scroll: true, gutter: '0 2 0 0' }
209 ]
210 });
211 layout.render();
212 });
213 });
214 resize = new YAHOO.util.Resize('file-picker-$suffix', {
215 handles: ['br'],
216 autoRatio: true,
217 status: true,
abbd635c 218 minWidth: 680,
9bdd9eee 219 minHeight: 400
220 });
abbd635c 221 if(YAHOO.env.ua.ie == 6){
77b57b29 222 var fp_title = document.getElementById('file-picker-$suffix');
223 fp_title.style.width = '680px';
abbd635c 224 }
9bdd9eee 225 resize.on('resize', function(args) {
226 var panelHeight = args.height;
227 var headerHeight = this.header.offsetHeight; // Content + Padding + Border
228 var bodyHeight = (panelHeight - headerHeight);
229 var bodyContentHeight = (IE_QUIRKS) ? bodyHeight : bodyHeight - PANEL_BODY_PADDING;
230 Dom.setStyle(this.body, 'height', bodyContentHeight + 'px');
abbd635c 231 if(YAHOO.env.ua.ie == 6){
77b57b29 232 var fp_title = document.getElementById('file-picker-$suffix');
233 fp_title.style.width = args.width;
abbd635c 234 }
9bdd9eee 235 if (IE_SYNC) {
236 this.sizeUnderlay();
237 this.syncIframe();
238 }
239 layout.set('height', bodyContentHeight);
240 layout.set('width', (args.width - PANEL_BODY_PADDING));
241 layout.resize();
242
243 }, filepicker, true);
20efad8b 244 filepicker.update_instances = function(){
245 _client.print_instances();
246 }
9bdd9eee 247 _client.viewbar = new YAHOO.widget.ButtonGroup({
248 id: 'btngroup-$suffix',
249 name: 'buttons',
250 disabled: true,
251 container: 'repo-viewbar-$suffix'
252 });
253}
254// public method
255this.show = function() {
20efad8b 256 filepicker.update_instances();
9bdd9eee 257 filepicker.show();
258}
259this.hide = function() {
260 filepicker.hide();
261}
262this.create_picker = function() {
263 // display UI
264 filepicker.render();
80483d75 265 _client.viewbar.addButtons([btn_thumb, btn_list]);
9bdd9eee 266 // init repository list
267 repo_list = new YAHOO.util.Element('repo-list-$suffix');
268 repo_list.on('contentReady', function(e) {
269 var searchbar = new YAHOO.util.Element('search-div-$suffix');
f823a796 270 searchbar.get('element').innerHTML = '<input id="search-input-$suffix" /><button id="search-btn-$suffix">$strfederatedsearch</button>';
77b57b29 271 var btn_search = new YAHOO.util.Element('search-btn-$suffix');
272 var input_keyword = new YAHOO.util.Element('search-input-$suffix');
273 btn_search.fnSearch = function(e) {
0507853e 274 var el = new YAHOO.util.Element('search-input-$suffix')
275 var keyword = el.get('value');
276 var params = [];
277 params['s'] = keyword;
278 params['env']=_client.env;
279 params['action']='gsearch';
c438f190 280 params['accepted_types'] = _client.accepted_types;
0507853e 281 params['sesskey']='$sesskey';
282 params['ctx_id']=$context->id;
283 _client.loading('load');
284 var trans = YAHOO.util.Connect.asyncRequest('POST',
77b57b29 285 '$CFG->httpswwwroot/repository/ws.php?action=gsearch', this.global_search_cb, _client.postdata(params));
0507853e 286 }
77b57b29 287 btn_search.global_search_cb={
9bdd9eee 288 success: function(o) {
289 var panel = new YAHOO.util.Element('panel-$suffix');
9bdd9eee 290 if(!o.responseText) {
00045af9 291 panel.get('element').innerHTML = '$strnoresult';
292 return;
9bdd9eee 293 }
00045af9 294 try {
77b57b29 295 var data = YAHOO.lang.JSON.parse(o.responseText);
9bdd9eee 296 } catch(e) {
77b57b29 297 alert('$strinvalidjson - |global_search_cb| -'+_client.stripHTML(o.responseText));
00045af9 298 return;
9bdd9eee 299 }
00045af9 300 _client.ds={};
77b57b29 301 if(!data.list || data.list.length<1){
00045af9 302 panel.get('element').innerHTML = '$strnoresult';
303 return;
9bdd9eee 304 }
77b57b29 305 _client.ds.list = data.list;
306 if(_client.viewmode) {
307 _client.viewlist();
308 } else {
309 _client.viewthumb();
9bdd9eee 310 }
77b57b29 311 var el = new YAHOO.util.Element('search-input-$suffix')
312 el.set('value', '');
9bdd9eee 313 }
314 }
77b57b29 315 btn_search.on('contentReady', function() {
316 btn_search.on('click', this.fnSearch, this.input_keyword);
0507853e 317 });
77b57b29 318 input_keyword.on('contentReady', function() {
4658b183 319 var scope = document.getElementById('search-input-$suffix');
77b57b29 320 var k1 = new YAHOO.util.KeyListener(scope, {keys:13}, {fn:function(){this.fnSearch()},scope:btn_search, correctScope: true});
0507853e 321 k1.enable();
9bdd9eee 322 });
20efad8b 323 _client.print_instances();
9bdd9eee 324 });
325}
326}
327
328// public static varible
329_client.repos = [];
330_client.repositoryid = 0;
331// _client.ds save all data received from server side
332_client.ds = null;
333_client.viewmode = 0;
77b57b29 334_client.viewbar = null;
20efad8b 335_client.print_instances = function() {
336 var container = new YAHOO.util.Element('repo-list-$suffix');
337 container.set('innerHTML', '');
338 for(var i in _client.repos) {
339 var repo = _client.repos[i];
340 var support = false;
841c1b23 341 if(repository_client_$suffix.env=='editor' && _client.accepted_types != '*'){
c167aa26 342 if(repo.supported_types!='*'){
343 for (var j in repo.supported_types){
344 if(mdl_in_array(repo.supported_types[j], _client.accepted_types)){
20efad8b 345 support = true;
346 }
347 }
348 }
349 }else{
350 support = true;
351 }
c167aa26 352 if(repo.supported_types == '*' || support){
20efad8b 353 var li = document.createElement('li');
354 li.id = 'repo-$suffix-'+repo.id;
355 var icon = document.createElement('img');
356 icon.src = repo.icon;
357 icon.width = '16';
358 icon.height = '16';
359 var link = document.createElement('a');
360 link.href = '###';
361 link.id = 'repo-call-$suffix-'+repo.id;
362 link.appendChild(icon);
363 link.className = 'fp-repo-name';
364 link.onclick = function() {
2eb332bf 365 // highlight active repo
366 for(var cc in _client.repos){
367 var tmp_id = 'repo-call-$suffix-'+ _client.repos[cc].id;
368 var el = document.getElementById(tmp_id);
0ce17b66 369 if(el){
370 el.style.background = 'transparent';
371 }
2eb332bf 372 }
373 this.style.background = '#CCC';
20efad8b 374 var re = /repo-call-$suffix-(\d+)/i;
375 var id = this.id.match(re);
5fa358d1 376 repository_client_$suffix.req(id[1], '');
20efad8b 377 }
378 link.innerHTML += ' '+repo.name;
379 li.appendChild(link);
380 container.appendChild(li);
381 repo = null;
382 }
383 }
384}
a40e6cdd 385_client.stripHTML = function(str){
386 var re= /<\S[^><]*>/g
387 var ret = str.replace(re, "")
388 return ret;
389}
77b57b29 390
9bdd9eee 391// public static mehtod
392_client.postdata = function(obj) {
393 var str = '';
394 for(k in obj) {
395 if(obj[k] instanceof Array) {
396 for(i in obj[k]) {
397 str += (encodeURIComponent(k) +'[]='+encodeURIComponent(obj[k][i]));
398 str += '&';
399 }
400 } else {
401 str += encodeURIComponent(k) +'='+encodeURIComponent(obj[k]);
402 str += '&';
403 }
404 }
405 return str;
406}
407_client.loading = function(type, name) {
408 var panel = new YAHOO.util.Element('panel-$suffix');
409 panel.get('element').innerHTML = '';
410 var content = document.createElement('div');
411 content.style.textAlign='center';
412 var para = document.createElement('P');
413 var img = document.createElement('IMG');
414 if(type=='load') {
415 img.src = '$CFG->pixpath/i/loading.gif';
416 para.innerHTML = '$strloading';
417 }else{
418 img.src = '$CFG->pixpath/i/progressbar.gif';
419 para.innerHTML = '$strcopying <strong>'+name+'</strong>';
420 }
421 content.appendChild(para);
422 content.appendChild(img);
423 //content.innerHTML = '';
424 panel.get('element').appendChild(content);
425}
426_client.rename = function(oldname, url, icon, repo_id) {
448f9363 427 var thumbnail = document.getElementById('fp-grid-panel-$suffix');
428 if(thumbnail){
429 thumbnail.style.display = 'none';
430 }
fa342c1c 431 var header = document.getElementById('fp-header-$suffix');
7ad67417 432 header.style.display = 'none';
433 var footer = document.getElementById('fp-footer-$suffix');
434 footer.style.display = 'none';
9bdd9eee 435 var panel = new YAHOO.util.Element('panel-$suffix');
436 var html = '<div class="fp-rename-form">';
437 _client.repositoryid=repo_id;
438 html += '<p><img src="'+icon+'" /></p>';
439 html += '<p><label for="newname-$suffix">$strsaveas</label>';
440 html += '<input type="text" id="newname-$suffix" value="'+oldname+'" /></p>';
441 /**
442 html += '<p><label for="syncfile-$suffix">$strsync</label> ';
443 html += '<input type="checkbox" id="syncfile-$suffix" /></p>';
444 */
445 html += '<p><input type="hidden" id="fileurl-$suffix" value="'+url+'" />';
9bdd9eee 446 html += '<input type="button" onclick="repository_client_$suffix.download()" value="$strdownbtn" />';
f9c717b0 447 html += '<input type="button" onclick="repository_client_$suffix.viewfiles()" value="$strcancel" /></p>';
9bdd9eee 448 html += '</div>';
7ad67417 449 panel.get('element').innerHTML += html;
7741692c 450 var tree = document.getElementById('treediv-$suffix');
451 if(tree){
452 tree.style.display = 'none';
453 }
9bdd9eee 454}
455_client.popup = function(url) {
456 active_instance = repository_client_$suffix;
457 _client.win = window.open(url,'repo_auth', 'location=0,status=0,scrollbars=0,width=500,height=300');
458 return false;
459}
460_client.print_login = function() {
461 var panel = new YAHOO.util.Element('panel-$suffix');
462 var data = _client.ds.login;
4572588a 463 var str = '<div class="fp-login-form">';
9bdd9eee 464 var has_pop = false;
465 for(var k in data) {
466 if(data[k].type=='popup') {
c196505b 467 str += '<p class="fp-popup">$strpopup</p>';
468 str += '<p class="fp-popup"><button onclick="repository_client_$suffix.popup(\''+data[k].url+'\')">$strlogin</button>';
469 str += '</p>';
9bdd9eee 470 has_pop = true;
471 }else if(data[k].type=='textarea') {
472 str += '<p><textarea id="'+data[k].id+'" name="'+data[k].name+'"></textarea></p>';
473 }else{
474 str += '<p>';
3de54d43 475 var label_id = '';
9bdd9eee 476 var field_id = '';
477 var field_value = '';
478 if(data[k].id) {
3de54d43 479 label_id = ' for="'+data[k].id+'"';
9bdd9eee 480 field_id = ' id="'+data[k].id+'"';
481 }
482 if (data[k].label) {
3de54d43 483 str += '<label'+label_id+'>'+data[k].label+'</label>&nbsp;';
9bdd9eee 484 }
485 if(data[k].value) {
486 field_value = ' value="'+data[k].value+'"';
487 }
488 str += '<input type="'+data[k].type+'"'+' name="'+data[k].name+'"'+field_id+field_value+' />';
489 str += '</p>';
490 }
491 }
492 if(!has_pop) {
493 str += '<p><input type="button" onclick="repository_client_$suffix.login()" value="$strsubmit" /></p>';
494 }
4572588a 495 str += '</div>';
9bdd9eee 496 panel.get('element').innerHTML = str;
497}
498
499_client.viewfiles = function() {
500 if(_client.viewmode) {
9bdd9eee 501 _client.viewlist();
80483d75 502 } else {
503 _client.viewthumb();
9bdd9eee 504 }
505}
159840f0 506_client.print_msg = function(msg) {
507 _client.print_header();
508 var panel = new YAHOO.util.Element('panel-$suffix');
509 panel.get('element').innerHTML += msg;
510 _client.print_footer();
511}
9bdd9eee 512_client.print_header = function() {
513 var panel = new YAHOO.util.Element('panel-$suffix');
fa342c1c 514 var str = '<div id="fp-header-$suffix">';
9bdd9eee 515 str += '<div class="fp-toolbar" id="repo-tb-$suffix"></div>';
4a7108a3 516 if(_client.ds.pages < 8){
517 str += _client.makepage('header');
518 }
fa342c1c 519 str += '</div>';
9bdd9eee 520 panel.set('innerHTML', str);
521 _client.makepath();
522}
523_client.print_footer = function() {
e8e396e5 524 var panel = document.getElementById('panel-$suffix');
525 var footer = document.createElement('DIV');
7ad67417 526 footer.id = 'fp-footer-$suffix';
e8e396e5 527 footer.innerHTML += _client.uploadcontrol();
3178967f 528 footer.innerHTML += _client.makepage('footer');
77b57b29 529 panel.appendChild(footer);
530 // add repository manage buttons here
9bdd9eee 531 var oDiv = document.getElementById('repo-tb-$suffix');
532 if(!_client.ds.nosearch) {
533 var search = document.createElement('A');
534 search.href = '###';
535 search.innerHTML = '<img src="$CFG->pixpath/a/search.png" /> $strsearch';
536 oDiv.appendChild(search);
537 search.onclick = function() {
86e68c2d 538 repository_client_$suffix.search_form(repository_client_$suffix.repositoryid);
9bdd9eee 539 }
540 }
541 // weather we use cache for this instance, this button will reload listing anyway
c4fa9169 542 if(!_client.ds.norefresh) {
7983d5e7 543 var ccache = document.createElement('A');
544 ccache.href = '###';
545 ccache.innerHTML = '<img src="$CFG->pixpath/a/refresh.png" /> $strrefresh';
546 oDiv.appendChild(ccache);
547 ccache.onclick = function() {
548 var params = [];
549 params['env']=_client.env;
550 params['sesskey']='$sesskey';
551 params['ctx_id']=$context->id;
552 params['repo_id']=repository_client_$suffix.repositoryid;
553 _client.loading('load');
554 var trans = YAHOO.util.Connect.asyncRequest('POST',
555 '$CFG->httpswwwroot/repository/ws.php?action=ccache', repository_client_$suffix.req_cb, _client.postdata(params));
556 }
9bdd9eee 557 }
558 if(_client.ds.manage) {
559 var mgr = document.createElement('A');
560 mgr.innerHTML = '<img src="$CFG->pixpath/a/setting.png" /> $strmgr';
561 mgr.href = _client.ds.manage;
562 mgr.target = "_blank";
563 oDiv.appendChild(mgr);
564 }
565 if(!_client.ds.nologin) {
566 var logout = document.createElement('A');
567 logout.href = '###';
568 logout.innerHTML = '<img src="$CFG->pixpath/a/logout.png" /> $strlogout';
569 oDiv.appendChild(logout);
570 logout.onclick = function() {
5fa358d1 571 repository_client_$suffix.logout(repository_client_$suffix.repositoryid, 1);
9bdd9eee 572 }
573 }
70920df7 574 if(_client.ds.help) {
575 var help = document.createElement('A');
576 help.href = _client.ds.help;
577 help.target = "_blank";
578 help.innerHTML = '<img src="$CFG->pixpath/a/help.png" /> $strhelp';
579 oDiv.appendChild(help);
580 }
9bdd9eee 581}
582_client.viewthumb = function(ds) {
80483d75 583 _client.viewmode = 0;
77b57b29 584 _client.viewbar.check(0);
448f9363 585 var container = document.getElementById('panel-$suffix');
586 var panel = document.createElement('DIV');
587 panel.id = 'fp-grid-panel-$suffix';
9bdd9eee 588 var list = null;
77b57b29 589 if(arguments.length == 1) {
9bdd9eee 590 list = ds;
591 } else {
592 // from button
593 list = _client.ds.list;
594 }
595 _client.print_header();
596 var count = 0;
597 for(k in list) {
77b57b29 598 // the container
9bdd9eee 599 var el = document.createElement('div');
77b57b29 600 el.className='fp-grid';
601 // the file name
45a5c8a5 602 var title = document.createElement('div');
fa342c1c 603 title.id = 'grid-title-'+String(count);
77b57b29 604 title.className = 'label';
20df4f50 605 if (list[k].shorttitle) {
606 list[k].title = list[k].shorttitle;
607 }
9bf4f1b5 608 title.innerHTML += '<a href="###"><span>'+list[k].title+"</span></a>";
45a5c8a5 609 if(list[k].thumbnail_width){
610 el.style.width = list[k].thumbnail_width+'px';
3de54d43 611 title.style.width = (list[k].thumbnail_width-10)+'px';
45a5c8a5 612 } else {
613 el.style.width = title.style.width = '80px';
614 }
9bdd9eee 615 var frame = document.createElement('DIV');
616 frame.style.textAlign='center';
1c4a1552 617 if(list[k].thumbnail_height){
618 frame.style.height = list[k].thumbnail_height+'px';
619 }
9bdd9eee 620 var img = document.createElement('img');
621 img.src = list[k].thumbnail;
20df4f50 622 if(list[k].thumbnail_alt) {
623 img.alt = list[k].thumbnail_alt;
624 }
625 if(list[k].thumbnail_title) {
626 img.title = list[k].thumbnail_title;
627 }
9bdd9eee 628 var link = document.createElement('A');
629 link.href='###';
630 link.id = 'img-id-'+String(count);
caad7034 631 if(list[k].url) {
632 el.innerHTML += '<p><a target="_blank" href="'+list[k].url+'">$strpreview</a></p>';
633 }
9bf4f1b5 634 link.appendChild(img);
635 frame.appendChild(link);
636 el.appendChild(frame);
9bdd9eee 637 el.appendChild(title);
caad7034 638
448f9363 639 panel.appendChild(el);
9bdd9eee 640 if(list[k].children) {
641 var folder = new YAHOO.util.Element(link.id);
642 folder.ds = list[k].children;
b7668e73 643 folder.path = list[k].path;
9bf4f1b5 644 var el_title = new YAHOO.util.Element(title.id);
9bdd9eee 645 folder.on('contentReady', function() {
646 this.on('click', function() {
647 if(_client.ds.dynload) {
b7668e73 648 var params = [];
649 params['p'] = this.path;
650 params['env'] = _client.env;
651 params['repo_id'] = _client.repositoryid;
652 params['ctx_id'] = $context->id;
653 params['sesskey']= '$sesskey';
c438f190 654 params['accepted_types'] = _client.accepted_types;
b7668e73 655 _client.loading('load');
656 var trans = YAHOO.util.Connect.asyncRequest('POST',
657 '$CFG->httpswwwroot/repository/ws.php?action=list', _client.req_cb, _client.postdata(params));
9bdd9eee 658 }else{
659 _client.viewthumb(this.ds);
660 }
661 });
662 });
9bf4f1b5 663 el_title.on('contentReady', function() {
664 this.on('click', function(){
665 folder.fireEvent('click');
666 });
667 });
9bdd9eee 668 } else {
fa342c1c 669 var el_title = new YAHOO.util.Element(title.id);
9bdd9eee 670 var file = new YAHOO.util.Element(link.id);
fa342c1c 671 el_title.title = file.title = list[k].title;
672 el_title.value = file.value = list[k].source;
673 el_title.icon = file.icon = list[k].thumbnail;
9bdd9eee 674 if(list[k].repo_id) {
fa342c1c 675 el_title.repo_id = file.repo_id = list[k].repo_id;
9bdd9eee 676 }else{
fa342c1c 677 el_title.repo_id = file.repo_id = _client.repositoryid;
9bdd9eee 678 }
679 file.on('contentReady', function() {
680 this.on('click', function() {
681 repository_client_$suffix.rename(this.title, this.value, this.icon, this.repo_id);
682 });
683 });
fa342c1c 684 el_title.on('contentReady', function() {
685 this.on('click', function() {
686 repository_client_$suffix.rename(this.title, this.value, this.icon, this.repo_id);
687 });
688 });
9bdd9eee 689 }
690 count++;
691 }
448f9363 692 container.appendChild(panel);
9bdd9eee 693 _client.print_footer();
694}
695_client.buildtree = function(node, level) {
696 if(node.children) {
697 node.title = '<i><u>'+node.title+'</u></i>';
698 }
e8e396e5 699 var info = {
700 label:node.title,
701 title:"$strdate"+node.date+' $strsize'+node.size,
702 filename:node.title,
703 value:node.source,
704 icon:node.thumbnail,
705 path:node.path
706 };
9bdd9eee 707 var tmpNode = new YAHOO.widget.TextNode(info, level, false);
708 var tooltip = new YAHOO.widget.Tooltip(tmpNode.labelElId, {
00045af9 709 context:tmpNode.labelElId, text:info.title});
9bdd9eee 710 if(node.repo_id) {
711 tmpNode.repo_id=node.repo_id;
712 }else{
713 tmpNode.repo_id=_client.repositoryid;
714 }
9bdd9eee 715 if(node.children) {
716 if(node.expanded) {
717 tmpNode.expand();
718 }
719 tmpNode.isLeaf = false;
720 if (node.path) {
721 tmpNode.path = node.path;
722 } else {
723 tmpNode.path = '';
724 }
725 for(var c in node.children) {
726 _client.buildtree(node.children[c], tmpNode);
727 }
728 } else {
729 tmpNode.isLeaf = true;
9bdd9eee 730 }
731}
732_client.dynload = function (node, fnLoadComplete) {
733 var callback = {
734 success: function(o) {
735 try {
736 var json = YAHOO.lang.JSON.parse(o.responseText);
737 } catch(e) {
a40e6cdd 738 alert('$strinvalidjson - |dynload| -'+_client.stripHTML(o.responseText));
b7668e73 739 return;
9bdd9eee 740 }
741 for(k in json.list) {
742 _client.buildtree(json.list[k], node);
743 }
744 o.argument.fnLoadComplete();
745 },
746 failure:function(oResponse) {
00045af9 747 alert('$strerror - |dynload| -');
9bdd9eee 748 oResponse.argument.fnLoadComplete();
749 },
00045af9 750 argument:{"node":node, "fnLoadComplete": fnLoadComplete}
9bdd9eee 751 }
752 var params = [];
753 params['p']=node.path;
754 params['env']=_client.env;
755 params['sesskey']='$sesskey';
756 params['ctx_id']=$context->id;
757 params['repo_id']=_client.repositoryid;
c438f190 758 params['accepted_types'] = _client.accepted_types;
9bdd9eee 759 var trans = YAHOO.util.Connect.asyncRequest('POST',
760 '$CFG->httpswwwroot/repository/ws.php?action=list', callback, _client.postdata(params));
761}
1e08b5cf 762_client.viewiframe = function() {
763 var panel = new YAHOO.util.Element('panel-$suffix');
764 panel.get('element').innerHTML = "<iframe frameborder=\"0\" width=\"98%\" height=\"400px\" src=\""+_client.ds.iframe+"\" />";
765}
9bdd9eee 766_client.viewlist = function() {
80483d75 767 _client.viewmode = 1;
9bdd9eee 768 var panel = new YAHOO.util.Element('panel-$suffix');
80483d75 769 _client.viewbar.check(1);
9bdd9eee 770 list = _client.ds.list;
771 _client.print_header();
772 panel.get('element').innerHTML += '<div id="treediv-$suffix"></div>';
773 var tree = new YAHOO.widget.TreeView('treediv-$suffix');
774 if(_client.ds.dynload) {
775 tree.setDynamicLoad(_client.dynload, 1);
776 } else {
777 }
778 for(k in list) {
779 _client.buildtree(list[k], tree.getRoot());
780 }
781 tree.draw();
e8e396e5 782 tree.subscribe('clickEvent', function(e){
783 if(e.node.isLeaf){
784 repository_client_$suffix.rename(e.node.data.filename, e.node.data.value, e.node.data.icon, e.node.repo_id);
785 }
786 });
9bdd9eee 787 _client.print_footer();
788}
789_client.upload = function() {
790 var u = _client.ds.upload;
791 var aform = document.getElementById(u.id);
792 var parent = document.getElementById(u.id+'_div');
793 var d = document.getElementById(_client.ds.upload.id+'-file');
794 if(d.value!='' && d.value!=null) {
795 var container = document.createElement('DIV');
796 container.id = u.id+'_loading';
797 container.style.textAlign='center';
798 var img = document.createElement('IMG');
799 img.src = '$CFG->pixpath/i/progressbar.gif';
800 var para = document.createElement('p');
801 para.innerHTML = '$struploading';
802 container.appendChild(para);
803 container.appendChild(img);
804 parent.appendChild(container);
805 YAHOO.util.Connect.setForm(aform, true, true);
806 var trans = YAHOO.util.Connect.asyncRequest('POST',
807 '$CFG->httpswwwroot/repository/ws.php?action=upload&sesskey=$sesskey&ctx_id=$context->id&repo_id='
808 +_client.repositoryid,
809 _client.upload_cb);
810 }else{
811 alert('$strfilenotnull');
812 }
813}
814_client.upload_cb = {
815upload: function(o) {
816 try {
817 var ret = YAHOO.lang.JSON.parse(o.responseText);
818 } catch(e) {
a40e6cdd 819 alert('$strinvalidjson - |upload| -'+_client.stripHTML(o.responseText));
9bdd9eee 820 }
821 if(ret && ret.e) {
822 var panel = new YAHOO.util.Element('panel-$suffix');
823 panel.get('element').innerHTML = ret.e;
824 return;
825 }
826 if(ret) {
827 alert('$strsaved');
828 repository_client_$suffix.end(ret);
9bdd9eee 829 }
830 }
831}
832_client.uploadcontrol = function() {
833 var str = '';
834 if(_client.ds.upload) {
835 str += '<div id="'+_client.ds.upload.id+'_div" class="fp-upload-form">';
836 str += '<form id="'+_client.ds.upload.id+'" onsubmit="return false">';
cdf083f9 837 str += '<label for="'+_client.ds.upload.id+'-file">'+_client.ds.upload.label+': </label>';
9bdd9eee 838 str += '<input type="file" id="'+_client.ds.upload.id+'-file" name="repo_upload_file" />';
839 str += '<p class="fp-upload-btn"><a href="###" onclick="return repository_client_$suffix.upload();">$strupload</a></p>';
840 str += '</form>';
841 str += '</div>';
842 }
843 return str;
844}
4a7108a3 845_client.paging_node = function(type, page) {
846 if (page == _client.ds.page) {
5fa358d1 847 str = '<a class="cur_page" onclick="repository_client_$suffix.'+type+'('+_client.repositoryid+', '+page+', '+page+')" href="###">';
4a7108a3 848 } else {
5fa358d1 849 str = '<a onclick="repository_client_$suffix.'+type+'('+_client.repositoryid+', '+page+', '+page+')" href="###">';
4a7108a3 850 }
851 return str;
852}
3178967f 853_client.makepage = function(id) {
9bdd9eee 854 var str = '';
855 if(_client.ds.pages) {
3178967f 856 str += '<div class="fp-paging" id="paging-'+id+'-$suffix">';
4a7108a3 857 if(!_client.ds.search_result){
858 var action = 'req';
859 } else {
860 var action = 'search_paging';
861 }
862 str += _client.paging_node(action, 1)+'1</a>';
863
864 if (_client.ds.page+2>=_client.ds.pages) {
865 var max = _client.ds.pages;
866 } else {
867 var max = _client.ds.page+2;
868 }
869 if (_client.ds.page-2 >= 3) {
870 str += ' ... ';
871 for(var i = _client.ds.page-2; i < max; i++) {
872 str += _client.paging_node(action, i);
873 str += String(i);
874 str += '</a> ';
86e68c2d 875 }
4a7108a3 876 } else {
877 for(var i = 2; i < max; i++) {
878 str += _client.paging_node(action, i);
879 str += String(i);
880 str += '</a> ';
881 }
882 }
883 if (max==_client.ds.pages) {
884 str += _client.paging_node(action, _client.ds.pages)+_client.ds.pages+'</a>';
885 } else {
886 str += _client.paging_node(action, max)+max+'</a>';
887 str += ' ... '+_client.paging_node(action, _client.ds.pages)+_client.ds.pages+'</a>';
9bdd9eee 888 }
889 str += '</div>';
890 }
891 return str;
892}
5fa358d1 893_client.search_paging = function(id, path, page) {
86e68c2d 894 _client.viewbar.set('disabled', false);
895 _client.loading('load');
896 _client.repositoryid = id;
897 var params = [];
898 params['p'] = path;
5fa358d1 899 params['page'] = page;
86e68c2d 900 params['env']=_client.env;
c438f190 901 params['accepted_types'] = _client.accepted_types;
86e68c2d 902 params['action']='search';
903 params['search_paging']='true';
904 params['sesskey']='$sesskey';
905 params['ctx_id']=$context->id;
906 params['repo_id']=id;
907 var trans = YAHOO.util.Connect.asyncRequest('POST', '$CFG->httpswwwroot/repository/ws.php?action='+action, _client.req_cb, _client.postdata(params));
908}
9bdd9eee 909_client.makepath = function() {
80483d75 910 if(_client.viewmode == 1) {
9bdd9eee 911 return;
912 }
913 var panel = new YAHOO.util.Element('panel-$suffix');
914 var p = _client.ds.path;
915 if(p && p.length!=0) {
916 var oDiv = document.createElement('DIV');
917 oDiv.id = "path-$suffix";
918 oDiv.className = "fp-pathbar";
919 panel.get('element').appendChild(oDiv);
920 for(var i = 0; i < _client.ds.path.length; i++) {
921 var link = document.createElement('A');
922 link.href = "###";
923 link.innerHTML = _client.ds.path[i].name;
924 link.id = 'path-'+i+'-el';
925 var sep = document.createElement('SPAN');
926 sep.innerHTML = '/';
927 oDiv.appendChild(link);
928 oDiv.appendChild(sep);
929 var el = new YAHOO.util.Element(link.id);
930 el.id = _client.repositoryid;
931 el.path = _client.ds.path[i].path;
932 el.on('contentReady', function() {
70920df7 933 var path_link = document.getElementById(link.id);
934 path_link.id = this.id;
935 path_link.path = this.path
936 path_link.onclick = function() {
5fa358d1 937 repository_client_$suffix.req(this.id, this.path);
70920df7 938 }
9bdd9eee 939 });
940 }
941 }
942}
943// send download request
944_client.download = function() {
945 var title = document.getElementById('newname-$suffix').value;
946 var file = document.getElementById('fileurl-$suffix').value;
947 _client.loading('download', title);
948 var params = [];
b423b4af 949 if(_client.itemid){
950 params['itemid']=_client.itemid;
951 }
9bdd9eee 952 params['env']=_client.env;
953 params['file']=file;
954 params['title']=title;
955 params['sesskey']='$sesskey';
956 params['ctx_id']=$context->id;
957 params['repo_id']=_client.repositoryid;
958 var trans = YAHOO.util.Connect.asyncRequest('POST',
959 '$CFG->httpswwwroot/repository/ws.php?action=download', _client.download_cb, _client.postdata(params));
960}
961// send login request
962_client.login = function() {
963 var params = [];
964 var data = _client.ds.login;
965 for (var k in data) {
966 if(data[k].type!='popup') {
967 var el = document.getElementsByName(data[k].name)[0];
968 params[data[k].name] = '';
969 if(el.type == 'checkbox') {
970 params[data[k].name] = el.checked;
971 } else {
972 params[data[k].name] = el.value;
973 }
974 }
975 }
976 params['env'] = _client.env;
977 params['repo_id'] = _client.repositoryid;
978 params['ctx_id'] = $context->id;
979 params['sesskey']= '$sesskey';
46ee50dc 980 params['accepted_types'] = _client.accepted_types;
9bdd9eee 981 _client.loading('load');
982 var trans = YAHOO.util.Connect.asyncRequest('POST',
983 '$CFG->httpswwwroot/repository/ws.php?action=sign', _client.req_cb, _client.postdata(params));
984}
b423b4af 985_client.end = function(obj) {
986 if(_client.env=='filepicker') {
987 _client.target.value = obj['id'];
988 }else if(_client.env=='editor'){
989 _client.target.value = obj['url'];
9bdd9eee 990 _client.target.onchange();
991 }
b423b4af 992 _client.formcallback(obj);
9bdd9eee 993 _client.instance.hide();
994 _client.viewfiles();
995}
996_client.hide = function() {
997 _client.instance.hide();
998 _client.viewfiles();
999}
1000// request file list or login
5fa358d1 1001_client.req = function(id, path, page) {
9bdd9eee 1002 _client.viewbar.set('disabled', false);
1003 _client.loading('load');
1004 _client.repositoryid = id;
9bdd9eee 1005 var params = [];
1006 params['p'] = path;
1007 params['env']=_client.env;
9bdd9eee 1008 params['sesskey']='$sesskey';
1009 params['ctx_id']=$context->id;
1010 params['repo_id']=id;
5fa358d1 1011 if (page) {
1012 params['page']=page;
1013 }
c167aa26 1014 params['accepted_types'] = _client.accepted_types;
c438f190 1015 var trans = YAHOO.util.Connect.asyncRequest('POST', '$CFG->httpswwwroot/repository/ws.php?action=list', _client.req_cb, _client.postdata(params));
9bdd9eee 1016}
5fa358d1 1017_client.logout = function(id) {
1018 _client.repositoryid = id;
1019 var params = [];
1020 params['repo_id'] = id;
1021 var trans = YAHOO.util.Connect.asyncRequest('POST', '$CFG->httpswwwroot/repository/ws.php?action=logout', _client.req_cb, _client.postdata(params));
1022}
9bdd9eee 1023_client.search_form_cb = {
1024success: function(o) {
1025 var el = document.getElementById('fp-search-dlg');
77b57b29 1026 var _r = repository_client_$suffix;
9bdd9eee 1027 if(el) {
1028 el.innerHTML = '';
1029 } else {
1030 var el = document.createElement('DIV');
1031 el.id = 'fp-search-dlg';
1032 }
1033 var div1 = document.createElement('DIV');
1034 div1.className = 'hd';
448b49ef 1035 div1.innerHTML = "$strsearching\"" + _r.repos[_r.repositoryid].name + '"';
9bdd9eee 1036 var div2 = document.createElement('DIV');
1037 div2.className = 'bd';
1038 var sform = document.createElement('FORM');
1039 sform.method = 'POST';
1040 sform.id = "fp-search-form";
494f9df3 1041 sform.action = '$CFG->httpswwwroot/repository/ws.php?action=search';
9bdd9eee 1042 sform.innerHTML = o.responseText;
1043 div2.appendChild(sform);
1044 el.appendChild(div1);
1045 el.appendChild(div2);
1046 document.body.appendChild(el);
1047 var dlg = new YAHOO.widget.Dialog("fp-search-dlg",{
1048 postmethod: 'async',
448b49ef 1049 draggable: true,
9bdd9eee 1050 width : "30em",
1051 fixedcenter : true,
1052 zindex: 766667,
865607b3 1053 visible : false,
9bdd9eee 1054 constraintoviewport : true,
865607b3 1055 buttons : [
448b49ef 1056 { text:"$strsubmit",handler: function() {
9bdd9eee 1057 _client.viewbar.set('disabled', false); _client.loading('load');
1058 YAHOO.util.Connect.setForm('fp-search-form', false, false);
1059 this.cancel();
1060 var trans = YAHOO.util.Connect.asyncRequest('POST',
1061 '$CFG->httpswwwroot/repository/ws.php?action=search&env='+_client.env, _client.req_cb);
448b49ef 1062 },isDefault:true},
1063 {text:"$strcancel",handler:function() {this.cancel()}}
9bdd9eee 1064 ]
1065 });
1066 dlg.render();
1067 dlg.show();
1068}
1069}
86e68c2d 1070_client.search_form = function(id) {
9bdd9eee 1071 var params = [];
1072 params['env']=_client.env;
1073 params['sesskey']='$sesskey';
1074 params['ctx_id']=$context->id;
1075 params['repo_id']=id;
1076 var trans = YAHOO.util.Connect.asyncRequest('POST', '$CFG->httpswwwroot/repository/ws.php?action=searchform', _client.search_form_cb, _client.postdata(params));
1077}
1078_client.req_cb = {
1079success: function(o) {
1080 var panel = new YAHOO.util.Element('panel-$suffix');
1081 try {
77b57b29 1082 var data = YAHOO.lang.JSON.parse(o.responseText);
9bdd9eee 1083 } catch(e) {
a40e6cdd 1084 alert('$strinvalidjson - |req_cb| -'+_client.stripHTML(o.responseText));
9bdd9eee 1085 };
77b57b29 1086 if(data && data.e) {
1087 panel.get('element').innerHTML = data.e;
9bdd9eee 1088 return;
1089 }
77b57b29 1090 _client.ds = data;
1091 if(!data) {
9bdd9eee 1092 return;
159840f0 1093 }else if(data.msg){
1094 _client.print_msg(data.msg);
77b57b29 1095 }else if(data.iframe) {
1e08b5cf 1096 _client.viewiframe();
77b57b29 1097 }else if(data.login) {
9bdd9eee 1098 _client.print_login();
77b57b29 1099 }else if(data.list) {
9bdd9eee 1100 if(_client.viewmode) {
9bdd9eee 1101 _client.viewlist();
80483d75 1102 } else {
1103 _client.viewthumb();
9bdd9eee 1104 }
1105 }
1106}
1107}
1108_client.download_cb = {
1109success: function(o) {
1110 var panel = new YAHOO.util.Element('panel-$suffix');
1111 try {
77b57b29 1112 var data = YAHOO.lang.JSON.parse(o.responseText);
9bdd9eee 1113 } catch(e) {
a40e6cdd 1114 alert('$strinvalidjson - |download_cb| -'+_client.stripHTML(o.responseText));
9bdd9eee 1115 }
77b57b29 1116 if(data && data.e) {
1117 panel.get('element').innerHTML = data.e;
9bdd9eee 1118 return;
1119 }
77b57b29 1120 if(data) {
1121 repository_client_$suffix.end(data);
9bdd9eee 1122 }
1123}
1124}
1125
1126return _client;
1127})();
1128EOD;
1129
d4fda077 1130$user_context = get_context_instance(CONTEXT_USER, $USER->id);
c167aa26 1131if (is_array($accepted_filetypes) && in_array('*', $accepted_filetypes)) {
1132 $accepted_filetypes = '*';
014c1ca0 1133}
c167aa26 1134$repos = repository::get_instances(array($user_context, $context, get_system_context()), null, true, null, $accepted_filetypes, $returnvalue);
fc11edbf 1135$js .= "\r\n".'repository_client_'.$suffix.'.repos=[];'."\r\n";
9bdd9eee 1136foreach ($repos as $repo) {
448b49ef 1137 $info = $repo->ajax_info();
9bdd9eee 1138 $js .= "\r\n";
448b49ef 1139 $js .= 'repository_client_'.$suffix.'.repos['.$info->id.']='.json_encode($repo->ajax_info()).';'."\n";
9bdd9eee 1140}
1141$js .= "\r\n";
1142
fc11edbf 1143$ft = new file_type_to_ext();
1144$image_file_ext = json_encode($ft->get_file_ext(array('image')));
1145$video_file_ext = json_encode($ft->get_file_ext(array('video')));
c438f190 1146$accepted_file_ext = json_encode($ft->get_file_ext($accepted_filetypes));
9bdd9eee 1147$js .= <<<EOD
1148function openpicker_$suffix(params) {
20efad8b 1149 if(params.filetype) {
1150 if(params.filetype == 'image') {
c167aa26 1151 repository_client_$suffix.accepted_types = $image_file_ext;
20efad8b 1152 } else if(params.filetype == 'video' || params.filetype== 'media') {
c167aa26 1153 repository_client_$suffix.accepted_types = $video_file_ext;
841c1b23 1154 } else if(params.filetype == 'file') {
1155 repository_client_$suffix.accepted_types = '*';
20efad8b 1156 }
1157 } else {
c438f190 1158 repository_client_$suffix.accepted_types = $accepted_file_ext;
20efad8b 1159 }
9bdd9eee 1160 if(!repository_client_$suffix.instance) {
1161 repository_client_$suffix.env = params.env;
1162 repository_client_$suffix.target = params.target;
b423b4af 1163 if(params.itemid){
1164 repository_client_$suffix.itemid = params.itemid;
159840f0 1165 } else if(tinyMCE && id2itemid[tinyMCE.selectedInstance.editorId]){
1166 repository_client_$suffix.itemid = id2itemid[tinyMCE.selectedInstance.editorId];
b423b4af 1167 }
9bdd9eee 1168 repository_client_$suffix.instance = new repository_client_$suffix();
1169 repository_client_$suffix.instance.create_picker();
1170 if(params.callback) {
1171 repository_client_$suffix.formcallback = params.callback;
1172 } else {
1173 repository_client_$suffix.formcallback = function() {};
1174 }
1175 } else {
de063645 1176 repository_client_$suffix.target = params.target;
9bdd9eee 1177 repository_client_$suffix.instance.show();
1178 }
1179}
1180//]]>
1181</script>
1182EOD;
1183return array('css'=>$css, 'js'=>$js, 'suffix'=>$suffix);
1184}