From 9565ea251daab076cdc89a5ce8fa409923e1eee8 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Thu, 28 Jul 2011 23:04:34 +0200
Subject: [PATCH] Implement inline renaming of files

Still needs some ui love
---
 files/ajax/rename.php   |  2 +-
 files/js/fileactions.js |  3 +--
 files/js/filelist.js    | 33 +++++++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/files/ajax/rename.php b/files/ajax/rename.php
index 65763fceb9..7554aa0dd6 100644
--- a/files/ajax/rename.php
+++ b/files/ajax/rename.php
@@ -1,7 +1,7 @@
 <?php
 
 // Init owncloud
-require_once('../lib/base.php');
+require_once('../../lib/base.php');
 
 // We send json data
 header( "Content-Type: application/jsonrequest" );
diff --git a/files/js/fileactions.js b/files/js/fileactions.js
index 32029c94da..1eb885f06d 100644
--- a/files/js/fileactions.js
+++ b/files/js/fileactions.js
@@ -126,8 +126,7 @@ FileActions.register('all','Delete',OC.imagePath('core','actions/delete'),functi
 });
 
 FileActions.register('all','Rename',OC.imagePath('core','actions/rename'),function(filename){
-	//todo
-	alert('Implement Me!!');
+	FileList.rename(filename);
 });
 
 FileActions.setDefault('all','Download');
diff --git a/files/js/filelist.js b/files/js/filelist.js
index e84a9acb53..fb96437f0a 100644
--- a/files/js/filelist.js
+++ b/files/js/filelist.js
@@ -73,5 +73,38 @@ FileList={
 	},
 	isLoading:function(name){
 		return $('tr[data-file="'+name+'"]').data('loading');
+	},
+	rename:function(name){
+		var tr=$('tr[data-file="'+name+'"]');
+		var td=tr.children('td.filename');
+		var input=$('<input value='+name+' class="filename"></input>');
+		var button=$('<input type="sumit" value="Ok"></input>');
+		var form=$('<form action="#"></form>')
+		form.append(input);
+		form.append(button);
+		td.children('a.name').text('');
+		td.children('a.name').append(form)
+		input.focus();
+		td.children('a.name').append(button);
+		form.submit(function(event){
+			var newname=input.val();
+			event.stopPropagation();
+			event.preventDefault();
+			tr.attr('data-file',newname);
+			td.children('a.name').empty();
+			td.children('a.name').text(newname);
+			$.ajax({
+				url: 'ajax/rename.php',
+				data: "dir="+$('#dir').val()+"&newname="+encodeURIComponent(newname)+"&file="+encodeURIComponent(name)
+			});
+		});
+		form.click(function(event){
+			event.stopPropagation();
+			event.preventDefault();
+		});
+		input.blur(function(){
+			td.children('a.name').empty();
+			td.children('a.name').text(name);
+		});
 	}
 }
-- 
GitLab