2015-11-22 23:52:02 -05:00
|
|
|
module ButtonHelper
|
2015-11-24 18:35:24 -05:00
|
|
|
# Output a "Copy to Clipboard" button
|
|
|
|
#
|
|
|
|
# data - Data attributes passed to `content_tag`
|
|
|
|
#
|
|
|
|
# Examples:
|
|
|
|
#
|
|
|
|
# # Define the clipboard's text
|
|
|
|
# clipboard_button(clipboard_text: "Foo")
|
|
|
|
# # => "<button class='...' data-clipboard-text='Foo'>...</button>"
|
|
|
|
#
|
|
|
|
# # Define the target element
|
2015-12-15 16:11:01 -05:00
|
|
|
# clipboard_button(clipboard_target: "div#foo")
|
|
|
|
# # => "<button class='...' data-clipboard-target='div#foo'>...</button>"
|
2015-11-24 18:35:24 -05:00
|
|
|
#
|
|
|
|
# See http://clipboardjs.com/#usage
|
2016-05-25 04:11:47 -04:00
|
|
|
def clipboard_button(data = {})
|
2016-07-08 21:06:12 -04:00
|
|
|
data = { toggle: 'tooltip', placement: 'bottom', container: 'body' }.merge(data)
|
2015-11-22 23:53:55 -05:00
|
|
|
content_tag :button,
|
|
|
|
icon('clipboard'),
|
2016-06-17 04:54:24 -04:00
|
|
|
class: "btn btn-clipboard",
|
2015-11-24 18:35:24 -05:00
|
|
|
data: data,
|
2016-07-08 21:06:12 -04:00
|
|
|
type: :button,
|
|
|
|
title: "Copy to Clipboard"
|
2016-05-24 12:06:49 -04:00
|
|
|
end
|
|
|
|
|
2016-07-05 17:48:48 -04:00
|
|
|
def http_clone_button(project, placement = 'right', append_link: true)
|
2016-03-20 01:46:56 -04:00
|
|
|
klass = 'http-selector'
|
2016-03-20 15:01:46 -04:00
|
|
|
klass << ' has-tooltip' if current_user.try(:require_password?)
|
2015-11-22 23:52:02 -05:00
|
|
|
|
|
|
|
protocol = gitlab_config.protocol.upcase
|
|
|
|
|
2016-07-05 17:48:48 -04:00
|
|
|
content_tag (append_link ? :a : :span), protocol,
|
2015-11-22 23:52:02 -05:00
|
|
|
class: klass,
|
2016-06-29 16:25:04 -04:00
|
|
|
href: (project.http_url_to_repo if append_link),
|
2015-11-22 23:52:02 -05:00
|
|
|
data: {
|
2016-03-20 01:46:56 -04:00
|
|
|
html: true,
|
2016-06-20 21:40:56 -04:00
|
|
|
placement: placement,
|
2016-03-20 10:52:06 -04:00
|
|
|
container: 'body',
|
2015-11-22 23:52:02 -05:00
|
|
|
title: "Set a password on your account<br>to pull or push via #{protocol}"
|
2016-03-20 01:46:56 -04:00
|
|
|
}
|
2015-11-22 23:52:02 -05:00
|
|
|
end
|
|
|
|
|
2016-07-05 17:48:48 -04:00
|
|
|
def ssh_clone_button(project, placement = 'right', append_link: true)
|
2016-03-20 01:46:56 -04:00
|
|
|
klass = 'ssh-selector'
|
2016-03-20 15:01:46 -04:00
|
|
|
klass << ' has-tooltip' if current_user.try(:require_ssh_key?)
|
2015-11-22 23:52:02 -05:00
|
|
|
|
2016-07-05 17:48:48 -04:00
|
|
|
content_tag (append_link ? :a : :span), 'SSH',
|
2015-11-22 23:52:02 -05:00
|
|
|
class: klass,
|
2016-06-29 16:25:04 -04:00
|
|
|
href: (project.ssh_url_to_repo if append_link),
|
2015-11-22 23:52:02 -05:00
|
|
|
data: {
|
2016-03-20 01:46:56 -04:00
|
|
|
html: true,
|
2016-06-20 21:40:56 -04:00
|
|
|
placement: placement,
|
2016-03-20 10:52:06 -04:00
|
|
|
container: 'body',
|
2015-11-22 23:52:02 -05:00
|
|
|
title: 'Add an SSH key to your profile<br>to pull or push via SSH.'
|
2016-03-20 01:46:56 -04:00
|
|
|
}
|
2015-11-22 23:52:02 -05:00
|
|
|
end
|
|
|
|
end
|