Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.2] Add clipboard button to public share link #25418

Merged
merged 2 commits into from Jul 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions apps/files_sharing/css/sharetabview.css
Expand Up @@ -10,8 +10,9 @@
top: 2px;
}

.shareTabView .shareWithRemoteInfo {
padding: 11px 20px;
.shareTabView .shareWithRemoteInfo,
.shareTabView .clipboardButton {
padding-left: 10px;
}

.shareTabView label {
Expand All @@ -28,7 +29,9 @@
width: 94%;
margin-left: 0;
}
.shareTabView input[type="text"].shareWithField {
.shareTabView input[type="text"].shareWithField,
.shareTabView input[type="text"].emailField,
.shareTabView input[type="text"].linkText {
width: 80%;
}

Expand Down
3 changes: 2 additions & 1 deletion bower.json
Expand Up @@ -30,6 +30,7 @@
"backbone": "~1.2.3",
"davclient.js": "https://github.com/evert/davclient.js.git",
"es6-promise": "https://github.com/jakearchibald/es6-promise.git#~2.3.0",
"base64": "~0.3.0"
"base64": "~0.3.0",
"clipboard": "^1.5.12"
}
}
8 changes: 8 additions & 0 deletions core/css/icons.css
Expand Up @@ -204,6 +204,10 @@ img.icon-loading-small-dark, object.icon-loading-small-dark, video.icon-loading-
background-image: url('../img/actions/mail.svg');
}

.icon-mail-grey {
background-image: url('../img/actions/mail-grey.svg');
}

.icon-menu {
background-image: url('../img/actions/menu.svg');
}
Expand Down Expand Up @@ -368,3 +372,7 @@ img.icon-loading-small-dark, object.icon-loading-small-dark, video.icon-loading-
.icon-picture {
background-image: url('../img/places/picture.svg');
}

.icon-clippy {
background-image: url('../img/actions/clippy.svg');
}
3 changes: 3 additions & 0 deletions core/img/actions/clippy.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion core/js/core.json
Expand Up @@ -10,7 +10,8 @@
"bootstrap/js/tooltip.js",
"backbone/backbone.js",
"es6-promise/dist/es6-promise.js",
"davclient.js/lib/client.js"
"davclient.js/lib/client.js",
"clipboard/dist/clipboard.js"
],
"libraries": [
"jquery-showpassword.js",
Expand Down
35 changes: 35 additions & 0 deletions core/js/sharedialoglinkshareview.js
Expand Up @@ -22,8 +22,11 @@
'<input type="checkbox" name="linkCheckbox" id="linkCheckbox-{{cid}}" class="checkbox linkCheckbox" value="1" {{#if isLinkShare}}checked="checked"{{/if}} />' +
'<label for="linkCheckbox-{{cid}}">{{linkShareLabel}}</label>' +
'<br />' +
'<div class="oneline">' +
'<label for="linkText-{{cid}}" class="hidden-visually">{{urlLabel}}</label>' +
'<input id="linkText-{{cid}}" class="linkText {{#unless isLinkShare}}hidden{{/unless}}" type="text" readonly="readonly" value="{{shareLinkURL}}" />' +
'<a class="{{#unless isLinkShare}}hidden-visually{{/unless}} clipboardButton icon icon-clippy" data-clipboard-target="#linkText-{{cid}}"></a>' +
'</div>' +
' {{#if publicUpload}}' +
'<div id="allowPublicUploadWrapper">' +
' <span class="icon-loading-small hidden"></span>' +
Expand Down Expand Up @@ -112,6 +115,38 @@
'onShowPasswordClick',
'onAllowPublicUploadChange'
);

var clipboard = new Clipboard('.clipboardButton');
clipboard.on('success', function(e) {
$input = $(e.trigger);
$input.tooltip({placement: 'bottom', trigger: 'manual', title: t('core', 'Copied!')});
$input.tooltip('show');
_.delay(function() {
$input.tooltip('hide');
}, 3000);
});
clipboard.on('error', function (e) {
$input = $(e.trigger);
var actionMsg = '';
if (/iPhone|iPad/i.test(navigator.userAgent)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we ever want to reuse that button elsewhere, would be good to have all this logic in a central place, like js.js in OC.Util or so

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can do this once necessary - I have no clue what the perf impact is if we setup the clipboard instance in js.js

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Note that the way I see it is more like a method OC.Util.setupClipboard($inputField) that does this lazily.

Anyway, let's merge this for now.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, let's merge this for now.

THX 🎉

actionMsg = t('core', 'Not supported!');
} else if (/Mac/i.test(navigator.userAgent)) {
actionMsg = t('core', 'Press ⌘-C to copy.');
} else {
actionMsg = t('core', 'Press Ctrl-C to copy.');
}

$input.tooltip({
placement: 'bottom',
trigger: 'manual',
title: actionMsg
});
$input.tooltip('show');
_.delay(function () {
$input.tooltip('hide');
}, 3000);
});

},

onLinkCheckBoxChange: function() {
Expand Down
8 changes: 4 additions & 4 deletions core/js/sharedialogmailview.js
Expand Up @@ -16,9 +16,9 @@
var TEMPLATE =
'{{#if shareAllowed}}' +
' {{#if mailPublicNotificationEnabled}}' +
'<form id="emailPrivateLink" class="emailPrivateLinkForm">' +
'<form id="emailPrivateLink" class="emailPrivateLinkForm oneline">' +
' <input id="email" class="emailField" value="{{email}}" placeholder="{{mailPrivatePlaceholder}}" type="text" />' +
' <input id="emailButton" class="emailButton" type="submit" value="{{mailButtonText}}" />' +
' <a id="emailButton" class="icon icon-mail-grey" />' +
'</form>' +
' {{/if}}' +
'{{/if}}'
Expand Down Expand Up @@ -48,7 +48,7 @@
showLink: true,

events: {
'submit .emailPrivateLinkForm': '_onEmailPrivateLink'
'click #emailButton': '_onEmailPrivateLink'
},

initialize: function(options) {
Expand Down Expand Up @@ -173,4 +173,4 @@

OC.Share.ShareDialogMailView = ShareDialogMailView;

})();
})();
2 changes: 1 addition & 1 deletion core/js/sharedialogview.js
Expand Up @@ -30,7 +30,7 @@
'<div class="loading hidden" style="height: 50px"></div>';

var TEMPLATE_REMOTE_SHARE_INFO =
'<a target="_blank" class="icon-info shareWithRemoteInfo hasTooltip" href="{{docLink}}" ' +
'<a target="_blank" class="icon icon-info shareWithRemoteInfo hasTooltip" href="{{docLink}}" ' +
'title="{{tooltip}}"></a>';

/**
Expand Down
4 changes: 2 additions & 2 deletions core/js/tests/specs/sharedialogviewSpec.js
Expand Up @@ -444,7 +444,7 @@ describe('OC.Share.ShareDialogView', function() {
dialog.render();

dialog.$el.find('.emailPrivateLinkForm .emailField').val('a@b.c');
dialog.$el.find('.emailPrivateLinkForm').trigger('submit');
dialog.$el.find('#emailButton').trigger('click');

expect(sendEmailPrivateLinkStub.callCount).toEqual(1);
expect(dialog.$el.find('.emailPrivateLinkForm .emailField').val()).toEqual('Sending ...');
Expand All @@ -463,7 +463,7 @@ describe('OC.Share.ShareDialogView', function() {
dialog.render();

dialog.$el.find('.emailPrivateLinkForm .emailField').val('a@b.c');
dialog.$el.find('.emailPrivateLinkForm').trigger('submit');
dialog.$el.find('#emailButton').trigger('click');

expect(sendEmailPrivateLinkStub.callCount).toEqual(1);
expect(dialog.$el.find('.emailPrivateLinkForm .emailField').val()).toEqual('Sending ...');
Expand Down
4 changes: 4 additions & 0 deletions core/vendor/.gitignore
Expand Up @@ -137,3 +137,7 @@ es6-promise/dist/*

# base64
base64/*min.js

# clipboard
clipboard/**
!clipboard/dist/clipboard.js