sharedialogresharerinfoview.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. (function() {
  11. if (!OC.Share) {
  12. OC.Share = {};
  13. }
  14. var TEMPLATE =
  15. '<span class="reshare">' +
  16. ' {{#if avatarEnabled}}' +
  17. ' <div class="avatar" data-userName="{{reshareOwner}}"></div>' +
  18. ' {{/if}}' +
  19. ' {{sharedByText}}' +
  20. '</span><br/>'
  21. ;
  22. /**
  23. * @class OCA.Share.ShareDialogView
  24. * @member {OC.Share.ShareItemModel} model
  25. * @member {jQuery} $el
  26. * @memberof OCA.Sharing
  27. * @classdesc
  28. *
  29. * Represents the GUI of the share dialogue
  30. *
  31. */
  32. var ShareDialogResharerInfoView = OC.Backbone.View.extend({
  33. /** @type {string} **/
  34. id: 'shareDialogResharerInfo',
  35. /** @type {string} **/
  36. tagName: 'div',
  37. /** @type {string} **/
  38. className: 'reshare',
  39. /** @type {OC.Share.ShareConfigModel} **/
  40. configModel: undefined,
  41. /** @type {Function} **/
  42. _template: undefined,
  43. initialize: function(options) {
  44. var view = this;
  45. this.model.on('change:reshare', function() {
  46. view.render();
  47. });
  48. if(!_.isUndefined(options.configModel)) {
  49. this.configModel = options.configModel;
  50. } else {
  51. throw 'missing OC.Share.ShareConfigModel';
  52. }
  53. },
  54. render: function() {
  55. if (!this.model.hasReshare()
  56. || this.model.getReshareOwner() === OC.currentUser)
  57. {
  58. this.$el.empty();
  59. return this;
  60. }
  61. var reshareTemplate = this.template();
  62. var ownerDisplayName = this.model.getReshareOwnerDisplayname();
  63. var sharedByText = '';
  64. if (this.model.getReshareType() === OC.Share.SHARE_TYPE_GROUP) {
  65. sharedByText = t(
  66. 'core',
  67. 'Shared with you and the group {group} by {owner}',
  68. {
  69. group: this.model.getReshareWith(),
  70. owner: ownerDisplayName
  71. }
  72. );
  73. } else {
  74. sharedByText = t(
  75. 'core',
  76. 'Shared with you by {owner}',
  77. { owner: ownerDisplayName }
  78. );
  79. }
  80. this.$el.html(reshareTemplate({
  81. avatarEnabled: this.configModel.areAvatarsEnabled(),
  82. reshareOwner: this.model.getReshareOwner(),
  83. sharedByText: sharedByText
  84. }));
  85. if(this.configModel.areAvatarsEnabled()) {
  86. this.$el.find('.avatar').each(function() {
  87. var $this = $(this);
  88. $this.avatar($this.data('username'), 32);
  89. });
  90. }
  91. return this;
  92. },
  93. /**
  94. * @returns {Function} from Handlebars
  95. * @private
  96. */
  97. template: function () {
  98. if (!this._template) {
  99. this._template = Handlebars.compile(TEMPLATE);
  100. }
  101. return this._template;
  102. }
  103. });
  104. OC.Share.ShareDialogResharerInfoView = ShareDialogResharerInfoView;
  105. })();