sharebreadcrumbview.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* global Handlebars, OC */
  2. /**
  3. * @copyright 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
  4. *
  5. * @author 2016 Christoph Wurst <christoph@winzerhof-wurst.at>
  6. *
  7. * @license GNU AGPL version 3 or any later version
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. (function() {
  24. 'use strict';
  25. var BreadCrumbView = OC.Backbone.View.extend({
  26. tagName: 'span',
  27. events: {
  28. click: '_onClick'
  29. },
  30. _dirInfo: undefined,
  31. /** @type OCA.Sharing.ShareTabView */
  32. _shareTab: undefined,
  33. initialize: function(options) {
  34. this._shareTab = options.shareTab;
  35. },
  36. render: function(data) {
  37. this._dirInfo = data.dirInfo || null;
  38. if (this._dirInfo !== null && (this._dirInfo.path !== '/' || this._dirInfo.name !== '')) {
  39. var isShared = data.dirInfo && data.dirInfo.shareTypes && data.dirInfo.shareTypes.length > 0;
  40. this.$el.removeClass('shared icon-public icon-shared');
  41. if (isShared) {
  42. this.$el.addClass('shared');
  43. if (data.dirInfo.shareTypes.indexOf(OC.Share.SHARE_TYPE_LINK) !== -1) {
  44. this.$el.addClass('icon-public');
  45. } else {
  46. this.$el.addClass('icon-shared');
  47. }
  48. } else {
  49. this.$el.addClass('icon-shared');
  50. }
  51. this.$el.show();
  52. this.delegateEvents();
  53. } else {
  54. this.$el.removeClass('shared icon-public icon-shared');
  55. this.$el.hide();
  56. }
  57. return this;
  58. },
  59. _onClick: function(e) {
  60. e.preventDefault();
  61. var fileInfoModel = new OCA.Files.FileInfoModel(this._dirInfo);
  62. var self = this;
  63. fileInfoModel.on('change', function() {
  64. self.render({
  65. dirInfo: self._dirInfo
  66. });
  67. });
  68. this._shareTab.on('sharesChanged', function(shareModel) {
  69. var shareTypes = [];
  70. var shares = shareModel.getSharesWithCurrentItem();
  71. for(var i = 0; i < shares.length; i++) {
  72. if (shareTypes.indexOf(shares[i].share_type) === -1) {
  73. shareTypes.push(shares[i].share_type);
  74. }
  75. }
  76. if (shareModel.hasLinkShares()) {
  77. shareTypes.push(OC.Share.SHARE_TYPE_LINK);
  78. }
  79. // Since the dirInfo isn't updated we need to do this dark hackery
  80. self._dirInfo.shareTypes = shareTypes;
  81. self.render({
  82. dirInfo: self._dirInfo
  83. });
  84. });
  85. OCA.Files.App.fileList.showDetailsView(fileInfoModel, 'shareTabView');
  86. }
  87. });
  88. OCA.Sharing.ShareBreadCrumbView = BreadCrumbView;
  89. })();