aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/js
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files/js')
-rw-r--r--apps/files/js/app.js25
-rw-r--r--apps/files/js/breadcrumb.js28
-rw-r--r--apps/files/js/file-upload.js2
-rw-r--r--apps/files/js/fileactions.js43
-rw-r--r--apps/files/js/filelist.js163
-rw-r--r--apps/files/js/files.js7
-rw-r--r--apps/files/js/filesummary.js7
-rw-r--r--apps/files/js/navigation.js11
-rw-r--r--apps/files/js/upload.js1
9 files changed, 230 insertions, 57 deletions
diff --git a/apps/files/js/app.js b/apps/files/js/app.js
index 89098e3a8a3..ee5330485e7 100644
--- a/apps/files/js/app.js
+++ b/apps/files/js/app.js
@@ -15,12 +15,34 @@
(function() {
if (!OCA.Files) {
+ /**
+ * Namespace for the files app
+ * @namespace OCA.Files
+ */
OCA.Files = {};
}
- var App = {
+ /**
+ * @namespace OCA.Files.App
+ */
+ OCA.Files.App = {
+ /**
+ * Navigation control
+ *
+ * @member {OCA.Files.Navigation}
+ */
navigation: null,
+ /**
+ * File list for the "All files" section.
+ *
+ * @member {OCA.Files.FileList}
+ */
+ fileList: null,
+
+ /**
+ * Initializes the files app
+ */
initialize: function() {
this.navigation = new OCA.Files.Navigation($('#app-navigation'));
@@ -191,7 +213,6 @@
OC.Util.History.pushState(params);
}
};
- OCA.Files.App = App;
})();
$(document).ready(function() {
diff --git a/apps/files/js/breadcrumb.js b/apps/files/js/breadcrumb.js
index 8df9b7ee6fe..af4e48c8f8c 100644
--- a/apps/files/js/breadcrumb.js
+++ b/apps/files/js/breadcrumb.js
@@ -19,10 +19,17 @@
*
*/
-/* global OC */
(function() {
/**
- * Creates an breadcrumb element in the given container
+ * @class BreadCrumb
+ * @memberof OCA.Files
+ * @classdesc Breadcrumbs that represent the current path.
+ *
+ * @param {Object} [options] options
+ * @param {Function} [options.onClick] click event handler
+ * @param {Function} [options.onDrop] drop event handler
+ * @param {Function} [options.getCrumbUrl] callback that returns
+ * the URL of a given breadcrumb
*/
var BreadCrumb = function(options){
this.$el = $('<div class="breadcrumb"></div>');
@@ -37,12 +44,17 @@
this.getCrumbUrl = options.getCrumbUrl;
}
};
+ /**
+ * @memberof OCA.Files
+ */
BreadCrumb.prototype = {
$el: null,
dir: null,
/**
* Total width of all breadcrumbs
+ * @type int
+ * @private
*/
totalWidth: 0,
breadcrumbs: [],
@@ -64,8 +76,9 @@
/**
* Returns the full URL to the given directory
- * @param part crumb data as map
- * @param index crumb index
+ *
+ * @param {Object.<String, String>} part crumb data as map
+ * @param {int} index crumb index
* @return full URL
*/
getCrumbUrl: function(part, index) {
@@ -121,8 +134,9 @@
/**
* Makes a breadcrumb structure based on the given path
- * @param dir path to split into a breadcrumb structure
- * @return array of map {dir: path, name: displayName}
+ *
+ * @param {String} dir path to split into a breadcrumb structure
+ * @return {Object.<String, String>} map of {dir: path, name: displayName}
*/
_makeCrumbs: function(dir) {
var crumbs = [];
@@ -166,6 +180,8 @@
/**
* Show/hide breadcrumbs to fit the given width
+ *
+ * @param {int} availableWidth available width
*/
setMaxWidth: function (availableWidth) {
if (this.availableWidth !== availableWidth) {
diff --git a/apps/files/js/file-upload.js b/apps/files/js/file-upload.js
index 460c2435642..ab450dc5cac 100644
--- a/apps/files/js/file-upload.js
+++ b/apps/files/js/file-upload.js
@@ -49,7 +49,7 @@ function supportAjaxUploadWithProgress() {
/**
* keeps track of uploads in progress and implements callbacks for the conflicts dialog
- * @type {OC.Upload}
+ * @namespace
*/
OC.Upload = {
_uploads: [],
diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index 8ae0d8f1b2e..5bf1618b0b8 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -13,11 +13,14 @@
/**
* Construct a new FileActions instance
+ * @constructs FileActions
+ * @memberof OCA.Files
*/
var FileActions = function() {
this.initialize();
- }
+ };
FileActions.prototype = {
+ /** @lends FileActions.prototype */
actions: {},
defaults: {},
icons: {},
@@ -31,9 +34,14 @@
/**
* List of handlers to be notified whenever a register() or
* setDefault() was called.
+ *
+ * @member {Function[]}
*/
_updateListeners: {},
+ /**
+ * @private
+ */
initialize: function() {
this.clear();
// abusing jquery for events until we get a real event lib
@@ -45,7 +53,7 @@
* Adds an event handler
*
* @param {String} eventName event name
- * @param Function callback
+ * @param {Function} callback
*/
on: function(eventName, callback) {
this.$el.on(eventName, callback);
@@ -75,7 +83,7 @@
* Merges the actions from the given fileActions into
* this instance.
*
- * @param fileActions instance of OCA.Files.FileActions
+ * @param {OCA.Files.FileActions} fileActions instance of OCA.Files.FileActions
*/
merge: function(fileActions) {
var self = this;
@@ -113,8 +121,9 @@
* to the name given in action.name
* @param {String} action.mime mime type
* @param {int} action.permissions permissions
- * @param {(Function|String)} action.icon icon
- * @param {Function} action.actionHandler function that performs the action
+ * @param {(Function|String)} action.icon icon path to the icon or function
+ * that returns it
+ * @param {OCA.Files.FileActions~actionHandler} action.actionHandler action handler function
*/
registerAction: function (action) {
var mime = action.mime;
@@ -130,6 +139,9 @@
this.icons[name] = action.icon;
this._notifyUpdateListeners('registerAction', {action: action});
},
+ /**
+ * Clears all registered file actions.
+ */
clear: function() {
this.actions = {};
this.defaults = {};
@@ -137,6 +149,12 @@
this.currentFile = null;
this._updateListeners = [];
},
+ /**
+ * Sets the default action for a given mime type.
+ *
+ * @param {String} mime mime type
+ * @param {String} name action name
+ */
setDefault: function (mime, name) {
this.defaults[mime] = name;
this._notifyUpdateListeners('setDefault', {defaultAction: {mime: mime, name: name}});
@@ -261,7 +279,7 @@
}
var html = '<a href="#" class="action action-' + name.toLowerCase() + '" data-action="' + name + '">';
if (img) {
- html += '<img class ="svg" src="' + img + '" />';
+ html += '<img class ="svg" alt="" src="' + img + '" />';
}
html += '<span> ' + actionText + '</span></a>';
@@ -370,6 +388,18 @@
OCA.Files.FileActions = FileActions;
+ /**
+ * Action handler function for file actions
+ *
+ * @callback OCA.Files.FileActions~actionHandler
+ * @param {String} fileName name of the clicked file
+ * @param context context
+ * @param {String} context.dir directory of the file
+ * @param context.$file jQuery element of the file
+ * @param {OCA.Files.FileList} context.fileList the FileList instance on which the action occurred
+ * @param {OCA.Files.FileActions} context.fileActions the FileActions instance on which the action occurred
+ */
+
// global file actions to be used by all lists
OCA.Files.fileActions = new OCA.Files.FileActions();
OCA.Files.legacyFileActions = new OCA.Files.FileActions();
@@ -380,6 +410,7 @@
// their actions on. Since legacy apps are very likely to break with other
// FileList views than the main one ("All files"), actions registered
// through window.FileActions will be limited to the main file list.
+ // @deprecated use OCA.Files.FileActions instead
window.FileActions = OCA.Files.legacyFileActions;
window.FileActions.register = function (mime, name, permissions, icon, action, displayName) {
console.warn('FileActions.register() is deprecated, please use OCA.Files.fileActions.register() instead', arguments);
diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js
index 86cba29e76c..6ffc10cdcbd 100644
--- a/apps/files/js/filelist.js
+++ b/apps/files/js/filelist.js
@@ -10,13 +10,26 @@
(function() {
/**
+ * @class OCA.Files.FileList
+ * @classdesc
+ *
* The FileList class manages a file list view.
* A file list view consists of a controls bar and
* a file list table.
+ *
+ * @param $el container element with existing markup for the #controls
+ * and a table
+ * @param [options] map of options, see other parameters
+ * @param [options.scrollContainer] scrollable container, defaults to $(window)
+ * @param [options.dragOptions] drag options, disabled by default
+ * @param [options.folderDropOptions] folder drop options, disabled by default
*/
var FileList = function($el, options) {
this.initialize($el, options);
};
+ /**
+ * @memberof OCA.Files
+ */
FileList.prototype = {
SORT_INDICATOR_ASC_CLASS: 'icon-triangle-n',
SORT_INDICATOR_DESC_CLASS: 'icon-triangle-s',
@@ -41,51 +54,72 @@
*/
$fileList: null,
+ /**
+ * @type OCA.Files.BreadCrumb
+ */
breadcrumb: null,
/**
- * Instance of FileSummary
+ * @type OCA.Files.FileSummary
*/
fileSummary: null,
+
+ /**
+ * Whether the file list was initialized already.
+ * @type boolean
+ */
initialized: false,
- // number of files per page
- pageSize: 20,
+ /**
+ * Number of files per page
+ *
+ * @return {int} page size
+ */
+ pageSize: function() {
+ return Math.ceil(this.$container.height() / 50);
+ },
/**
* Array of files in the current folder.
* The entries are of file data.
+ *
+ * @type Array.<Object>
*/
files: [],
/**
* File actions handler, defaults to OCA.Files.FileActions
+ * @type OCA.Files.FileActions
*/
fileActions: null,
/**
* Map of file id to file data
+ * @type Object.<int, Object>
*/
_selectedFiles: {},
/**
* Summary of selected files.
- * Instance of FileSummary.
+ * @type OCA.Files.FileSummary
*/
_selectionSummary: null,
/**
* Sort attribute
+ * @type String
*/
_sort: 'name',
/**
* Sort direction: 'asc' or 'desc'
+ * @type String
*/
_sortDirection: 'asc',
/**
* Sort comparator function for the current sort
+ * @type Function
*/
_sortComparator: null,
@@ -98,6 +132,7 @@
/**
* Current directory
+ * @type String
*/
_currentDirectory: null,
@@ -114,6 +149,7 @@
* @param options.dragOptions drag options, disabled by default
* @param options.folderDropOptions folder drop options, disabled by default
* @param options.scrollTo name of file to scroll to after the first load
+ * @private
*/
initialize: function($el, options) {
var self = this;
@@ -190,6 +226,11 @@
this.fileActions.off('setDefault', this._onFileActionsUpdated);
},
+ /**
+ * Initializes the file actions, set up listeners.
+ *
+ * @param {OCA.Files.FileActions} fileActions file actions
+ */
_initFileActions: function(fileActions) {
this.fileActions = fileActions;
if (!this.fileActions) {
@@ -485,7 +526,8 @@
mimetype: $el.attr('data-mime'),
type: $el.attr('data-type'),
size: parseInt($el.attr('data-size'), 10),
- etag: $el.attr('data-etag')
+ etag: $el.attr('data-etag'),
+ permissions: parseInt($el.attr('data-permissions'), 10)
};
},
@@ -496,7 +538,7 @@
*/
_nextPage: function(animate) {
var index = this.$fileList.children().length,
- count = this.pageSize,
+ count = this.pageSize(),
tr,
fileData,
newTrs = [],
@@ -586,8 +628,8 @@
},
/**
* Creates a new table row element using the given file data.
- * @param fileData map of file attributes
- * @param options map of attribute "loading" whether the entry is currently loading
+ * @param {OCA.Files.FileInfo} fileData file info attributes
+ * @param options map of attributes
* @return new tr element (not appended to the table)
*/
_createRow: function(fileData, options) {
@@ -726,12 +768,14 @@
* Adds an entry to the files array and also into the DOM
* in a sorted manner.
*
- * @param fileData map of file attributes
- * @param options map of attributes:
- * @param options.updateSummary true to update the summary after adding (default), false otherwise
- * @param options.silent true to prevent firing events like "fileActionsReady"
- * @param options.animate true to animate preview loading (defaults to true here)
- * @param options.scrollTo true to automatically scroll to the file's location
+ * @param {OCA.Files.FileInfo} fileData map of file attributes
+ * @param {Object} [options] map of attributes
+ * @param {boolean} [options.updateSummary] true to update the summary
+ * after adding (default), false otherwise. Defaults to true.
+ * @param {boolean} [options.silent] true to prevent firing events like "fileActionsReady",
+ * defaults to false.
+ * @param {boolean} [options.animate] true to animate the thumbnail image after load
+ * defaults to true.
* @return new tr element (not appended to the table)
*/
add: function(fileData, options) {
@@ -797,11 +841,13 @@
* Creates a new row element based on the given attributes
* and returns it.
*
- * @param fileData map of file attributes
- * @param options map of attributes:
- * - "index" optional index at which to insert the element
- * - "updateSummary" true to update the summary after adding (default), false otherwise
- * - "animate" true to animate the preview rendering
+ * @param {OCA.Files.FileInfo} fileData map of file attributes
+ * @param {Object} [options] map of attributes
+ * @param {int} [options.index] index at which to insert the element
+ * @param {boolean} [options.updateSummary] true to update the summary
+ * after adding (default), false otherwise. Defaults to true.
+ * @param {boolean} [options.animate] true to animate the thumbnail image after load
+ * defaults to true.
* @return new tr element (not appended to the table)
*/
_renderRow: function(fileData, options) {
@@ -868,6 +914,7 @@
},
/**
* Returns the current directory
+ * @method getCurrentDirectory
* @return current directory
*/
getCurrentDirectory: function(){
@@ -1049,7 +1096,10 @@
/**
* Generates a preview URL based on the URL space.
- * @param urlSpec map with {x: width, y: height, file: file path}
+ * @param urlSpec attributes for the URL
+ * @param {int} urlSpec.x width
+ * @param {int} urlSpec.y height
+ * @param {String} urlSpec.file path to the file
* @return preview URL
*/
generatePreviewUrl: function(urlSpec) {
@@ -1156,8 +1206,9 @@
/**
* Removes a file entry from the list
* @param name name of the file to remove
- * @param options optional options as map:
- * "updateSummary": true to update the summary (default), false otherwise
+ * @param {Object} [options] map of attributes
+ * @param {boolean} [options.updateSummary] true to update the summary
+ * after removing, false otherwise. Defaults to true.
* @return deleted element
*/
remove: function(name, options){
@@ -1189,7 +1240,7 @@
// if there are less elements visible than one page
// but there are still pending elements in the array,
// then directly append the next page
- if (lastIndex < this.files.length && lastIndex < this.pageSize) {
+ if (lastIndex < this.files.length && lastIndex < this.pageSize()) {
this._nextPage(true);
}
@@ -1199,6 +1250,8 @@
* Finds the index of the row before which the given
* fileData should be inserted, considering the current
* sorting
+ *
+ * @param {OCA.Files.FileInfo} fileData file info
*/
_findInsertionIndex: function(fileData) {
var index = 0;
@@ -1513,7 +1566,7 @@
/**
* Shows the loading mask.
*
- * @see #hideMask
+ * @see OCA.Files.FileList#hideMask
*/
showMask: function() {
// in case one was shown before
@@ -1534,7 +1587,7 @@
},
/**
* Hide the loading mask.
- * @see #showMask
+ * @see OCA.Files.FileList#showMask
*/
hideMask: function() {
this.$el.find('.mask').remove();
@@ -1584,7 +1637,7 @@
this.$el.find('.selectedActions').addClass('hidden');
}
else {
- canDelete = (this.getDirectoryPermissions() & OC.PERMISSION_DELETE);
+ canDelete = (this.getDirectoryPermissions() & OC.PERMISSION_DELETE) && this.isSelectedDeletable();
this.$el.find('.selectedActions').removeClass('hidden');
this.$el.find('#headerSize a>span:first').text(OC.Util.humanFileSize(summary.totalSize));
var selection = '';
@@ -1605,6 +1658,15 @@
},
/**
+ * Check whether all selected files are deletable
+ */
+ isSelectedDeletable: function() {
+ return _.reduce(this.getSelectedFiles(), function(deletable, file) {
+ return deletable && (file.permissions & OC.PERMISSION_DELETE);
+ }, true);
+ },
+
+ /**
* Returns whether all files are selected
* @return true if all files are selected, false otherwise
*/
@@ -1919,7 +1981,13 @@
// Animation
var _this = this;
- this.$container.animate({
+ var $scrollContainer = this.$container;
+ if ($scrollContainer[0] === window) {
+ // need to use "body" to animate scrolling
+ // when the scroll container is the window
+ $scrollContainer = $('body');
+ }
+ $scrollContainer.animate({
// Scrolling to the top of the new element
scrollTop: currentOffset + $fileRow.offset().top - $fileRow.height() * 2 - additionalOffset
}, {
@@ -1953,15 +2021,17 @@
/**
* Sort comparators.
+ * @namespace OCA.Files.FileList.Comparators
+ * @private
*/
FileList.Comparators = {
/**
* Compares two file infos by name, making directories appear
* first.
*
- * @param fileInfo1 file info
- * @param fileInfo2 file info
- * @return -1 if the first file must appear before the second one,
+ * @param {OCA.Files.FileInfo} fileInfo1 file info
+ * @param {OCA.Files.FileInfo} fileInfo2 file info
+ * @return {int} -1 if the first file must appear before the second one,
* 0 if they are identify, 1 otherwise.
*/
name: function(fileInfo1, fileInfo2) {
@@ -1976,9 +2046,9 @@
/**
* Compares two file infos by size.
*
- * @param fileInfo1 file info
- * @param fileInfo2 file info
- * @return -1 if the first file must appear before the second one,
+ * @param {OCA.Files.FileInfo} fileInfo1 file info
+ * @param {OCA.Files.FileInfo} fileInfo2 file info
+ * @return {int} -1 if the first file must appear before the second one,
* 0 if they are identify, 1 otherwise.
*/
size: function(fileInfo1, fileInfo2) {
@@ -1987,9 +2057,9 @@
/**
* Compares two file infos by timestamp.
*
- * @param fileInfo1 file info
- * @param fileInfo2 file info
- * @return -1 if the first file must appear before the second one,
+ * @param {OCA.Files.FileInfo} fileInfo1 file info
+ * @param {OCA.Files.FileInfo} fileInfo2 file info
+ * @return {int} -1 if the first file must appear before the second one,
* 0 if they are identify, 1 otherwise.
*/
mtime: function(fileInfo1, fileInfo2) {
@@ -1997,6 +2067,27 @@
}
};
+ /**
+ * File info attributes.
+ *
+ * @todo make this a real class in the future
+ * @typedef {Object} OCA.Files.FileInfo
+ *
+ * @property {int} id file id
+ * @property {String} name file name
+ * @property {String} [path] file path, defaults to the list's current path
+ * @property {String} mimetype mime type
+ * @property {String} type "file" for files or "dir" for directories
+ * @property {int} permissions file permissions
+ * @property {int} mtime modification time in milliseconds
+ * @property {boolean} [isShareMountPoint] whether the file is a share mount
+ * point
+ * @property {boolean} [isPreviewAvailable] whether a preview is available
+ * for the given file type
+ * @property {String} [icon] path to the mime type icon
+ * @property {String} etag etag of the file
+ */
+
OCA.Files.FileList = FileList;
})();
diff --git a/apps/files/js/files.js b/apps/files/js/files.js
index 5fcf99d24af..b11ef03eab2 100644
--- a/apps/files/js/files.js
+++ b/apps/files/js/files.js
@@ -195,7 +195,10 @@
/**
* Generates a preview URL based on the URL space.
- * @param urlSpec map with {x: width, y: height, file: file path}
+ * @param urlSpec attributes for the URL
+ * @param {int} urlSpec.x width
+ * @param {int} urlSpec.y height
+ * @param {String} urlSpec.file path to the file
* @return preview URL
* @deprecated used OCA.Files.FileList.generatePreviewUrl instead
*/
@@ -350,7 +353,7 @@ var createDragShadow = function(event) {
}
// do not show drag shadow for too many files
- var selectedFiles = _.first(FileList.getSelectedFiles(), FileList.pageSize);
+ var selectedFiles = _.first(FileList.getSelectedFiles(), FileList.pageSize());
selectedFiles = _.sortBy(selectedFiles, FileList._fileInfoCompare);
if (!isDragSelected && selectedFiles.length === 1) {
diff --git a/apps/files/js/filesummary.js b/apps/files/js/filesummary.js
index ca70259335c..f83eb54678b 100644
--- a/apps/files/js/filesummary.js
+++ b/apps/files/js/filesummary.js
@@ -19,14 +19,15 @@
*
*/
-/* global OC, n, t */
-
(function() {
/**
* The FileSummary class encapsulates the file summary values and
* the logic to render it in the given container
+ *
+ * @constructs FileSummary
+ * @memberof OCA.Files
+ *
* @param $tr table row element
- * $param summary optional initial summary value
*/
var FileSummary = function($tr) {
this.$el = $tr;
diff --git a/apps/files/js/navigation.js b/apps/files/js/navigation.js
index b959e016e8c..be385f21f50 100644
--- a/apps/files/js/navigation.js
+++ b/apps/files/js/navigation.js
@@ -13,10 +13,19 @@
(function() {
+ /**
+ * @class OCA.Files.Navigation
+ * @classdesc Navigation control for the files app sidebar.
+ *
+ * @param $el element containing the navigation
+ */
var Navigation = function($el) {
this.initialize($el);
};
+ /**
+ * @memberof OCA.Files
+ */
Navigation.prototype = {
/**
@@ -31,6 +40,8 @@
/**
* Initializes the navigation from the given container
+ *
+ * @private
* @param $el element containing the navigation
*/
initialize: function($el) {
diff --git a/apps/files/js/upload.js b/apps/files/js/upload.js
index 617cf4b1c1d..518608615e0 100644
--- a/apps/files/js/upload.js
+++ b/apps/files/js/upload.js
@@ -8,7 +8,6 @@
*
*/
-/* global OC */
function Upload(fileSelector) {
if ($.support.xhrFileUpload) {
return new XHRUpload(fileSelector.target.files);