sharebreadcrumbview.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /**
  2. * @copyright 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
  3. *
  4. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  5. * @author John Molakvoæ <skjnldsv@protonmail.com>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. *
  8. * @license AGPL-3.0-or-later
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. import { Type as ShareTypes } from '@nextcloud/sharing'
  25. (function() {
  26. 'use strict'
  27. const BreadCrumbView = OC.Backbone.View.extend({
  28. tagName: 'span',
  29. events: {
  30. click: '_onClick',
  31. },
  32. _dirInfo: undefined,
  33. render(data) {
  34. this._dirInfo = data.dirInfo || null
  35. if (this._dirInfo !== null && (this._dirInfo.path !== '/' || this._dirInfo.name !== '')) {
  36. const isShared = data.dirInfo && data.dirInfo.shareTypes && data.dirInfo.shareTypes.length > 0
  37. this.$el.removeClass('shared icon-public icon-shared')
  38. if (isShared) {
  39. this.$el.addClass('shared')
  40. if (data.dirInfo.shareTypes.indexOf(ShareTypes.SHARE_TYPE_LINK) !== -1) {
  41. this.$el.addClass('icon-public')
  42. } else {
  43. this.$el.addClass('icon-shared')
  44. }
  45. } else {
  46. this.$el.addClass('icon-shared')
  47. }
  48. this.$el.show()
  49. this.delegateEvents()
  50. } else {
  51. this.$el.removeClass('shared icon-public icon-shared')
  52. this.$el.hide()
  53. }
  54. return this
  55. },
  56. _onClick(e) {
  57. e.preventDefault()
  58. e.stopPropagation()
  59. const fileInfoModel = new OCA.Files.FileInfoModel(this._dirInfo)
  60. const self = this
  61. fileInfoModel.on('change', function() {
  62. self.render({
  63. dirInfo: self._dirInfo,
  64. })
  65. })
  66. const path = fileInfoModel.attributes.path + '/' + fileInfoModel.attributes.name
  67. OCA.Files.Sidebar.open(path)
  68. OCA.Files.Sidebar.setActiveTab('sharing')
  69. },
  70. })
  71. OCA.Sharing.ShareBreadCrumbView = BreadCrumbView
  72. })()