From c73dd86713de9e249bee432f7728dfd06859fac3 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind1991@gmail.com>
Date: Fri, 29 Jul 2011 00:26:23 +0200
Subject: [PATCH] confirmation dialogs for deletions

---
 files/css/files.css       |  2 +-
 files/js/fileactions.js   | 28 +++++++++++++++++------
 files/js/files.js         | 47 ++++++++++++++++++++++++++++-----------
 files/templates/index.php |  4 ++++
 4 files changed, 60 insertions(+), 21 deletions(-)

diff --git a/files/css/files.css b/files/css/files.css
index 166baebf86..d79e75468a 100644
--- a/files/css/files.css
+++ b/files/css/files.css
@@ -51,7 +51,7 @@ table td.delete { background-image:url('../img/delete.png'); }
 #fileList tr input[type=checkbox]:checked, #fileList tr:hover input[type=checkbox] { display:inline; }
 #fileList tr.selected td.filename a, #fileList tr:hover td.filename a { background-image:none !important }
 #select_all { float:left; margin:0.2em; margin-left:0.6em; }
-#uploadsize-message { display:none; }
+#uploadsize-message,#delete-confirm { display:none; }
 .selectedActions a, a.file_action { float:right; display:inline; margin:0 .5em; padding:.3em .3em 0 .3em !important; }
 .selectedActions { display:none; }
 .selectedActions a:hover, a.file_action:hover { background:#fff; -moz-box-shadow:0 0 10px #fff; -webkit-box-shadow:0 0 10px #fff; box-shadow:0 0 10px #fff; -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px; }
diff --git a/files/js/fileactions.js b/files/js/fileactions.js
index 1eb885f06d..e1f25885fe 100644
--- a/files/js/fileactions.js
+++ b/files/js/fileactions.js
@@ -114,13 +114,27 @@ FileActions.register('all','Download',OC.imagePath('core','actions/download'),fu
 });
 
 FileActions.register('all','Delete',OC.imagePath('core','actions/delete'),function(filename){
-	$.ajax({
-		url: 'ajax/delete.php',
-		data: "dir="+encodeURIComponent($('#dir').val())+"&file="+encodeURIComponent(filename),
-		complete: function(data){
-			boolOperationFinished(data, function(){
-				FileList.remove(filename);
-			});
+	$( "#delete-confirm" ).dialog({
+		resizable: false,
+		height:200,
+		title:"Delete "+filename,
+		modal: true,
+		buttons: {
+			"Delete": function() {
+				$( this ).dialog( "close" );
+				$.ajax({
+					url: 'ajax/delete.php',
+					data: "dir="+encodeURIComponent($('#dir').val())+"&file="+encodeURIComponent(filename),
+					complete: function(data){
+						boolOperationFinished(data, function(){
+							FileList.remove(filename);
+						});
+					}
+				});
+			},
+			Cancel: function() {
+				$( this ).dialog( "close" );
+			}
 		}
 	});
 });
diff --git a/files/js/files.js b/files/js/files.js
index f68e4d0c3c..cd1689a2dd 100644
--- a/files/js/files.js
+++ b/files/js/files.js
@@ -100,19 +100,40 @@ $(document).ready(function() {
 	});
 	
 	$('.delete').click(function(event) {
-		var files=getSelectedFiles('name').join(';');
-		
-		$.ajax({
-			url: 'ajax/delete.php',
-			data: "dir="+$('#dir').val()+"&files="+encodeURIComponent(files),
-			complete: function(data){
-				boolOperationFinished(data, function(){
-					var files=getSelectedFiles('name');
-					for(var i=0;i<files.length;i++){
-						FileList.remove(files[i]);
-					}
-					procesSelection();
-				});
+		var fileNames=getSelectedFiles('name');
+		var files=fileNames.join(';');
+		var lastFileName=fileNames.pop();
+		if(fileNames.length>0){
+			fileNames=fileNames.join(', ')+' and '+lastFileName;
+		}else{
+			fileNames=lastFileName;
+		}
+
+		$( "#delete-confirm" ).dialog({
+			resizable: false,
+			height:200,
+			modal: true,
+			title:"Delete "+fileNames,
+			buttons: {
+				"Delete": function() {
+					$( this ).dialog( "close" );
+					$.ajax({
+						url: 'ajax/delete.php',
+						data: "dir="+$('#dir').val()+"&files="+encodeURIComponent(files),
+						complete: function(data){
+							boolOperationFinished(data, function(){
+								var files=getSelectedFiles('name');
+							for(var i=0;i<files.length;i++){
+								FileList.remove(files[i]);
+							}
+							procesSelection();
+							});
+						}
+					});
+				},
+				Cancel: function() {
+					$( this ).dialog( "close" );
+				}
 			}
 		});
 		
diff --git a/files/templates/index.php b/files/templates/index.php
index c098a4e063..336cca19cd 100644
--- a/files/templates/index.php
+++ b/files/templates/index.php
@@ -48,4 +48,8 @@
 	</p>
 </div>
 
+<div id="delete-confirm" title="">
+	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
+</div>
+
 <span id="file_menu"/>
-- 
GitLab