Skip to content

Commit

Permalink
Send custom link share mail notification when specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent Petry authored and felixheidecke committed Jan 11, 2018
1 parent f7d0545 commit da9f0b9
Show file tree
Hide file tree
Showing 7 changed files with 162 additions and 97 deletions.
1 change: 1 addition & 0 deletions apps/files_sharing/css/sharetabview.css
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@
}

.public-link-modal--label, .public-link-modal--input {
position: relative;
display: block;
width: calc(100% - 15px) !important;
}
Expand Down
22 changes: 19 additions & 3 deletions core/ajax/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
$defaults,
\OC::$server->getURLGenerator()
);

$result = $mailNotification->sendInternalShareMail($recipientList, $itemSource, $itemType);

// if we were able to send to at least one recipient, mark as sent
Expand Down Expand Up @@ -162,11 +163,18 @@ function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
// read post variables
$link = (string)$_POST['link'];
$file = (string)$_POST['file'];
$to_address = (string)$_POST['toaddress'];
$to_address = (string)$_POST['toAddress'];
$to_cc_address = (string)$_POST['toCcAddress'];
$emailBody = null;
if (isset($_POST['emailBody'])) {
$emailBody = trim((string)$_POST['emailBody']);
}

$l10n = \OC::$server->getL10N('lib');

$mailNotification = new \OC\Share\MailNotifications(
\OC::$server->getUserSession()->getUser(),
\OC::$server->getL10N('lib'),
$l10n,
\OC::$server->getMailer(),
\OC::$server->getLogger(),
$defaults,
Expand All @@ -183,7 +191,15 @@ function usersInGroup($gid, $search = '', $limit = -1, $offset = 0) {
}
}

$result = $mailNotification->sendLinkShareMail($to_address, $file, $link, $expiration);
$subject = (string)$l10n->t('%s shared »%s« with you', [$this->senderDisplayName, $filename]);
if ($emailBody === null || $emailBody === '') {
list($htmlBody, $textBody) = $mailNotification->createMailBody($file, $link, $expiration);
} else {
$htmlBody = null;
$textBody = strip_tags($emailBody);
}

$result = $mailNotification->sendLinkShareMailFromBody($to_address, $subject, $htmlBody, $textBody);
if(empty($result)) {
// Get the token from the link
$linkParts = explode('/', $link);
Expand Down
32 changes: 28 additions & 4 deletions core/css/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@

/* Global Components */

/* Positioning */

.absolute-center {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

.pull-left {
float: left;
}
Expand All @@ -24,7 +33,7 @@
clear: both;
}

.hidden {
.hidden.hidden {
display: none;
}

Expand All @@ -41,10 +50,25 @@
font-weight:600;
}

.center {
text-align:center;
.text-small {
font-size: 80%;
}

.inlineblock {
display: inline-block;
}
}

/* Text */

.text-right {
text-align: right;
}

.center,
.text-center {
text-align: center;
}

.text-left {
text-align: left;
}
36 changes: 10 additions & 26 deletions core/css/jquery.ocdialog.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,40 +79,19 @@
width: 100%; height: 100%;
}

.error-message-global {
.error-message-global,
.success-message-global {
background-color: rgb(242, 222, 222);
border-bottom-color: rgb(235, 204, 209);
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
border-bottom-style: solid;
border-bottom-width: 1px;
border-image-outset: 0 0 0 0;
border-image-repeat: stretch stretch;
border-image-slice: 100% 100% 100% 100%;
border-image-source: none;
border-image-width: 1 1 1 1;
border-left-color: rgb(235, 204, 209);
border-left-style: solid;
border-left-width: 1px;
border-right-color: rgb(235, 204, 209);
border-right-style: solid;
border-right-width: 1px;
border-top-color: rgb(235, 204, 209);
border-top-left-radius: 4px;
border-top-right-radius: 4px;
border-top-style: solid;
border-top-width: 1px;
border: 1px solid rgb(235, 204, 209);
border-radius: 4px;
box-sizing: border-box;
color: rgb(169, 68, 66);
font-family: Verdana,sans-serif;
font-size: 15px;
line-height: 22.5px;
margin-bottom: 20px;
opacity: 1;
padding-bottom: 15px;
padding-left: 15px;
padding-right: 35px;
padding-top: 15px;
padding: 15px 35px 15px 15px;
transition-delay: 0s;
transition-duration: 0.15s;
transition-property: opacity;
Expand All @@ -121,5 +100,10 @@
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
}

.success-message-global {
background-color: rgb(222, 242, 226);
border-color: rgb(177, 218, 186);
color: rgb(66, 169, 76);
}
20 changes: 20 additions & 0 deletions core/css/share.css
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,23 @@ a.showCruds:hover,a.unshare:hover {
padding-top: 12px;
color: #999;
}

/* Private Link share Form */

.emailPrivateLinkForm {
position: relative;
}

.emailPrivateLinkForm--send-indicator {
z-index: 2;
/* overriding default padding */
padding: 5px 15px !important;
}

.emailPrivateLinkForm--addAddressButton {
position: absolute;
right: 13px;
margin-top: -30px;
z-index: 1;
color: #999;
}
130 changes: 72 additions & 58 deletions core/js/sharedialogmailview.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@

var TEMPLATE =
'<form id="emailPrivateLink" class="emailPrivateLinkForm">' +
' <span class="emailPrivateLinkForm--send-indicator success-message-global absolute-center hidden">{{sending}}</span>' +
' <label class="public-link-modal--label" for="emailPrivateLinkField-{{cid}}">{{mailLabel}}</label>' +
' <input class="public-link-modal--input emailField" id="emailPrivateLinkField-{{cid}}" value="{{email}}" placeholder="{{mailPlaceholder}}" type="email" />' +
' <label class="public-link-modal--label" for="emailBodyPrivateLinkField-{{cid}}">{{mailMessageLabel}}</label>' +
' <textarea class="public-link-modal--input emailBodyField" id="emailBodyPrivateLinkField-{{cid}}" rows="3" placeholder="{{mailBodyPlaceholder}}" style="display:none"></textarea>' +
' <input class="public-link-modal--input emailPrivateLinkForm--emailField" id="emailPrivateLinkField-{{cid}}" value="{{email}}" placeholder="{{mailPlaceholder}}" type="email" />' +
' <div class="emailPrivateLinkForm--elements hidden">' +
' <a href="#" class="emailPrivateLinkForm--addAddressButton text-small pull-right">{{addCcAddress}}</a>' +
' <input class="public-link-modal--input emailPrivateLinkForm--emailCcField hidden" id="emailCcPrivateLinkField-{{cid}}" value="{{email}}" placeholder="{{mailPlaceholder}} (CC)" type="email" />' +
' <label class="public-link-modal--label" for="emailBodyPrivateLinkField-{{cid}}">{{mailMessageLabel}}</label>' +
' <textarea class="public-link-modal--input emailPrivateLinkForm--emailBodyField" id="emailBodyPrivateLinkField-{{cid}}" rows="3" placeholder="{{mailBodyPlaceholder}}"></textarea>' +
' </div>' +
'</form>';

/**
Expand All @@ -36,8 +41,9 @@
id: 'shareDialogMailView',

events: {
"keyup .emailField": "toggleMailBody",
"keydown .emailBodyField": "expandMailBody"
"keyup .emailPrivateLinkForm--emailField" : "toggleMailElements",
"keydown .emailPrivateLinkForm--emailBodyField" : "expandMailBody",
"click .emailPrivateLinkForm--addAddressButton" : "toggleEmailCcField"
},

/** @type {Function} **/
Expand All @@ -51,53 +57,69 @@
}
},

toggleMailBody: function() {
var $email = this.$el.find('.emailField');
var $emailBody = this.$el.find('.emailBodyField');
toggleMailElements: function() {
var $email = this.$el.find('.emailPrivateLinkForm--emailField');
var $emailElements = this.$el.find('.emailPrivateLinkForm--elements');

if ($email.val().length > 0 && $emailBody.is(":hidden")) {
$emailBody.slideDown();
} else if ($email.val().length === 0 && $emailBody.is(":visible")) {
$emailBody.slideUp();
if ($email.val().length > 0 && $emailElements.is(":hidden")) {
$emailElements.slideDown();
} else if ($email.val().length === 0 && $emailElements.is(":visible")) {
$emailElements.slideUp();
}
},

expandMailBody: function(event) {
var $emailBody = this.$el.find('.emailBodyField');
var $emailBody = this.$el.find('.emailPrivateLinkForm--emailBodyField');
$emailBody.css('minHeight', $emailBody[0].scrollHeight - 12);

if (event.keyCode == 13) {
event.stopPropagation();
}
},

toggleEmailCcField: function() {
this.$el.find('.emailPrivateLinkForm--addAddressButton').remove();
this.$el.find('.emailPrivateLinkForm--emailCcField').slideDown();
},

/**
* Send the link share information by email
*
* @param {string} recipientEmail recipient email address
*/
_sendEmailPrivateLink: function(recipientEmail, emailBody) {
var deferred = $.Deferred();
var itemType = this.itemModel.get('itemType');
_sendEmailPrivateLink: function(mail) {
var deferred = $.Deferred();
var itemType = this.itemModel.get('itemType');
var itemSource = this.itemModel.get('itemSource');

if (!this.validateEmail(recipientEmail)) {
if (!this.validateEmail(mail.to)) {
return deferred.reject({
message: t('core', '{email} is not a valid address!', {email: recipientEmail})
message: t('core', '{email} is not a valid address!', {email: mail.to})
});
}

if (!this.validateEmail(mail.cc)) {
return deferred.reject({
message: t('core', '{email} is not a valid address!', {email: mail.cc})
});
}

var params = {
action : 'email',
toAddress : mail.to,
toCcAddress : mail.cc,
emailBody : mail.body,
link : this.model.getLink(),
itemType : itemType,
itemSource : itemSource,
file : this.itemModel.getFileInfo().get('name'),
expiration : this.model.get('expireDate') || ''
};

console.log(params);

$.post(
OC.generateUrl('core/ajax/share.php'), {
action: 'email',
toaddress: recipientEmail,
emailBody: emailBody,
link: this.model.getLink(),
itemType: itemType,
itemSource: itemSource,
file: this.itemModel.getFileInfo().get('name'),
expiration: this.model.get('expireDate') || ''
},
OC.generateUrl('core/ajax/share.php'), params,
function(result) {
if (!result || result.status !== 'success') {
deferred.reject({
Expand All @@ -114,43 +136,33 @@
},

validateEmail: function(email) {
if (email.length === 0)
return true

return email.match(/([\w\.\-_]+)?\w+@[\w-_]+(\.\w+){1,}$/);
},

sendEmails: function() {
var $emailField = this.$el.find('.emailField');
var $emailBodyField = this.$el.find('.emailBodyField');
var $emailButton = this.$el.find('.emailButton');
var email = $emailField.val();
var emailBody = $emailBodyField.val().trim();

if (email !== '') {
$emailButton.prop('disabled', true);
$emailField.val(t('core', 'Sending ...'));
return this._sendEmailPrivateLink(email, emailBody).done(function() {
$emailField.css('font-weight', 'bold').val(t('core', 'Email sent'));
var $formItems = this.$el.find('.emailPrivateLinkForm input, .emailPrivateLinkForm textarea');
var $formSendIndicator = this.$el.find('.emailPrivateLinkForm--send-indicator');
var mail = {
to : this.$el.find('.emailPrivateLinkForm--emailField').val(),
cc : this.$el.find('.emailPrivateLinkForm--emailCcField').val(),
body : this.$el.find('.emailPrivateLinkForm--emailBodyField').val()
};

if (mail.to !== '') {
$formItems.prop('disabled', true);
$formSendIndicator.removeClass('hidden');
return this._sendEmailPrivateLink(mail).done(function() {
setTimeout(function() {
$emailField.val('');
$emailField.css('font-weight', 'normal');
$emailField.prop('disabled', false);
$emailButton.prop('disabled', false);
$formItems.prop('disabled', false);
$formSendIndicator.addClass('hidden');
}, 2000);
}).fail(function() {
$emailField.val(email);
$emailField.css('font-weight', 'normal');
$emailField.prop('disabled', false);
$emailButton.prop('disabled', false);
$emailField
.prop('disabled', false)
.val('');

}).fail(function(error) {
OC.dialogs.info(error.message, t('core', 'An error occured'));
$emailButton.prop('disabled', false);
$emailField
.css('color', 'red')
.prop('disabled', false)
.val(email);
$formSendIndicator.addClass('hidden');
$formItems.prop('disabled', false);
});
}
return $.Deferred().resolve();
Expand All @@ -163,9 +175,11 @@
this.$el.html(this.template({
cid: this.cid,
mailPlaceholder: t('core', 'Email link to person'),
addCcAddress: t('core', 'Add CC address'),
mailLabel: t('core', 'Send link via email'),
mailBodyPlaceholder: t('core', 'Add personal message'),
email: email
email: email,
sending : t('core', 'Sending') + ' ...'
}));

if ($email.length !== 0) {
Expand Down
Loading

0 comments on commit da9f0b9

Please sign in to comment.