2014-05-08 21:00:42 +04: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 18:10:09 +03:00
|
|
|
/* global dragOptions, folderDropOptions, OC */
|
2014-05-09 00:06:30 +04:00
|
|
|
(function() {
|
2014-05-08 21:00:42 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
if (!OCA.Files) {
|
2014-06-24 01:56:10 +04:00
|
|
|
/**
|
|
|
|
* Namespace for the files app
|
|
|
|
* @namespace OCA.Files
|
|
|
|
*/
|
2014-05-09 00:06:30 +04:00
|
|
|
OCA.Files = {};
|
|
|
|
}
|
|
|
|
|
2014-06-24 01:56:10 +04:00
|
|
|
/**
|
|
|
|
* @namespace OCA.Files.App
|
|
|
|
*/
|
|
|
|
OCA.Files.App = {
|
|
|
|
/**
|
|
|
|
* Navigation control
|
|
|
|
*
|
|
|
|
* @member {OCA.Files.Navigation}
|
|
|
|
*/
|
2014-05-09 00:06:30 +04:00
|
|
|
navigation: null,
|
|
|
|
|
2014-06-24 01:56:10 +04:00
|
|
|
/**
|
|
|
|
* File list for the "All files" section.
|
|
|
|
*
|
|
|
|
* @member {OCA.Files.FileList}
|
|
|
|
*/
|
|
|
|
fileList: null,
|
|
|
|
|
2016-04-12 18:10:09 +03:00
|
|
|
/**
|
|
|
|
* Backbone model for storing files preferences
|
|
|
|
*/
|
|
|
|
_filesConfig: null,
|
|
|
|
|
2014-06-24 01:56:10 +04:00
|
|
|
/**
|
|
|
|
* Initializes the files app
|
|
|
|
*/
|
2014-05-09 00:06:30 +04:00
|
|
|
initialize: function() {
|
|
|
|
this.navigation = new OCA.Files.Navigation($('#app-navigation'));
|
2016-04-12 18:10:09 +03:00
|
|
|
this.$showHiddenFiles = $('input#showhiddenfilesToggle');
|
|
|
|
var showHidden = $('#showHiddenFiles').val() === "1";
|
|
|
|
this.$showHiddenFiles.prop('checked', showHidden);
|
2016-06-07 14:51:16 +03:00
|
|
|
if ($('#fileNotFound').val() === "1") {
|
2017-02-14 23:26:00 +03:00
|
|
|
OC.Notification.show(t('files', 'File could not be found'), {type: 'error'});
|
2016-06-07 14:51:16 +03:00
|
|
|
}
|
2016-04-12 18:10:09 +03:00
|
|
|
|
|
|
|
this._filesConfig = new OC.Backbone.Model({
|
|
|
|
showhidden: showHidden
|
|
|
|
});
|
2014-05-09 00:06:30 +04:00
|
|
|
|
2014-09-04 14:20:11 +04:00
|
|
|
var urlParams = OC.Util.History.parseUrlQuery();
|
2014-05-20 18:01:34 +04: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 14:26:33 +04: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 15:36:18 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
this.files = OCA.Files.Files;
|
|
|
|
|
2014-05-20 18:01:34 +04:00
|
|
|
// TODO: ideally these should be in a separate class / app (the embedded "all files" app)
|
2014-05-12 21:54:20 +04:00
|
|
|
this.fileList = new OCA.Files.FileList(
|
|
|
|
$('#app-content-files'), {
|
|
|
|
scrollContainer: $('#app-content'),
|
|
|
|
dragOptions: dragOptions,
|
2014-05-20 18:01:34 +04:00
|
|
|
folderDropOptions: folderDropOptions,
|
|
|
|
fileActions: fileActions,
|
2014-09-04 14:20:11 +04:00
|
|
|
allowLegacyActions: true,
|
2015-07-13 18:38:13 +03:00
|
|
|
scrollTo: urlParams.scrollto,
|
2016-04-12 11:19:52 +03:00
|
|
|
filesClient: OC.Files.getClient(),
|
2018-06-02 18:15:19 +03:00
|
|
|
multiSelectMenu: [
|
|
|
|
{
|
2018-06-06 21:01:25 +03:00
|
|
|
name: 'copyMove',
|
2018-06-02 18:15:19 +03: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 12:08:26 +03:00
|
|
|
sorting: {
|
|
|
|
mode: $('#defaultFileSorting').val(),
|
|
|
|
direction: $('#defaultFileSortingDirection').val()
|
2016-04-12 18:10:09 +03:00
|
|
|
},
|
|
|
|
config: this._filesConfig,
|
2016-10-07 17:27:54 +03:00
|
|
|
enableUpload: true,
|
|
|
|
maxChunkSize: OC.appConfig.files && OC.appConfig.files.max_chunk_size
|
2014-05-12 21:54:20 +04:00
|
|
|
}
|
|
|
|
);
|
2014-05-09 00:06:30 +04: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 20:53:45 +03:00
|
|
|
OC.Plugins.attach('OCA.Files.App', this);
|
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
this._setupEvents();
|
|
|
|
// trigger URL change event handlers
|
2014-09-04 14:20:11 +04:00
|
|
|
this._onPopState(urlParams);
|
2016-04-12 18:10:09 +03:00
|
|
|
|
2017-06-08 17:42:43 +03:00
|
|
|
$('#quota.has-tooltip').tooltip({
|
2017-06-13 01:03:54 +03:00
|
|
|
placement: 'top'
|
2017-06-08 17:42:43 +03:00
|
|
|
});
|
|
|
|
|
2016-04-12 18:10:09 +03:00
|
|
|
this._debouncedPersistShowHiddenFilesState = _.debounce(this._persistShowHiddenFilesState, 1200);
|
2014-05-09 00:06:30 +04:00
|
|
|
},
|
|
|
|
|
2014-07-09 14:26:33 +04: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 18:15:19 +03:00
|
|
|
_onActionsUpdated: function(ev) {
|
2014-07-09 14:26:33 +04: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-09 00:06:30 +04:00
|
|
|
/**
|
|
|
|
* Returns the container of the currently visible app.
|
|
|
|
*
|
|
|
|
* @return app container
|
|
|
|
*/
|
|
|
|
getCurrentAppContainer: function() {
|
|
|
|
return this.navigation.getActiveContainer();
|
|
|
|
},
|
2014-05-08 21:00:42 +04:00
|
|
|
|
2014-05-19 17:20:44 +04:00
|
|
|
/**
|
|
|
|
* Sets the currently active view
|
|
|
|
* @param viewId view id
|
|
|
|
*/
|
|
|
|
setActiveView: function(viewId, options) {
|
|
|
|
this.navigation.setActiveItem(viewId, options);
|
|
|
|
},
|
|
|
|
|
2014-05-21 14:54:34 +04:00
|
|
|
/**
|
|
|
|
* Returns the view id of the currently active view
|
|
|
|
* @return view id
|
|
|
|
*/
|
|
|
|
getActiveView: function() {
|
|
|
|
return this.navigation.getActiveItem();
|
|
|
|
},
|
|
|
|
|
2016-04-12 18:10:09 +03:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @returns {Backbone.Model}
|
|
|
|
*/
|
|
|
|
getFilesConfig: function() {
|
|
|
|
return this._filesConfig;
|
|
|
|
},
|
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
/**
|
|
|
|
* Setup events based on URL changes
|
|
|
|
*/
|
|
|
|
_setupEvents: function() {
|
|
|
|
OC.Util.History.addOnPopStateHandler(_.bind(this._onPopState, this));
|
2014-05-08 21:00:42 +04:00
|
|
|
|
2014-05-09 00:06:30 +04:00
|
|
|
// detect when app changed their current directory
|
2014-05-12 21:54:20 +04:00
|
|
|
$('#app-content').delegate('>div', 'changeDirectory', _.bind(this._onDirectoryChanged, this));
|
2016-05-04 12:17:53 +03:00
|
|
|
$('#app-content').delegate('>div', 'afterChangeDirectory', _.bind(this._onAfterDirectoryChanged, this));
|
2014-05-12 21:54:20 +04:00
|
|
|
$('#app-content').delegate('>div', 'changeViewerMode', _.bind(this._onChangeViewerMode, this));
|
2014-05-09 00:06:30 +04:00
|
|
|
|
|
|
|
$('#app-navigation').on('itemChanged', _.bind(this._onNavigationChanged, this));
|
2016-04-12 18:10:09 +03: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();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Persist show hidden preference on ther server
|
|
|
|
*
|
|
|
|
* @returns {undefined}
|
|
|
|
*/
|
|
|
|
_persistShowHiddenFilesState: function() {
|
|
|
|
var show = this._filesConfig.get('showhidden');
|
|
|
|
$.post(OC.generateUrl('/apps/files/api/v1/showhidden'), {
|
|
|
|
show: show
|
|
|
|
});
|
2014-05-09 00:06:30 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Event handler for when the current navigation item has changed
|
|
|
|
*/
|
|
|
|
_onNavigationChanged: function(e) {
|
|
|
|
var params;
|
|
|
|
if (e && e.itemId) {
|
|
|
|
params = {
|
|
|
|
view: e.itemId,
|
|
|
|
dir: '/'
|
|
|
|
};
|
|
|
|
this._changeUrl(params.view, params.dir);
|
2015-08-25 12:07:47 +03:00
|
|
|
OC.Apps.hideAppSidebar($('.detailsView'));
|
2014-05-09 00:06:30 +04: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 12:17:53 +03: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-09 00:06:30 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-05-12 21:54:20 +04: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 12:07:47 +03:00
|
|
|
if (e.viewerModeEnabled) {
|
|
|
|
OC.Apps.hideAppSidebar($('.detailsView'));
|
|
|
|
}
|
2014-05-12 21:54:20 +04:00
|
|
|
$('#app-navigation').toggleClass('hidden', state);
|
|
|
|
$('.app-files').toggleClass('viewer-mode no-sidebar', state);
|
|
|
|
},
|
|
|
|
|
2014-05-09 00:06:30 +04: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 21:54:20 +04:00
|
|
|
if (!this.navigation.itemExists(params.view)) {
|
|
|
|
params.view = 'files';
|
|
|
|
}
|
2014-05-09 00:06:30 +04: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 17:13:39 +03: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-09 00:06:30 +04:00
|
|
|
/**
|
|
|
|
* Change the URL to point to the given dir and view
|
|
|
|
*/
|
2016-05-04 12:17:53 +03:00
|
|
|
_changeUrl: function(view, dir, fileId) {
|
2014-05-09 00:06:30 +04:00
|
|
|
var params = {dir: dir};
|
|
|
|
if (view !== 'files') {
|
|
|
|
params.view = view;
|
2016-05-04 12:17:53 +03: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 17:13:39 +03:00
|
|
|
OC.Util.History.replaceState(this._makeUrlParams(params));
|
2016-05-04 12:17:53 +03:00
|
|
|
} else {
|
2016-05-06 17:13:39 +03:00
|
|
|
OC.Util.History.pushState(this._makeUrlParams(params));
|
2014-05-09 00:06:30 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
})();
|
|
|
|
|
|
|
|
$(document).ready(function() {
|
2014-05-20 18:01:34 +04:00
|
|
|
// wait for other apps/extensions to register their event handlers and file actions
|
2014-05-09 00:06:30 +04:00
|
|
|
// in the "ready" clause
|
|
|
|
_.defer(function() {
|
|
|
|
OCA.Files.App.initialize();
|
|
|
|
});
|
2014-05-08 21:00:42 +04:00
|
|
|
});
|