app.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /**
  2. * Copyright (c) 2014
  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. * @namespace OCA.Trashbin
  12. */
  13. OCA.Trashbin = {}
  14. /**
  15. * @namespace OCA.Trashbin.App
  16. */
  17. OCA.Trashbin.App = {
  18. _initialized: false,
  19. /** @type {OC.Files.Client} */
  20. client: null,
  21. initialize: function($el) {
  22. if (this._initialized) {
  23. return
  24. }
  25. this._initialized = true
  26. this.client = new OC.Files.Client({
  27. host: OC.getHost(),
  28. port: OC.getPort(),
  29. root: OC.linkToRemoteBase('dav') + '/trashbin/' + OC.getCurrentUser().uid,
  30. useHTTPS: OC.getProtocol() === 'https',
  31. })
  32. const urlParams = OC.Util.History.parseUrlQuery()
  33. this.fileList = new OCA.Trashbin.FileList(
  34. $('#app-content-trashbin'), {
  35. fileActions: this._createFileActions(),
  36. detailsViewEnabled: false,
  37. scrollTo: urlParams.scrollto,
  38. config: OCA.Files.App.getFilesConfig(),
  39. multiSelectMenu: [
  40. {
  41. name: 'restore',
  42. displayName: t('files_trashbin', 'Restore'),
  43. iconClass: 'icon-history',
  44. },
  45. {
  46. name: 'delete',
  47. displayName: t('files_trashbin', 'Delete permanently'),
  48. iconClass: 'icon-delete',
  49. },
  50. ],
  51. client: this.client,
  52. // The file list is created when a "show" event is handled, so
  53. // it should be marked as "shown" like it would have been done
  54. // if handling the event with the file list already created.
  55. shown: true,
  56. }
  57. )
  58. },
  59. _createFileActions: function() {
  60. const client = this.client
  61. const fileActions = new OCA.Files.FileActions()
  62. fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function(filename, context) {
  63. const dir = context.fileList.getCurrentDirectory()
  64. context.fileList.changeDirectory(OC.joinPaths(dir, filename))
  65. })
  66. fileActions.setDefault('dir', 'Open')
  67. fileActions.registerAction({
  68. name: 'Restore',
  69. displayName: t('files_trashbin', 'Restore'),
  70. type: OCA.Files.FileActions.TYPE_INLINE,
  71. mime: 'all',
  72. permissions: OC.PERMISSION_READ,
  73. iconClass: 'icon-history',
  74. actionHandler: function(filename, context) {
  75. const fileList = context.fileList
  76. const tr = fileList.findFileEl(filename)
  77. fileList.showFileBusyState(tr, true)
  78. const dir = context.fileList.getCurrentDirectory()
  79. client.move(OC.joinPaths('trash', dir, filename), OC.joinPaths('restore', filename), true)
  80. .then(
  81. fileList._removeCallback.bind(fileList, [filename]),
  82. function() {
  83. fileList.showFileBusyState(tr, false)
  84. OC.Notification.show(t('files_trashbin', 'Error while restoring file from trashbin'))
  85. }
  86. )
  87. },
  88. })
  89. fileActions.registerAction({
  90. name: 'Delete',
  91. displayName: t('files_trashbin', 'Delete permanently'),
  92. mime: 'all',
  93. permissions: OC.PERMISSION_READ,
  94. iconClass: 'icon-delete',
  95. render: function(actionSpec, isDefault, context) {
  96. const $actionLink = fileActions._makeActionLink(actionSpec, context)
  97. $actionLink.attr('original-title', t('files_trashbin', 'Delete permanently'))
  98. $actionLink.children('img').attr('alt', t('files_trashbin', 'Delete permanently'))
  99. context.$file.find('td:last').append($actionLink)
  100. return $actionLink
  101. },
  102. actionHandler: function(filename, context) {
  103. const fileList = context.fileList
  104. $('.tipsy').remove()
  105. const tr = fileList.findFileEl(filename)
  106. fileList.showFileBusyState(tr, true)
  107. const dir = context.fileList.getCurrentDirectory()
  108. client.remove(OC.joinPaths('trash', dir, filename))
  109. .then(
  110. fileList._removeCallback.bind(fileList, [filename]),
  111. function() {
  112. fileList.showFileBusyState(tr, false)
  113. OC.Notification.show(t('files_trashbin', 'Error while removing file from trashbin'))
  114. }
  115. )
  116. },
  117. })
  118. return fileActions
  119. },
  120. }
  121. $(document).ready(function() {
  122. $('#app-content-trashbin').one('show', function() {
  123. const App = OCA.Trashbin.App
  124. App.initialize($('#app-content-trashbin'))
  125. // force breadcrumb init
  126. // App.fileList.changeDirectory(App.fileList.getCurrentDirectory(), false, true);
  127. })
  128. })