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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2014-05-12 17:54:20 +00:00
|
|
|
/* global dragOptions, folderDropOptions */
|
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) {
|
|
|
|
OCA.Files = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
var App = {
|
|
|
|
navigation: null,
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
this.navigation = new OCA.Files.Navigation($('#app-navigation'));
|
|
|
|
|
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,
|
|
|
|
scrollTo: urlParams.scrollto
|
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;
|
|
|
|
|
|
|
|
this._setupEvents();
|
|
|
|
// trigger URL change event handlers
|
2014-09-04 10:20:11 +00:00
|
|
|
this._onPopState(urlParams);
|
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);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onActionsUpdated: function(ev, newAction) {
|
|
|
|
// 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();
|
|
|
|
},
|
|
|
|
|
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));
|
|
|
|
$('#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));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
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) {
|
|
|
|
this._changeUrl(this.navigation.getActiveItem(), e.dir);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
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;
|
|
|
|
$('#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));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Change the URL to point to the given dir and view
|
|
|
|
*/
|
|
|
|
_changeUrl: function(view, dir) {
|
|
|
|
var params = {dir: dir};
|
|
|
|
if (view !== 'files') {
|
|
|
|
params.view = view;
|
|
|
|
}
|
|
|
|
OC.Util.History.pushState(params);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
OCA.Files.App = App;
|
|
|
|
})();
|
|
|
|
|
|
|
|
$(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
|
|
|
});
|
|
|
|
|