aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/js/app.js
blob: bf853f926dcf969bff35e634e7aa92df40acf79e (plain)
1
2
3
4
5
6
7
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
 * Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com>
 *
 * This file is licensed under the Affero General Public License version 3
 * or later.
 *
 * See the COPYING-README file.
 *
 */

if (!OCA.External) {
	/**
	 * @namespace
	 */
	OCA.External = {};
}
/**
 * @namespace
 */
OCA.External.App = {

	fileList: null,

	initList: function($el) {
		if (this.fileList) {
			return this.fileList;
		}

		this.fileList = new OCA.External.FileList(
			$el,
			{
				scrollContainer: $('#app-content'),
				fileActions: this._createFileActions()
			}
		);

		this._extendFileList(this.fileList);
		this.fileList.appName = t('files_external', 'External storage');
		return this.fileList;
	},

	removeList: function() {
		if (this.fileList) {
			this.fileList.$fileList.empty();
		}
	},

	_createFileActions: function() {
		// inherit file actions from the files app
		var fileActions = new OCA.Files.FileActions();
		fileActions.registerDefaultActions();

		// when the user clicks on a folder, redirect to the corresponding
		// folder in the files app instead of opening it directly
		fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
			OCA.Files.App.setActiveView('files', {silent: true});
			OCA.Files.App.fileList.changeDirectory(context.$file.attr('data-path') + '/' + filename, true, true);
		});
		fileActions.setDefault('dir', 'Open');
		return fileActions;
	},

	_extendFileList: function(fileList) {
		// remove size column from summary
		fileList.fileSummary.$el.find('.filesize').remove();
	}
};

$(document).ready(function() {
	$('#app-content-extstoragemounts').on('show', function(e) {
		OCA.External.App.initList($(e.target));
	});
	$('#app-content-extstoragemounts').on('hide', function() {
		OCA.External.App.removeList();
	});
});