Merge tag '0.10.2'
[ganeti_webmgr.git] / ganeti_web / templates / ganeti / ssh_keys / header.html
blob19fa56cb9395da89e1335e59fc42000f260b491f
1 <style>
2 #key_list a {background:none;}
3 #key_list a.edit div {padding-right:10px;}
4 </style>
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">
8 var id = null;
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") {
13 // handle errors
14 fail(responseText);
16 } else {
17 // everything went fine
19 // int is the value of record ID and means success
20 $(".qtip").hide();
22 // get only one table row, not the whole table
23 if (id!=null) {
24 // old record, update existing row
25 $("#sshkey_"+id).replaceWith(responseText);
26 id = null;
27 } else {
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) {
36 // parse errors
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");
47 $(obj).qtip({
48 content: {
49 url: get_url,
50 title: {text:"SSH key: ", button: "close"}
52 position: {
53 corner: {target:"bottomLeft", tooltip:"topRight"}
55 style: {name:"dark",border:{radius:5},width:390,tip:false,
56 background:"#eee"},
57 show: {when: false, ready: true},
58 hide: {fixed: true, when: false},
59 api: {onShow: function(){$(".ajax_form textarea").focus()}}
60 });
63 $(function() {
65 // "Add" button clicked
66 $("#add_key").live("click", function() {
67 // popup new qtip window
68 popup_qtip(this, this.href);
70 return false;
71 });
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(){
83 $(parent).remove();
84 });
87 // ensures we don't save already deleted key
88 if (id==_id) {
89 $(".qtip").qtip("destroy");
90 id = null;
92 });
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);
103 // Form submitted
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});
112 </script>