aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_external/js
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-06-06 13:16:47 +0200
committerVincent Petry <pvince81@owncloud.com>2014-06-06 15:06:26 +0200
commit01c2c3107a8370fc57dc6144dcdcc108a92347a9 (patch)
tree725548f12f0906942aaaf6b1154546c7936fee5f /apps/files_external/js
parent933c05566e21c27e4f2d4b4e9c2d54e7b363d304 (diff)
downloadnextcloud-server-01c2c3107a8370fc57dc6144dcdcc108a92347a9.tar.gz
nextcloud-server-01c2c3107a8370fc57dc6144dcdcc108a92347a9.zip
Added external storage list in files app
Diffstat (limited to 'apps/files_external/js')
-rw-r--r--apps/files_external/js/app.js71
-rw-r--r--apps/files_external/js/mountsfilelist.js116
2 files changed, 187 insertions, 0 deletions
diff --git a/apps/files_external/js/app.js b/apps/files_external/js/app.js
new file mode 100644
index 00000000000..58ad1a0f6ef
--- /dev/null
+++ b/apps/files_external/js/app.js
@@ -0,0 +1,71 @@
+/*
+ * Copyright (c) 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.
+ *
+ */
+
+if (!OCA.External) {
+ OCA.External = {};
+}
+OCA.External.App = {
+
+ fileList: null,
+
+ initList: function($el) {
+ if (this.fileList) {
+ return this.fileList;
+ }
+
+ this.fileList = new OCA.External.FileList(
+ $el,
+ {
+ scrollContainer: $('#app-content'),
+ fileActions: this._createFileActions()
+ }
+ );
+
+ this._extendFileList(this.fileList);
+ this.fileList.appName = t('files_external', 'External storage');
+ return this.fileList;
+ },
+
+ removeList: function() {
+ if (this.fileList) {
+ this.fileList.$fileList.empty();
+ }
+ },
+
+ _createFileActions: function() {
+ // inherit file actions from the files app
+ var fileActions = new OCA.Files.FileActions();
+ fileActions.registerDefaultActions();
+
+ // when the user clicks on a folder, redirect to the corresponding
+ // folder in the files app instead of opening it directly
+ fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
+ OCA.Files.App.setActiveView('files', {silent: true});
+ OCA.Files.App.fileList.changeDirectory(context.$file.attr('data-path') + '/' + filename, true, true);
+ });
+ fileActions.setDefault('dir', 'Open');
+ return fileActions;
+ },
+
+ _extendFileList: function(fileList) {
+ // remove size column from summary
+ fileList.fileSummary.$el.find('.filesize').remove();
+ }
+};
+
+$(document).ready(function() {
+ $('#app-content-extstoragemounts').on('show', function(e) {
+ OCA.External.App.initList($(e.target));
+ });
+ $('#app-content-extstoragemounts').on('hide', function() {
+ OCA.External.App.removeList();
+ });
+});
+
diff --git a/apps/files_external/js/mountsfilelist.js b/apps/files_external/js/mountsfilelist.js
new file mode 100644
index 00000000000..52a9aff728c
--- /dev/null
+++ b/apps/files_external/js/mountsfilelist.js
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 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.
+ *
+ */
+(function() {
+
+ /**
+ * External storage file list
+ */
+ var FileList = function($el, options) {
+ this.initialize($el, options);
+ };
+
+ FileList.prototype = _.extend({}, OCA.Files.FileList.prototype, {
+ appName: 'External storage',
+
+ initialize: function($el, options) {
+ OCA.Files.FileList.prototype.initialize.apply(this, arguments);
+ if (this.initialized) {
+ return;
+ }
+ },
+
+ _createRow: function(fileData) {
+ // TODO: hook earlier and render the whole row here
+ var $tr = OCA.Files.FileList.prototype._createRow.apply(this, arguments);
+ $tr.find('.filesize,.date').remove();
+ $tr.find('td.filename').after('<td></td>');
+ $tr.find('td.filename input:checkbox').remove();
+ return $tr;
+ },
+
+ updateEmptyContent: function() {
+ var dir = this.getCurrentDirectory();
+ if (dir === '/') {
+ // root has special permissions
+ this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty);
+ this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty);
+ }
+ else {
+ OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments);
+ }
+ },
+
+ getDirectoryPermissions: function() {
+ return OC.PERMISSION_READ | OC.PERMISSION_DELETE;
+ },
+
+ updateStorageStatistics: function() {
+ // no op because it doesn't have
+ // storage info like free space / used space
+ },
+
+ reload: function() {
+ var self = this;
+ this.showMask();
+ if (this._reloadCall) {
+ this._reloadCall.abort();
+ }
+ this._reloadCall = $.ajax({
+ url: OC.linkToOCS('apps/files_external/api/v1') + 'mounts',
+ data: {
+ format: 'json'
+ },
+ type: 'GET',
+ beforeSend: function(xhr) {
+ xhr.setRequestHeader('OCS-APIREQUEST', 'true');
+ },
+ error: function(result) {
+ self.reloadCallback(result);
+ },
+ success: function(result) {
+ self.reloadCallback(result);
+ }
+ });
+ },
+
+ reloadCallback: function(result) {
+ delete this._reloadCall;
+ this.hideMask();
+
+ if (result.ocs && result.ocs.data) {
+ this.setFiles(this._makeFiles(result.ocs.data));
+ }
+ else {
+ // TODO: error handling
+ }
+ },
+
+ /**
+ * Converts the OCS API response data to a file info
+ * list
+ * @param OCS API mounts array
+ * @return array of file info maps
+ */
+ _makeFiles: function(data) {
+ var files = _.chain(data)
+ .map(function(fileData) {
+ fileData.icon = OC.imagePath('core', 'filetypes/folder-external');
+ return fileData;
+ })
+ // Sort by expected sort comparator
+ .sortBy(this._sortComparator)
+ .value();
+
+ return files;
+ }
+ });
+
+ OCA.External.FileList = FileList;
+})();