gotoplugin.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
  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. (function (OCA) {
  11. OCA.Files = OCA.Files || {};
  12. /**
  13. * @namespace OCA.Files.GotoPlugin
  14. *
  15. */
  16. OCA.Files.GotoPlugin = {
  17. name: 'Goto',
  18. disallowedLists: [
  19. 'files',
  20. 'trashbin'
  21. ],
  22. attach: function (fileList) {
  23. if (this.disallowedLists.indexOf(fileList.id) !== -1) {
  24. return;
  25. }
  26. // lists where the "Open" default action is disabled should
  27. // also have the goto action disabled
  28. if (fileList._defaultFileActionsDisabled) {
  29. return
  30. }
  31. var fileActions = fileList.fileActions;
  32. fileActions.registerAction({
  33. name: 'Goto',
  34. displayName: t('files', 'View in folder'),
  35. mime: 'all',
  36. permissions: OC.PERMISSION_ALL,
  37. iconClass: 'icon-goto nav-icon-extstoragemounts',
  38. type: OCA.Files.FileActions.TYPE_DROPDOWN,
  39. actionHandler: function (fileName, context) {
  40. var fileModel = context.fileInfoModel;
  41. OCA.Files.Sidebar.close();
  42. OCA.Files.App.setActiveView('files', { silent: true });
  43. OCA.Files.App.fileList.changeDirectory(fileModel.get('path'), true, true).then(function() {
  44. OCA.Files.App.fileList.scrollTo(fileModel.get('name'));
  45. });
  46. },
  47. render: function (actionSpec, isDefault, context) {
  48. return fileActions._defaultRenderAction.call(fileActions, actionSpec, isDefault, context)
  49. .removeClass('permanent');
  50. }
  51. });
  52. }
  53. };
  54. })(OCA);
  55. OC.Plugins.register('OCA.Files.FileList', OCA.Files.GotoPlugin);