Completed
Push — stable9 ( 485cb1...e094cf )
by Lukas
26:41 queued 26:23
created

apps/files_trashbin/js/app.js (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
/*
2
 * Copyright (c) 2014
3
 *
4
 * This file is licensed under the Affero General Public License version 3
5
 * or later.
6
 *
7
 * See the COPYING-README file.
8
 *
9
 */
10
11
/**
12
 * @namespace OCA.Trashbin
13
 */
14
OCA.Trashbin = {};
15
/**
16
 * @namespace OCA.Trashbin.App
17
 */
18
OCA.Trashbin.App = {
19
	_initialized: false,
20
21
	initialize: function($el) {
0 ignored issues
show
$el does not seem to be used.
Loading history...
22
		if (this._initialized) {
23
			return;
24
		}
25
		this._initialized = true;
26
		var urlParams = OC.Util.History.parseUrlQuery();
27
		this.fileList = new OCA.Trashbin.FileList(
28
			$('#app-content-trashbin'), {
29
				scrollContainer: $('#app-content'),
30
				fileActions: this._createFileActions(),
31
				detailsViewEnabled: false,
32
				scrollTo: urlParams.scrollto
33
			}
34
		);
35
	},
36
37
	_createFileActions: function() {
38
		var fileActions = new OCA.Files.FileActions();
39
		fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
40
			var dir = context.fileList.getCurrentDirectory();
41
			context.fileList.changeDirectory(OC.joinPaths(dir, filename));
42
		});
43
44
		fileActions.setDefault('dir', 'Open');
45
46
		fileActions.registerAction({
47
			name: 'Restore',
48
			displayName: t('files_trashbin', 'Restore'),
49
			type: OCA.Files.FileActions.TYPE_INLINE,
50
			mime: 'all',
51
			permissions: OC.PERMISSION_READ,
52
			iconClass: 'icon-history',
53
			actionHandler: function(filename, context) {
54
				var fileList = context.fileList;
55
				var tr = fileList.findFileEl(filename);
56
				var deleteAction = tr.children("td.date").children(".action.delete");
57
				deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
58
				fileList.disableActions();
59
				$.post(OC.filePath('files_trashbin', 'ajax', 'undelete.php'), {
60
						files: JSON.stringify([filename]),
61
						dir: fileList.getCurrentDirectory()
62
					},
63
					_.bind(fileList._removeCallback, fileList)
64
				);
65
			}
66
		});
67
68
		fileActions.registerAction({
69
			name: 'Delete',
70
			displayName: t('files', 'Delete'),
71
			mime: 'all',
72
			permissions: OC.PERMISSION_READ,
73
			iconClass: 'icon-delete',
74
			render: function(actionSpec, isDefault, context) {
75
				var $actionLink = fileActions._makeActionLink(actionSpec, context);
76
				$actionLink.attr('original-title', t('files_trashbin', 'Delete permanently'));
77
				$actionLink.children('img').attr('alt', t('files_trashbin', 'Delete permanently'));
78
				context.$file.find('td:last').append($actionLink);
79
				return $actionLink;
80
			},
81
			actionHandler: function(filename, context) {
82
				var fileList = context.fileList;
83
				$('.tipsy').remove();
84
				var tr = fileList.findFileEl(filename);
85
				var deleteAction = tr.children("td.date").children(".action.delete");
86
				deleteAction.removeClass('icon-delete').addClass('icon-loading-small');
87
				fileList.disableActions();
88
				$.post(OC.filePath('files_trashbin', 'ajax', 'delete.php'), {
89
						files: JSON.stringify([filename]),
90
						dir: fileList.getCurrentDirectory()
91
					},
92
					_.bind(fileList._removeCallback, fileList)
93
				);
94
			}
95
		});
96
		return fileActions;
97
	}
98
};
99
100
$(document).ready(function() {
101
	$('#app-content-trashbin').one('show', function() {
102
		var App = OCA.Trashbin.App;
103
		App.initialize($('#app-content-trashbin'));
104
		// force breadcrumb init
105
		// App.fileList.changeDirectory(App.fileList.getCurrentDirectory(), false, true);
106
	});
107
});
108
109