]> source.dussan.org Git - nextcloud-server.git/commitdiff
don't reload the whole page after file upload
authorArthur Schiwon <blizzz@arthur-schiwon.de>
Sun, 17 Apr 2011 13:59:06 +0000 (15:59 +0200)
committerArthur Schiwon <blizzz@arthur-schiwon.de>
Sun, 17 Apr 2011 13:59:06 +0000 (15:59 +0200)
files/ajax/list.php
files/index.php
files/js/files.js
files/templates/index.php

index 4694f8428323648624d0cb176be210b4c1d2809c..ef43e72fcae4b0d71f9f1c25ac00bd0d8c5844c9 100644 (file)
@@ -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));
 
 ?>
index e07e80aabb5921d2d2b2287a1784fec73b335727..28743f77fca4b1e52c80467e0df7e403b78dd009 100644 (file)
@@ -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();
index 9eeeb7f6bfd23d15aef95b6a59da8fa3f3a3c0f1..445067630329475b061f757a3f113f5d976d7c14 100644 (file)
@@ -55,6 +55,28 @@ 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 refreshContents(data) {
+       result = eval("("+data.responseText+");");
+       if(typeof(result.data.breadcrumb) != 'undefined'){
+               updateBreadcrumb(result.data.breadcrumb);
+       }
+       updateFileList(result.data.files);
+       $('#file_upload_button').click();
+}
+
+function updateBreadcrumb(breadcrumbHtml) {
+       $('p.nav').empty().html(breadcrumbHtml);
+}
+
+function updateFileList(fileListHtml) {
+       $('#fileList').empty().html(fileListHtml);
+}
index 40113c9fe0cc0c5926554d58cad7f4b253229d3f..5277441b53514f4e5fff601b72d5ea3f7b00e9fa 100644 (file)
@@ -17,10 +17,7 @@ name="file_upload_target" src=""></iframe></form>
 </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 +30,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>