2014-05-08 17:00:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014
|
|
|
|
*
|
|
|
|
* @author Vincent Petry
|
|
|
|
* @copyright 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-04-12 15:10:09 +00:00
|
|
|
/* global dragOptions, folderDropOptions, OC */
|
2014-05-08 20:06:30 +00:00
|
|
|
(function() {
|
2014-05-08 17:00:42 +00:00
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
if (!OCA.Files) {
|
2014-06-23 21:56:10 +00:00
|
|
|
/**
|
|
|
|
* Namespace for the files app
|
|
|
|
* @namespace OCA.Files
|
|
|
|
*/
|
2014-05-08 20:06:30 +00:00
|
|
|
OCA.Files = {};
|
|
|
|
}
|
|
|
|
|
2014-06-23 21:56:10 +00:00
|
|
|
/**
|
|
|
|
* @namespace OCA.Files.App
|
|
|
|
*/
|
|
|
|
OCA.Files.App = {
|
|
|
|
/**
|
|
|
|
* Navigation control
|
|
|
|
*
|
|
|
|
* @member {OCA.Files.Navigation}
|
|
|
|
*/
|
2014-05-08 20:06:30 +00:00
|
|
|
navigation: null,
|
|
|
|
|
2014-06-23 21:56:10 +00:00
|
|
|
/**
|
|
|
|
* File list for the "All files" section.
|
|
|
|
*
|
|
|
|
* @member {OCA.Files.FileList}
|
|
|
|
*/
|
|
|
|
fileList: null,
|
|
|
|
|
2016-04-12 15:10:09 +00:00
|
|
|
/**
|
|
|
|
* Backbone model for storing files preferences
|
|
|
|
*/
|
|
|
|
_filesConfig: null,
|
|
|
|
|
2014-06-23 21:56:10 +00:00
|
|
|
/**
|
|
|
|
* Initializes the files app
|
|
|
|
*/
|
2014-05-08 20:06:30 +00:00
|
|
|
initialize: function() {
|
|
|
|
this.navigation = new OCA.Files.Navigation($('#app-navigation'));
|
2016-04-12 15:10:09 +00:00
|
|
|
this.$showHiddenFiles = $('input#showhiddenfilesToggle');
|
|
|
|
var showHidden = $('#showHiddenFiles').val() === "1";
|
|
|
|
this.$showHiddenFiles.prop('checked', showHidden);
|
2018-06-01 18:29:43 +00:00
|
|
|
|
|
|
|
|
2016-06-07 11:51:16 +00:00
|
|
|
if ($('#fileNotFound').val() === "1") {
|
2017-02-14 20:26:00 +00:00
|
|
|
OC.Notification.show(t('files', 'File could not be found'), {type: 'error'});
|
2016-06-07 11:51:16 +00:00
|
|
|
}
|
2016-04-12 15:10:09 +00:00
|
|
|
|
|
|
|
this._filesConfig = new OC.Backbone.Model({
|
2018-06-16 20:44:18 +00:00
|
|
|
showhidden: showHidden
|
2016-04-12 15:10:09 +00:00
|
|
|
});
|
2014-05-08 20:06:30 +00:00
|
|
|
|
2014-09-04 10:20:11 +00:00
|
|
|
var urlParams = OC.Util.History.parseUrlQuery();
|
2014-05-20 14:01:34 +00:00
|
|
|
var fileActions = new OCA.Files.FileActions();
|
|
|
|
// default actions
|
|
|
|
fileActions.registerDefaultActions();
|
|
|
|
// legacy actions
|
|
|
|
fileActions.merge(window.FileActions);
|
|
|
|
// regular actions
|
|
|
|
fileActions.merge(OCA.Files.fileActions);
|
|
|
|
|
2014-07-09 10:26:33 +00:00
|
|
|
this._onActionsUpdated = _.bind(this._onActionsUpdated, this);
|
|
|
|
OCA.Files.fileActions.on('setDefault.app-files', this._onActionsUpdated);
|
|
|
|
OCA.Files.fileActions.on('registerAction.app-files', this._onActionsUpdated);
|
|
|
|
window.FileActions.on('setDefault.app-files', this._onActionsUpdated);
|
|
|
|
window.FileActions.on('registerAction.app-files', this._onActionsUpdated);
|
2014-06-27 11:36:18 +00:00
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
this.files = OCA.Files.Files;
|
|
|
|
|
2014-05-20 14:01:34 +00:00
|
|
|
// TODO: ideally these should be in a separate class / app (the embedded "all files" app)
|
2014-05-12 17:54:20 +00:00
|
|
|
this.fileList = new OCA.Files.FileList(
|
|
|
|
$('#app-content-files'), {
|
|
|
|
scrollContainer: $('#app-content'),
|
|
|
|
dragOptions: dragOptions,
|
2014-05-20 14:01:34 +00:00
|
|
|
folderDropOptions: folderDropOptions,
|
|
|
|
fileActions: fileActions,
|
2014-09-04 10:20:11 +00:00
|
|
|
allowLegacyActions: true,
|
2015-07-13 15:38:13 +00:00
|
|
|
scrollTo: urlParams.scrollto,
|
2016-04-12 08:19:52 +00:00
|
|
|
filesClient: OC.Files.getClient(),
|
2018-06-02 15:15:19 +00:00
|
|
|
multiSelectMenu: [
|
|
|
|
{
|
2018-06-06 18:01:25 +00:00
|
|
|
name: 'copyMove',
|
2018-06-02 15:15:19 +00:00
|
|
|
displayName: t('files', 'Move or copy'),
|
|
|
|
iconClass: 'icon-external',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'download',
|
|
|
|
displayName: t('files', 'Download'),
|
|
|
|
iconClass: 'icon-download',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'delete',
|
|
|
|
displayName: t('files', 'Delete'),
|
|
|
|
iconClass: 'icon-delete',
|
|
|
|
}
|
|
|
|
],
|
2016-04-12 09:08:26 +00:00
|
|
|
sorting: {
|
|
|
|
mode: $('#defaultFileSorting').val(),
|
|
|
|
direction: $('#defaultFileSortingDirection').val()
|
2016-04-12 15:10:09 +00:00
|
|
|
},
|
|
|
|
config: this._filesConfig,
|
2016-10-07 14:27:54 +00:00
|
|
|
enableUpload: true,
|
|
|
|
maxChunkSize: OC.appConfig.files && OC.appConfig.files.max_chunk_size
|
2014-05-12 17:54:20 +00:00
|
|
|
}
|
|
|
|
);
|
2014-05-08 20:06:30 +00:00
|
|
|
this.files.initialize();
|
|
|
|
|
|
|
|
// for backward compatibility, the global FileList will
|
|
|
|
// refer to the one of the "files" view
|
|
|
|
window.FileList = this.fileList;
|
|
|
|
|
2014-11-18 17:53:45 +00:00
|
|
|
OC.Plugins.attach('OCA.Files.App', this);
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
this._setupEvents();
|
|
|
|
// trigger URL change event handlers
|
2014-09-04 10:20:11 +00:00
|
|
|
this._onPopState(urlParams);
|
2016-04-12 15:10:09 +00:00
|
|
|
|
2017-06-08 14:42:43 +00:00
|
|
|
$('#quota.has-tooltip').tooltip({
|
2017-06-12 22:03:54 +00:00
|
|
|
placement: 'top'
|
2017-06-08 14:42:43 +00:00
|
|
|
});
|
|
|
|
|
2016-04-12 15:10:09 +00:00
|
|
|
this._debouncedPersistShowHiddenFilesState = _.debounce(this._persistShowHiddenFilesState, 1200);
|
2018-07-04 22:41:59 +00:00
|
|
|
|
|
|
|
OCP.WhatsNew.query(); // for Nextcloud server
|
2014-05-08 20:06:30 +00:00
|
|
|
},
|
|
|
|
|
2014-07-09 10:26:33 +00:00
|
|
|
/**
|
|
|
|
* Destroy the app
|
|
|
|
*/
|
|
|
|
destroy: function() {
|
|
|
|
this.navigation = null;
|
|
|
|
this.fileList.destroy();
|
|
|
|
this.fileList = null;
|
|
|
|
this.files = null;
|
|
|
|
OCA.Files.fileActions.off('setDefault.app-files', this._onActionsUpdated);
|
|
|
|
OCA.Files.fileActions.off('registerAction.app-files', this._onActionsUpdated);
|
|
|
|
window.FileActions.off('setDefault.app-files', this._onActionsUpdated);
|
|
|
|
window.FileActions.off('registerAction.app-files', this._onActionsUpdated);
|
|
|
|
},
|
|
|
|
|
2018-06-02 15:15:19 +00:00
|
|
|
_onActionsUpdated: function(ev) {
|
2014-07-09 10:26:33 +00:00
|
|
|
// forward new action to the file list
|
|
|
|
if (ev.action) {
|
|
|
|
this.fileList.fileActions.registerAction(ev.action);
|
|
|
|
} else if (ev.defaultAction) {
|
|
|
|
this.fileList.fileActions.setDefault(
|
|
|
|
ev.defaultAction.mime,
|
|
|
|
ev.defaultAction.name
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the container of the currently visible app.
|
|
|
|
*
|
|
|
|
* @return app container
|
|
|
|
*/
|
|
|
|
getCurrentAppContainer: function() {
|
|
|
|
return this.navigation.getActiveContainer();
|
|
|
|
},
|
2014-05-08 17:00:42 +00:00
|
|
|
|
2014-05-19 13:20:44 +00:00
|
|
|
/**
|
|
|
|
* Sets the currently active view
|
|
|
|
* @param viewId view id
|
|
|
|
*/
|
|
|
|
setActiveView: function(viewId, options) {
|
|
|
|
this.navigation.setActiveItem(viewId, options);
|
|
|
|
},
|
|
|
|
|
2014-05-21 10:54:34 +00:00
|
|
|
/**
|
|
|
|
* Returns the view id of the currently active view
|
|
|
|
* @return view id
|
|
|
|
*/
|
|
|
|
getActiveView: function() {
|
|
|
|
return this.navigation.getActiveItem();
|
|
|
|
},
|
|
|
|
|
2016-04-12 15:10:09 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {Backbone.Model}
|
|
|
|
*/
|
|
|
|
getFilesConfig: function() {
|
|
|
|
return this._filesConfig;
|
|
|
|
},
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
/**
|
|
|
|
* Setup events based on URL changes
|
|
|
|
*/
|
|
|
|
_setupEvents: function() {
|
|
|
|
OC.Util.History.addOnPopStateHandler(_.bind(this._onPopState, this));
|
2014-05-08 17:00:42 +00:00
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
// detect when app changed their current directory
|
2014-05-12 17:54:20 +00:00
|
|
|
$('#app-content').delegate('>div', 'changeDirectory', _.bind(this._onDirectoryChanged, this));
|
2016-05-04 09:17:53 +00:00
|
|
|
$('#app-content').delegate('>div', 'afterChangeDirectory', _.bind(this._onAfterDirectoryChanged, this));
|
2014-05-12 17:54:20 +00:00
|
|
|
$('#app-content').delegate('>div', 'changeViewerMode', _.bind(this._onChangeViewerMode, this));
|
2014-05-08 20:06:30 +00:00
|
|
|
|
|
|
|
$('#app-navigation').on('itemChanged', _.bind(this._onNavigationChanged, this));
|
2016-04-12 15:10:09 +00:00
|
|
|
this.$showHiddenFiles.on('change', _.bind(this._onShowHiddenFilesChange, this));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle showing hidden files according to the settings checkbox
|
|
|
|
*
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
_onShowHiddenFilesChange: function() {
|
|
|
|
var show = this.$showHiddenFiles.is(':checked');
|
|
|
|
this._filesConfig.set('showhidden', show);
|
|
|
|
this._debouncedPersistShowHiddenFilesState();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
2018-06-16 20:44:18 +00:00
|
|
|
* Persist show hidden preference on the server
|
2016-04-12 15:10:09 +00:00
|
|
|
*
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
_persistShowHiddenFilesState: function() {
|
|
|
|
var show = this._filesConfig.get('showhidden');
|
|
|
|
$.post(OC.generateUrl('/apps/files/api/v1/showhidden'), {
|
|
|
|
show: show
|
|
|
|
});
|
2014-05-08 20:06:30 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for when the current navigation item has changed
|
|
|
|
*/
|
|
|
|
_onNavigationChanged: function(e) {
|
|
|
|
var params;
|
|
|
|
if (e && e.itemId) {
|
|
|
|
params = {
|
2018-07-12 14:49:25 +00:00
|
|
|
view: typeof e.view === 'string' && e.view !== '' ? e.view : e.itemId,
|
2018-07-12 07:56:46 +00:00
|
|
|
dir: e.dir ? e.dir : '/'
|
2014-05-08 20:06:30 +00:00
|
|
|
};
|
|
|
|
this._changeUrl(params.view, params.dir);
|
2015-08-25 09:07:47 +00:00
|
|
|
OC.Apps.hideAppSidebar($('.detailsView'));
|
2014-05-08 20:06:30 +00:00
|
|
|
this.navigation.getActiveContainer().trigger(new $.Event('urlChanged', params));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for when an app notified that its directory changed
|
|
|
|
*/
|
|
|
|
_onDirectoryChanged: function(e) {
|
|
|
|
if (e.dir) {
|
2016-05-04 09:17:53 +00:00
|
|
|
this._changeUrl(this.navigation.getActiveItem(), e.dir, e.fileId);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for when an app notified that its directory changed
|
|
|
|
*/
|
|
|
|
_onAfterDirectoryChanged: function(e) {
|
|
|
|
if (e.dir && e.fileId) {
|
|
|
|
this._changeUrl(this.navigation.getActiveItem(), e.dir, e.fileId);
|
2014-05-08 20:06:30 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
/**
|
|
|
|
* Event handler for when an app notifies that it needs space
|
|
|
|
* for viewer mode.
|
|
|
|
*/
|
|
|
|
_onChangeViewerMode: function(e) {
|
|
|
|
var state = !!e.viewerModeEnabled;
|
2015-08-25 09:07:47 +00:00
|
|
|
if (e.viewerModeEnabled) {
|
|
|
|
OC.Apps.hideAppSidebar($('.detailsView'));
|
|
|
|
}
|
2014-05-12 17:54:20 +00:00
|
|
|
$('#app-navigation').toggleClass('hidden', state);
|
|
|
|
$('.app-files').toggleClass('viewer-mode no-sidebar', state);
|
|
|
|
},
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
/**
|
|
|
|
* Event handler for when the URL changed
|
|
|
|
*/
|
|
|
|
_onPopState: function(params) {
|
|
|
|
params = _.extend({
|
|
|
|
dir: '/',
|
|
|
|
view: 'files'
|
|
|
|
}, params);
|
|
|
|
var lastId = this.navigation.getActiveItem();
|
2014-05-12 17:54:20 +00:00
|
|
|
if (!this.navigation.itemExists(params.view)) {
|
|
|
|
params.view = 'files';
|
|
|
|
}
|
2014-05-08 20:06:30 +00:00
|
|
|
this.navigation.setActiveItem(params.view, {silent: true});
|
|
|
|
if (lastId !== this.navigation.getActiveItem()) {
|
|
|
|
this.navigation.getActiveContainer().trigger(new $.Event('show'));
|
|
|
|
}
|
|
|
|
this.navigation.getActiveContainer().trigger(new $.Event('urlChanged', params));
|
|
|
|
},
|
|
|
|
|
2016-05-06 14:13:39 +00:00
|
|
|
/**
|
|
|
|
* Encode URL params into a string, except for the "dir" attribute
|
|
|
|
* that gets encoded as path where "/" is not encoded
|
|
|
|
*
|
|
|
|
* @param {Object.<string>} params
|
|
|
|
* @return {string} encoded params
|
|
|
|
*/
|
|
|
|
_makeUrlParams: function(params) {
|
|
|
|
var dir = params.dir;
|
|
|
|
delete params.dir;
|
|
|
|
return 'dir=' + OC.encodePath(dir) + '&' + OC.buildQueryString(params);
|
|
|
|
},
|
|
|
|
|
2014-05-08 20:06:30 +00:00
|
|
|
/**
|
|
|
|
* Change the URL to point to the given dir and view
|
|
|
|
*/
|
2016-05-04 09:17:53 +00:00
|
|
|
_changeUrl: function(view, dir, fileId) {
|
2014-05-08 20:06:30 +00:00
|
|
|
var params = {dir: dir};
|
|
|
|
if (view !== 'files') {
|
|
|
|
params.view = view;
|
2016-05-04 09:17:53 +00:00
|
|
|
} else if (fileId) {
|
|
|
|
params.fileid = fileId;
|
|
|
|
}
|
|
|
|
var currentParams = OC.Util.History.parseUrlQuery();
|
|
|
|
if (currentParams.dir === params.dir && currentParams.view === params.view && currentParams.fileid !== params.fileid) {
|
|
|
|
// if only fileid changed or was added, replace instead of push
|
2016-05-06 14:13:39 +00:00
|
|
|
OC.Util.History.replaceState(this._makeUrlParams(params));
|
2016-05-04 09:17:53 +00:00
|
|
|
} else {
|
2016-05-06 14:13:39 +00:00
|
|
|
OC.Util.History.pushState(this._makeUrlParams(params));
|
2014-05-08 20:06:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
2014-05-20 14:01:34 +00:00
|
|
|
// wait for other apps/extensions to register their event handlers and file actions
|
2014-05-08 20:06:30 +00:00
|
|
|
// in the "ready" clause
|
|
|
|
_.defer(function() {
|
|
|
|
OCA.Files.App.initialize();
|
|
|
|
});
|
2014-05-08 17:00:42 +00:00
|
|
|
});
|