summaryrefslogtreecommitdiffstats
path: root/apps/files/js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2016-05-04 11:17:53 +0200
committerVincent Petry <pvince81@owncloud.com>2016-05-06 16:46:59 +0200
commitfdeafef6a08c45f8b45ab9fac303e3bffc3607b0 (patch)
treea96ca5a4bfeca3b5a2a330c125e7f6738f67b10a /apps/files/js
parent093e9dd4225e6681140523c75bfc20809cd6d651 (diff)
downloadnextcloud-server-fdeafef6a08c45f8b45ab9fac303e3bffc3607b0.tar.gz
nextcloud-server-fdeafef6a08c45f8b45ab9fac303e3bffc3607b0.zip
Auto-add fileid in URL for currently displayed folder
Diffstat (limited to 'apps/files/js')
-rw-r--r--apps/files/js/app.js24
-rw-r--r--apps/files/js/fileactions.js2
-rw-r--r--apps/files/js/filelist.js36
3 files changed, 49 insertions, 13 deletions
diff --git a/apps/files/js/app.js b/apps/files/js/app.js
index eac080a009d..60b5f1816ab 100644
--- a/apps/files/js/app.js
+++ b/apps/files/js/app.js
@@ -174,6 +174,7 @@
// detect when app changed their current directory
$('#app-content').delegate('>div', 'changeDirectory', _.bind(this._onDirectoryChanged, this));
+ $('#app-content').delegate('>div', 'afterChangeDirectory', _.bind(this._onAfterDirectoryChanged, this));
$('#app-content').delegate('>div', 'changeViewerMode', _.bind(this._onChangeViewerMode, this));
$('#app-navigation').on('itemChanged', _.bind(this._onNavigationChanged, this));
@@ -224,7 +225,16 @@
*/
_onDirectoryChanged: function(e) {
if (e.dir) {
- this._changeUrl(this.navigation.getActiveItem(), e.dir);
+ 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);
}
},
@@ -263,12 +273,20 @@
/**
* Change the URL to point to the given dir and view
*/
- _changeUrl: function(view, dir) {
+ _changeUrl: function(view, dir, fileId) {
var params = {dir: dir};
if (view !== 'files') {
params.view = view;
+ } 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
+ OC.Util.History.replaceState(params);
+ } else {
+ OC.Util.History.pushState(params);
}
- OC.Util.History.pushState(params);
}
};
})();
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index 69e32d500c4..c3d4fba9ef5 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -619,7 +619,7 @@
this.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
var dir = context.$file.attr('data-path') || context.fileList.getCurrentDirectory();
- context.fileList.changeDirectory(OC.joinPaths(dir, filename));
+ context.fileList.changeDirectory(OC.joinPaths(dir, filename), true, false, parseInt(context.$file.attr('data-id'), 10));
});
this.registerAction({
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 16ca5e91ed2..9395112bce3 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -1362,19 +1362,20 @@
return parseInt(this.$el.find('#permissions').val(), 10);
},
/**
- * @brief Changes the current directory and reload the file list.
- * @param targetDir target directory (non URL encoded)
- * @param changeUrl false if the URL must not be changed (defaults to true)
- * @param {boolean} force set to true to force changing directory
+ * Changes the current directory and reload the file list.
+ * @param {string} targetDir target directory (non URL encoded)
+ * @param {boolean} [changeUrl=true] if the URL must not be changed (defaults to true)
+ * @param {boolean} [force=false] set to true to force changing directory
+ * @param {string} [fileId] optional file id, if known, to be appended in the URL
*/
- changeDirectory: function(targetDir, changeUrl, force) {
+ changeDirectory: function(targetDir, changeUrl, force, fileId) {
var self = this;
var currentDir = this.getCurrentDirectory();
targetDir = targetDir || '/';
if (!force && currentDir === targetDir) {
return;
}
- this._setCurrentDir(targetDir, changeUrl);
+ this._setCurrentDir(targetDir, changeUrl, fileId);
this.reload().then(function(success){
if (!success) {
self.changeDirectory(currentDir, true);
@@ -1389,8 +1390,9 @@
* Sets the current directory name and updates the breadcrumb.
* @param targetDir directory to display
* @param changeUrl true to also update the URL, false otherwise (default)
+ * @param {string} [fileId] file id
*/
- _setCurrentDir: function(targetDir, changeUrl) {
+ _setCurrentDir: function(targetDir, changeUrl, fileId) {
targetDir = targetDir.replace(/\\/g, '/');
var previousDir = this.getCurrentDirectory(),
baseDir = OC.basename(targetDir);
@@ -1408,10 +1410,14 @@
this.$el.find('#dir').val(targetDir);
if (changeUrl !== false) {
- this.$el.trigger(jQuery.Event('changeDirectory', {
+ var params = {
dir: targetDir,
previousDir: previousDir
- }));
+ };
+ if (fileId) {
+ params.fileId = fileId;
+ }
+ this.$el.trigger(jQuery.Event('changeDirectory', params));
}
this.breadcrumb.setDirectory(this.getCurrentDirectory());
},
@@ -1557,6 +1563,18 @@
result.sort(this._sortComparator);
this.setFiles(result);
+
+ if (this.dirInfo) {
+ var newFileId = this.dirInfo.id;
+ // update fileid in URL
+ var params = {
+ dir: this.getCurrentDirectory()
+ };
+ if (newFileId) {
+ params.fileId = newFileId;
+ }
+ this.$el.trigger(jQuery.Event('afterChangeDirectory', params));
+ }
return true;
},