|
| 1 | +/* |
| 2 | + * Copyright (c) 2014 Vincent Petry <[email protected]> |
| 3 | + * |
| 4 | + * This file is licensed under the Affero General Public License version 3 |
| 5 | + * or later. |
| 6 | + * |
| 7 | + * See the COPYING-README file. |
| 8 | + * |
| 9 | + */ |
| 10 | + |
| 11 | +(function (OCA) { |
| 12 | + /** |
| 13 | + * @namespace OCA.Files.RecentPlugin |
| 14 | + * |
| 15 | + * Registers the recent file list from the files app sidebar. |
| 16 | + */ |
| 17 | + OCA.Files.RecentPlugin = { |
| 18 | + name: 'Recent', |
| 19 | + |
| 20 | + /** |
| 21 | + * @type OCA.Files.RecentFileList |
| 22 | + */ |
| 23 | + recentFileList: null, |
| 24 | + |
| 25 | + attach: function () { |
| 26 | + var self = this; |
| 27 | + $('#app-content-recent').on('show.plugin-recent', function (e) { |
| 28 | + self.showFileList($(e.target)); |
| 29 | + }); |
| 30 | + $('#app-content-recent').on('hide.plugin-recent', function () { |
| 31 | + self.hideFileList(); |
| 32 | + }); |
| 33 | + }, |
| 34 | + |
| 35 | + detach: function () { |
| 36 | + if (this.recentFileList) { |
| 37 | + this.recentFileList.destroy(); |
| 38 | + OCA.Files.fileActions.off('setDefault.plugin-recent', this._onActionsUpdated); |
| 39 | + OCA.Files.fileActions.off('registerAction.plugin-recent', this._onActionsUpdated); |
| 40 | + $('#app-content-recent').off('.plugin-recent'); |
| 41 | + this.recentFileList = null; |
| 42 | + } |
| 43 | + }, |
| 44 | + |
| 45 | + showFileList: function ($el) { |
| 46 | + if (!this.recentFileList) { |
| 47 | + this.recentFileList = this._createRecentFileList($el); |
| 48 | + } |
| 49 | + return this.recentFileList; |
| 50 | + }, |
| 51 | + |
| 52 | + hideFileList: function () { |
| 53 | + if (this.recentFileList) { |
| 54 | + this.recentFileList.$fileList.empty(); |
| 55 | + } |
| 56 | + }, |
| 57 | + |
| 58 | + /** |
| 59 | + * Creates the recent file list. |
| 60 | + * |
| 61 | + * @param $el container for the file list |
| 62 | + * @return {OCA.Files.RecentFileList} file list |
| 63 | + */ |
| 64 | + _createRecentFileList: function ($el) { |
| 65 | + var fileActions = this._createFileActions(); |
| 66 | + // register recent list for sidebar section |
| 67 | + return new OCA.Files.RecentFileList( |
| 68 | + $el, { |
| 69 | + fileActions: fileActions, |
| 70 | + scrollContainer: $('#app-content') |
| 71 | + } |
| 72 | + ); |
| 73 | + }, |
| 74 | + |
| 75 | + _createFileActions: function () { |
| 76 | + // inherit file actions from the files app |
| 77 | + var fileActions = new OCA.Files.FileActions(); |
| 78 | + // note: not merging the legacy actions because legacy apps are not |
| 79 | + // compatible with the sharing overview and need to be adapted first |
| 80 | + fileActions.registerDefaultActions(); |
| 81 | + fileActions.merge(OCA.Files.fileActions); |
| 82 | + |
| 83 | + if (!this._globalActionsInitialized) { |
| 84 | + // in case actions are registered later |
| 85 | + this._onActionsUpdated = _.bind(this._onActionsUpdated, this); |
| 86 | + OCA.Files.fileActions.on('setDefault.plugin-recent', this._onActionsUpdated); |
| 87 | + OCA.Files.fileActions.on('registerAction.plugin-recent', this._onActionsUpdated); |
| 88 | + this._globalActionsInitialized = true; |
| 89 | + } |
| 90 | + |
| 91 | + // when the user clicks on a folder, redirect to the corresponding |
| 92 | + // folder in the files app instead of opening it directly |
| 93 | + fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) { |
| 94 | + OCA.Files.App.setActiveView('files', {silent: true}); |
| 95 | + var path = OC.joinPaths(context.$file.attr('data-path'), filename); |
| 96 | + OCA.Files.App.fileList.changeDirectory(path, true, true); |
| 97 | + }); |
| 98 | + fileActions.setDefault('dir', 'Open'); |
| 99 | + return fileActions; |
| 100 | + }, |
| 101 | + |
| 102 | + _onActionsUpdated: function (ev) { |
| 103 | + if (ev.action) { |
| 104 | + this.recentFileList.fileActions.registerAction(ev.action); |
| 105 | + } else if (ev.defaultAction) { |
| 106 | + this.recentFileList.fileActions.setDefault( |
| 107 | + ev.defaultAction.mime, |
| 108 | + ev.defaultAction.name |
| 109 | + ); |
| 110 | + } |
| 111 | + } |
| 112 | + }; |
| 113 | + |
| 114 | +})(OCA); |
| 115 | + |
| 116 | +OC.Plugins.register('OCA.Files.App', OCA.Files.RecentPlugin); |
| 117 | + |
0 commit comments