sharetabview.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2015
  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. /* @global Handlebars */
  11. (function() {
  12. var TEMPLATE =
  13. '<div>' +
  14. '<div class="dialogContainer"></div>' +
  15. '</div>';
  16. /**
  17. * @memberof OCA.Sharing
  18. */
  19. var ShareTabView = OCA.Files.DetailTabView.extend(
  20. /** @lends OCA.Sharing.ShareTabView.prototype */ {
  21. id: 'shareTabView',
  22. className: 'tab shareTabView',
  23. template: function(params) {
  24. return TEMPLATE;
  25. },
  26. getLabel: function() {
  27. return t('files_sharing', 'Sharing');
  28. },
  29. getIcon: function() {
  30. return 'icon-shared';
  31. },
  32. /**
  33. * Renders this details view
  34. */
  35. render: function() {
  36. var self = this;
  37. if (this._dialog) {
  38. // remove/destroy older instance
  39. this._dialog.model.off();
  40. this._dialog.remove();
  41. this._dialog = null;
  42. }
  43. if (this.model) {
  44. this.$el.html(this.template());
  45. if (_.isUndefined(this.model.get('sharePermissions'))) {
  46. this.model.set('sharePermissions', OCA.Sharing.Util.getSharePermissions(this.model.attributes));
  47. }
  48. // TODO: the model should read these directly off the passed fileInfoModel
  49. var attributes = {
  50. itemType: this.model.isDirectory() ? 'folder' : 'file',
  51. itemSource: this.model.get('id'),
  52. possiblePermissions: this.model.get('sharePermissions')
  53. };
  54. var configModel = new OC.Share.ShareConfigModel();
  55. var shareModel = new OC.Share.ShareItemModel(attributes, {
  56. configModel: configModel,
  57. fileInfoModel: this.model
  58. });
  59. this._dialog = new OC.Share.ShareDialogView({
  60. configModel: configModel,
  61. model: shareModel
  62. });
  63. this.$el.find('.dialogContainer').append(this._dialog.$el);
  64. this._dialog.render();
  65. this._dialog.model.fetch();
  66. this._dialog.model.on('change', function() {
  67. self.trigger('sharesChanged', shareModel);
  68. });
  69. } else {
  70. this.$el.empty();
  71. // TODO: render placeholder text?
  72. }
  73. }
  74. });
  75. OCA.Sharing.ShareTabView = ShareTabView;
  76. })();