123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620 |
- //é
- var blockNewFolder = false;
- var pendingTask = false;
- $(function(){
- $(document).ajaxStop(function() {
- $('.preloader').fadeOut(200);
- });
- $(document).ajaxStart(function() {
- $('.preloader').show();
- });
- getFiles();
- addedFiles = Array();
- $('.tooltips').poshytip({
- className: 'tooltip',
- showTimeout: 0,
- alignTo: 'target',
- alignX: 'center',
- offsetY: 10,
- allowTipHover: false
- });
- imageExtension = Array();
- imageExtensionRoot = 'tpl/UnderBlack/img/extension/';
- imageExtensionMiniRoot = 'img/extension_mini/';
- imageExtension['sql']='sql.png';
- imageExtension['zip']='zip.png';
- imageExtension['rar']='rar.png';
- imageExtension['tar.gz']='archive.png';
- imageExtension['7z']='zip.png';
- imageExtension['gzip']='gzip.png';
- imageExtension['php']='php.png';
- imageExtension['py']='py.png';
- imageExtension['jsp']='html.png';
- imageExtension['html']='html.png';
- imageExtension['htm']='html.png';
- imageExtension['css']='css.png';
- imageExtension['java']='java.png';
- imageExtension['cpp']='cpp.png';
- imageExtension['c']='c.png';
- imageExtension['h']='h.png';
- imageExtension['hpp']='hpp.png';
- imageExtension['js']='js.png';
- imageExtension['rss']='rss.png';
- imageExtension['rb']='rb.png';
- imageExtension['vcard']='authors.png';
- imageExtension['exe']='exe.png';
- imageExtension['deb']='package.png';
- imageExtension['psd']='psd.png';
- imageExtension['nfo']='readme.png';
- imageExtension['csv']='calc.png';
- imageExtension['xls']='calc.png';
- imageExtension['xlsx']='calc.png';
- imageExtension['ppt']='pres.png';
- imageExtension['pptx']='pres.png';
- imageExtension['doc']='doc.png';
- imageExtension['odf']='doc.png';
- imageExtension['docx']='doc.png';
- imageExtension['otf']='doc.png';
- imageExtension['rtf']='rtf.png';
- imageExtension['txt']='txt.png';
- imageExtension['log']='log.png';
- imageExtension['src']='source.png';
- imageExtension['tex']='tex.png';
- imageExtension['bin']='bin.png';
- imageExtension['cd']='cd.png';
- imageExtension['sh']='script.png';
- imageExtension['bash']='script.png';
- imageExtension['bat']='script.png';
- imageExtension['vcal']='vcal.png';
- imageExtension['ical']='vcal.png';
- imageExtension['mp3']='playlist.png';
- imageExtension['avi']='playlist.png';
- imageExtension['mp4']='video.png';
- imageExtension['webm']='video.png';
- imageExtension['wmv']='video.png';
- imageExtension['mkv']='video.png';
- imageExtension['rpm']='rpm.png';
- imageExtension['tiff']='tiff.png';
- imageExtension['jpg']='jpg.png';
- imageExtension['jpeg']='jpg.png';
- imageExtension['png']='png.png';
- imageExtension['gif']='gif.png';
- imageExtension['bmp']='bmp.png';
- imageExtension['ico']='ico.png';
- imageExtension['eps']='draw.png';
- imageExtension['ai']='eps.png';
- imageExtension['pdf']='pdf.png';
- imageExtension['xml']='xml.png';
- imageExtension['fla']='makefile.png';
- imageExtension['swf']='makefile.png';
-
- // var dropbox = $('.message'),
- // message = $('.message', dropbox);
- $(function () {
- $('#uploadButton').fileupload({
- dataType: 'json',
- autoUpload: true,
- dropZone : '#uploadButton',
- maxFileSize: 5000000,
- sequentialUploads: true,
- add: function (e, data) {
- createImage(data.files[0]);
- pendingTask = true;
- data.submit();
- },
- done: function (e, data) {
- addedFiles.push({name:data.files[0].name,size:data.files[0].size,type:data.result.extension,path:data.result.filePath});
- },
- stop: function (e, data) {
- //enregistrement de l'evenement
- $.ajax({
- url: "php/action.php?action=addEventForUpload",
- data:{files:array2json(addedFiles)}
- });
- addedFiles = Array();
- pendingTask = false;
- //rafraichissement du bousin
- getFiles(null,'//CURRENT');
-
- },
- progress: function (e, data) {
- var progress = parseInt(data.loaded / data.total * 100, 10);
- $.data(data.files[0]).find('.progress').width(progress+'%');
- $.data(data.files[0]).find('.progressCount').html(progress+'%');
-
- }
- });
- });
-
-
- var template = '<div class="preview">'+
- '<span class="imageHolder">'+
- '<img />'+'<span class="uploaded"></span>'+
- '<span class="fileName"></span>'+
- '</span>'+
- '<div class="progressHolder">'+
- '<div class="progress"></div>'+
- '</div><span class="progressCount"></span>'+
- '</div>';
-
-
- function createImage(file){
- var preview = $(template),
- image = $('img', preview);
- fileName = $('.fileName', preview);
- image.width = 48;
- image.height = 48;
- var extension = file.name.split('.');
- if(extension.length==1){
- extension = null;
- }else{
- extension = extension[extension.length-1];
- }
- fileName.html(file.name);
- if(imageExtension[extension]!=null){
- ext = imageExtensionRoot+imageExtension[extension] ;
- }else{
- ext = imageExtensionRoot+'unknown.png';
- }
- image.attr('src',ext);
- preview.appendTo($("#dropbox"));
- $.data(file,preview);
- }
- function showMessage(msg){
- message.html(msg);
- }
-
- checkVersion();
- });
- function checkPendingTask(){
- if(pendingTask){
- alert('Certaines tâches sont encore en cours d\'execution, vous risquez de perdre des données.');
- }
- }
- function generateBreadCrumb(folder){
- returned = '';
- if(folder!=null){
- var dissolvedPath = explode('/',str_replace('../','',folder));
- var path = '../';
- for(i=0;i<dissolvedPath.length;i++){
- if(dissolvedPath[i]!=''){
- path +=dissolvedPath[i]+'/';
- returned +='<li alt="'+addslashes(path)+'" onclick="getFiles(null,\''+addslashes(path)+'\')">'+dissolvedPath[i]+'</li>';
- }
- }
- }
- return returned;
- }
- function getFiles(keywords,folder){
- if(!pendingTask){
- if(keywords==null){keywords='';}else{keywords = "&keywords="+keywords}
- if(folder==null){folderVar='';}else{folderVar = "&folder="+folder}
- $.ajax({
- url: "php/action.php?action=getFiles"+keywords+folderVar,
- success: function(returnedValue){
-
-
- response = $.parseJSON(returnedValue);
- if(response.succes){
-
- $('.breadcrumb').html(generateBreadCrumb(response.currentFolder));
-
- t= response.status;
- $('#dropbox .preview,.tooltip').remove();
- for(i=0;i<t.length;i++){
- addFile(t[i]);
- }
- $('.imageHolder,.imageHolder .addOptions li,.lien,.folderHolder').poshytip({
- className: 'tooltip',
- showTimeout: 0,
- alignTo: 'target',
- alignX: 'center',
- offsetY: 10,
- allowTipHover: false
- });
-
-
- $('.fileOption').click(function(){getFileOption(this);});
- $(".imageHolder").draggable({ revert: "invalid" });
-
-
- $( ".folderPreview" ).droppable({
- activeClass: "folderPreviewDroppableHover",
- hoverClass: "folderPreviewDroppableHover",
- drop: function( event, ui ) {
- var parent = $( ui.draggable ).parent();
- var fileUrl = $('.fileUrl',parent).html();
- var fileName = $('.fileName',parent).attr('alt');
- var folder = $('.fileUrl',this).html();
-
- $.ajax({
- url: "php/action.php?action=moveFile",
- data:{fileName:fileName,fileUrl:fileUrl,folder:folder},
- success: function(response){
- var response = $.parseJSON(response);
- parent.fadeOut(300);
- tell(response.status);
- }
- });
-
- }
- });
- }
- }
- });
- }else{
- alert('Des fichiers sont encore en téléchargement, veuillez patienter');
- }
- }
-
- function addFile(file){
- if(imageExtension[file.extension]!=null){
- ext = imageExtensionRoot+imageExtension[file.extension] ;
- }else{
- ext = imageExtensionRoot+'unknown.png';
- }
-
- if(file.type=='folder')ext = imageExtensionRoot+'folder-page.png';
- if(file.name=='..')ext = imageExtensionRoot+'folder-parent.png';
-
- if(file.type=='file'){
- var tpl = '<div class="preview filePreview" >'+
- '<div class="fileUrl">'+stripslashes(file.url)+'</div>'+
- '<span title="'+stripslashes(file.toolTipName)+'" class="imageHolder'+(file.published?' filePublished':'')+'"><div onclick="deleteFile(this)" class="deleteFile">x</div>'+
-
- '<div onclick="openFile(this)">'+
- '<img width="48px" height="48px" src="'+ext+'"/>'+
- '<ul>'+
- '<li>'+file.size+'</li>'+
- '<li>'+file.mtimeDate+' '+file.mtimeHour+'</li>'+
-
- '</ul>'+
- '</div>'+
- '<span ondblclick="renameFile(this)\" title="'+stripslashes(file.name)+'" alt="'+stripslashes(file.name)+'" class="fileName">'+stripslashes(file.shortname)+'</span>'+
- '</span>'+
- '</div>';
- }else if(file.type=='folder'){
- var tpl = '<div class="preview folderPreview">'+
- '<div class="fileUrl">'+stripslashes(file.url)+'</div>'+
- '<span title="'+stripslashes(file.name)+'" class="folderHolder ">';
- if(file.name!='..') tpl += '<div onclick="deleteFile(this)" class="deleteFile">x</div>';
- tpl += '<img width="48px" height="48px" onclick="getFiles(null,$(\'.fileUrl\',$(this).parent().parent()).html())" src="'+ext+'"/>'+
- '<span ';
- if(file.name!='..') tpl +='ondblclick="renameFile(this)\"';
- tpl += ' title="'+stripslashes(file.name)+'" alt="'+stripslashes(file.name)+'" class="fileName">'+stripslashes(file.shortname)+'</span>'+
- '</span></div>';
- }
- $('#dropbox').append(tpl);
- }
- function zipFile(element){
- var parent = $(element).parent().parent().parent().parent();
- var file =$('.fileUrl',parent).html();
- $.ajax({
- url: "php/action.php?action=zipFile",
- data:{file:file},
- success: function(response){
- var response = $.parseJSON(response);
- if(response.succes==true){
- window.location= './'+response.status;
- }else{
- tell(response.status);
- }
- }
- });
- }
- function publishFile(element){
- var parent = $(element).parent().parent().parent().parent();
- var file =$('.fileUrl',parent).html();
-
- $.ajax({
- url: "php/action.php?action=publishFile",
- data:{file:file},
- success: function(response){
- var response = $.parseJSON(response);
- if(response.succes==true){
- $(element).attr('onclick','unpublishFile(this);');
- $(element).parent().parent().parent().addClass('filePublished');
- tell(response.status);
- }else{
- tell(response.status);
- }
- }
- });
- }
- function unpublishFile(element){
- var parent = $(element).parent().parent().parent().parent();
- var file =$('.fileUrl',parent).html();
-
- $.ajax({
- url: "php/action.php?action=unpublishFile",
- data:{file:file},
- success: function(response){
- var response = $.parseJSON(response);
- if(response.succes==true){
- $(element).parent().parent().parent().removeClass('filePublished');
- $(element).attr('onclick','publishFile(this);');
- tell(response.status);
- }else{
- tell(response.status);
- }
- }
- });
- }
- function addFolder(){
- if(!blockNewFolder){
- blockNewFolder = true;
- $('.newFolder').hide();
- $.ajax({
- async:false,
- url: "php/action.php?action=addFolder",
- data:{name:$('input[name="folderName"]').val()},
- success: function(response){
- var response = $.parseJSON(response);
- if(response.succes){
- getFiles(null,'//CURRENT');
- $('.folderNameBloc').fadeOut(150);
- $('.folderNameBloc input').val('');
- }else{
- tell(response.status,3000);
- }
- }
- });
- $('.newFolder').fadeIn(300);
- blockNewFolder = false;
- }
- }
- function deleteUser(message,id,tmpToken){
- if(confirm(message))window.location="php/action.php?action=deleteUser&user="+id+"&tmpToken="+tmpToken;
- }
- function tell(message,time){
- var fix = false;
- if(time==null)time = 3000;
- if(time==0)fix = true;
- var options = {
- position: 'top-right',
- timeout: time,
- sticky: fix
- };
- message = '<i style="height: 20px; width: 20px; display: block; float: left; margin-right: 5px;" class="icon-ok"></i>'+message;
- TINYPOP.show(message,options);
- }
- function openFile(element){
- var parent = $(element).parent().parent();
- var file = $('.fileUrl',parent).html();
- window.location='./php/action.php?action=openFile&file='+file;
- }
- function focusFile(element){
- var parent = $(element).parent().parent();
- $('.imageHolder').css("color","#C9C9C9");
- $('.imageHolder').css("font-weight","normal");
- $('.imageHolder',parent).css("color","#ffffff");
- $('.imageHolder',parent).css("font-weight","bold");
- }
- function deleteFile(element){
- if(confirm('Etes vous sûr de vouloir supprimer cet élement?')){
- var parent = $(element).parent().parent();
- var file =$('.fileUrl',parent).html();
- file = file;
- $.ajax({
- url: "php/action.php?action=deleteFiles",
- data:{file:file},
- success: function(response){
- var response = $.parseJSON(response);
- tell(response.status);
- if(response.succes)$(element).parent().parent().fadeOut(300);
- }
- });
- }
- }
- function searchFiles(){
- var keywords = $('input[name="search"]').val();
- keywords = keywords.replace(' ',',');
- keywords = keywords.split(',');
- getFiles(keywords);
- }
-
- function renameFile(element){
- var parent = $(element).parent();
- file = $('.fileUrl',parent.parent()).html();
- value = $('.fileName',parent).attr("title");
- $('.fileName',parent).html('');
- $('.fileName',parent).append('<input type="text" value="'+value+'" class="fileNameArea">');
- pressEnter('.fileNameArea',function(){
- newValue = $('.fileNameArea',parent).val();
-
- if(newValue!=value){
-
- $.ajax({
- url: "php/action.php?action=renameFile",
- data:{file:file,newName:newValue},
- success: function(response){
- var response = $.parseJSON(response);
- if(!response.succes){
- tell(response.status);
- $('.fileName',parent).html(value);
- }else{
- $('.fileName',parent).html(newValue);
- $('.fileName',parent).attr("title",newValue);
- $('.fileName',parent).attr("alt",newValue);
- $('.fileUrl',parent.parent()).html($('.fileUrl',parent.parent()).html().replace(value,newValue));
-
- parent.poshytip('destroy');
- parent.attr("title",newValue);
- parent.poshytip({
- content:newValue,
- className: 'tooltip',
- showTimeout: 0,
- alignTo: 'target',
- alignX: 'center',
- offsetY: 10,
- allowTipHover: false
- });
- }
-
- }
- });
-
- }else{
- $('.fileName',parent).html(value);
- }
- });
- }
-
- function checkVersion(){
- if(typeof(lastVersion) != 'undefined' && typeof(lastVersionNumber) != 'undefined' && typeof(lastVersionName) != 'undefined' && typeof(lastVersionUrl) != 'undefined'){
- $.ajax({
- url: "php/action.php?action=checkVersion",
- success: function(response){
- if(response<lastVersionNumber || (typeof(specialMessage)!= 'undefined' && specialMessage!='')){
-
- var status= 'La nouvelle version '+lastVersion+' ('+lastVersionName+' - N° '+lastVersionNumber+') de DropCenter est <a target="_blank" href="'+lastVersionUrl+'">disponible ici.</a>'
-
- if(typeof(specialMessage)!= 'undefined' && specialMessage!='') status = specialMessage;
-
- $('#versionBloc').html(status);
- $('#versionBloc').fadeIn(300);
- }}});
- }
- }
-
-
- function pressEnter(input,func){
- var testTextBox = $(input);
- var code =null;
- testTextBox.keypress(function(e)
- {
- code= (e.keyCode ? e.keyCode : e.which);
- if (code == 13) func();
- // e.preventDefault();
- });
- }
- function getFileOption(elem){
- $(".addOptions",$(elem).parent().parent()).slideToggle(200);
- }
- function explode(delimiter,string,limit){var emptyArray={0:''};if(arguments.length<2||typeof arguments[0]=='undefined'||typeof arguments[1]=='undefined'){return null;}
- if(delimiter===''||delimiter===false||delimiter===null){return false;}
- if(typeof delimiter=='function'||typeof delimiter=='object'||typeof string=='function'||typeof string=='object'){return emptyArray;}
- if(delimiter===true){delimiter='1';}
- if(!limit){return string.toString().split(delimiter.toString());}
- var splitted=string.toString().split(delimiter.toString());var partA=splitted.splice(0,limit-1);var partB=splitted.join(delimiter.toString());partA.push(partB);return partA;}
- function str_replace(search,replace,subject,count){var i=0,j=0,temp='',repl='',sl=0,fl=0,f=[].concat(search),r=[].concat(replace),s=subject,ra=Object.prototype.toString.call(r)==='[object Array]',sa=Object.prototype.toString.call(s)==='[object Array]';s=[].concat(s);if(count){this.window[count]=0;}
- for(i=0,sl=s.length;i<sl;i++){if(s[i]===''){continue;}
- for(j=0,fl=f.length;j<fl;j++){temp=s[i]+'';repl=ra?(r[j]!==undefined?r[j]:''):r[0];s[i]=(temp).split(f[j]).join(repl);if(count&&s[i]!==temp){this.window[count]+=(temp.length-s[i].length)/f[j].length;}}}
- return sa?s:s[0];}
- function addslashes(str){return(str+'').replace(/[\\"']/g,'\\$&').replace(/\u0000/g,'\\0');}
- function stripslashes(str){return(str+'').replace(/\\(.?)/g,function(s,n1){switch(n1){case'\\':return'\\';case'0':return'\u0000';case'':return'';default:return n1;}});}
- function array2json(arr) {
- var parts = [];
- var is_list = (Object.prototype.toString.apply(arr) === '[object Array]');
- for(var key in arr) {
- var value = arr[key];
- if(typeof value == "object") { //Custom handling for arrays
- if(is_list) parts.push(array2json(value)); /* :RECURSION: */
- else parts[key] = array2json(value); /* :RECURSION: */
- } else {
- var str = "";
- if(!is_list) str = '"' + key + '":';
- //Custom handling for multiple data types
- if(typeof value == "number") str += value; //Numbers
- else if(value === false) str += 'false'; //The booleans
- else if(value === true) str += 'true';
- else str += '"' + value + '"'; //All other things
- // :TODO: Is there any more datatype we should be in the lookout for? (Functions?)
- parts.push(str);
- }
- }
- var json = parts.join(",");
-
- if(is_list) return '[' + json + ']';//Return numerical JSON
- return '{' + json + '}';//Return associative JSON
- }
|