Skip to content

Commit

Permalink
Merge pull request #4 from final-gene/copy-to-clipboard
Browse files Browse the repository at this point in the history
Copy to clipboard
  • Loading branch information
FrankGiesecke authored Oct 5, 2017
2 parents e795eeb + 9305252 commit d334f4a
Show file tree
Hide file tree
Showing 12 changed files with 268 additions and 199 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Path-based git attributes
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html

/.docker export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/docker-compose.dev.yml export-ignore
/Makefile export-ignore
134 changes: 91 additions & 43 deletions system/js/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,107 +5,126 @@ $(document).ready(function () {
var password_exploded = password_id.split('-');
password_id = password_exploded[1];


$('#id-' + password_id).replaceWith('<a id="id-' + password_id + '">loading...</a>');

$.ajax({
type: "GET",
url: mrp_base_url + "/passwords/gethistory/" + password_id,
success: function(html){
$('#id-' + password_id).replaceWith(html);
$('#id-' + password_id).replaceWith(generateCopyBox(html));
}


});

});

$(".show_password").click(function () {
var password_id = $(this).attr("id");
var password_exploded = password_id.split('-');
password_id = password_exploded[1];


$('#id-' + password_id).replaceWith('<a id="id-' + password_id + '">loading...</a>');

$.ajax({
type: "GET",
url: mrp_base_url + "/passwords/get/" + password_id,
success: function(html){
$('#id-' + password_id).replaceWith(html);
$('#id-' + password_id).replaceWith(generateCopyBox(html));
}


});

});

$(".show_share_password").click(function () {
var password_id = $(this).attr("id");
var password_exploded = password_id.split('-');
password_id = password_exploded[1];


$('#id-' + password_id).replaceWith('<a id="id-' + password_id + '">loading...</a>');

$.ajax({
type: "GET",
url: mrp_base_url + "/passwords/getshare/" + password_id,
success: function(html){
$('#id-' + password_id).replaceWith(html);
$('#id-' + password_id).replaceWith(generateCopyBox(html));
}


});

});

$(".show_global_password").click(function () {
var password_id = $(this).attr("id");
var password_exploded = password_id.split('-');
password_id = password_exploded[1];


$('#id-' + password_id).replaceWith('<a id="id-' + password_id + '">loading...</a>');

$.ajax({
type: "GET",
url: mrp_base_url + "/passwords/getglobal/" + password_id,
success: function(html){
$('#id-' + password_id).replaceWith(html);
$('#id-' + password_id).replaceWith(generateCopyBox(html));
}


});

});

var generateCopyBox = function (value) {
var box = $("<div>");

var input = $("<input>");
input.val(value);
input.appendTo(box);
input.prop("readonly", true);

var copy = $("<a>");
copy.attr("href", "#");
copy.addClass("copy_value");
copy.attr("alt", "Copy value");
copy.data("value", value);
copy.html("copy");
copy.appendTo(box);

return box;
};

$(".generate_password").click(function (e) {
e.preventDefault();

var type = 0;

type = $("input:radio[name=password_type]:checked").val();

$(".generate_field").val(generatePassword(type));


$(".generate_field").val(generatePassword(type));


});

var generatePassword = function (type) {

var words = ["password", "alpha", "bravo", "charlie", "delta", "echo", "foxtrot", "golf", "hotel", "india", "juliet", "kilo", "lima", "mike", "november", "oscar", "papa", "quebec", "romeo", "sierra", "tango", "uniform", "victor", "whiskey", "x-ray", "yankee", "zulu"];
var symbols = ["!", "\"", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "{", "]", "}", ";", ":", "'", "@", "#", "~", "|", ",", "<", ".", ">", "/", "?"];
var symbols = ["!", "\"", "$", "%", "^", "&", "*", "(", ")", "-", "_", "=", "+", "[", "{", "]", "}", ";", ":", "'", "@", "#", "~", "|", ",", "<", ".", ">", "/", "?"];

var passwd = '';

if (type == 1) {
var word = words[Math.floor(Math.random()*words.length)];
var symbol = symbols[Math.floor(Math.random()*symbols.length)];

passwd = word;
passwd = word;
passwd += symbol;

var length = 3;
var chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
}
Expand All @@ -118,7 +137,7 @@ $(document).ready(function () {
var chars = '~!@#$%^&*()_+=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';

}

for (i=1;i<=length;i++) {
var c = Math.floor(Math.random()*chars.length + 1);
passwd += chars.charAt(c);
Expand All @@ -127,28 +146,28 @@ $(document).ready(function () {
return passwd;

};

$('#add_extra_file').click(function (e) {
e.preventDefault();

$('#attach_file_area').append('<div><div class="pull-left"><input name="file[]" type="file" /></div><div class="pull-right"><a href="#" id="remove_this_file"><span class="glyphicon glyphicon-remove"></span></a></div></div>');

});

//Delete existing file
$('body').on('click', '.delete_existing_password_file', function(e){
e.preventDefault();

if (confirm("Are you sure you wish to delete this file?")){

var ticket_id = $(this).closest('li').attr("id");
var ticket_exploded = ticket_id.split('-');
ticket_id = ticket_exploded[1];

var file_id = $(this).attr("id");
var file_exploded = file_id.split('-');
file_id = file_exploded[1];

$.ajax({
type: "POST",
url: mrp_base_url + "/passwords/deletefile/" + file_id + "/",
Expand All @@ -157,15 +176,44 @@ $(document).ready(function () {
//alert(html);
}
});
$(this).parent('li').remove();

$(this).parent('li').remove();
}
else {
return false;
}

});



});
});

$('body').on('click', '.copy_value', function(e) {
var temp = $("<input>");
$("body").append(temp);
temp.val($(this).prev("input").val());

if (navigator.userAgent.match(/ipad|ipod|iphone/i)) {
var el = temp.get(0);
var editable = el.contentEditable;
var readOnly = el.readOnly;
el.contentEditable = true;
el.readOnly = false;
var range = document.createRange();
range.selectNodeContents(el);
var sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(range);
el.setSelectionRange(0, 999999);
el.contentEditable = editable;
el.readOnly = readOnly;
} else {
temp.select();
}

document.execCommand("copy");
temp.remove();
});

$(".content-as-copy-box").each(function (e) {
$(this).replaceWith(generateCopyBox($(this).text()));
});

});
12 changes: 12 additions & 0 deletions user/themes/bootstrap3/core6/stylesheets/theme-custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -432,3 +432,15 @@ body {
background-color: #85d0e7 !important; }
.navbar-collapse .navbar-nav.navbar-right {
padding-right: 0; } }

a.copy_value {
display: inline-block;
width: 16px;
height: 16px;
background-image: url("../../images/icons/clipboard.png");
margin-left: 5px;

text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
Binary file added user/themes/bootstrap3/images/icons/clipboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d334f4a

Please sign in to comment.