1 <script type=
"text/javascript">
2 /** @namespace data.opresult */
7 // poll for job status, first poll is delayed by 3000ms
8 function poll_job_status(job_id
, callback
, errback
) {
9 actions_enabled
= false;
10 $('#actions a').addClass('disabled');
11 checkInterval
= setInterval(get_job_status
, 3000, job_id
, callback
, errback
);
15 function get_job_status(job_id
, callback
, errback
) {
17 url
: "{% url cluster-detail cluster.slug %}/job/"+job_id
+"/status/",
18 success: function(data
) {
19 if (data
.status
== 'success'){
20 $("#messages").empty();
21 clearInterval(checkInterval
);
22 if (callback
!=undefined){
25 } else if (data
.status
== 'error' && errback
!= undefined) {
30 if (data
.status
== 'error'){
31 if (checkInterval
!= undefined){
32 clearInterval(checkInterval
);
33 checkInterval
= undefined;
40 function display_job(data
) {
41 // get the sub operation that is either running or errored
42 for (var sub_op
=0; sub_op
<data
['opstatus'].length
-1;) {
43 if (data
['opstatus'][sub_op
] != 'success') {
49 $("#messages").empty();
51 var op
= format_op(data
['ops'][sub_op
]['OP_ID']);
52 var html
= $("<li class='job'><h3>"+op
+"</h3></li>");
53 $("#messages").append(html
);
54 var scrollable
= $('<div class="scrollable"><div class="detector"></div></div>');
55 var error
= undefined;
56 html
.append(scrollable
);
58 if (data
.status
== 'error') {
59 html
.addClass('error');
60 var reason
= data
.opresult
[sub_op
][1][0];
61 var job_id
= data
['id'];
62 var href
= "{% url cluster-detail cluster.slug %}/job/"+job_id
+"/clear/";
64 .append("<a class='clear' title='clear error' href='"+href
+"'></a>");
65 error
= $("<pre class='error'>" + reason
+ "</pre>");
66 scrollable
.append(error
);
67 actions_enabled
= true;
68 $('#actions a').removeClass('disabled');
71 // append log messages that are not already displayed
72 var current_log_count
= $("#log ul li").length
;
73 if (data
['oplog'][sub_op
].length
!= 0) {
74 var log_html
= html
.children('.op_log');
75 if (log_html
.length
==0){
76 log_html
= $("<pre class='op_log'><ul></ul></pre>");
77 scrollable
.append(log_html
);
79 var log
= data
['oplog'][sub_op
];
80 for (var i
=current_log_count
; i
<log
.length
; i
++) {
81 log_html
.children("ul")
82 .append("<li>"+log
[i
][3]+"</li>");
86 // XXX hack to ensure log area is same width as error area.
87 if (log_html
!= undefined) {
88 var width
= $(html
).find('.scrollable .detector').width()
89 width
-= (log_html
.innerWidth() - log_html
.width()) // subtract padding
90 log_html
.width(width
);
91 $(html
).find('.scrollable').css('display', 'block')
95 function format_op(str
){
96 str
= str
.substring(3).replace('_',' ').toLowerCase();
101 function cap_first(str
) {
103 str
= str
.split(' ');
104 for(var i
=0; i
< str
.length
; i
++) {
105 new_str
+= str
[i
].substring(0,1).toUpperCase() +
106 str
[i
].substring(1,str
[i
].length
) + ' ';
111 $("#messages a.clear").live("click", function(event
){
112 event
.preventDefault();
113 var error
= $(this).parent().parent();
114 $.post(this.href
, function(){
115 error
.fadeOut(1000, function(){