2 #key_list a {background:none;}
3 #key_list a.edit div {padding-right:
10px;}
5 <script type=
"text/javascript" src=
"{{STATIC_URL}}/js/jquery.ajax.delete.js"></script>
6 <script type=
"text/javascript" src=
"{{STATIC_URL}}/js/jquery.form.js"></script>
7 <script type=
"text/javascript">
10 // update appropriate row or add new in case the request succeded
11 function update(responseText
, statusText
, xhr
, $form
) {
12 if (xhr
.getResponseHeader("Content-Type") == "application/json") {
17 // everything went fine
19 // int is the value of record ID and means success
22 // get only one table row, not the whole table
24 // old record, update existing row
25 $("#sshkey_"+id
).replaceWith(responseText
);
28 // new record, add to the end of table
29 $("#key_list").append(responseText
);
34 // show list of errors from XHR object request
35 function fail(responseText
) {
37 for (var key
in responseText
) {
38 $(".qtip #errors").append("<li>"+ responseText
[key
] +"</li>");
42 // Open new qtip popup window
43 function popup_qtip(obj
, get_url
) {
44 // destroy old qtip before showing new one
45 $(".qtip").qtip("destroy");
50 title
: {text
:"SSH key: ", button
: "close"}
53 corner
: {target
:"bottomLeft", tooltip
:"topRight"}
55 style
: {name
:"dark",border
:{radius
:5},width
:390,tip
:false,
57 show
: {when
: false, ready
: true},
58 hide
: {fixed
: true, when
: false},
59 api
: {onShow: function(){$(".ajax_form textarea").focus()}}
65 // "Add" button clicked
66 $("#add_key").live("click", function() {
67 // popup new qtip window
68 popup_qtip(this, this.href
);
73 // "Delete" link clicked
74 $("#key_list a.delete").live("click", function(event
){
75 event
.preventDefault();
76 var host
= $(this).parents("tr").children("[name=\"host\"]").html();
77 var key
= $(this).parents("tr").children("[name=\"key\"]").html();
78 var _id
= $(this).parents("tr").attr("id").substring(7);
80 if (confirm("Remove key \""+key
+"\" with comment "+host
+ "?")) {
81 var parent
= this.parentNode
.parentNode
;
82 $.delete_(this.href
, function(){
87 // ensures we don't save already deleted key
89 $(".qtip").qtip("destroy");
94 // "Edit" link clicked
95 $("#key_list a.edit").live("click", function(event
){
96 event
.preventDefault();
97 id
= $(this).parents("tr").attr("id").substring(7);
99 // popup new qtip window
100 popup_qtip(this, this.href
);
104 $(".ajax_form").live("submit", function(event
) {
105 event
.preventDefault();
106 //makes sure no errors are presented
107 $(".qtip #errors").empty();
109 $(this).ajaxSubmit({success
: update
});