Blame view

sources/apps/files_trashbin/js/trash.js 7.3 KB
03e52840d   Kload   Init
1
2
3
4
  
  $(document).ready(function() {
  
  	if (typeof FileActions !== 'undefined') {
31b7f2792   Kload   Upgrade to ownclo...
5
  		FileActions.register('all', 'Restore', OC.PERMISSION_READ, OC.imagePath('core', 'actions/history'), function(filename) {
a293d369c   Kload   Update sources to...
6
7
  			var tr = FileList.findFileEl(filename);
  			var deleteAction = tr.children("td.date").children(".action.delete");
31b7f2792   Kload   Upgrade to ownclo...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  			deleteAction.removeClass('delete-icon').addClass('progress-icon');
  			disableActions();
  			$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'),
  					{files: JSON.stringify([$('#dir').val() + '/' + filename]), dirlisting: tr.attr('data-dirlisting')},
  					function(result) {
  						for (var i = 0; i < result.data.success.length; i++) {
  							var row = document.getElementById(result.data.success[i].filename);
  							row.parentNode.removeChild(row);
  						}
  						if (result.status !== 'success') {
  							OC.dialogs.alert(result.data.message, t('core', 'Error'));
  						}
  						enableActions();
  						FileList.updateFileSummary();
  						FileList.updateEmptyContent();
  					}
  			);
  
  		});
  	};
  
  	FileActions.register('all', 'Delete', OC.PERMISSION_READ, function() {
  		return OC.imagePath('core', 'actions/delete');
  	}, function(filename) {
  		$('.tipsy').remove();
a293d369c   Kload   Update sources to...
33
34
  		var tr = FileList.findFileEl(filename);
  		var deleteAction = tr.children("td.date").children(".action.delete");
31b7f2792   Kload   Upgrade to ownclo...
35
36
37
38
39
  		deleteAction.removeClass('delete-icon').addClass('progress-icon');
  		disableActions();
  		$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
  				{files: JSON.stringify([$('#dir').val() + '/' +filename]), dirlisting: tr.attr('data-dirlisting')},
  				function(result) {
03e52840d   Kload   Init
40
41
42
43
  					for (var i = 0; i < result.data.success.length; i++) {
  						var row = document.getElementById(result.data.success[i].filename);
  						row.parentNode.removeChild(row);
  					}
31b7f2792   Kload   Upgrade to ownclo...
44
45
  					if (result.status !== 'success') {
  						OC.dialogs.alert(result.data.message, t('core', 'Error'));
03e52840d   Kload   Init
46
  					}
31b7f2792   Kload   Upgrade to ownclo...
47
48
49
50
51
  					enableActions();
  					FileList.updateFileSummary();
  					FileList.updateEmptyContent();
  				}
  		);
03e52840d   Kload   Init
52

31b7f2792   Kload   Upgrade to ownclo...
53
  	});
03e52840d   Kload   Init
54

31b7f2792   Kload   Upgrade to ownclo...
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
  	// Sets the select_all checkbox behaviour :
  	$('#select_all').click(function() {
  		if ($(this).attr('checked')) {
  			// Check all
  			$('td.filename input:checkbox').attr('checked', true);
  			$('td.filename input:checkbox').parent().parent().addClass('selected');
  		} else {
  			// Uncheck all
  			$('td.filename input:checkbox').attr('checked', false);
  			$('td.filename input:checkbox').parent().parent().removeClass('selected');
  		}
  		procesSelection();
  	});
  
  	$('.undelete').click('click', function(event) {
  		event.preventDefault();
  		var files = getSelectedFiles('file');
  		var fileslist = JSON.stringify(files);
  		var dirlisting = getSelectedFiles('dirlisting')[0];
  		disableActions();
  		for (var i = 0; i < files.length; i++) {
a293d369c   Kload   Update sources to...
76
  			var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
31b7f2792   Kload   Upgrade to ownclo...
77
78
79
80
81
82
  			deleteAction.removeClass('delete-icon').addClass('progress-icon');
  		}
  
  		$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'),
  				{files: fileslist, dirlisting: dirlisting},
  				function(result) {
03e52840d   Kload   Init
83
84
85
86
  					for (var i = 0; i < result.data.success.length; i++) {
  						var row = document.getElementById(result.data.success[i].filename);
  						row.parentNode.removeChild(row);
  					}
31b7f2792   Kload   Upgrade to ownclo...
87
88
  					if (result.status !== 'success') {
  						OC.dialogs.alert(result.data.message, t('core', 'Error'));
03e52840d   Kload   Init
89
  					}
31b7f2792   Kload   Upgrade to ownclo...
90
91
92
  					enableActions();
  					FileList.updateFileSummary();
  					FileList.updateEmptyContent();
03e52840d   Kload   Init
93
  				}
31b7f2792   Kload   Upgrade to ownclo...
94
95
  		);
  	});
03e52840d   Kload   Init
96

31b7f2792   Kload   Upgrade to ownclo...
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
  	$('.delete').click('click', function(event) {
  		event.preventDefault();
  		var allFiles = $('#select_all').is(':checked');
  		var files = [];
  		var params = {};
  		if (allFiles) {
  			params = {
  			   allfiles: true,
  			   dir: $('#dir').val()
  			};
  		}
  		else {
  			files = getSelectedFiles('file');
  			params = {
  				files: JSON.stringify(files),
  				dirlisting: getSelectedFiles('dirlisting')[0]
  			};
  		};
  
  		disableActions();
  		if (allFiles) {
  			FileList.showMask();
  		}
  		else {
  			for (var i = 0; i < files.length; i++) {
a293d369c   Kload   Update sources to...
122
  				var deleteAction = FileList.findFileEl(files[i]).children("td.date").children(".action.delete");
31b7f2792   Kload   Upgrade to ownclo...
123
  				deleteAction.removeClass('delete-icon').addClass('progress-icon');
03e52840d   Kload   Init
124
  			}
31b7f2792   Kload   Upgrade to ownclo...
125
  		}
03e52840d   Kload   Init
126

31b7f2792   Kload   Upgrade to ownclo...
127
128
129
130
131
132
133
134
135
  		$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'),
  				params,
  				function(result) {
  					if (allFiles) {
  						FileList.hideMask();
  						// simply remove all files
  						$('#fileList').empty();
  					}
  					else {
03e52840d   Kload   Init
136
137
138
139
  						for (var i = 0; i < result.data.success.length; i++) {
  							var row = document.getElementById(result.data.success[i].filename);
  							row.parentNode.removeChild(row);
  						}
31b7f2792   Kload   Upgrade to ownclo...
140
141
142
143
144
145
146
147
148
  					}
  					if (result.status !== 'success') {
  						OC.dialogs.alert(result.data.message, t('core', 'Error'));
  					}
  					enableActions();
  					FileList.updateFileSummary();
  					FileList.updateEmptyContent();
  				}
  		);
03e52840d   Kload   Init
149

31b7f2792   Kload   Upgrade to ownclo...
150
  	});
03e52840d   Kload   Init
151

31b7f2792   Kload   Upgrade to ownclo...
152
153
154
  	$('#fileList').on('click', 'td.filename input', function() {
  		var checkbox = $(this).parent().children('input:checkbox');
  		$(checkbox).parent().parent().toggleClass('selected');
a293d369c   Kload   Update sources to...
155
156
157
158
159
160
161
162
  		if ($(checkbox).is(':checked')) {
  			var selectedCount = $('td.filename input:checkbox:checked').length;
  			if (selectedCount === $('td.filename input:checkbox').length) {
  				$('#select_all').prop('checked', true);
  			}
  		} else {
  			$('#select_all').prop('checked',false);
  		}
31b7f2792   Kload   Upgrade to ownclo...
163
164
  		procesSelection();
  	});
03e52840d   Kload   Init
165
166
167
168
169
170
171
  
  	$('#fileList').on('click', 'td.filename a', function(event) {
  		var mime = $(this).parent().parent().data('mime');
  		if (mime !== 'httpd/unix-directory') {
  			event.preventDefault();
  		}
  		var filename = $(this).parent().parent().attr('data-file');
a293d369c   Kload   Update sources to...
172
  		var tr = FileList.findFileEl(filename);
03e52840d   Kload   Init
173
174
175
176
177
178
179
180
181
182
183
184
185
  		var renaming = tr.data('renaming');
  		if(!renaming && !FileList.isLoading(filename)){
  			if(mime.substr(0, 5) === 'text/'){ //no texteditor for now
  				return;
  			}
  			var type = $(this).parent().parent().data('type');
  			var permissions = $(this).parent().parent().data('permissions');
  			var action = FileActions.getDefault(mime, type, permissions);
  			if(action){
  				event.preventDefault();
  				action(filename);
  			}
  		}
31b7f2792   Kload   Upgrade to ownclo...
186
187
188
  
  		// event handlers for breadcrumb items
  		$('#controls').delegate('.crumb:not(.home) a', 'click', onClickBreadcrumb);
03e52840d   Kload   Init
189
  	});
31b7f2792   Kload   Upgrade to ownclo...
190
191
192
193
  	FileActions.actions.dir = {
  		// only keep 'Open' action for navigation
  		'Open': FileActions.actions.dir.Open
  	};
03e52840d   Kload   Init
194
  });
03e52840d   Kload   Init
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
  /**
   * @brief get a list of selected files
   * @param string property (option) the property of the file requested
   * @return array
   *
   * possible values for property: name, mime, size and type
   * if property is set, an array with that property for each file is returnd
   * if it's ommited an array of objects with all properties is returned
   */
  function getSelectedFiles(property){
  	var elements=$('td.filename input:checkbox:checked').parent().parent();
  	var files=[];
  	elements.each(function(i,element){
  		var file={
  			name:$(element).attr('data-filename'),
31b7f2792   Kload   Upgrade to ownclo...
210
  			file:$('#dir').val() + "/" + $(element).attr('data-file'),
03e52840d   Kload   Init
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
  			timestamp:$(element).attr('data-timestamp'),
  			type:$(element).attr('data-type'),
  			dirlisting:$(element).attr('data-dirlisting')
  		};
  		if(property){
  			files.push(file[property]);
  		}else{
  			files.push(file);
  		}
  	});
  	return files;
  }
  
  function fileDownloadPath(dir, file) {
  	return OC.filePath('files_trashbin', '', 'download.php') + '?file='+encodeURIComponent(file);
  }
31b7f2792   Kload   Upgrade to ownclo...
227
228
229
230
231
232
233
234
235
236
  
  function enableActions() {
  	$(".action").css("display", "inline");
  	$(":input:checkbox").css("display", "inline");
  }
  
  function disableActions() {
  	$(".action").css("display", "none");
  	$(":input:checkbox").css("display", "none");
  }