From 00711341e9da369a2c99ff0085b7e36531986f0f Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Jun 2011 02:44:31 +0200 Subject: [PATCH 01/15] new file uploader that should work with more browsers tested with konqueror, chromium and firefox 4 --- files/css/files.css | 28 ++++++- files/js/files.js | 171 +++++++++++--------------------------- files/templates/index.php | 22 ++++- 3 files changed, 92 insertions(+), 129 deletions(-) diff --git a/files/css/files.css b/files/css/files.css index c3f7d82aa6..1cfca68ff5 100644 --- a/files/css/files.css +++ b/files/css/files.css @@ -23,24 +23,44 @@ display: inline; } -#fileSelector, #file_upload_cancel, #file_newfolder_submit { +#fileSelector, #file_upload_submit, #file_newfolder_submit { display: none; } -#file_upload_start, #file_newfolder_name { +#file_upload_filename, #file_newfolder_name { background-repeat: no-repeat; background-position: 0.5em 0; padding-left: 2em; } -#file_upload_start {background-image:url(../../img/mimetypes/file.png);} +#file_upload_filename { + background-image:url(../../img/mimetypes/file.png); +} +#file_upload_start {opacity:0;} #file_newfolder_name { background-image:url(../../img/places/folder.png); font-weight: bold; width: 14em; } -#file_newfolder_submit { +#file_upload_start, #file_upload_filename{ + position:absolute; + top:0px; + left:0px; + width:30ex; + font-size: 0.9em; +} + +#file_upload_wrapper{ + position:relative; + top:-1.2em; + left:-2em; + display: -moz-inline-box; /* fallback for older firefox versions*/ + display: inline-block; + width:30ex; +} + +#file_newfolder_submit, #file_upload_submit { width: 3em; } diff --git a/files/js/files.js b/files/js/files.js index aed2d59627..70774f6ac4 100644 --- a/files/js/files.js +++ b/files/js/files.js @@ -1,7 +1,5 @@ $(document).ready(function() { $('#file_action_panel').attr('activeAction', false); - $('#file_upload_start').attr('mode', 'menu'); - $('#file_upload_form').attr('uploading', false); $('#file_newfolder_name').css('width', '14em'); $('#file_newfolder_submit').css('width', '3em'); @@ -15,16 +13,6 @@ $(document).ready(function() { } ); - // Sets logs table behaviour : - $('.logs tr').hover( - function() { - $(this).addClass('mouseOver'); - }, - function() { - $(this).removeClass('mouseOver'); - } - ); - // Sets the file-action buttons behaviour : $('td.fileaction a').click(function() { $(this).parent().append($('#file_menu')); @@ -74,53 +62,6 @@ $(document).ready(function() { return false; }); - $('#file_upload_start').click(function() { - if($('#file_upload_start').attr('mode') == 'menu') { - $('#file_upload_form')[0].reset(); - $('#fileSelector').change(function() { - //Chromium prepends C:\fakepath.... - bspos = $('#fileSelector').val().lastIndexOf('\\')+1; - filename = $('#fileSelector').val().substr(bspos); - - $('#file_upload_start').val('Upload ' + filename); - $('#fileSelector').hide(); - $('#file_upload_cancel').slideDown(250); - $('#file_upload_start').attr('mode', 'action'); - }); - $('#file_upload_start').focusin(function() { - if($('#fileSelector').val() == '') { - $('#fileSelector').hide(); - $('#file_upload_start').unbind('focusin'); - } - }); - $('#fileSelector').focusout(function() { - if($('#fileSelector').val() == '') { - $('#fileSelector').hide(); - } - }); - $('#fileSelector').show(); //needed for Chromium compatibility - //rekonq does not call change-event, when click() is executed by script - if(navigator.userAgent.indexOf('rekonq') == -1){ - $('#fileSelector').click(); - } - $('#fileSelector').focus(); - } else if($('#file_upload_start').attr('mode') == 'action') { - $('#file_upload_cancel').slideUp(250); - $('#file_upload_form').attr('uploading', true); - $('#file_upload_target').load(uploadFinished); - } - }); - - $('#file_upload_cancel').click(function() { - $('#file_upload_form')[0].reset(); - $('#file_upload_start').val('Upload ' + $('.max_human_file_size:first').val()); - $('#file_upload_start').attr('mode', 'menu'); - $('#file_upload_cancel').hide(); -// $('#file_action_panel').attr('activeAction', 'false'); -// $('#file_upload_form').hide(); -// $('p.actions a.upload:first').show(); - }); - $('#file_new_dir_submit').click(function() { $.ajax({ url: 'ajax/newfolder.php', @@ -163,42 +104,6 @@ $(document).ready(function() { $('#file_newfolder_submit').fadeOut(250).trigger('vanish'); }); -// $('.upload').click(function(){ -// if($('#file_action_panel').attr('activeAction') != 'upload') { -// $('#file_action_panel').attr('activeAction', 'upload'); -// $('#fileSelector').replaceWith(''); -// $('#fileSelector').change(function() { -// $('#file_upload_start').val('Upload ' + $('#fileSelector').val()); -// $('p.actions a.upload:first').after($('#file_upload_form')); -// $('#file_upload_form').css('display', 'inline'); -// $('p.actions a.upload:first').hide(); -// $('#fileSelector').hide(); -// }); -// $('#file_action_panel form').slideUp(250); -// // $('#file_upload_form').slideDown(250); -// $('#fileSelector').click(); -// } else { -// $('#file_action_panel').attr('activeAction', 'false'); -// $('#file_upload_form').slideUp(250); -// } -// return false; -// }); - - - -// $('.new-dir').click(function(){ -// if($('#file_action_panel').attr('activeAction') != 'new-dir') { -// $('#file_action_panel').attr('activeAction', 'new-dir'); -// $('#file_new_dir_name').val(''); -// $('#file_action_panel form').slideUp(250); -// $('#file_newfolder_form').slideDown(250); -// } else { -// $('#file_newfolder_form').slideUp(250); -// $('#file_action_panel').attr('activeAction', false); -// } -// return false; -// }); - $('.download').click(function(event) { var files=''; $('td.selection input:checkbox:checked').parent().parent().children('.filename').each(function(i,element){ @@ -230,6 +135,38 @@ $(document).ready(function() { return false; }); + + $('#file_upload_start').change(function(){ + var filename=$(this).val(); + filename=filename.replace(/^.*[\/\\]/g, ''); + $('#file_upload_filename').val(filename); + $('#file_upload_submit').show(); + }) + + $('#file_upload_submit').click(function(){ + $('#file_upload_form').submit(); + var name=$('#file_upload_filename').val(); + if($('#file_upload_start')[0].files[0] && $('#file_upload_start')[0].files[0].size>0){ + var size=humanFileSize($('#file_upload_start')[0].files[0].size); + }else{ + var size='Pending'; + } + var date=new Date(); + var monthNames = [ "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" ]; + var uploadTime=monthNames[date.getMonth()]+' '+date.getDate()+', '+date.getFullYear()+', '+((date.getHours()<10)?'0':'')+date.getHours()+':'+date.getMinutes(); + var html=''; + html+=''; + html+=''+name+''; + html+=''+size+''; + html+=''+uploadTime+''; + html+=''; + html+=''; + $('#fileList').append($(html)); + $('#file_upload_filename').val($('#file_upload_filename').data('upload_text')); + }); + //save the original upload button text + $('#file_upload_filename').data('upload_text',$('#file_upload_filename').val()); }); var adjustNewFolderSize = function() { @@ -251,32 +188,6 @@ function unsplitSize(stayingEl, vanishingEl) { $(vanishingEl).fadeOut(250); } -function uploadFinished() { - result = $('#file_upload_target').contents().text(); - result = eval("(" + result + ");"); - $('#file_upload_target').load(function(){}); - if(result.status == "error") { - if($('#file_upload_form').attr('uploading') == true) { - alert('An error occcured, upload failed.\nError code: ' + result.data.error + '\nFilename: ' + result.data.file); - } - } else { - dir = $('#dir').val(); - $.ajax({ - url: 'ajax/list.php', - data: "dir="+dir, - complete: function(data) { - refreshContents(data); -// $('#file_action_panel').prepend($('#file_upload_form')); -// $('#file_upload_form').css('display', 'block').hide(); -// $('p.actions a.upload:first').show(); - $('#file_upload_start').val('Upload ' + $('.max_human_file_size:first').val()); - $('#file_upload_start').attr('mode', 'menu'); - } - }); - } - $('#file_upload_form').attr('uploading', false); -} - function resetFileActionPanel() { $('#file_action_panel form').css({"display":"none"}); $('#file_action_panel').attr('activeAction', false); @@ -322,3 +233,21 @@ function updateBreadcrumb(breadcrumbHtml) { function updateFileList(fileListHtml) { $('#fileList').empty().html(fileListHtml); } + +function humanFileSize(bytes){ + if( bytes < 1024 ){ + return bytes+' B'; + } + bytes = Math.round(bytes / 1024, 1 ); + if( bytes < 1024 ){ + return bytes+' kB'; + } + bytes = Math.round( bytes / 1024, 1 ); + if( bytes < 1024 ){ + return bytes+' MB'; + } + + // Wow, heavy duty for owncloud + bytes = Math.round( bytes / 1024, 1 ); + return bytes+' GB'; +} \ No newline at end of file diff --git a/files/templates/index.php b/files/templates/index.php index 4d34222b96..6222724e7b 100644 --- a/files/templates/index.php +++ b/files/templates/index.php @@ -1,9 +1,23 @@
-
" id="max_upload">)">" id="dir">)" /> 
 
DownloadDelete +
+ " id="max_upload"> + )"> + " id="dir"> +
+ )"/> + +
  + + +
+
+   + +
+ Download + + Delete
From 815f2390142e0a9a73df8fc2f726d4799886f2d4 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Fri, 3 Jun 2011 02:54:54 +0200 Subject: [PATCH 02/15] fix download links of newly uploaded files --- files/js/files.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/files/js/files.js b/files/js/files.js index 70774f6ac4..b8bfb02b2b 100644 --- a/files/js/files.js +++ b/files/js/files.js @@ -157,7 +157,7 @@ $(document).ready(function() { var uploadTime=monthNames[date.getMonth()]+' '+date.getDate()+', '+date.getFullYear()+', '+((date.getHours()<10)?'0':'')+date.getHours()+':'+date.getMinutes(); var html=''; html+=''; - html+=''+name+''; + html+=''+name+''; html+=''+size+''; html+=''+uploadTime+''; html+=''; From d8ba312679a9bdeedbae5cf64fe05874f1108620 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 4 Jun 2011 18:34:15 +0200 Subject: [PATCH 03/15] fix incorrect variable name in libfilestorage --- lib/filestorage.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/filestorage.php b/lib/filestorage.php index d4db77f2c8..157e44ff29 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -386,7 +386,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{ } } if($return=rmdir($dir)){ - $this->clearFolderSizeCache($path); + $this->clearFolderSizeCache($dir); } return $return; } From 3892fe55110ce86d742cabcf1422d96115590c5b Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 4 Jun 2011 18:44:14 +0200 Subject: [PATCH 04/15] some refactoring of the filebrowsers javascript code --- files/index.php | 1 + files/js/filelist.js | 54 ++++++++++++ files/js/files.js | 152 +++++++++++++--------------------- files/templates/part.list.php | 2 +- 4 files changed, 114 insertions(+), 95 deletions(-) create mode 100644 files/js/filelist.js diff --git a/files/index.php b/files/index.php index 7ac3bce605..79f8b67701 100644 --- a/files/index.php +++ b/files/index.php @@ -35,6 +35,7 @@ if( !OC_USER::isLoggedIn()){ // Load the files we need OC_UTIL::addStyle( "files", "files" ); OC_UTIL::addScript( "files", "files" ); +OC_UTIL::addScript( 'files', 'filelist' ); OC_APP::setActiveNavigationEntry( "files_index" ); // Load the files $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; diff --git a/files/js/filelist.js b/files/js/filelist.js new file mode 100644 index 0000000000..14cce8a389 --- /dev/null +++ b/files/js/filelist.js @@ -0,0 +1,54 @@ +FileList={ + update:function(fileListHtml) { + $('#fileList').empty().html(fileListHtml); + }, + addFile:function(name,size,lastModified){ + var html=''; + html+=''; + html+=''+name+''; + html+=''+size+''; + html+=''+lastModified+''; + html+=''; + html+=''; + FileList.insertElement(name,'file',$(html)); + }, + addDir:function(name,size,lastModified){ + var html=''; + html+=''; + html+=''+name+''; + html+=''+size+''; + html+=''+lastModified+''; + html+=''; + html+=''; + + FileList.insertElement(name,'dir',$(html)); + }, + refresh:function(data) { + result = jQuery.parseJSON(data.responseText); + if(typeof(result.data.breadcrumb) != 'undefined'){ + updateBreadcrumb(result.data.breadcrumb); + } + FileList.update(result.data.files); + resetFileActionPanel(); + }, + remove:function(name){ + $('tr[data-file="'+name+'"]').remove(); + }, + insertElement:function(name,type,element){ + //find the correct spot to insert the file or folder + var fileElements=$('tr[data-file][data-type="'+type+'"]'); + var pos; + if(name.localeCompare($(fileElements[0]).attr('data-file'))<0){ + pos=0; + }else if(name.localeCompare($(fileElements[fileElements.length-1]).attr('data-file'))>0){ + pos=fileElements.length-1; + }else{ + for(var pos=1;pos0 && name.localeCompare($(fileElements[pos+1]).attr('data-file'))<0){ + break; + } + } + } + $(fileElements[pos]).after(element); + } +} \ No newline at end of file diff --git a/files/js/files.js b/files/js/files.js index b8bfb02b2b..2c595ee445 100644 --- a/files/js/files.js +++ b/files/js/files.js @@ -3,35 +3,34 @@ $(document).ready(function() { $('#file_newfolder_name').css('width', '14em'); $('#file_newfolder_submit').css('width', '3em'); - // Sets browser table behaviour : - $('.browser tr').hover( - function() { - $(this).addClass('mouseOver'); - }, - function() { - $(this).removeClass('mouseOver'); - } - ); + // Sets browser table behaviour : + $('.browser tr').hover( + function() { + $(this).addClass('mouseOver'); + }, + function() { + $(this).removeClass('mouseOver'); + } + ); - // Sets the file-action buttons behaviour : - $('td.fileaction a').click(function() { - $(this).parent().append($('#file_menu')); - $('#file_menu').slideToggle(250); - return false; - }); + // Sets the file-action buttons behaviour : + $('td.fileaction a').live('click',function() { + $(this).parent().append($('#file_menu')); + $('#file_menu').slideToggle(250); + return false; + }); - // Sets the select_all checkbox behaviour : - $('#select_all').click(function() { - - if($(this).attr('checked')) - // Check all - $('td.selection input:checkbox').attr('checked', true); - else - // Uncheck all - $('td.selection input:checkbox').attr('checked', false); - }); + // Sets the select_all checkbox behaviour : + $('#select_all').click(function() { + if($(this).attr('checked')) + // Check all + $('td.selection input:checkbox').attr('checked', true); + else + // Uncheck all + $('td.selection input:checkbox').attr('checked', false); + }); - $('td.selection input:checkbox').click(function() { + $('td.selection input:checkbox').live('click',function() { if(!$(this).attr('checked')){ $('#select_all').attr('checked',false); }else{ @@ -51,23 +50,29 @@ $(document).ready(function() { // Delete current file $('#delete_single_file').click(function() { - filename = $('#file_menu').parents('tr:first').find('.filename:first').children('a:first').text(); + filename = $('#file_menu').parents('tr:first').attr('data-file'); $.ajax({ url: 'ajax/delete.php', data: "dir="+$('#dir').val()+"&file="+filename, complete: function(data){ - boolOperationFinished(data, true, $('#file_menu').parents('tr:first')); + boolOperationFinished(data, function(){ + FileList.remove(filename); + }); } }); return false; }); - $('#file_new_dir_submit').click(function() { + $('#file_newfolder_submit').click(function() { $.ajax({ url: 'ajax/newfolder.php', - data: "dir="+$('#dir').val()+"&foldername="+$('#file_new_dir_name').val(), - complete: function(data){boolOperationFinished(data, false);} + data: "dir="+$('#dir').val()+"&foldername="+$('#file_newfolder_name').val(), + complete: function(data){boolOperationFinished(data, function(){ + var date=formatDate(new Date()); + FileList.addDir($('#file_newfolder_name').val(),'0 B',date) + });} }); + $('#file_newfolder_submit').fadeOut(250).trigger('vanish'); }); $('#file_newfolder_name').click(function(){ @@ -90,24 +95,10 @@ $(document).ready(function() { } }); - $('#file_newfolder_submit').click(function() { - if($('#file_newfolder_name').val() != '') { - $.ajax({ - url: 'ajax/newfolder.php', - data: "dir="+$('#dir').val()+"&foldername="+$('#file_newfolder_name').val(), - complete: function(data){ - boolOperationFinished(data, false); - $('#file_newfolder_form')[0].reset(); - } - }); - } - $('#file_newfolder_submit').fadeOut(250).trigger('vanish'); - }); - - $('.download').click(function(event) { + $('.download').live('click',function(event) { var files=''; - $('td.selection input:checkbox:checked').parent().parent().children('.filename').each(function(i,element){ - files+=';'+$(element).text(); + $('td.selection input:checkbox:checked').parent().parent().each(function(i,element){ + files+=';'+$(element).attr('data-file'); }); files=files.substr(1);//remove leading ; @@ -118,10 +109,10 @@ $(document).ready(function() { return false; }); - $('.delete').click(function(event) { + $('.delete').live('click',function(event) { var files=''; - $('td.selection input:checkbox:checked').parent().parent().children('.filename').each(function(i,element){ - files+=';'+$(element).text(); + $('td.selection input:checkbox:checked').parent().parent().each(function(i,element){ + files+=';'+$(element).attr('data-file'); }); files=files.substr(1);//remove leading ; @@ -129,7 +120,11 @@ $(document).ready(function() { url: 'ajax/delete.php', data: "dir="+$('#dir').val()+"&files="+files, complete: function(data){ - boolOperationFinished(data, false); + boolOperationFinished(data, function(){ + $('td.selection input:checkbox:checked').parent().parent().each(function(i,element){ + FileList.remove($(element).attr('data-file')); + }); + }); } }); @@ -152,17 +147,8 @@ $(document).ready(function() { var size='Pending'; } var date=new Date(); - var monthNames = [ "January", "February", "March", "April", "May", "June", - "July", "August", "September", "October", "November", "December" ]; - var uploadTime=monthNames[date.getMonth()]+' '+date.getDate()+', '+date.getFullYear()+', '+((date.getHours()<10)?'0':'')+date.getHours()+':'+date.getMinutes(); - var html=''; - html+=''; - html+=''+name+''; - html+=''+size+''; - html+=''+uploadTime+''; - html+=''; - html+=''; - $('#fileList').append($(html)); + var uploadTime=formatDate(date); + FileList.addFile(name,size,uploadTime); $('#file_upload_filename').val($('#file_upload_filename').data('upload_text')); }); //save the original upload button text @@ -193,47 +179,19 @@ function resetFileActionPanel() { $('#file_action_panel').attr('activeAction', false); } -function boolOperationFinished(data, single, el) { - result = eval("("+data.responseText+");"); +function boolOperationFinished(data, callback) { + result = jQuery.parseJSON(data.responseText); if(result.status == 'success'){ - if(single) { - $('#file_menu').slideToggle(0); - $('body').append($('#file_menu')); - $(el).remove(); - } else { - $.ajax({ - url: 'ajax/list.php', - data: "dir="+$('#dir').val(), - complete: refreshContents - }); - } + callback.call(); } else { alert(result.data.message); } } -function refreshContents(data) { - result = eval("("+data.responseText+");"); - if(typeof(result.data.breadcrumb) != 'undefined'){ - updateBreadcrumb(result.data.breadcrumb); - } - updateFileList(result.data.files); - $('td.fileaction a').click(function() { - $(this).parent().append($('#file_menu')); - $('#file_menu').slideToggle(250); - return false; - }); - resetFileActionPanel(); -} - function updateBreadcrumb(breadcrumbHtml) { $('p.nav').empty().html(breadcrumbHtml); } -function updateFileList(fileListHtml) { - $('#fileList').empty().html(fileListHtml); -} - function humanFileSize(bytes){ if( bytes < 1024 ){ return bytes+' B'; @@ -250,4 +208,10 @@ function humanFileSize(bytes){ // Wow, heavy duty for owncloud bytes = Math.round( bytes / 1024, 1 ); return bytes+' GB'; +} + +function formatDate(date){ + var monthNames = [ "January", "February", "March", "April", "May", "June", + "July", "August", "September", "October", "November", "December" ]; + return monthNames[date.getMonth()]+' '+date.getDate()+', '+date.getFullYear()+', '+((date.getHours()<10)?'0':'')+date.getHours()+':'+date.getMinutes(); } \ No newline at end of file diff --git a/files/templates/part.list.php b/files/templates/part.list.php index 0d3355678c..f99cd87be2 100644 --- a/files/templates/part.list.php +++ b/files/templates/part.list.php @@ -1,5 +1,5 @@ - + ' data-type=''> )" href="" title=""> From 1eb0faa2642babdd3031fdfa611ee10d1a3ccec5 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 4 Jun 2011 20:16:44 +0200 Subject: [PATCH 05/15] make fileactions extendable by plugins --- .htaccess | 4 ++ files/css/files.css | 10 +++- files/index.php | 1 + files/js/fileactions.js | 100 ++++++++++++++++++++++++++++++++++ files/js/files.js | 44 ++++++--------- files/templates/index.php | 3 - files/templates/part.list.php | 2 +- 7 files changed, 131 insertions(+), 33 deletions(-) create mode 100644 .htaccess create mode 100644 files/js/fileactions.js diff --git a/.htaccess b/.htaccess new file mode 100644 index 0000000000..58230365bf --- /dev/null +++ b/.htaccess @@ -0,0 +1,4 @@ +ErrorDocument 404 //owncloud/templates/404.php +php_value upload_max_filesize 20M +php_value post_max_size 20M +SetEnv htaccessWorking true diff --git a/files/css/files.css b/files/css/files.css index 1cfca68ff5..7c7965ab84 100644 --- a/files/css/files.css +++ b/files/css/files.css @@ -4,6 +4,7 @@ { display: none; position: absolute; + right:0px; background-color: #EEE; } @@ -36,7 +37,7 @@ #file_upload_filename { background-image:url(../../img/mimetypes/file.png); } -#file_upload_start {opacity:0;} +#file_upload_start {opacity:0;filter: alpha(opacity = 0);} #file_newfolder_name { background-image:url(../../img/places/folder.png); font-weight: bold; @@ -104,3 +105,10 @@ table td.filename a text-decoration: none; } +.dropArrow{ + height:16px; + width:16px; + display: -moz-inline-box; /* fallback for older firefox versions*/ + display: inline-block; + background-image:url('../../img/drop-arrow.png'); +} \ No newline at end of file diff --git a/files/index.php b/files/index.php index 79f8b67701..d796583a4a 100644 --- a/files/index.php +++ b/files/index.php @@ -36,6 +36,7 @@ if( !OC_USER::isLoggedIn()){ OC_UTIL::addStyle( "files", "files" ); OC_UTIL::addScript( "files", "files" ); OC_UTIL::addScript( 'files', 'filelist' ); +OC_UTIL::addScript( 'files', 'fileactions' ); OC_APP::setActiveNavigationEntry( "files_index" ); // Load the files $dir = isset( $_GET['dir'] ) ? $_GET['dir'] : ''; diff --git a/files/js/fileactions.js b/files/js/fileactions.js new file mode 100644 index 0000000000..bb02b639c5 --- /dev/null +++ b/files/js/fileactions.js @@ -0,0 +1,100 @@ +FileActions={ + actions:{}, + defaults:{}, + register:function(mime,name,action){ + if(!FileActions.actions[mime]){ + FileActions.actions[mime]={}; + } + FileActions.actions[mime][name]=action; + }, + setDefault:function(mime,name){ + FileActions.defaults[mime]=FileActions.actions[mime][name]; + }, + get:function(mime,type){ + var actions={}; + if(FileActions.actions.all){ + actions=$.extend( actions, FileActions.actions.all ) + } + if(mime){ + if(FileActions.actions[mime]){ + actions=$.extend( actions, FileActions.actions[mime] ) + } + var mimePart=mime.substr(0,mime.indexOf('/')); + if(FileActions.actions[mimePart]){ + actions=$.extend( actions, FileActions.actions[mimePart] ) + } + } + if(type){//type is 'dir' or 'file' + if(FileActions.actions[type]){ + actions=$.extend( actions, FileActions.actions[type] ) + } + } + return actions; + }, + getDefault:function(mime,type){ + if(mime){ + var mimePart=mime.substr(0,mime.indexOf('/')); + } + if(mime && FileActions.defaults[mime]){ + return FileActions.defaults[mime]; + }else if(mime && FileActions.defaults[mimePart]){ + return FileActions.defaults[mimePart]; + }else if(type && FileActions.defaults[type]){ + return FileActions.defaults[type]; + }else{ + return FileActions.defaults.all; + } + }, + display:function(parent){ + $('#file_menu>ul').empty(); + parent.append($('#file_menu')); + var actions=FileActions.get(FileActions.getCurrentMimeType(),FileActions.getCurrentType()); + for(name in actions){ + var html='
  • '+name+'
  • '; + var element=$(html); + element.data('action',name); + element.click(function(){ + event.preventDefault(); + actions[$(this).data('action')](FileActions.getCurrentFile()); + }); + $('#file_menu>ul').append(element); + } + $('#file_menu').slideToggle(250); + return false; + }, + getCurrentFile:function(){ + return $('#file_menu').parents('tr:first').attr('data-file'); + }, + getCurrentMimeType:function(){ + return $('#file_menu').parents('tr:first').attr('data-mime'); + }, + getCurrentType:function(){ + return $('#file_menu').parents('tr:first').attr('data-type'); + } +} + +FileActions.register('all','Download',function(filename){ + window.location='ajax/download.php?files='+filename+'&dir='+$('#dir').val(); + $('#file_menu').slideToggle(250); +}); + +FileActions.register('all','Delete',function(filename){ + $.ajax({ + url: 'ajax/delete.php', + data: "dir="+$('#dir').val()+"&file="+filename, + complete: function(data){ + boolOperationFinished(data, function(){ + FileList.remove(filename); + }); + } + }); +}); + +FileActions.setDefault('all','Download'); + +FileActions.register('dir','Open',function(filename){ + window.location='index.php?dir='+$('#dir').val()+'/'+filename; + $('#file_menu').slideToggle(250); +}); + +FileActions.setDefault('dir','Open'); \ No newline at end of file diff --git a/files/js/files.js b/files/js/files.js index 2c595ee445..c758432a4f 100644 --- a/files/js/files.js +++ b/files/js/files.js @@ -15,11 +15,22 @@ $(document).ready(function() { // Sets the file-action buttons behaviour : $('td.fileaction a').live('click',function() { - $(this).parent().append($('#file_menu')); - $('#file_menu').slideToggle(250); - return false; + event.preventDefault(); + FileActions.display($(this).parent()); }); - + + // Sets the file link behaviour : + $('td.filename a').live('click',function() { + event.preventDefault(); + var filename=$(this).text(); + var mime=$(this).parent().parent().attr('data-mime'); + var type=$(this).parent().parent().attr('data-type'); + var action=FileActions.getDefault(mime,type); + if(action){ + action(filename); + } + }); + // Sets the select_all checkbox behaviour : $('#select_all').click(function() { if($(this).attr('checked')) @@ -40,33 +51,10 @@ $(document).ready(function() { } }); - // Download current file - $('#download_single_file').click(function() { - filename = $('#file_menu').parents('tr:first').find('.filename:first').children('a:first').text(); - window.location='ajax/download.php?files='+filename+'&dir='+$('#dir').val(); - $('#file_menu').slideToggle(250); - return false; - }); - - // Delete current file - $('#delete_single_file').click(function() { - filename = $('#file_menu').parents('tr:first').attr('data-file'); - $.ajax({ - url: 'ajax/delete.php', - data: "dir="+$('#dir').val()+"&file="+filename, - complete: function(data){ - boolOperationFinished(data, function(){ - FileList.remove(filename); - }); - } - }); - return false; - }); - $('#file_newfolder_submit').click(function() { $.ajax({ url: 'ajax/newfolder.php', - data: "dir="+$('#dir').val()+"&foldername="+$('#file_newfolder_name').val(), + data: "dir="+$('#dir').val()+"&foldername="+$('#file_newfolder_name').val(), complete: function(data){boolOperationFinished(data, function(){ var date=formatDate(new Date()); FileList.addDir($('#file_newfolder_name').val(),'0 B',date) diff --git a/files/templates/index.php b/files/templates/index.php index 6222724e7b..11cf0360e1 100644 --- a/files/templates/index.php +++ b/files/templates/index.php @@ -44,8 +44,5 @@ diff --git a/files/templates/part.list.php b/files/templates/part.list.php index f99cd87be2..16d9d92c04 100644 --- a/files/templates/part.list.php +++ b/files/templates/part.list.php @@ -1,5 +1,5 @@ - ' data-type=''> + ' data-type='' data-mime=''> )" href="" title=""> From 4b9665a952e723075185b7ef8837c9e38432f63a Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sat, 4 Jun 2011 20:43:32 +0200 Subject: [PATCH 06/15] image viewer plugin --- apps/files_imageviewer/appinfo/app.php | 6 ++++ apps/files_imageviewer/appinfo/info.xml | 10 ++++++ apps/files_imageviewer/css/lightbox.css | 21 +++++++++++ apps/files_imageviewer/js/lightbox.js | 46 +++++++++++++++++++++++++ 4 files changed, 83 insertions(+) create mode 100644 apps/files_imageviewer/appinfo/app.php create mode 100644 apps/files_imageviewer/appinfo/info.xml create mode 100644 apps/files_imageviewer/css/lightbox.css create mode 100644 apps/files_imageviewer/js/lightbox.js diff --git a/apps/files_imageviewer/appinfo/app.php b/apps/files_imageviewer/appinfo/app.php new file mode 100644 index 0000000000..bc0059b8b6 --- /dev/null +++ b/apps/files_imageviewer/appinfo/app.php @@ -0,0 +1,6 @@ + diff --git a/apps/files_imageviewer/appinfo/info.xml b/apps/files_imageviewer/appinfo/info.xml new file mode 100644 index 0000000000..f658409be7 --- /dev/null +++ b/apps/files_imageviewer/appinfo/info.xml @@ -0,0 +1,10 @@ + + + files_imageview + Imageviewer + Simple image viewer for owncloud + 1.0 + AGPL + Robin Appelman + 2 + \ No newline at end of file diff --git a/apps/files_imageviewer/css/lightbox.css b/apps/files_imageviewer/css/lightbox.css new file mode 100644 index 0000000000..225b11ff9a --- /dev/null +++ b/apps/files_imageviewer/css/lightbox.css @@ -0,0 +1,21 @@ +#lightbox_overlay{ + position:absolute; + height:100%; + width:100%; + top:0px; + left:0px; + opacity:0.5; + filter: alpha(opacity = 50); + background-color:black; + z-index:9999; +} + +#lightbox{ + position:absolute; + max-height:90%; + max-width:90%; + top:10px; + margin-left:auto; + margin-right:auto; + z-index:9999; +} \ No newline at end of file diff --git a/apps/files_imageviewer/js/lightbox.js b/apps/files_imageviewer/js/lightbox.js new file mode 100644 index 0000000000..dd091aa0d7 --- /dev/null +++ b/apps/files_imageviewer/js/lightbox.js @@ -0,0 +1,46 @@ +$(document).ready(function() { + images={};//image cache + FileActions.register('image','View',function(filename){ + var location='ajax/download.php?files='+filename+'&dir='+$('#dir').val(); + var overlay=$('