sharedialogresharerinfoview.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. undefined,
  72. {escape: false}
  73. );
  74. } else {
  75. sharedByText = t(
  76. 'core',
  77. 'Shared with you by {owner}',
  78. { owner: ownerDisplayName },
  79. undefined,
  80. {escape: false}
  81. );
  82. }
  83. this.$el.html(reshareTemplate({
  84. reshareOwner: this.model.getReshareOwner(),
  85. sharedByText: sharedByText
  86. }));
  87. this.$el.find('.avatar').each(function() {
  88. var $this = $(this);
  89. $this.avatar($this.data('username'), 32);
  90. });
  91. this.$el.find('.reshare').contactsMenu(
  92. this.model.getReshareOwner(),
  93. OC.Share.SHARE_TYPE_USER,
  94. this.$el);
  95. return this;
  96. },
  97. /**
  98. * @returns {Function} from Handlebars
  99. * @private
  100. */
  101. template: function () {
  102. if (!this._template) {
  103. this._template = Handlebars.compile(TEMPLATE);
  104. }
  105. return this._template;
  106. }
  107. });
  108. OC.Share.ShareDialogResharerInfoView = ShareDialogResharerInfoView;
  109. })();