summaryrefslogtreecommitdiffstats
path: root/apps/files/js/app.js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-05-08 22:06:30 +0200
committerVincent Petry <pvince81@owncloud.com>2014-05-15 17:51:04 +0200
commit9d38e3602b2faf37d861729c52690ce51b8fee97 (patch)
tree5da63d26db4a4e8ec356dee45fc8f7804c6fe38a /apps/files/js/app.js
parentfb10bf4048aaf5b2a9665fc9dff217c790efe005 (diff)
downloadnextcloud-server-9d38e3602b2faf37d861729c52690ce51b8fee97.tar.gz
nextcloud-server-9d38e3602b2faf37d861729c52690ce51b8fee97.zip
Namespacing for FileList, FileActions and trashbin app
- FileList is now an instantiable class - FileActions is now in namespace - added App class for trashbin app - moved trashbin overrides into classes extending FileList - replaced many static calls with "this." or "self." to make the classes reusable/extendable - new URL parameter "view" to specify which view is shown, for example "files" or "trashbin" - added OC.Util.History utility class in core for handling history - moved URL handling/routing to OCA.Files.App - popstate will correctly update the current view and notify the view of the URL change so it can update the current dir - added JS unitt tests for the trashbin app - fixed public app to work with the new namespaces
Diffstat (limited to 'apps/files/js/app.js')
-rw-r--r--apps/files/js/app.js116
1 files changed, 109 insertions, 7 deletions
diff --git a/apps/files/js/app.js b/apps/files/js/app.js
index 87f7e2bb6ba..6cdb339b22d 100644
--- a/apps/files/js/app.js
+++ b/apps/files/js/app.js
@@ -11,15 +11,117 @@
*
*/
-if (!OCA.Files) {
- OCA.Files = {};
-}
+(function() {
-$(document).ready(function() {
- var nav = new OCA.Files.Navigation($('#app-navigation ul'));
+ if (!OCA.Files) {
+ OCA.Files = {};
+ }
+
+ var App = {
+ navigation: null,
+
+ initialize: function() {
+ this.navigation = new OCA.Files.Navigation($('#app-navigation'));
+
+ // TODO: ideally these should be in a separate class / app (the embedded "all files" app)
+ this.fileList = OCA.Files.FileList;
+ this.fileActions = OCA.Files.FileActions;
+ this.files = OCA.Files.Files;
+
+ this.fileList = new OCA.Files.FileList($('#app-content-files'));
+ this.files.initialize();
+ this.fileActions.registerDefaultActions(this.fileList);
+ this.fileList.setFileActions(this.fileActions);
+
+ // 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
+ this._onPopState(OC.Util.History.parseUrlQuery());
+ },
+
+ /**
+ * Returns the container of the currently visible app.
+ *
+ * @return app container
+ */
+ getCurrentAppContainer: function() {
+ return this.navigation.getActiveContainer();
+ },
- nav.setSelectedItem('files');
+ /**
+ * Setup events based on URL changes
+ */
+ _setupEvents: function() {
+ OC.Util.History.addOnPopStateHandler(_.bind(this._onPopState, this));
- // TODO: init file list, actions and others
+ // detect when app changed their current directory
+ $('#app-content>div').on('changeDirectory', _.bind(this._onDirectoryChanged, this));
+
+ $('#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);
+ }
+ },
+
+ /**
+ * Event handler for when the URL changed
+ */
+ _onPopState: function(params) {
+ params = _.extend({
+ dir: '/',
+ view: 'files'
+ }, params);
+ var lastId = this.navigation.getActiveItem();
+ 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() {
+ // wait for other apps/extensions to register their event handlers
+ // in the "ready" clause
+ _.defer(function() {
+ OCA.Files.App.initialize();
+ });
});