You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sharedialogmailview.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /*
  2. * Copyright (c) 2016
  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. '{{#if shareAllowed}}' +
  16. ' {{#if mailPublicNotificationEnabled}}' +
  17. '<form id="emailPrivateLink" class="emailPrivateLinkForm oneline">' +
  18. ' <input id="email" class="emailField" value="{{email}}" placeholder="{{mailPrivatePlaceholder}}" type="text" />' +
  19. ' <a id="emailButton" class="icon icon-mail-grey" />' +
  20. '</form>' +
  21. ' {{/if}}' +
  22. '{{/if}}'
  23. ;
  24. /**
  25. * @class OCA.Share.ShareDialogMailView
  26. * @member {OC.Share.ShareItemModel} model
  27. * @member {jQuery} $el
  28. * @memberof OCA.Sharing
  29. * @classdesc
  30. *
  31. * Represents the GUI of the share dialogue
  32. *
  33. */
  34. var ShareDialogMailView = OC.Backbone.View.extend({
  35. /** @type {string} **/
  36. id: 'shareDialogMailView',
  37. /** @type {OC.Share.ShareConfigModel} **/
  38. configModel: undefined,
  39. /** @type {Function} **/
  40. _template: undefined,
  41. /** @type {boolean} **/
  42. showLink: true,
  43. events: {
  44. 'click #emailButton': '_onEmailPrivateLink'
  45. },
  46. initialize: function(options) {
  47. var view = this;
  48. this.model.on('change:linkShare', function() {
  49. view.render();
  50. });
  51. if(!_.isUndefined(options.configModel)) {
  52. this.configModel = options.configModel;
  53. } else {
  54. throw 'missing OC.Share.ShareConfigModel';
  55. }
  56. _.bindAll(
  57. this,
  58. '_onEmailPrivateLink'
  59. );
  60. },
  61. _onEmailPrivateLink: function(event) {
  62. event.preventDefault();
  63. var $emailField = this.$el.find('.emailField');
  64. var $emailButton = this.$el.find('.emailButton');
  65. var email = $emailField.val();
  66. if (email !== '') {
  67. $emailField.prop('disabled', true);
  68. $emailButton.prop('disabled', true);
  69. $emailField.val(t('core', 'Sending ...'));
  70. this.model.sendEmailPrivateLink(email).done(function() {
  71. $emailField.css('font-weight', 'bold').val(t('core','Email sent'));
  72. setTimeout(function() {
  73. $emailField.val('');
  74. $emailField.css('font-weight', 'normal');
  75. $emailField.prop('disabled', false);
  76. $emailButton.prop('disabled', false);
  77. }, 2000);
  78. }).fail(function() {
  79. $emailField.val(email);
  80. $emailField.css('font-weight', 'normal');
  81. $emailField.prop('disabled', false);
  82. $emailButton.prop('disabled', false);
  83. });
  84. }
  85. return false;
  86. },
  87. render: function() {
  88. var linkShareTemplate = this.template();
  89. var resharingAllowed = this.model.sharePermissionPossible();
  90. var email = this.$el.find('.emailField').val();
  91. if(!resharingAllowed
  92. || !this.showLink
  93. || !this.configModel.isShareWithLinkAllowed())
  94. {
  95. var templateData = {shareAllowed: false};
  96. if (!resharingAllowed) {
  97. // add message
  98. templateData.noSharingPlaceholder = t('core', 'Resharing is not allowed');
  99. }
  100. this.$el.html(linkShareTemplate(templateData));
  101. return this;
  102. }
  103. var isLinkShare = this.model.get('linkShare').isLinkShare;
  104. this.$el.html(linkShareTemplate({
  105. cid: this.cid,
  106. shareAllowed: true,
  107. mailPublicNotificationEnabled: isLinkShare && this.configModel.isMailPublicNotificationEnabled(),
  108. mailPrivatePlaceholder: t('core', 'Email link to person'),
  109. mailButtonText: t('core', 'Send link via email'),
  110. email: email
  111. }));
  112. var $emailField = this.$el.find('.emailField');
  113. if (isLinkShare && $emailField.length !== 0) {
  114. $emailField.autocomplete({
  115. minLength: 1,
  116. source: function (search, response) {
  117. $.get(
  118. OC.generateUrl('core/ajax/share.php'), {
  119. fetch: 'getShareWithEmail',
  120. search: search.term
  121. }, function(result) {
  122. if (result.status == 'success' && result.data.length > 0) {
  123. response(result.data);
  124. }
  125. });
  126. },
  127. select: function( event, item ) {
  128. $emailField.val(item.item.email);
  129. return false;
  130. }
  131. })
  132. .data("ui-autocomplete")._renderItem = function( ul, item ) {
  133. return $('<li>')
  134. .append('<a>' + escapeHTML(item.displayname) + "<br>" + escapeHTML(item.email) + '</a>' )
  135. .appendTo( ul );
  136. };
  137. }
  138. this.delegateEvents();
  139. return this;
  140. },
  141. /**
  142. * @returns {Function} from Handlebars
  143. * @private
  144. */
  145. template: function () {
  146. if (!this._template) {
  147. this._template = Handlebars.compile(TEMPLATE);
  148. }
  149. return this._template;
  150. }
  151. });
  152. OC.Share.ShareDialogMailView = ShareDialogMailView;
  153. })();