/** * Klasa generująca przeglądarkę plików znajdujących się na serwerze. * * (c) 2008 by Marcin Wrzyciel **/ var fb = null; var FileBrowserEx = new Class({ options:{ path: "", base_path: "", // musi kończyć się slashem write_dir: "", type: "list", allowFolderSelect: false, showFoldersOnly: false, multipleSelect: false, onSelect: Class.empty(), access_rights: 0 }, initialize: function(options){ this.setOptions(options) this.dialog = new MooDialog() this.dialog.setWidth('812px') this.dialog.setHeight('544px') }, show: function(){ /* wyświetla filebrowsera wraz z całą zawartością */ this.dialog.getHandle().innerHTML = this.__headerAndFooter() var top=window.getScrollTop()+350; this.dialog.getHandle().setStyle( 'top',top+'px'); $('fb_close_btn').addEvent('click', this.hide.bind(this)) $('fb_change_view').addEvent('click', this.change_view.bind(this)) if((this.options.access_rights&2)>0){ $('fb_add_folder').addEvent('click', this.add_folder.bind(this)) $('fb_add_file').addEvent('click', this.add_file.bind(this)) } if(this.options.multipleSelect) $('fb-btn-wstaw-zaznaczone').addEvent('click', this.insert_selected.bind(this)) this.fc_iframe = new Element( 'iframe', { 'styles' :{ 'display' : 'none'}, 'src' : 'js/explorer/addFile.php?path='+this.options.base_path+this.options.path, 'frameborder': "no", 'scroling': 'no' }) //$('fb-file-folder').appendChild(this.fc_iframe); this.fc_iframe.setStyle('display', '') this.dialog.show() this.update() }, hide: function(){ this.dialog.hide() }, go: function(folder){ if(folder == ".."){ for (var pI = this.options.path.length - 1; pI >= 0; pI--) { if((this.options.path.charAt(pI) == '/') || (this.options.path.charAt(pI) == '\\')) break; } this.options.path = this.options.path.substring(0, pI); }else{ if(folder != '.') this.options.path += '/' + folder; } this.update() }, update: function(){ /* aktualizuje zawartośc filebrowsera */ url = 'js/explorer/explorer.php?path='+this.options.base_path+this.options.path; $('fb_path').innerHTML = this.options.path; o = this $('fb-file-folder').empty(); $('fb-content').empty().addClass('fex-load') new Ajax(url, { method: 'get', onSuccess: function(response){ eval("objects = ("+response+")"); o.is_writable = (o.options.base_path+o.options.path.substr(1)).indexOf(o.options.write_dir); if(0 != o.is_writable && ((this.options.access_rights&2)>0)){ $('fb_add_folder').setStyle('display', 'none'); $('fb_add_file').setStyle('display', 'none'); }else{ $('fb_add_folder').setStyle('display', ''); $('fb_add_file').setStyle('display', ''); } if(o.options.type == 'thumb'){ o._showThumb(objects) }else{ o._showList(objects) } } }).request(); }, change_view: function() { if(this.options.type == 'list') this.options.type = "thumb"; else this.options.type = "list" this.update() }, add_folder: function(){ $('fb-file-folder').innerHTML = '
' + ' ' + '
' }, add_file : function(){ $('fb-file-folder').empty() $('fb-file-folder').innerHTML='
' + '   ' + '
'; }, uploadFile: function(){ alert('aaa'); $('btn_add_file_fire').send({onComplete:function(){this.update();}}); }, insert_selected: function(){ $$('input.mftp_chx').filterByAttribute("checked").each(function(e,i){ this.options.onSelect(e.value) }.bind(this)) this.hide() }, /** metody prywatne **/ __headerAndFooter: function(){ html = '
' html += '' + '

MENADŻER PLIKÓW

' + '

zamknij

' html += '
' html += '

'; html +=''; if((this.options.access_rights&2)>0){ html +='' } html += ' ' if((this.options.access_rights&2)>0){ html += '' } html += '' html+= '

' html+= '
' html+= '

tutaj jesteś: '+this.options.path+ '

'//'kat. główna » folder » folder » podfolder

' if(this.type == 'list'){ html+= '' html+= '' html+= '' html+= '' html+= '' //html+= '' html+= '' html+= '' html+= '' html+= '
typnazwaopisrozmiardataakcja
' } html+= '
' if(this.options.multipleSelect){ html+= '

zaznacz wszystkie | odwróć zaznaczenie

' html+= '

wstaw zaznaczone' // usuń zacznaczone

' } html+= '
' html+= '
' return html; }, _showList: function(objects){ // code 2 - details code = '
' code+= '' code+= '' for(i=0;i' if(this.options.multipleSelect) code+= ' ' code+= ' ' code+= ' ' //code+= ' ' code+= ' ' code+= ' ' code+= ' ' code+= '' }else{ code+= '' if(this.options.multipleSelect) code+= ' ' code+= ' ' code+= ' ' //code+= ' ' code+= ' ' code+= ' ' code+= ' ' code+= '' } } if(!this.options.showFoldersOnly){ for(i=0;i' code+= ' ' code+= ' ' //code+= ' ' code+= ' ' code+= ' ' code+= ' ' code+= '' } } code += "
..
'+objects.folders[i].name+''+objects.folders[i].date+'' if(this.options.allowFolderSelect) code+='wstaw'; //code+= ' usuń
'+objects.files[i].name+'pl en'+objects.files[i].size+''+objects.files[i].date+'wstaw '; // code+= 'usuń
" $('fb-content').setHTML(code).removeClass('fex-load'); }, /** metody chronione **/ _showThumb: function(objects){ // code 1 - thumb code = '' last=0 for(i=0;i' code_2ln+= '' last = i%5 if(last == 4) {code+= ''; code_2ln += ''; code+= code_2ln;} }else{ if(i%5 == 0) { code+= ''; code_2ln = ''; } code+= ' ' code_2ln+= '' last = i%5 if(last == 4) {code+= ''; code_2ln += ''; code+= code_2ln;} } } if(!this.options.showFoldersOnly){ if(objects.files.length >0) last+=1 shift = last for(i=0;i' }else{ code+= ' ' } code_2ln+= '' if(last == 4) {code+= ''; code_2ln += ''; code+= code_2ln;} i++ } } if(last != 4){ // uzupełnienie listy do końca tabelki for(i=last+1;i<5;i++){ code+= '' code_2ln+= ''; } code+= ''; code_2ln+= '' code+= code_2ln; } code += "

..

+ ' if(this.options.multipleSelect) code_2ln+= ' ' code_2ln+= ((objects.folders[i].name.length > 15) ? objects.folders[i].name.substring(0,12)+'...' : objects.folders[i].name)+'

+ ' if(this.options.multipleSelect) code_2ln+= '' code_2ln+=((objects.files[i].name.length > 15) ? objects.files[i].name.substring(0,12)+'...':objects.files[i].name)+'

" $('fb-content').setHTML(code).removeClass("fex-load"); } }); FileBrowserEx.implement(new Options) window.addEvent('domready', function(){ fb = new FileBrowserEx })