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

Access Token Popup (GCI) #4021

Merged
merged 11 commits into from
Nov 26, 2018
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
82 changes: 82 additions & 0 deletions app/views/users/_token.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<script type="text/javascript">
$('#btn-token').on('click',function() {
var token = '<%= @user.user.token %>';

var mask = document.createElement('div');
mask.className = 'mask';
mask.id = 'token-mask';

mask.innerHTML = '\
<div class="modal-dialog" id="token-popup">\
<div class="modal-content">\
<div class="modal-header">\
<button type="button" class="close" id="close-btn">&times;</button>\
<h4 class="modal-title">Access Token</h4>\
</div>\
<div class="modal-body">\
<p><span class="token form-control text-center"></span></p>\
</div>\
<div class="modal-footer">\
<button type="button" class="btn btn-default" id="copy-btn">Copy</button>\
</div>\
</div>\
</div>\
';

$('body').append(mask);
$('#token-mask').fadeIn(200, function(){
$('#token-popup .token').text(token);
$('#token-popup .modal-content').animate({marginTop: '30px', opacity: '1'}, 300);
$('#token-mask').on('click', closePopup);
$('#token-popup #copy-btn').on('click', copyToken);
});
});

function copyToken(){
var temp = $('<input>');
$("body").append(temp);
temp.val($('#token-popup .token').text()).select();
document.execCommand('copy');
temp.remove();

$('#token-popup #copy-btn').text('Copied').attr('disabled', 'true');
};

function closePopup(e){
var tokenPopup = document.querySelector('#token-popup .modal-content');
if (tokenPopup === e.target || tokenPopup.contains(e.target) && e.target.id !== 'close-btn'){
return;
};

$('#token-popup .modal-content').animate({marginTop: '0', opacity: '0'}, 300, function(){
$(this).remove();
$('#token-mask').fadeOut(200, function(){
$(this).remove();
});
});
};
</script>

<style type="text/css">
.mask{
display: none;
z-index: 10000;
position: fixed;
height: 100%;
width: 100%;
top: 0;
background-color: rgba(0, 0, 0, 0.7);
}

.modal-dialog{
margin-top: 0;
}

.modal-content{
opacity: 0;
}

.token{
font-weight: bold;
}
</style>
7 changes: 2 additions & 5 deletions app/views/users/profile.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,13 @@
<% end %>
</div>


</div>

<%= render partial: 'users/token' %>

<script src = "https://cdn.jsdelivr.net/npm/frappe-charts@0.0.8/dist/frappe-charts.min.iife.js"></script>

<script type = "text/javascript">
$('#btn-token').click(function() {
alert("Your access token is: <%= @user.user.token %>");
});

$('#link_social_media').click(function(){
sign = document.getElementById('social-name').value;
$.post('/profile/tags/create/<%=@user.uid %> ',{"name": sign,"id":<%=@user.uid %>}, function(data) {
Expand Down