From 45074d5023d408f4f81bc45380ce68b1008f9414 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 10 Dec 2012 18:41:08 +0100 Subject: [PATCH 1/3] restoring feature to send sharing link via email --- apps/files_sharing/ajax/email.php | 39 +++++++++++++++++++++++++++++++ apps/files_sharing/js/share.js | 24 ++++++++++++++++++- core/css/share.css | 14 +++++++---- core/js/share.js | 12 ++++++++-- 4 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 apps/files_sharing/ajax/email.php diff --git a/apps/files_sharing/ajax/email.php b/apps/files_sharing/ajax/email.php new file mode 100644 index 0000000000..4ed4eef723 --- /dev/null +++ b/apps/files_sharing/ajax/email.php @@ -0,0 +1,39 @@ +t('User %s shared a file with you', $user); +if ($type === 'dir') + $subject = (string)$l->t('User %s shared a folder with you', $user); + +$text = (string)$l->t('User %s shared the file "%s" with you. It is available for download here: %s', array($user, $file, $link)); +if ($type === 'dir') + $text = (string)$l->t('User %s shared the folder "%s" with you. It is available for download here: %s', array($user, $file, $link)); + +// handle localhost installations +$server_host = OCP\Util::getServerHost(); +if ($server_host === 'localhost') + $server_host = "example.com"; + +$default_from = 'sharing-noreply@' . $server_host; +$from_address = OCP\Config::getUserValue($user, 'settings', 'email', $default_from ); + +// send it out now +try { + OCP\Util::sendMail($to_address, $to_address, $subject, $text, $from_address, $user); + OCP\JSON::success(); +} catch (Exception $exception) { + OCP\JSON::error(array('data' => array('message' => $exception->getMessage()))); +} diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index 7eb086712f..a83252867a 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -33,6 +33,28 @@ $(document).ready(function() { }); OC.Share.loadIcons('file'); } - + + $('#emailPrivateLink').live('submit', function(event) { + event.preventDefault(); + var link = $('#linkText').val(); + var itemType = $('#dropdown').data('item-type'); + var itemSource = $('#dropdown').data('item-source'); + + var file = $('tr').filterAttr('data-id', String(itemSource)).data('file'); + var email = $('#email').val(); + if (email != '') { + $.post(OC.filePath('files_sharing', 'ajax', 'email.php'), { toaddress: email, link: link, type: itemType, file: file }, function(result) { + if (result && result.status == 'success') { + $('#email').css('font-weight', 'bold'); + $('#email').animate({ fontWeight: 'normal' }, 2000, function() { + $(this).val(''); + }).val('Email sent'); + } else { + OC.dialogs.alert(result.data.message, 'Error while sharing'); + } + }); + } + }); + }); \ No newline at end of file diff --git a/core/css/share.css b/core/css/share.css index 5aca731356..e806d25982 100644 --- a/core/css/share.css +++ b/core/css/share.css @@ -50,11 +50,17 @@ padding-top:.5em; } - #dropdown input[type="text"],#dropdown input[type="password"] { - width:90%; - } +#dropdown input[type="text"],#dropdown input[type="password"] { + width:90%; +} - #linkText,#linkPass,#expiration { +#dropdown form { + font-size: 100%; + margin-left: 0; + margin-right: 0; +} + +#linkText,#linkPass,#expiration { display:none; } diff --git a/core/js/share.js b/core/js/share.js index 475abb58bf..962983e2f3 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -168,6 +168,10 @@ OC.Share={ html += ''; html += ''; html += ''; + html += ''; } html += '
'; html += ''; @@ -349,13 +353,17 @@ OC.Share={ $('#linkPassText').attr('placeholder', t('core', 'Password protected')); } $('#expiration').show(); + $('#emailPrivateLink #email').show(); + $('#emailPrivateLink #emailButton').show(); }, hideLink:function() { $('#linkText').hide('blind'); $('#showPassword').hide(); $('#linkPass').hide(); - }, - dirname:function(path) { + $('#emailPrivateLink #email').hide(); + $('#emailPrivateLink #emailButton').hide(); + }, + dirname:function(path) { return path.replace(/\\/g,'/').replace(/\/[^\/]*$/, ''); }, showExpirationDate:function(date) { From 162a2c0fba6f7d7be3aa2372554e4a77a70a3e00 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Mon, 10 Dec 2012 23:22:42 +0100 Subject: [PATCH 2/3] moving sharing email code to core --- apps/files_sharing/ajax/email.php | 39 ------------------------------- apps/files_sharing/js/share.js | 26 +-------------------- core/ajax/share.php | 36 ++++++++++++++++++++++++++++ core/js/share.js | 23 ++++++++++++++++++ 4 files changed, 60 insertions(+), 64 deletions(-) delete mode 100644 apps/files_sharing/ajax/email.php diff --git a/apps/files_sharing/ajax/email.php b/apps/files_sharing/ajax/email.php deleted file mode 100644 index 4ed4eef723..0000000000 --- a/apps/files_sharing/ajax/email.php +++ /dev/null @@ -1,39 +0,0 @@ -t('User %s shared a file with you', $user); -if ($type === 'dir') - $subject = (string)$l->t('User %s shared a folder with you', $user); - -$text = (string)$l->t('User %s shared the file "%s" with you. It is available for download here: %s', array($user, $file, $link)); -if ($type === 'dir') - $text = (string)$l->t('User %s shared the folder "%s" with you. It is available for download here: %s', array($user, $file, $link)); - -// handle localhost installations -$server_host = OCP\Util::getServerHost(); -if ($server_host === 'localhost') - $server_host = "example.com"; - -$default_from = 'sharing-noreply@' . $server_host; -$from_address = OCP\Config::getUserValue($user, 'settings', 'email', $default_from ); - -// send it out now -try { - OCP\Util::sendMail($to_address, $to_address, $subject, $text, $from_address, $user); - OCP\JSON::success(); -} catch (Exception $exception) { - OCP\JSON::error(array('data' => array('message' => $exception->getMessage()))); -} diff --git a/apps/files_sharing/js/share.js b/apps/files_sharing/js/share.js index a83252867a..8a546d6216 100644 --- a/apps/files_sharing/js/share.js +++ b/apps/files_sharing/js/share.js @@ -33,28 +33,4 @@ $(document).ready(function() { }); OC.Share.loadIcons('file'); } - - $('#emailPrivateLink').live('submit', function(event) { - event.preventDefault(); - var link = $('#linkText').val(); - var itemType = $('#dropdown').data('item-type'); - var itemSource = $('#dropdown').data('item-source'); - - var file = $('tr').filterAttr('data-id', String(itemSource)).data('file'); - var email = $('#email').val(); - if (email != '') { - $.post(OC.filePath('files_sharing', 'ajax', 'email.php'), { toaddress: email, link: link, type: itemType, file: file }, function(result) { - if (result && result.status == 'success') { - $('#email').css('font-weight', 'bold'); - $('#email').animate({ fontWeight: 'normal' }, 2000, function() { - $(this).val(''); - }).val('Email sent'); - } else { - OC.dialogs.alert(result.data.message, 'Error while sharing'); - } - }); - } - }); - - -}); \ No newline at end of file +}); diff --git a/core/ajax/share.php b/core/ajax/share.php index 41832a3c65..12206e0fd7 100644 --- a/core/ajax/share.php +++ b/core/ajax/share.php @@ -69,6 +69,42 @@ if (isset($_POST['action']) && isset($_POST['itemType']) && isset($_POST['itemSo ($return) ? OC_JSON::success() : OC_JSON::error(); } break; + case 'email': + // read post variables + $user = OCP\USER::getUser(); + $type = $_POST['itemType']; + $link = $_POST['link']; + $file = $_POST['file']; + $to_address = $_POST['toaddress']; + + // enable l10n support + $l = OC_L10N::get('core'); + + // setup the email + $subject = (string)$l->t('User %s shared a file with you', $user); + if ($type === 'dir') + $subject = (string)$l->t('User %s shared a folder with you', $user); + + $text = (string)$l->t('User %s shared the file "%s" with you. It is available for download here: %s', array($user, $file, $link)); + if ($type === 'dir') + $text = (string)$l->t('User %s shared the folder "%s" with you. It is available for download here: %s', array($user, $file, $link)); + + // handle localhost installations + $server_host = OCP\Util::getServerHost(); + if ($server_host === 'localhost') + $server_host = "example.com"; + + $default_from = 'sharing-noreply@' . $server_host; + $from_address = OCP\Config::getUserValue($user, 'settings', 'email', $default_from ); + + // send it out now + try { + OCP\Util::sendMail($to_address, $to_address, $subject, $text, $from_address, $user); + OCP\JSON::success(); + } catch (Exception $exception) { + OCP\JSON::error(array('data' => array('message' => $exception->getMessage()))); + } + break; } } else if (isset($_GET['fetch'])) { switch ($_GET['fetch']) { diff --git a/core/js/share.js b/core/js/share.js index 962983e2f3..9f71f1bb66 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -555,4 +555,27 @@ $(document).ready(function() { }); }); + + $('#emailPrivateLink').live('submit', function(event) { + event.preventDefault(); + var link = $('#linkText').val(); + var itemType = $('#dropdown').data('item-type'); + var itemSource = $('#dropdown').data('item-source'); + var file = $('tr').filterAttr('data-id', String(itemSource)).data('file'); + var email = $('#email').val(); + if (email != '') { + $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'email', toaddress: email, link: link, itemType: itemType, itemSource: itemSource, file: file}, function(result) { + if (result && result.status == 'success') { + $('#email').css('font-weight', 'bold'); + $('#email').animate({ fontWeight: 'normal' }, 2000, function() { + $(this).val(''); + }).val(t('core','Email sent')); + } else { + OC.dialogs.alert(result.data.message, t('core', 'Error while sharing')); + } + }); + } + }); + + }); From c938a4f791182d86045a45bcffda37c1b6e651f8 Mon Sep 17 00:00:00 2001 From: Thomas Mueller Date: Wed, 12 Dec 2012 12:34:28 +0100 Subject: [PATCH 3/3] feedback to the user while request is being processed --- core/js/share.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/js/share.js b/core/js/share.js index 9f71f1bb66..df5ebf008b 100644 --- a/core/js/share.js +++ b/core/js/share.js @@ -170,7 +170,7 @@ OC.Share={ html += '
'; html += ''; } html += '
'; @@ -564,7 +564,14 @@ $(document).ready(function() { var file = $('tr').filterAttr('data-id', String(itemSource)).data('file'); var email = $('#email').val(); if (email != '') { - $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'email', toaddress: email, link: link, itemType: itemType, itemSource: itemSource, file: file}, function(result) { + $('#email').attr('disabled', "disabled"); + $('#email').val(t('core', 'Sending ...')); + $('#emailButton').attr('disabled', "disabled"); + + $.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'email', toaddress: email, link: link, itemType: itemType, itemSource: itemSource, file: file}, + function(result) { + $('#email').attr('disabled', "false"); + $('#emailButton').attr('disabled', "false"); if (result && result.status == 'success') { $('#email').css('font-weight', 'bold'); $('#email').animate({ fontWeight: 'normal' }, 2000, function() {