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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*
* 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.
*
*/
(function() {
/**
* @class OCA.External.FileList
* @augments OCA.Files.FileList
*
* @classdesc External storage file list.
*
* Displays a list of mount points visible
* for the current user.
*
* @param $el container element with existing markup for the #controls
* and a table
* @param [options] map of options, see other parameters
**/
var FileList = function($el, options) {
this.initialize($el, options);
};
FileList.prototype = _.extend({}, OCA.Files.FileList.prototype,
/** @lends OCA.External.FileList.prototype */ {
appName: 'External storages',
/**
* @private
*/
initialize: function($el, options) {
OCA.Files.FileList.prototype.initialize.apply(this, arguments);
if (this.initialized) {
return;
}
},
/**
* @param {OCA.External.MountPointInfo} fileData
*/
_createRow: function(fileData) {
// TODO: hook earlier and render the whole row here
var $tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments);
var $scopeColumn = $('<td class="column-scope column-last"><span></span></td>');
var $backendColumn = $('<td class="column-backend"></td>');
var scopeText = t('files_external', 'Personal');
if (fileData.scope === 'system') {
scopeText = t('files_external', 'System');
}
$tr.find('.filesize,.date').remove();
$scopeColumn.find('span').text(scopeText);
$backendColumn.text(fileData.backend);
$tr.find('td.filename').after($scopeColumn).after($backendColumn);
$tr.find('td.filename input:checkbox').remove();
return $tr;
},
updateEmptyContent: function() {
var dir = this.getCurrentDirectory();
if (dir === '/') {
// root has special permissions
this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty);
this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty);
}
else {
OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments);
}
},
getDirectoryPermissions: function() {
return OC.PERMISSION_READ | OC.PERMISSION_DELETE;
},
updateStorageStatistics: function() {
// no op because it doesn't have
// storage info like free space / used space
},
reload: function() {
this.showMask();
if (this._reloadCall) {
this._reloadCall.abort();
}
// there is only root
this._setCurrentDir('/', false);
this._reloadCall = $.ajax({
url: OC.linkToOCS('apps/files_external/api/v1') + 'mounts',
data: {
format: 'json'
},
type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader('OCS-APIREQUEST', 'true');
}
});
var callBack = this.reloadCallback.bind(this);
return this._reloadCall.then(callBack, callBack);
},
reloadCallback: function(result) {
delete this._reloadCall;
this.hideMask();
if (result.ocs && result.ocs.data) {
this.setFiles(this._makeFiles(result.ocs.data));
return true;
}
return false;
},
/**
* Converts the OCS API response data to a file info
* list
* @param OCS API mounts array
* @return array of file info maps
*/
_makeFiles: function(data) {
var files = _.map(data, function(fileData) {
fileData.icon = OC.imagePath('core', 'filetypes/folder-external');
fileData.mountType = 'external';
return fileData;
});
files.sort(this._sortComparator);
return files;
}
});
/**
* Mount point info attributes.
*
* @typedef {Object} OCA.External.MountPointInfo
*
* @property {String} name mount point name
* @property {String} scope mount point scope "personal" or "system"
* @property {String} backend external storage backend name
*/
OCA.External.FileList = FileList;
})();
|