From d46288b0abea28a4e0184f6720e990a05d5f19a9 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Sun, 23 Oct 2011 11:40:40 +0200 Subject: 'New' button, needs some css work --- files/ajax/newfile.php | 27 ++++++++++++++ files/css/files.css | 13 +++++-- files/js/files.js | 93 +++++++++++++++++++++++++++++++++++------------ files/templates/index.php | 33 ++++++++++------- 4 files changed, 126 insertions(+), 40 deletions(-) create mode 100644 files/ajax/newfile.php (limited to 'files') diff --git a/files/ajax/newfile.php b/files/ajax/newfile.php new file mode 100644 index 00000000000..5c4f49a3675 --- /dev/null +++ b/files/ajax/newfile.php @@ -0,0 +1,27 @@ + array( "message" => "Empty Filename" ))); + exit(); +} + +if(OC_Files::newFile($dir, $filename, 'file')) { + if($content){ + OC_Filesystem::file_put_contents($dir.'/'.$filename,$content); + } + OC_JSON::success(array("data" => array('content'=>$content))); + exit(); +} + + +OC_JSON::error(array("data" => array( "message" => "Error when creating the file" ))); \ No newline at end of file diff --git a/files/css/files.css b/files/css/files.css index ac1f523f862..c6f76215155 100644 --- a/files/css/files.css +++ b/files/css/files.css @@ -7,11 +7,17 @@ .actions input { margin:0; } #file_menu { right:0; position:absolute; top:0; } #file_menu a { display:block; float:left; background-image:none; text-decoration:none; } -.file_upload_form, #file_newfolder_form { display:inline; float: left; margin-left:.5em; } +.file_upload_form, #file_newfolder_form { display:inline; float: left; margin-left:0; } #fileSelector, #file_upload_submit, #file_newfolder_submit { display:none; } .file_upload_wrapper, #file_newfolder_name { background-repeat:no-repeat; background-position:.5em .5em; padding-left:2em; } -.file_upload_wrapper { font-weight:bold; display:-moz-inline-box; /* fallback for older firefox versions*/ display:inline-block; padding-left:0; overflow:hidden; position:relative; margin:.1em .1em .1em 0em;} +.file_upload_wrapper { font-weight:bold; display:-moz-inline-box; /* fallback for older firefox versions*/ display:inline-block; padding-left:0; overflow:hidden; position:relative; margin:0;} .file_upload_wrapper .file_upload_button_wrapper { position:absolute; top:0; left:0; width:100%; height:100%; cursor:pointer; z-index:1000; } +#new { float:left; border-top-right-radius:0; border-bottom-right-radius:0; margin-top:-0.075em; margin-right:0; border-right:none } +#new.active { border-bottom-left-radius:0; border-bottom:none; } +#new>a{ padding-left:1em; padding-right:1em; } +#new>ul { display:none; position:fixed; text-align:left; padding:0.5em; background:#f8f8f8; margin-top:0.4em; border:1px solid #ddd; min-width:7em; margin-left:-0.5em; } +#new>ul>li { margin:0.3em; padding-left:1.3em; background-repeat:no-repeat; cursor:pointer; } +#new>ul>li>p { cursor:pointer; } #file_newfolder_name { background-image:url('../../core/img/places/folder.svg'); font-weight:normal; width:7em; } .file_upload_start, .file_upload_filename { font-size:1em; } @@ -19,7 +25,8 @@ .file_upload_target { display:none; } .file_upload_start { opacity:0; filter:alpha(opacity=0); z-index:1; position:absolute; left:0; top:0; width:100%; cursor:pointer;} -.file_upload_filename { z-index:100; cursor:pointer;} +input.file_upload_filename.active { border-bottom-right-radius:0 } +input.file_upload_filename { z-index:100; cursor:pointer; border-top-left-radius:0; border-bottom-left-radius:0; } .file_upload_form, .file_upload_wrapper, .file_upload_start, .file_upload_filename, #file_upload_submit { cursor:pointer; } diff --git a/files/js/files.js b/files/js/files.js index 902c5e54934..db3f3135b9f 100644 --- a/files/js/files.js +++ b/files/js/files.js @@ -255,32 +255,77 @@ $(document).ready(function() { text=text.substr(0,text.length-6)+'...'; crumb.text(text); } + + $(window).click(function(){ + $('#new>ul').hide(); + $('#new').removeClass('active'); + $('input.file_upload_filename').removeClass('active'); + $('#new li').each(function(i,element){ + if($(element).children('p').length==0){ + $(element).children('input').remove(); + $(element).append('

'+$(element).data('text')+'

'); + } + }); + }); + $('#new').click(function(event){ + event.stopPropagation(); + }); + $('#new>a').click(function(){ + $('#new>ul').toggle(); + $('#new').toggleClass('active'); + $('input.file_upload_filename').toggleClass('active'); + }); + $('#new li').click(function(){ + if($(this).children('p').length==0){ + return; + } + + $('#new li').each(function(i,element){ + if($(element).children('p').length==0){ + $(element).children('input').remove(); + $(element).append('

'+$(element).data('text')+'

'); + } + }); + + var type=$(this).data('type'); + var text=$(this).children('p').text(); + $(this).data('text',text); + $(this).children('p').remove(); + var input=$(''); + $(this).append(input); + input.focus(); + input.change(function(){ + var name=$(this).val(); + switch(type){ + case 'file': + $.ajax({ + url: OC.filePath('files','ajax','newfile.php'), + data: "dir="+encodeURIComponent($('#dir').val())+"&filename="+encodeURIComponent(name)+'&content=%20%0A', + complete: function(data){boolOperationFinished(data, function(){ + var date=new Date(); + FileList.addFile(name,0,date); + });} + }); + break; + case 'folder': + $.ajax({ + url: OC.filePath('files','ajax','newfolder.php'), + data: "dir="+encodeURIComponent($('#dir').val())+"&foldername="+encodeURIComponent(name), + complete: function(data){boolOperationFinished(data, function(){ + var date=new Date(); + FileList.addDir(name,0,date); + });} + }); + break; + } + var li=$(this).parent(); + $(this).remove(); + li.append('

'+li.data('text')+'

'); + $('#new>a').click(); + }); + }); }); -var adjustNewFolderSize = function() { - if($('#file_newfolder_name').val() != '') { - splitSize($('#file_newfolder_name'),$('#file_newfolder_submit')); - $('#file_newfolder_name').unbind('keyup', adjustNewFolderSize); - }; -} - -function splitSize(existingEl, appearingEl) { - nw = parseInt($(existingEl).css('width')) - parseInt($(appearingEl).css('width')); - $(existingEl).css('width', nw + 'px'); - $(appearingEl).fadeIn(250); -} - -function unsplitSize(stayingEl, vanishingEl) { - nw = parseInt($(stayingEl).css('width')) + parseInt($(vanishingEl).css('width')); - $(stayingEl).css('width', nw + 'px'); - $(vanishingEl).fadeOut(250); -} - -function resetFileActionPanel() { - $('#file_action_panel form').css({"display":"none"}); - $('#file_action_panel').attr('activeAction', false); -} - function boolOperationFinished(data, callback) { result = jQuery.parseJSON(data.responseText); if(result.status == 'success'){ diff --git a/files/templates/index.php b/files/templates/index.php index a63f6e62b63..902c5cfa140 100644 --- a/files/templates/index.php +++ b/files/templates/index.php @@ -2,20 +2,27 @@
-
- - - -
- + +
+ + + + + - -
- - -
- -
+ + + +
-- cgit v1.2.3