2014-06-06 15:16:47 +04:00
|
|
|
/*
|
|
|
|
* 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() {
|
|
|
|
|
|
|
|
/**
|
2014-06-24 01:56:10 +04:00
|
|
|
* @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
|
|
|
|
**/
|
2014-06-06 15:16:47 +04:00
|
|
|
var FileList = function($el, options) {
|
|
|
|
this.initialize($el, options);
|
|
|
|
};
|
|
|
|
|
2014-06-24 01:56:10 +04:00
|
|
|
FileList.prototype = _.extend({}, OCA.Files.FileList.prototype,
|
|
|
|
/** @lends OCA.External.FileList.prototype */ {
|
2017-04-27 13:58:16 +03:00
|
|
|
appName: 'External storages',
|
2014-06-06 15:16:47 +04:00
|
|
|
|
2014-06-24 01:56:10 +04:00
|
|
|
/**
|
|
|
|
* @private
|
|
|
|
*/
|
2014-06-06 15:16:47 +04:00
|
|
|
initialize: function($el, options) {
|
|
|
|
OCA.Files.FileList.prototype.initialize.apply(this, arguments);
|
|
|
|
if (this.initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-06-24 01:56:10 +04:00
|
|
|
/**
|
|
|
|
* @param {OCA.External.MountPointInfo} fileData
|
|
|
|
*/
|
2014-06-06 15:16:47 +04:00
|
|
|
_createRow: function(fileData) {
|
|
|
|
// TODO: hook earlier and render the whole row here
|
|
|
|
var $tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments);
|
2014-06-06 17:33:33 +04:00
|
|
|
var $scopeColumn = $('<td class="column-scope column-last"><span></span></td>');
|
|
|
|
var $backendColumn = $('<td class="column-backend"></td>');
|
2014-06-06 15:50:41 +04:00
|
|
|
var scopeText = t('files_external', 'Personal');
|
|
|
|
if (fileData.scope === 'system') {
|
|
|
|
scopeText = t('files_external', 'System');
|
|
|
|
}
|
2014-06-06 15:16:47 +04:00
|
|
|
$tr.find('.filesize,.date').remove();
|
2014-06-06 17:33:33 +04:00
|
|
|
$scopeColumn.find('span').text(scopeText);
|
2014-06-06 15:50:41 +04:00
|
|
|
$backendColumn.text(fileData.backend);
|
|
|
|
$tr.find('td.filename').after($scopeColumn).after($backendColumn);
|
2014-06-06 15:16:47 +04:00
|
|
|
$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();
|
|
|
|
}
|
2015-10-27 13:51:54 +03:00
|
|
|
|
|
|
|
// there is only root
|
|
|
|
this._setCurrentDir('/', false);
|
|
|
|
|
2014-06-06 15:16:47 +04:00
|
|
|
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');
|
|
|
|
}
|
|
|
|
});
|
2014-07-04 13:45:36 +04:00
|
|
|
var callBack = this.reloadCallback.bind(this);
|
|
|
|
return this._reloadCall.then(callBack, callBack);
|
2014-06-06 15:16:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
reloadCallback: function(result) {
|
|
|
|
delete this._reloadCall;
|
|
|
|
this.hideMask();
|
|
|
|
|
|
|
|
if (result.ocs && result.ocs.data) {
|
|
|
|
this.setFiles(this._makeFiles(result.ocs.data));
|
2015-10-27 13:51:54 +03:00
|
|
|
return true;
|
2014-06-06 15:16:47 +04:00
|
|
|
}
|
2015-10-27 13:51:54 +03:00
|
|
|
return false;
|
2014-06-06 15:16:47 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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) {
|
2014-06-06 15:32:01 +04:00
|
|
|
var files = _.map(data, function(fileData) {
|
|
|
|
fileData.icon = OC.imagePath('core', 'filetypes/folder-external');
|
2014-07-10 19:25:46 +04:00
|
|
|
fileData.mountType = 'external';
|
2014-06-06 15:32:01 +04:00
|
|
|
return fileData;
|
|
|
|
});
|
|
|
|
|
|
|
|
files.sort(this._sortComparator);
|
2014-06-06 15:16:47 +04:00
|
|
|
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-06-24 01:56:10 +04:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
|
2014-06-06 15:16:47 +04:00
|
|
|
OCA.External.FileList = FileList;
|
|
|
|
})();
|