summaryrefslogtreecommitdiffstats
path: root/files
diff options
context:
space:
mode:
authorJakob Sack <kde@jakobsack.de>2011-04-17 18:06:17 +0200
committerJakob Sack <kde@jakobsack.de>2011-04-17 18:06:17 +0200
commitd59b0df401c76e7434fda889af81f47adb5bd656 (patch)
treed60112d3b19f6a606fc86d8fdc3cb6f408cd190b /files
parent79d8aa871a56c18f3857fba86dc5dec14ece51d3 (diff)
parent56a3a96e65e665088cde7a23761be790c67a7132 (diff)
downloadnextcloud-server-d59b0df401c76e7434fda889af81f47adb5bd656.tar.gz
nextcloud-server-d59b0df401c76e7434fda889af81f47adb5bd656.zip
Merge branch 'refactoring' of git://anongit.kde.org/owncloud into refactoring
Diffstat (limited to 'files')
-rw-r--r--files/ajax/list.php37
-rw-r--r--files/ajax/newfolder.php29
-rw-r--r--files/css/files.css4
-rw-r--r--files/index.php11
-rw-r--r--files/js/files.js86
-rw-r--r--files/templates/index.php22
-rw-r--r--files/templates/part.breadcrumb.php4
-rw-r--r--files/templates/part.list.php9
8 files changed, 164 insertions, 38 deletions
diff --git a/files/ajax/list.php b/files/ajax/list.php
index 4694f842832..ef43e72fcae 100644
--- a/files/ajax/list.php
+++ b/files/ajax/list.php
@@ -2,6 +2,7 @@
// Init owncloud
require_once('../../lib/base.php');
+require_once('../../lib/template.php');
// We send json data
header( "Content-Type: application/jsonrequest" );
@@ -14,23 +15,37 @@ if( !OC_USER::isLoggedIn()){
// Load the files
$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
+$doBreadcrumb = isset( $_GET['breadcrumb'] ) ? true : false;
+$data = array();
+// Make breadcrumb
+if($doBreadcrumb){
+ $breadcrumb = array();
+ $pathtohere = "/";
+ foreach( explode( "/", $dir ) as $i ){
+ if( $i != "" ){
+ $pathtohere .= "$i/";
+ $breadcrumb[] = array( "dir" => $pathtohere, "name" => $i );
+ }
+ }
+
+ $breadcrumbNav = new OC_TEMPLATE( "files", "part.breadcrumb", "" );
+ $breadcrumbNav->assign( "breadcrumb", $breadcrumb );
+
+ $data['breadcrumb'] = $breadcrumbNav->fetchPage();
+}
+
+// make filelist
$files = array();
foreach( OC_FILES::getdirectorycontent( $dir ) as $i ){
- $i["date"] = date( $CONFIG_DATEFORMAT, $i["mtime"] );
+ $i["date"] = OC_UTIL::formatDate($i["mtime"] );
$files[] = $i;
}
-// Make breadcrumb
-$breadcrumb = array();
-$pathtohere = "/";
-foreach( explode( "/", $dir ) as $i ){
- if( $i != "" ){
- $pathtohere .= "$i/";
- $breadcrumb[] = array( "dir" => $pathtohere, "name" => $i );
- }
-}
+$list = new OC_TEMPLATE( "files", "part.list", "" );
+$list->assign( "files", $files );
+$data = array('files' => $list->fetchPage());
-echo json_encode( array( "status" => "success", "data" => array( "files" => $files, "breadcrumb" => $breadcrumb )));
+echo json_encode( array( "status" => "success", "data" => $data));
?>
diff --git a/files/ajax/newfolder.php b/files/ajax/newfolder.php
new file mode 100644
index 00000000000..988e7f04012
--- /dev/null
+++ b/files/ajax/newfolder.php
@@ -0,0 +1,29 @@
+<?php
+
+// Init owncloud
+require_once('../../lib/base.php');
+
+// We send json data
+header( "Content-Type: application/jsonrequest" );
+
+// Check if we are a user
+if( !OC_USER::isLoggedIn()){
+ echo json_encode( array( "status" => "error", "data" => array( "message" => "Authentication error" )));
+ exit();
+}
+
+// Get the params
+$dir = isset( $_GET['dir'] ) ? $_GET['dir'] : '';
+$foldername = isset( $_GET['foldername'] ) ? $_GET['foldername'] : '';
+
+if($foldername == '') {
+ echo json_encode( array( "status" => "error", "data" => array( "message" => "Empty Foldername" )));
+ exit();
+}
+error_log('try to create ' . $foldername . ' in ' . $dir);
+if(OC_FILES::newFile($dir, $foldername, 'dir')) {
+ echo json_encode( array( "status" => "success", "data" => array()));
+ exit();
+}
+
+echo json_encode( array( "status" => "error", "data" => array( "message" => "Error when creating the folder" ))); \ No newline at end of file
diff --git a/files/css/files.css b/files/css/files.css
index 160c9307409..4c5bd0427b6 100644
--- a/files/css/files.css
+++ b/files/css/files.css
@@ -23,6 +23,10 @@
display: none;
}
+#file_newfolder_form {
+ display: none;
+}
+
#file_upload_target {
display: none;
}
diff --git a/files/index.php b/files/index.php
index e07e80aabb5..28743f77fca 100644
--- a/files/index.php
+++ b/files/index.php
@@ -55,10 +55,15 @@ foreach( explode( "/", $dir ) as $i ){
}
}
-// return template
+// make breadcrumb und filelist markup
+$list = new OC_TEMPLATE( "files", "part.list", "" );
+$list->assign( "files", $files );
+$breadcrumbNav = new OC_TEMPLATE( "files", "part.breadcrumb", "" );
+$breadcrumbNav->assign( "breadcrumb", $breadcrumb );
+
$tmpl = new OC_TEMPLATE( "files", "index", "user" );
-$tmpl->assign( "files", $files );
-$tmpl->assign( "breadcrumb", $breadcrumb );
+$tmpl->assign( "fileList", $list->fetchPage() );
+$tmpl->assign( "breadcrumb", $breadcrumbNav->fetchPage() );
$tmpl->assign( 'dir', $dir);
$tmpl->assign( 'uploadMaxFilesize', OC_HELPER::computerFileSize(ini_get('upload_max_filesize')));
$tmpl->printPage();
diff --git a/files/js/files.js b/files/js/files.js
index 9eeeb7f6bfd..313727cedbc 100644
--- a/files/js/files.js
+++ b/files/js/files.js
@@ -1,4 +1,6 @@
$(document).ready(function() {
+ $('#file_action_panel').attr('activeAction', false);
+
// Sets browser table behaviour :
$('.browser tr').hover(
function() {
@@ -37,16 +39,43 @@ $(document).ready(function() {
$('.browser input:checkbox').attr('checked', false);
});
- // Shows and hides file upload form
- $('#file_upload_button').toggle(function() {
- $('#file_upload_form').css({"display":"block"});
- }, function() {
- $('#file_upload_form').css({"display":"none"});
- });
-
$('#file_upload_start').click(function() {
$('#file_upload_target').load(uploadFinished);
});
+
+ $('#file_new_dir_submit').click(function() {
+ $.ajax({
+ url: 'ajax/newfolder.php',
+ data: "dir="+$('#dir').val()+"&foldername="+$('#file_new_dir_name').val(),
+ complete: boolOpFinished
+ });
+ });
+
+ $('.upload').click(function(){
+ if($('#file_action_panel').attr('activeAction') != 'upload') {
+ $('#file_action_panel').attr('activeAction', 'upload');
+ $('#fileSelector').replaceWith('<input type="file" name="file" id="fileSelector">');
+ $('#file_action_panel form').css({"display":"none"});
+ $('#file_upload_form').css({"display":"block"});
+ } else {
+ $('#file_action_panel').attr('activeAction', 'false');
+ $('#file_upload_form').css({"display":"none"})
+ }
+ 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').css({"display":"none"});
+ $('#file_newfolder_form').css({"display":"block"})
+ } else {
+ $('#file_newfolder_form').css({"display":"none"})
+ $('#file_action_panel').attr('activeAction', false);
+ }
+ return false;
+ });
});
function uploadFinished() {
@@ -55,6 +84,47 @@ function uploadFinished() {
if(result.status == "error") {
alert('An error occcured, upload failed.\nError code: ' + result.data.error);
} else {
- location.href = 'index.php?dir=' + $('#dir').val();
+ dir = $('#dir').val();
+ $.ajax({
+ url: 'ajax/list.php',
+ data: "dir="+dir,
+ complete: refreshContents
+ });
+ }
+}
+
+function resetFileActionPanel() {
+ $('#file_action_panel form').css({"display":"none"});
+ $('#file_action_panel').attr('activeAction', false);
+}
+
+function boolOpFinished(data) {
+ result = eval("("+data.responseText+");");
+ if(result.status == 'success'){
+ $.ajax({
+ url: 'ajax/list.php',
+ data: "dir="+$('#dir').val(),
+ complete: refreshContents
+ });
+ } 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);
+ $('#file_upload_button').click();
+ resetFileActionPanel();
+}
+
+function updateBreadcrumb(breadcrumbHtml) {
+ $('p.nav').empty().html(breadcrumbHtml);
+}
+
+function updateFileList(fileListHtml) {
+ $('#fileList').empty().html(fileListHtml);
+}
diff --git a/files/templates/index.php b/files/templates/index.php
index 40113c9fe0c..c6dc123cee0 100644
--- a/files/templates/index.php
+++ b/files/templates/index.php
@@ -5,22 +5,20 @@ href="" title="" class="new-dir">New folder</a><a href="" title=""
class="download">Download</a><a href="" title="" class="share">Share</a><a
href="" title="" class="delete">Delete</a>
</p>
- <div id="file_upload_form">
- <form action="ajax/upload.php"
+ <div id="file_action_panel">
+ <form id="file_upload_form" action="ajax/upload.php"
method="post" enctype="multipart/form-data" target="file_upload_target"><input
type="hidden" name="MAX_FILE_SIZE" value="<?php echo $_["uploadMaxFilesize"] ?>" id="max_upload"><input
type="hidden" name="dir" value="<?php echo $_["dir"] ?>" id="dir"><input
type="file" name="file" id="fileSelector"><input type="submit"
id="file_upload_start" value="Upload" /><iframe id="file_upload_target"
name="file_upload_target" src=""></iframe></form>
+ <form id="file_newfolder_form"><input type="text" name="file_new_dir_name" id="file_new_dir_name" />&nbsp;<input type="button" id="file_new_dir_submit" name="file_new_dir_submit" value="OK" /></form>
</div>
</div>
<p class="nav">
- <a href="<?php echo link_to("files", "index.php?dir=/"); ?>"><img src="<?php echo image_path("", "actions/go-home.png"); ?>" alt="Root" /></a>
- <?php foreach($_["breadcrumb"] as $crumb): ?>
- <a href="<?php echo link_to("files", "index.php?dir=".$crumb["dir"]); ?>"><?php echo $crumb["name"]; ?></a>
- <?php endforeach; ?>
+ <?php echo($_['breadcrumb']); ?>
</p>
<table cellspacing="0">
@@ -33,16 +31,8 @@ name="file_upload_target" src=""></iframe></form>
<th></th>
</tr>
</thead>
- <tbody>
- <?php foreach($_["files"] as $file): ?>
- <tr>
- <td class="selection"><input type="checkbox" /></td>
- <td class="filename"><a style="background-image:url(<?php if($file["type"] == "dir") echo mimetype_icon("dir"); else echo mimetype_icon($file["mime"]); ?>)" href="<?php if($file["type"] == "dir") echo link_to("files", "index.php?dir=".$file["directory"]."/".$file["name"]); else echo link_to("files", "download.php?file=".$file["directory"]."/".$file["name"]); ?>" title=""><?php echo $file["name"]; ?></a></td>
- <td class="filesize"><?php echo human_file_size($file["size"]); ?></td>
- <td class="date"><?php if($file["type"] != "dir") echo $file["date"]; ?></td>
- <td class="fileaction"><a href="" title=""><img src="images/drop-arrow.png" alt="+" /></a></td>
- </tr>
- <?php endforeach; ?>
+ <tbody id="fileList">
+ <?php echo($_['fileList']); ?>
</tbody>
</table>
diff --git a/files/templates/part.breadcrumb.php b/files/templates/part.breadcrumb.php
new file mode 100644
index 00000000000..4d11edb984a
--- /dev/null
+++ b/files/templates/part.breadcrumb.php
@@ -0,0 +1,4 @@
+ <a href="<?php echo link_to("files", "index.php?dir=/"); ?>"><img src="<?php echo image_path("", "actions/go-home.png"); ?>" alt="Root" /></a>
+ <?php foreach($_["breadcrumb"] as $crumb): ?>
+ <a href="<?php echo link_to("files", "index.php?dir=".$crumb["dir"]); ?>"><?php echo $crumb["name"]; ?></a>
+ <?php endforeach; ?> \ No newline at end of file
diff --git a/files/templates/part.list.php b/files/templates/part.list.php
new file mode 100644
index 00000000000..76d938326b6
--- /dev/null
+++ b/files/templates/part.list.php
@@ -0,0 +1,9 @@
+ <?php foreach($_["files"] as $file): ?>
+ <tr>
+ <td class="selection"><input type="checkbox" /></td>
+ <td class="filename"><a style="background-image:url(<?php if($file["type"] == "dir") echo mimetype_icon("dir"); else echo mimetype_icon($file["mime"]); ?>)" href="<?php if($file["type"] == "dir") echo link_to("files", "index.php?dir=".$file["directory"]."/".$file["name"]); else echo link_to("files", "download.php?file=".$file["directory"]."/".$file["name"]); ?>" title=""><?php echo $file["name"]; ?></a></td>
+ <td class="filesize"><?php echo human_file_size($file["size"]); ?></td>
+ <td class="date"><?php if($file["type"] != "dir") echo $file["date"]; ?></td>
+ <td class="fileaction"><a href="" title=""><img src="images/drop-arrow.png" alt="+" /></a></td>
+ </tr>
+ <?php endforeach; ?> \ No newline at end of file