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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2018-10-19 18:35:13 +03:00
|
|
|
if (!OCA.Files_External) {
|
2015-11-24 10:16:14 +03:00
|
|
|
/**
|
|
|
|
* @namespace
|
|
|
|
*/
|
2018-10-19 18:35:13 +03:00
|
|
|
OCA.Files_External = {};
|
2014-06-06 15:16:47 +04:00
|
|
|
}
|
2014-06-24 01:56:10 +04:00
|
|
|
/**
|
|
|
|
* @namespace
|
|
|
|
*/
|
2018-10-19 18:35:13 +03:00
|
|
|
OCA.Files_External.App = {
|
2014-06-06 15:16:47 +04:00
|
|
|
|
2015-11-24 10:16:14 +03:00
|
|
|
fileList: null,
|
2014-06-06 15:16:47 +04:00
|
|
|
|
2015-11-24 10:16:14 +03:00
|
|
|
initList: function($el) {
|
|
|
|
if (this.fileList) {
|
|
|
|
return this.fileList;
|
|
|
|
}
|
2014-06-06 15:16:47 +04:00
|
|
|
|
2018-10-19 18:35:13 +03:00
|
|
|
this.fileList = new OCA.Files_External.FileList(
|
2015-11-24 10:16:14 +03:00
|
|
|
$el,
|
|
|
|
{
|
|
|
|
fileActions: this._createFileActions()
|
|
|
|
}
|
|
|
|
);
|
2014-06-06 15:16:47 +04:00
|
|
|
|
2015-11-24 10:16:14 +03:00
|
|
|
this._extendFileList(this.fileList);
|
2021-05-20 13:13:04 +03:00
|
|
|
this.fileList.appName = t('files_external', 'External storage');
|
2015-11-24 10:16:14 +03:00
|
|
|
return this.fileList;
|
|
|
|
},
|
2014-06-06 15:16:47 +04:00
|
|
|
|
2015-11-24 10:16:14 +03:00
|
|
|
removeList: function() {
|
|
|
|
if (this.fileList) {
|
|
|
|
this.fileList.$fileList.empty();
|
|
|
|
}
|
|
|
|
},
|
2014-06-06 15:16:47 +04:00
|
|
|
|
2015-11-24 10:16:14 +03:00
|
|
|
_createFileActions: function() {
|
|
|
|
// inherit file actions from the files app
|
|
|
|
var fileActions = new OCA.Files.FileActions();
|
|
|
|
fileActions.registerDefaultActions();
|
2014-06-06 15:16:47 +04:00
|
|
|
|
2015-11-24 10:16:14 +03:00
|
|
|
// 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});
|
2015-11-18 19:54:00 +03:00
|
|
|
OCA.Files.App.fileList.changeDirectory(OC.joinPaths(context.$file.attr('data-path'), filename), true, true);
|
2015-11-24 10:16:14 +03:00
|
|
|
});
|
|
|
|
fileActions.setDefault('dir', 'Open');
|
|
|
|
return fileActions;
|
|
|
|
},
|
2014-06-06 15:16:47 +04:00
|
|
|
|
2015-11-24 10:16:14 +03:00
|
|
|
_extendFileList: function(fileList) {
|
|
|
|
// remove size column from summary
|
|
|
|
fileList.fileSummary.$el.find('.filesize').remove();
|
|
|
|
}
|
2014-06-06 15:16:47 +04:00
|
|
|
};
|
|
|
|
|
2020-07-20 13:30:35 +03:00
|
|
|
window.addEventListener('DOMContentLoaded', function() {
|
2015-11-24 10:16:14 +03:00
|
|
|
$('#app-content-extstoragemounts').on('show', function(e) {
|
2018-10-19 18:35:13 +03:00
|
|
|
OCA.Files_External.App.initList($(e.target));
|
2015-11-24 10:16:14 +03:00
|
|
|
});
|
|
|
|
$('#app-content-extstoragemounts').on('hide', function() {
|
2018-10-19 18:35:13 +03:00
|
|
|
OCA.Files_External.App.removeList();
|
2015-11-24 10:16:14 +03:00
|
|
|
});
|
2015-11-12 15:40:28 +03:00
|
|
|
|
2015-11-24 10:16:14 +03:00
|
|
|
/* Status Manager */
|
|
|
|
if ($('#filesApp').val()) {
|
2015-11-12 15:40:28 +03:00
|
|
|
|
2015-11-24 10:16:14 +03:00
|
|
|
$('#app-content-files')
|
|
|
|
.add('#app-content-extstoragemounts')
|
|
|
|
.on('changeDirectory', function(e){
|
|
|
|
if (e.dir === '/') {
|
|
|
|
var mount_point = e.previousDir.split('/', 2)[1];
|
|
|
|
// Every time that we return to / root folder from a mountpoint, mount_point status is rechecked
|
2018-10-19 18:35:13 +03:00
|
|
|
OCA.Files_External.StatusManager.getMountPointList(function() {
|
|
|
|
OCA.Files_External.StatusManager.recheckConnectivityForMount([mount_point], true);
|
2015-11-24 10:16:14 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('fileActionsReady', function(e){
|
|
|
|
if ($.isArray(e.$files)) {
|
2018-10-19 18:35:13 +03:00
|
|
|
if (OCA.Files_External.StatusManager.mountStatus === null ||
|
|
|
|
OCA.Files_External.StatusManager.mountPointList === null ||
|
|
|
|
_.size(OCA.Files_External.StatusManager.mountStatus) !== _.size(OCA.Files_External.StatusManager.mountPointList)) {
|
2015-11-24 10:16:14 +03:00
|
|
|
// Will be the very first check when the files view will be loaded
|
2018-10-19 18:35:13 +03:00
|
|
|
OCA.Files_External.StatusManager.launchFullConnectivityCheckOneByOne();
|
2015-11-24 10:16:14 +03:00
|
|
|
} else {
|
|
|
|
// When we change between general files view and external files view
|
2018-10-19 18:35:13 +03:00
|
|
|
OCA.Files_External.StatusManager.getMountPointList(function(){
|
2015-11-24 10:16:14 +03:00
|
|
|
var fileNames = [];
|
|
|
|
$.each(e.$files, function(key, value){
|
|
|
|
fileNames.push(value.attr('data-file'));
|
|
|
|
});
|
|
|
|
// Recheck if launched but work from cache
|
2018-10-19 18:35:13 +03:00
|
|
|
OCA.Files_External.StatusManager.recheckConnectivityForMount(fileNames, false);
|
2015-11-24 10:16:14 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
/* End Status Manager */
|
2014-06-06 15:16:47 +04:00
|
|
|
});
|