diff --git a/core/js/sharedialoglinkshareview.js b/core/js/sharedialoglinkshareview.js index cadec3071d..599ffd3c43 100644 --- a/core/js/sharedialoglinkshareview.js +++ b/core/js/sharedialoglinkshareview.js @@ -36,7 +36,7 @@ '' + ' {{/if}}' + ' {{#if mailPublicNotificationEnabled}}' + - '' + @@ -69,6 +69,10 @@ /** @type {boolean} **/ showLink: true, + events: { + 'submit .emailPrivateLinkForm': '_onEmailPrivateLink' + }, + initialize: function(options) { var view = this; @@ -160,6 +164,28 @@ this.model.saveLinkShare(); }, + _onEmailPrivateLink: function(event) { + event.preventDefault(); + + var $emailField = this.$el.find('#email'); + var $emailButton = this.$el.find('#emailButton'); + var email = this.$el.find('#email').val(); + if (email !== '') { + $emailField.prop('disabled', true); + $emailButton.prop('disabled', true); + $emailField.val(t('core', 'Sending ...')); + this.model.sendEmailPrivateLink(email).then(function() { + $emailField.css('font-weight', 'bold').val(t('core','Email sent')); + setTimeout(function() { + $emailField.css('font-weight', 'normal').val(''); + $emailField.prop('disabled', false); + $emailButton.prop('disabled', false); + }, 2000); + }); + } + return false; + }, + render: function() { var linkShareTemplate = this.template(); @@ -222,6 +248,8 @@ } }); + this.delegateEvents(); + return this; }, diff --git a/core/js/shareitemmodel.js b/core/js/shareitemmodel.js index 595670faae..e0d4458661 100644 --- a/core/js/shareitemmodel.js +++ b/core/js/shareitemmodel.js @@ -476,7 +476,7 @@ var itemType = this.get('itemType'); var itemSource = this.get('itemSource'); - $.post( + return $.post( OC.generateUrl('core/ajax/share.php'), { action: state ? 'informRecipients' : 'informRecipientsDisabled', @@ -487,12 +487,41 @@ }, function(result) { if (result.status !== 'success') { + // FIXME: a model should not show dialogs OC.dialogs.alert(t('core', result.data.message), t('core', 'Warning')); } } ); }, + /** + * Send the link share information by email + * + * @param {string} recipientEmail recipient email address + */ + sendEmailPrivateLink: function(recipientEmail) { + var itemType = this.get('itemType'); + var itemSource = this.get('itemSource'); + var linkShare = this.get('linkShare'); + + return $.post( + OC.generateUrl('core/ajax/share.php'), { + action: 'email', + toaddress: recipientEmail, + link: linkShare.link, + itemType: itemType, + itemSource: itemSource, + file: this.fileInfoModel.get('name'), + expiration: linkShare.expiration || '' + }, + function(result) { + if (!result || result.status !== 'success') { + // FIXME: a model should not show dialogs + OC.dialogs.alert(result.data.message, t('core', 'Error while sending notification')); + } + }); + }, + /** * @returns {boolean} */