sharedialogresharerinfoview.js 2.6 KB

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