Skip to content

Commit

Permalink
set and get mail send status from database and update the user interface
Browse files Browse the repository at this point in the history
  • Loading branch information
Bjoern Schiessle committed Aug 28, 2013
1 parent 04e248d commit 24b387b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 15 deletions.
19 changes: 19 additions & 0 deletions apps/files_sharing/lib/share/fileshare.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class FileShare extends Share {
protected $encrypted;
protected $unencryptedSize;
protected $etag;
protected $mailSend;

public function __construct() {
$this->addType('itemSource', 'int');
Expand Down Expand Up @@ -227,6 +228,23 @@ public function setEtag($etag) {
$this->etag = $etag;
}

/**
* Get the mail send status
* @return string
*/
public function getMailSend() {
return $this->mailSend;
}

/**
* Set the mail send statis
* @param integer $mailSend (0 = not send; 1 = send)
*/
public function setMailSend($mailSend) {
$this->mailSend = $mailSend;
$this->markPropertyUpdated('mailSend');
}

/**
* Get the metadata
* @return array
Expand All @@ -246,6 +264,7 @@ public function getMetadata() {
'encrypted' => $this->getEncrypted(),
'unencrypted_size' => $this->getUnencryptedSize(),
'etag' => $this->getEtag(),
'mail_send' => $this->getMailNotification(),
);
}

Expand Down
16 changes: 15 additions & 1 deletion core/ajax/share.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,27 @@
);
} catch (Exception $exception) {
$noMail[] = \OCP\User::getDisplayName($recipient['displayName']);
}
}
}

$share[0]->setMailSend(1);
$shareManager->update($share[0]);

if (empty($noMail)) {
OCP\JSON::success();
} else {
OCP\JSON::error(array('data' => array('message' => $l->t("Couldn't send mail to following users: %s ", implode(', ', $noMail)))));
}
break;
case 'informRecipientsDisabled':
$itemSource = $_POST['itemSource'];
$itemType = $_POST['itemType'];
$recipient = $_POST['recipient'];
$share = $shareManager->getShares($itemType, array('shareWith' => $recipient, 'isShareWithUser' => true, 'itemSource' => $itemSource));
$share[0]->setMailSend(0);
$shareManager->update($share[0]);
break;

case 'email':
// read post variables
$user = OCP\USER::getUser();
Expand Down Expand Up @@ -334,6 +346,7 @@
'permissions' => $share->getPermissions(),
'share_with_displayname' => $share->getShareWithDisplayName(),
'displayname_owner' => $share->getShareOwnerDisplayName(),
'mailSend' => $share->getMailSend(),
'expiration' => $expiration,
);
}
Expand Down Expand Up @@ -367,6 +380,7 @@
'permissions' => $share->getPermissions(),
'share_with_displayname' => $share->getShareWithDisplayName(),
'displayname_owner' => $share->getShareOwnerDisplayName(),
'mailSend' => $share->getMailSend(),
'expiration' => $expiration,
);
}
Expand Down
34 changes: 20 additions & 14 deletions core/js/share.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ OC.Share={
OC.Share.showLink(share.token, share.share_with, itemSource);
} else {
if (share.collection) {
OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.collection);
OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mailSend, share.collection);
} else {
OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, false);
OC.Share.addShareWith(share.share_type, share.share_with, share.share_with_displayname, share.permissions, possiblePermissions, share.mailSend, false);
}
}
if (share.expiration != null) {
Expand Down Expand Up @@ -299,7 +299,7 @@ OC.Share={
}
});
},
addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, collection) {
addShareWith:function(shareType, shareWith, shareWithDisplayName, permissions, possiblePermissions, mailSend ,collection) {
if (!OC.Share.itemShares[shareType]) {
OC.Share.itemShares[shareType] = [];
}
Expand Down Expand Up @@ -344,7 +344,11 @@ OC.Share={
}
mailNotificationEnabled = $('input:hidden[name=mailNotificationEnabled]').val();
if (mailNotificationEnabled === 'yes') {
html += '<input type="checkbox" name="mailNotification" class="mailNotification" '+mailNotificationChecked+' />'+t('core', 'notify user by email')+'</label>';
checked = '';
if (mailSend === '1') {
checked = 'checked';
}
html += '<input type="checkbox" name="mailNotification" class="mailNotification" '+mailNotificationChecked+ ' ' + checked + ' />'+t('core', 'notify user by email')+'</label>';
}
if (possiblePermissions & OC.PERMISSION_CREATE || possiblePermissions & OC.PERMISSION_UPDATE || possiblePermissions & OC.PERMISSION_DELETE) {
if (editChecked == '') {
Expand Down Expand Up @@ -606,18 +610,20 @@ $(document).ready(function() {
var itemType = $('#dropdown').data('item-type');
var itemSource = $('#dropdown').data('item-source');
if (this.checked) {
console.log(li);
shareType = $(li).data('share-type');
shareWith = $(li).data('share-with');
action='informRecipients';
} else {
action='informRecipientsDisabled';
}

$.post(OC.filePath('core', 'ajax', 'share.php'), { action: 'informRecipients', recipient: shareWith, shareType: shareType, itemSource : itemSource, itemType : itemType }, function(result) {
if (result.status !== 'success') {
OC.dialogs.alert(t('core', result.data.message), t('core', 'Warning'));
}
});
shareType = $(li).data('share-type');
shareWith = $(li).data('share-with');

$.post(OC.filePath('core', 'ajax', 'share.php'), { action: action, recipient: shareWith, shareType: shareType, itemSource : itemSource, itemType : itemType }, function(result) {
if (result.status !== 'success') {
OC.dialogs.alert(t('core', result.data.message), t('core', 'Warning'));
}
});

//TODO Update status in db!
}
});

$(document).on('click', '#dropdown #showPassword', function() {
Expand Down

0 comments on commit 24b387b

Please sign in to comment.