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