| 
									
										
										
										
											2010-07-23 20:43:35 +08:00
										 |  |  | UNKNOWN_REPR = '<span class="unknown">?</span>'; | 
					
						
							| 
									
										
										
										
											2011-02-04 22:38:26 +08:00
										 |  |  | FD_THRESHOLDS=[[0.95, 'red'], | 
					
						
							| 
									
										
										
										
											2011-02-18 22:26:12 +08:00
										 |  |  |                [0.8, 'yellow']]; | 
					
						
							| 
									
										
										
										
											2011-02-04 22:38:26 +08:00
										 |  |  | SOCKETS_THRESHOLDS=[[1.0, 'red'], | 
					
						
							| 
									
										
										
										
											2011-02-18 22:26:12 +08:00
										 |  |  |                     [0.8, 'yellow']]; | 
					
						
							| 
									
										
										
										
											2011-02-04 22:38:26 +08:00
										 |  |  | PROCESS_THRESHOLDS=[[0.75, 'red'], | 
					
						
							| 
									
										
										
										
											2011-02-18 22:26:12 +08:00
										 |  |  |                     [0.5, 'yellow']]; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-26 01:02:03 +08:00
										 |  |  | function fmt_string(str, unknown) { | 
					
						
							| 
									
										
										
										
											2013-08-16 23:42:52 +08:00
										 |  |  |     if (unknown == undefined) unknown = UNKNOWN_REPR; | 
					
						
							| 
									
										
										
										
											2012-06-26 01:02:03 +08:00
										 |  |  |     if (str == undefined) return unknown; | 
					
						
							| 
									
										
										
										
											2011-11-30 21:43:42 +08:00
										 |  |  |     return fmt_escape_html("" + str); | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_bytes(bytes) { | 
					
						
							| 
									
										
										
										
											2010-07-23 20:43:35 +08:00
										 |  |  |     if (bytes == undefined) return UNKNOWN_REPR; | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  |     return fmt_si_prefix(bytes, bytes, 1024) + 'B'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_si_prefix(num, max, thousand) { | 
					
						
							|  |  |  |     if (num == 0) return 0; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  |     function f(n, m, p) { | 
					
						
							|  |  |  |         if (m > thousand) return f(n / thousand, m / thousand, p + 1); | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  |         else return [n, p]; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  |     var num_power = f(num, max, 0); | 
					
						
							| 
									
										
										
										
											2010-09-01 00:56:33 +08:00
										 |  |  |     var num = num_power[0]; | 
					
						
							|  |  |  |     var power = num_power[1]; | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  |     var powers = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; | 
					
						
							|  |  |  |     return ((power == 0 || num > 10) ? num.toFixed(0) : | 
					
						
							|  |  |  |             num.toFixed(1)) + powers[power]; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-19 06:47:42 +08:00
										 |  |  | function fmt_memory(memory, key) { | 
					
						
							| 
									
										
										
										
											2012-12-18 23:57:34 +08:00
										 |  |  |     return '<div class="colour-key memory_' + key + '"></div>' + | 
					
						
							| 
									
										
										
										
											2012-09-19 06:47:42 +08:00
										 |  |  |         fmt_bytes(memory[key]); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | function fmt_boolean(b) { | 
					
						
							| 
									
										
										
										
											2010-07-23 20:43:35 +08:00
										 |  |  |     if (b == undefined) return UNKNOWN_REPR; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return b ? "●" : "○"; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-14 19:45:45 +08:00
										 |  |  | function fmt_date(d) { | 
					
						
							|  |  |  |     function f(i) { | 
					
						
							|  |  |  |         return i < 10 ? "0" + i : i; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-04 00:38:53 +08:00
										 |  |  |     return d.getFullYear() + "-" + f(d.getMonth() + 1) + "-" + | 
					
						
							| 
									
										
										
										
											2012-01-14 01:41:39 +08:00
										 |  |  |         f(d.getDate()) + " " + f(d.getHours()) + ":" + f(d.getMinutes()) + | 
					
						
							| 
									
										
										
										
											2011-05-04 00:38:53 +08:00
										 |  |  |         ":" + f(d.getSeconds()); | 
					
						
							| 
									
										
										
										
											2011-01-14 19:45:45 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-06-12 20:07:41 +08:00
										 |  |  | function fmt_time(t, suffix) { | 
					
						
							|  |  |  |     if (t == undefined || t == 0) return ''; | 
					
						
							|  |  |  |     return t + suffix; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-02 23:53:39 +08:00
										 |  |  | function fmt_millis(millis) { | 
					
						
							|  |  |  |     return Math.round(millis / 1000) + "s"; | 
					
						
							| 
									
										
										
										
											2012-09-27 22:46:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  | function fmt_parameters(obj) { | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |     return fmt_table_short(args_to_params(obj)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_parameters_short(obj) { | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  |     var res = ''; | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |     var params = args_to_params(obj); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (var k in ALL_ARGS) { | 
					
						
							|  |  |  |         if (params[k] != undefined) { | 
					
						
							| 
									
										
										
										
											2011-11-30 21:43:42 +08:00
										 |  |  |             res += '<acronym title="' + k + ': ' + fmt_string(params[k]) + | 
					
						
							|  |  |  |                 '">' + ALL_ARGS[k].short + '</acronym> '; | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (params.arguments) { | 
					
						
							|  |  |  |         res += '<acronym title="' + fmt_table_flat(params.arguments) + | 
					
						
							|  |  |  |         '">Args</acronym>'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-19 23:29:16 +08:00
										 |  |  | function short_conn(name) { | 
					
						
							|  |  |  |     var pat = /^(.*)->/; | 
					
						
							|  |  |  |     var match = pat.exec(name); | 
					
						
							|  |  |  |     return (match != null && match.length == 2) ? match[1] : name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function short_chan(name) { | 
					
						
							|  |  |  |     var pat = /^(.*)->.*( \(.*\))/; | 
					
						
							|  |  |  |     var match = pat.exec(name); | 
					
						
							|  |  |  |     return (match != null && match.length == 3) ? match[1] + match[2] : name; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  | function args_to_params(obj) { | 
					
						
							|  |  |  |     var res = {}; | 
					
						
							|  |  |  |     for (var k in obj.arguments) { | 
					
						
							|  |  |  |         if (k in KNOWN_ARGS) { | 
					
						
							|  |  |  |             res[k] = obj.arguments[k]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             if (res.arguments == undefined) res.arguments = {}; | 
					
						
							|  |  |  |             res.arguments[k] = obj.arguments[k]; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  |     if (obj.durable) { | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |         res['durable'] = true; | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (obj.auto_delete) { | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |         res['auto-delete'] = true; | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-11-15 20:32:42 +08:00
										 |  |  |     if (obj.internal != undefined && obj.internal) { | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  |         res['internal'] = true; | 
					
						
							| 
									
										
										
										
											2010-10-29 20:01:22 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-25 18:58:56 +08:00
										 |  |  | function fmt_mirrors(queue) { | 
					
						
							| 
									
										
										
										
											2011-07-15 22:52:29 +08:00
										 |  |  |     var synced = queue.synchronised_slave_nodes || []; | 
					
						
							|  |  |  |     var unsynced = queue.slave_nodes || []; | 
					
						
							|  |  |  |     unsynced = jQuery.grep(unsynced, | 
					
						
							|  |  |  |                            function (node, i) { | 
					
						
							|  |  |  |                                return jQuery.inArray(node, synced) == -1 | 
					
						
							|  |  |  |                            }); | 
					
						
							|  |  |  |     var res = ''; | 
					
						
							| 
									
										
										
										
											2011-08-16 20:24:17 +08:00
										 |  |  |     if (synced.length > 0) { | 
					
						
							|  |  |  |         res += ' <acronym title="Synchronised mirrors: ' + synced + '">+' + | 
					
						
							| 
									
										
										
										
											2011-07-15 22:52:29 +08:00
										 |  |  |             synced.length + '</acronym>'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-08-16 20:24:17 +08:00
										 |  |  |     if (synced.length == 0 && unsynced.length > 0) { | 
					
						
							|  |  |  |         res += ' <acronym title="There are no synchronised mirrors">+0</acronym>'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-07-15 22:52:29 +08:00
										 |  |  |     if (unsynced.length > 0) { | 
					
						
							|  |  |  |         res += ' <acronym class="warning" title="Unsynchronised mirrors: ' + | 
					
						
							|  |  |  |             unsynced + '">+' + unsynced.length + '</acronym>'; | 
					
						
							| 
									
										
										
										
											2011-05-25 18:58:56 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-07-15 22:52:29 +08:00
										 |  |  |     return res; | 
					
						
							| 
									
										
										
										
											2011-05-25 18:58:56 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-08 23:41:53 +08:00
										 |  |  | function fmt_sync_status(queue) { | 
					
						
							|  |  |  |     var res = '<p><b>Syncing: '; | 
					
						
							| 
									
										
										
										
											2013-01-09 03:38:03 +08:00
										 |  |  |     res += (queue.messages == 0) ? 100 : Math.round(100 * queue.sync_messages / | 
					
						
							|  |  |  |                                                     queue.messages); | 
					
						
							| 
									
										
										
										
											2013-01-08 23:41:53 +08:00
										 |  |  |     res += '%</b></p>'; | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-01-21 21:17:41 +08:00
										 |  |  | function fmt_channel_mode(ch) { | 
					
						
							|  |  |  |     if (ch.transactional) { | 
					
						
							|  |  |  |         return '<acronym title="Transactional">T</acronym>'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else if (ch.confirm) { | 
					
						
							|  |  |  |         return '<acronym title="Confirm">C</acronym>'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         return ''; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-29 23:32:17 +08:00
										 |  |  | function fmt_color(r, thresholds) { | 
					
						
							| 
									
										
										
										
											2010-07-23 20:43:35 +08:00
										 |  |  |     if (r == undefined) return ''; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-29 23:32:17 +08:00
										 |  |  |     for (var i in thresholds) { | 
					
						
							| 
									
										
										
										
											2011-02-18 22:26:12 +08:00
										 |  |  |         var threshold = thresholds[i][0]; | 
					
						
							|  |  |  |         var color = thresholds[i][1]; | 
					
						
							| 
									
										
										
										
											2010-10-29 23:32:17 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-18 22:26:12 +08:00
										 |  |  |         if (r >= threshold) { | 
					
						
							|  |  |  |             return color; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-10-29 23:32:17 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-10-30 00:58:21 +08:00
										 |  |  |     return 'green'; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-05 23:56:51 +08:00
										 |  |  | function fmt_deliver_rate(obj, show_redeliver) { | 
					
						
							|  |  |  |     var res = fmt_rate(obj, 'deliver_get'); | 
					
						
							|  |  |  |     if (show_redeliver) { | 
					
						
							|  |  |  |         res += '<sub>' + fmt_rate(obj, 'redeliver') + '</sub>'; | 
					
						
							| 
									
										
										
										
											2011-02-28 19:19:36 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-02-05 23:56:51 +08:00
										 |  |  |     return res; | 
					
						
							| 
									
										
										
										
											2010-09-02 19:58:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-05 01:16:20 +08:00
										 |  |  | function fmt_rate_num(num) { | 
					
						
							|  |  |  |     if (num == undefined) return UNKNOWN_REPR; | 
					
						
							| 
									
										
										
										
											2012-01-05 05:23:58 +08:00
										 |  |  |     else if (num < 1)     return num.toFixed(2); | 
					
						
							|  |  |  |     else if (num < 10)    return num.toFixed(1); | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  |     else                  return fmt_num_thousands(num.toFixed(0)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_num_thousands(num) { | 
					
						
							| 
									
										
										
										
											2013-08-16 23:38:42 +08:00
										 |  |  |     if (num == undefined) return UNKNOWN_REPR; | 
					
						
							| 
									
										
										
										
											2013-06-29 00:30:08 +08:00
										 |  |  |     num = '' + num; | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  |     if (num.length < 4) return num; | 
					
						
							|  |  |  |     return fmt_num_thousands(num.slice(0, -3)) + ',' + num.slice(-3); | 
					
						
							| 
									
										
										
										
											2012-01-05 01:16:20 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-19 21:31:26 +08:00
										 |  |  | function fmt_rate(obj, name, mode) { | 
					
						
							| 
									
										
										
										
											2013-01-25 21:09:11 +08:00
										 |  |  |     var raw = fmt_rate0(obj, name, mode, fmt_rate_num); | 
					
						
							|  |  |  |     return raw == '' ? '' : (raw + '/s'); | 
					
						
							| 
									
										
										
										
											2010-09-02 19:58:34 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-07-28 01:04:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-19 01:13:44 +08:00
										 |  |  | function fmt_rate_bytes(obj, name, mode) { | 
					
						
							| 
									
										
										
										
											2013-01-25 23:28:47 +08:00
										 |  |  |     var raw = fmt_rate0(obj, name, mode, fmt_bytes); | 
					
						
							|  |  |  |     return raw == '' ? '' : (raw + '/s' + | 
					
						
							|  |  |  |                              '<sub>(' + fmt_bytes(obj[name]) + ' total)</sub>'); | 
					
						
							| 
									
										
										
										
											2010-07-28 01:04:48 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-19 21:31:26 +08:00
										 |  |  | function fmt_rate_large(obj, name, mode) { | 
					
						
							|  |  |  |     return '<strong>' + fmt_rate0(obj, name, mode, fmt_rate_num) + | 
					
						
							|  |  |  |         '</strong>msg/s'; | 
					
						
							| 
									
										
										
										
											2010-09-02 19:58:34 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-07-28 01:04:48 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-19 21:31:26 +08:00
										 |  |  | function fmt_rate_bytes_large(obj, name, mode) { | 
					
						
							|  |  |  |     return '<strong>' + fmt_rate0(obj, name, mode, fmt_bytes) + '/s</strong>' + | 
					
						
							|  |  |  |         '(' + fmt_bytes(obj[name]) + ' total)'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_rate0(obj, name, mode, fmt) { | 
					
						
							|  |  |  |     if (obj == undefined || obj[name] == undefined || | 
					
						
							|  |  |  |         obj[name + '_details'] == undefined) return ''; | 
					
						
							|  |  |  |     var details = obj[name + '_details']; | 
					
						
							|  |  |  |     return fmt(mode == 'avg' ? details.avg_rate : details.rate); | 
					
						
							| 
									
										
										
										
											2010-07-28 01:04:48 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-05 23:56:51 +08:00
										 |  |  | function fmt_msgs(obj, name, mode) { | 
					
						
							|  |  |  |     return fmt_msgs0(obj, name, mode) + ' msg'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_msgs_large(obj, name, mode) { | 
					
						
							|  |  |  |     return '<strong>' + fmt_msgs0(obj, name, mode) + '</strong>' + | 
					
						
							|  |  |  |         fmt_rate0(obj, name, mode, fmt_msgs_rate); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_msgs0(obj, name, mode) { | 
					
						
							|  |  |  |     if (obj == undefined || obj[name] == undefined || | 
					
						
							|  |  |  |         obj[name + '_details'] == undefined) return ''; | 
					
						
							|  |  |  |     var details = obj[name + '_details']; | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  |     return mode == 'avg' ? fmt_rate_num(details.avg) : | 
					
						
							| 
									
										
										
										
											2013-06-29 00:30:08 +08:00
										 |  |  |         fmt_num_thousands(obj[name]); | 
					
						
							| 
									
										
										
										
											2013-02-05 23:56:51 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_msgs_rate(num) { | 
					
						
							|  |  |  |     if (num > 0)      return '+' + fmt_rate_num(num)  + ' msg/s'; | 
					
						
							|  |  |  |     else if (num < 0) return '-' + fmt_rate_num(-num) + ' msg/s'; | 
					
						
							|  |  |  |     else              return ' '; | 
					
						
							| 
									
										
										
										
											2011-07-06 19:03:23 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  | function fmt_rate_axis(num, max) { | 
					
						
							|  |  |  |     return fmt_si_prefix(num, max, 1000) + '/s'; | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  | function fmt_msgs_axis(num, max) { | 
					
						
							|  |  |  |     return fmt_si_prefix(num, max, 1000); | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-06-17 22:40:42 +08:00
										 |  |  | function fmt_rate_bytes_axis(num, max) { | 
					
						
							| 
									
										
										
										
											2013-05-01 18:54:15 +08:00
										 |  |  |     num = parseInt(num); | 
					
						
							|  |  |  |     return fmt_bytes(isNaN(num) ? 0 : num) + '/s'; | 
					
						
							| 
									
										
										
										
											2011-07-06 19:03:23 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-26 01:32:04 +08:00
										 |  |  | function is_stat_empty(obj, name) { | 
					
						
							| 
									
										
										
										
											2011-02-17 23:23:08 +08:00
										 |  |  |     if (obj == undefined | 
					
						
							| 
									
										
										
										
											2011-02-18 18:38:41 +08:00
										 |  |  |         || obj[name] == undefined | 
					
						
							|  |  |  |         || obj[name + '_details'] == undefined | 
					
						
							|  |  |  |         || obj[name + '_details'].rate < 0.00001) return true; | 
					
						
							| 
									
										
										
										
											2011-02-17 23:23:08 +08:00
										 |  |  |     return false; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-05 20:19:06 +08:00
										 |  |  | function is_col_empty(objects, name, accessor) { | 
					
						
							|  |  |  |     if (accessor == undefined) accessor = function(o) {return o.message_stats;}; | 
					
						
							|  |  |  |     for (var i = 0; i < objects.length; i++) { | 
					
						
							|  |  |  |         var object = objects[i]; | 
					
						
							|  |  |  |         if (!is_stat_empty(accessor(object), name)) { | 
					
						
							| 
									
										
										
										
											2011-02-26 01:32:04 +08:00
										 |  |  |             return false; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  | function fmt_exchange(name) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     return fmt_escape_html(fmt_exchange0(name)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_exchange0(name) { | 
					
						
							|  |  |  |     return name == '' ? '(AMQP default)' : name; | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-25 21:13:04 +08:00
										 |  |  | function fmt_exchange_type(type) { | 
					
						
							|  |  |  |     for (var i in exchange_types) { | 
					
						
							|  |  |  |         if (exchange_types[i].name == type) { | 
					
						
							|  |  |  |             return fmt_escape_html(type); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-10-23 18:27:52 +08:00
										 |  |  |     return '<div class="status-red"><acronym title="Exchange type not found. ' + | 
					
						
							| 
									
										
										
										
											2012-01-25 21:13:04 +08:00
										 |  |  |         'Publishing to this exchange will fail.">' + fmt_escape_html(type) + | 
					
						
							|  |  |  |         '</acronym></div>'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  | function fmt_exchange_url(name) { | 
					
						
							| 
									
										
										
										
											2011-11-30 21:43:42 +08:00
										 |  |  |     return name == '' ? 'amq.default' : fmt_escape_html(name); | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-29 20:22:46 +08:00
										 |  |  | function fmt_download_filename(host) { | 
					
						
							|  |  |  |     var now = new Date(); | 
					
						
							| 
									
										
										
										
											2010-10-01 01:02:05 +08:00
										 |  |  |     return host.replace('@', '_') + "_" + now.getFullYear() + "-" + | 
					
						
							|  |  |  |         (now.getMonth() + 1) + "-" + now.getDate() + ".json"; | 
					
						
							| 
									
										
										
										
											2010-09-29 20:22:46 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-09 01:26:49 +08:00
										 |  |  | function fmt_fd_used(used, total) { | 
					
						
							| 
									
										
										
										
											2012-03-13 20:16:27 +08:00
										 |  |  |     if (used == 'install_handle_from_sysinternals') { | 
					
						
							| 
									
										
										
										
											2012-11-09 01:26:49 +08:00
										 |  |  |         return '<p class="c">handle.exe missing <span class="help" id="handle-exe"></span><sub>' + total + ' available</sub></p>'; | 
					
						
							| 
									
										
										
										
											2012-03-13 20:16:27 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         return used; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-10-12 21:08:17 +08:00
										 |  |  | function fmt_table_short(table) { | 
					
						
							| 
									
										
										
										
											2011-02-12 02:04:05 +08:00
										 |  |  |     return '<table class="mini">' + fmt_table_body(table, ':') + '</table>'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_table_long(table) { | 
					
						
							|  |  |  |     return '<table class="facts">' + fmt_table_body(table, '') + | 
					
						
							| 
									
										
										
										
											2011-07-29 19:58:18 +08:00
										 |  |  |         '</table>'; | 
					
						
							| 
									
										
										
										
											2011-02-12 02:04:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_table_body(table, x) { | 
					
						
							| 
									
										
										
										
											2010-10-12 21:08:17 +08:00
										 |  |  |     var res = ''; | 
					
						
							|  |  |  |     for (k in table) { | 
					
						
							| 
									
										
										
										
											2011-02-12 02:04:05 +08:00
										 |  |  |         res += '<tr><th>' + k + x + '</th><td>' + fmt_amqp_value(table[k]) + | 
					
						
							|  |  |  |             '</td>'; | 
					
						
							| 
									
										
										
										
											2010-10-12 21:08:17 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-12 02:04:05 +08:00
										 |  |  | function fmt_amqp_value(val) { | 
					
						
							| 
									
										
										
										
											2011-02-17 00:00:12 +08:00
										 |  |  |     if (val instanceof Array) { | 
					
						
							| 
									
										
										
										
											2011-03-03 00:49:00 +08:00
										 |  |  |         var val2 = new Array(); | 
					
						
							|  |  |  |         for (var i = 0; i < val.length; i++) { | 
					
						
							|  |  |  |             val2[i] = fmt_amqp_value(val[i]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return val2.join("<br/>"); | 
					
						
							| 
									
										
										
										
											2011-02-17 00:00:12 +08:00
										 |  |  |     } else if (val instanceof Object) { | 
					
						
							| 
									
										
										
										
											2011-02-17 19:47:23 +08:00
										 |  |  |         return fmt_table_short(val); | 
					
						
							| 
									
										
										
										
											2011-02-12 02:04:05 +08:00
										 |  |  |     } else { | 
					
						
							| 
									
										
										
										
											2012-05-02 00:39:07 +08:00
										 |  |  |         var t = typeof(val); | 
					
						
							|  |  |  |         if (t == 'string') { | 
					
						
							|  |  |  |             return '<acronym class="type" title="string">' + | 
					
						
							|  |  |  |                 fmt_escape_html(val) + '</acronym>'; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return '<acronym class="type" title="' + t + '">' + val + '</acronym>'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2010-10-28 22:30:32 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-05-25 19:58:06 +08:00
										 |  |  | function fmt_table_flat(table) { | 
					
						
							|  |  |  |     var res = []; | 
					
						
							|  |  |  |     for (k in table) { | 
					
						
							|  |  |  |         res.push(k + ': ' + fmt_amqp_value_flat(table[k])); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return res.join(', '); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_amqp_value_flat(val) { | 
					
						
							|  |  |  |     if (val instanceof Array) { | 
					
						
							|  |  |  |         var val2 = new Array(); | 
					
						
							|  |  |  |         for (var i = 0; i < val.length; i++) { | 
					
						
							|  |  |  |             val2[i] = fmt_amqp_value_flat(val[i]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return '[' + val2.join(",") + ']'; | 
					
						
							|  |  |  |     } else if (val instanceof Object) { | 
					
						
							|  |  |  |         return '(' + fmt_table_flat(val) + ')'; | 
					
						
							|  |  |  |     } else if (typeof(val) == 'string') { | 
					
						
							|  |  |  |         return fmt_escape_html(val); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return val; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-09 18:49:47 +08:00
										 |  |  | function fmt_uptime(u) { | 
					
						
							|  |  |  |     var uptime = Math.floor(u / 1000); | 
					
						
							|  |  |  |     var sec = uptime % 60; | 
					
						
							|  |  |  |     var min = Math.floor(uptime / 60) % 60; | 
					
						
							|  |  |  |     var hour = Math.floor(uptime / 3600) % 24; | 
					
						
							|  |  |  |     var day = Math.floor(uptime / 86400); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (day > 0) | 
					
						
							|  |  |  |         return day + 'd ' + hour + 'h'; | 
					
						
							|  |  |  |     else if (hour > 0) | 
					
						
							|  |  |  |         return hour + 'h ' + min + 'm'; | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |         return min + 'm ' + sec + 's'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-04 00:49:03 +08:00
										 |  |  | function fmt_rabbit_version(applications) { | 
					
						
							|  |  |  |     for (var i in applications) { | 
					
						
							|  |  |  |         if (applications[i].name == 'rabbit') { | 
					
						
							|  |  |  |             return applications[i].version; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return 'unknown'; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-16 23:41:17 +08:00
										 |  |  | function fmt_idle(obj) { | 
					
						
							|  |  |  |     if (obj.idle_since == undefined) { | 
					
						
							|  |  |  |         return 'Active'; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return '<acronym title="Idle since ' + obj.idle_since + | 
					
						
							|  |  |  |             '">Idle</acronym>'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_idle_long(obj) { | 
					
						
							|  |  |  |     if (obj.idle_since == undefined) { | 
					
						
							|  |  |  |         return 'Active'; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return 'Idle since<br/>' + obj.idle_since; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-02-22 02:20:33 +08:00
										 |  |  | function fmt_escape_html(txt) { | 
					
						
							| 
									
										
										
										
											2012-04-24 20:35:32 +08:00
										 |  |  |     return fmt_escape_html0(txt).replace(/\n/g, '<br/>'); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_escape_html_one_line(txt) { | 
					
						
							|  |  |  |     return fmt_escape_html0(txt).replace(/\n/g, ''); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_escape_html0(txt) { | 
					
						
							| 
									
										
										
										
											2012-01-23 23:34:25 +08:00
										 |  |  |     return txt.replace(/&/g, '&') | 
					
						
							|  |  |  |         .replace(/</g, '<') | 
					
						
							| 
									
										
										
										
											2011-03-17 00:22:59 +08:00
										 |  |  |         .replace(/>/g, '>') | 
					
						
							| 
									
										
										
										
											2011-12-14 22:55:27 +08:00
										 |  |  |         .replace(/\"/g, '"'); | 
					
						
							| 
									
										
										
										
											2011-03-17 00:22:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_maybe_wrap(txt, encoding) { | 
					
						
							|  |  |  |     if (encoding == 'string') return fmt_escape_html(txt); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var WRAP = 120; | 
					
						
							|  |  |  |     var res = ''; | 
					
						
							|  |  |  |     while (txt != '') { | 
					
						
							|  |  |  |         var i = txt.indexOf('\n'); | 
					
						
							|  |  |  |         if (i == -1 || i > WRAP) { | 
					
						
							|  |  |  |             i = Math.min(WRAP, txt.length); | 
					
						
							|  |  |  |             res += txt.substring(0, i) + '\n'; | 
					
						
							|  |  |  |             txt = txt.substring(i); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         else { | 
					
						
							|  |  |  |             res += txt.substring(0, i + 1); | 
					
						
							|  |  |  |             txt = txt.substring(i + 1); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return fmt_escape_html(res); | 
					
						
							| 
									
										
										
										
											2011-02-22 02:20:33 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-05 21:26:32 +08:00
										 |  |  | function fmt_node(node_host) { | 
					
						
							| 
									
										
										
										
											2011-06-14 00:36:26 +08:00
										 |  |  |     var both = node_host.split('@'); | 
					
						
							|  |  |  |     var node = both.slice(0, 1); | 
					
						
							|  |  |  |     var host = both.slice(1); | 
					
						
							| 
									
										
										
										
											2012-11-05 21:26:32 +08:00
										 |  |  |     return '<small>' + node + '@</small>' + host; | 
					
						
							| 
									
										
										
										
											2011-06-14 00:36:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  | function fmt_connection_state(conn) { | 
					
						
							| 
									
										
										
										
											2012-01-18 20:18:24 +08:00
										 |  |  |     if (conn.state == undefined) return ''; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |     var colour = 'green'; | 
					
						
							|  |  |  |     var text = conn.state; | 
					
						
							|  |  |  |     var explanation; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-24 19:44:21 +08:00
										 |  |  |     if (conn.last_blocked_by == 'resource' && conn.state == 'blocked') { | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |         colour = 'red'; | 
					
						
							| 
									
										
										
										
											2012-09-24 19:44:21 +08:00
										 |  |  |         explanation = 'Resource alarm: Connection blocked.'; | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else if (conn.state == 'blocking') { | 
					
						
							|  |  |  |         colour = 'yellow'; | 
					
						
							| 
									
										
										
										
											2012-09-24 19:44:21 +08:00
										 |  |  |         explanation = 'Resource alarm: Connection will block on publish.'; | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else if (conn.last_blocked_by == 'flow') { | 
					
						
							|  |  |  |         var age = conn.last_blocked_age.toFixed(); | 
					
						
							|  |  |  |         if (age < 5) { | 
					
						
							|  |  |  |             colour = 'yellow'; | 
					
						
							|  |  |  |             text = 'flow'; | 
					
						
							| 
									
										
										
										
											2012-01-14 00:15:04 +08:00
										 |  |  |             explanation = 'Publishing rate recently restricted by server.'; | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-01-13 03:03:36 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-01-13 23:10:30 +08:00
										 |  |  |     if (explanation) { | 
					
						
							| 
									
										
										
										
											2012-10-03 18:10:06 +08:00
										 |  |  |         return '<div class="status-' + colour + '"><acronym title="' + | 
					
						
							|  |  |  |             explanation + '">' + text + '</acronym></div>'; | 
					
						
							| 
									
										
										
										
											2012-01-13 03:03:36 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2012-10-03 18:10:06 +08:00
										 |  |  |         return '<div class="status-' + colour + '">' + text + '</div>'; | 
					
						
							| 
									
										
										
										
											2012-01-13 03:03:36 +08:00
										 |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-03 01:29:42 +08:00
										 |  |  | function fmt_resource_bar(used_label, limit_label, ratio, colour, help) { | 
					
						
							| 
									
										
										
										
											2012-10-03 17:46:32 +08:00
										 |  |  |     var width = 120; | 
					
						
							| 
									
										
										
										
											2012-10-03 01:29:42 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     var res = ''; | 
					
						
							| 
									
										
										
										
											2012-10-03 17:46:32 +08:00
										 |  |  |     var other_colour = colour; | 
					
						
							| 
									
										
										
										
											2012-10-03 01:29:42 +08:00
										 |  |  |     if (ratio > 1) { | 
					
						
							|  |  |  |         ratio = 1 / ratio; | 
					
						
							|  |  |  |         inverted = true; | 
					
						
							| 
									
										
										
										
											2012-10-03 17:46:32 +08:00
										 |  |  |         colour += '-dark'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         other_colour += '-dark'; | 
					
						
							| 
									
										
										
										
											2012-10-03 01:29:42 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     var offset = Math.round(width * (1 - ratio)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-03 17:46:32 +08:00
										 |  |  |     res += '<div class="status-bar" style="width: ' + width + 'px;">'; | 
					
						
							|  |  |  |     res += '<div class="status-bar-main ' + colour + '" style="background-image: url(img/bg-' + other_colour + '.png); background-position: -' + offset + 'px 0px; background-repeat: no-repeat;">'; | 
					
						
							| 
									
										
										
										
											2012-10-03 01:29:42 +08:00
										 |  |  |     res += used_label; | 
					
						
							|  |  |  |     if (help != null) { | 
					
						
							|  |  |  |         res += ' <span class="help" id="' + help + '"></span>'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     res += '</div>'; // status-bar-main
 | 
					
						
							|  |  |  |     if (limit_label != null) { | 
					
						
							|  |  |  |         res += '<sub>' + limit_label + '</sub>'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     res += '</div>'; // status-bar
 | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-09 23:38:09 +08:00
										 |  |  | function fmt_resource_bar_count(used, total, thresholds) { | 
					
						
							| 
									
										
										
										
											2012-11-09 01:26:49 +08:00
										 |  |  |     if (typeof used == 'number') { | 
					
						
							|  |  |  |         return fmt_resource_bar(used, total + ' available', used / total, | 
					
						
							|  |  |  |                                 fmt_color(used / total, thresholds)); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         return used; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2012-10-09 23:38:09 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-02 01:31:34 +08:00
										 |  |  | function fmt_shortened_uri(uri) { | 
					
						
							|  |  |  |     if (typeof uri == 'object') { | 
					
						
							|  |  |  |         var res = ''; | 
					
						
							|  |  |  |         for (i in uri) { | 
					
						
							|  |  |  |             res += fmt_shortened_uri(uri[i]) + '<br/>'; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         return res; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     var uri = fmt_escape_html(uri); | 
					
						
							| 
									
										
										
										
											2012-04-24 01:43:28 +08:00
										 |  |  |     if (uri.indexOf('?') == -1) { | 
					
						
							|  |  |  |         return uri; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         return '<acronym title="' + uri + '">' + | 
					
						
							|  |  |  |             uri.substr(0, uri.indexOf('?')) + '?...</acronym>'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-09-06 23:14:13 +08:00
										 |  |  | function fmt_client_name(properties) { | 
					
						
							|  |  |  |     var res = []; | 
					
						
							|  |  |  |     if (properties.product != undefined) { | 
					
						
							| 
									
										
										
										
											2013-01-21 20:30:55 +08:00
										 |  |  |         res.push(fmt_trunc(properties.product, 10)); | 
					
						
							| 
									
										
										
										
											2012-09-06 23:14:13 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     if (properties.platform != undefined) { | 
					
						
							| 
									
										
										
										
											2013-01-21 20:30:55 +08:00
										 |  |  |         res.push(fmt_trunc(properties.platform, 10)); | 
					
						
							| 
									
										
										
										
											2012-09-06 23:14:13 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     res = res.join(" / "); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (properties.version != undefined) { | 
					
						
							| 
									
										
										
										
											2013-01-21 20:30:55 +08:00
										 |  |  |         res += '<sub>' + fmt_trunc(properties.version) + '</sub>'; | 
					
						
							| 
									
										
										
										
											2012-09-06 23:14:13 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-21 20:30:55 +08:00
										 |  |  | function fmt_trunc(str, max_length) { | 
					
						
							|  |  |  |     return str.length > max_length ? | 
					
						
							|  |  |  |         ('<acronym class="normal" title="' + str + '">' + | 
					
						
							|  |  |  |          str.substring(0, max_length) + '...</acronym>') : str; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  | function alt_rows(i, args) { | 
					
						
							|  |  |  |     var css = [(i % 2 == 0) ? 'alt1' : 'alt2']; | 
					
						
							|  |  |  |     if (args != undefined && args['x-internal-purpose'] != undefined) { | 
					
						
							|  |  |  |         css.push('internal-purpose'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ' class="' + css.join(' ') + '"'; | 
					
						
							| 
									
										
										
										
											2010-07-22 23:29:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-24 18:37:54 +08:00
										 |  |  | function esc(str) { | 
					
						
							| 
									
										
										
										
											2010-09-14 22:46:19 +08:00
										 |  |  |     return encodeURIComponent(str); | 
					
						
							| 
									
										
										
										
											2010-08-25 19:24:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-19 23:29:16 +08:00
										 |  |  | function link_conn(name, desc) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     if (desc == undefined) { | 
					
						
							|  |  |  |         return _link_to(short_conn(name), '#/connections/' + esc(name)); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         return _link_to(desc, '#/connections/' + esc(name), false); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-08-25 19:24:34 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  | function link_channel(name) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     return _link_to(short_chan(name), '#/channels/' + esc(name)) | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  | function link_exchange(vhost, name, args) { | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  |     var url = esc(vhost) + '/' + (name == '' ? 'amq.default' : esc(name)); | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  |     return _link_to(fmt_exchange0(name), '#/exchanges/' + url, true, args); | 
					
						
							| 
									
										
										
										
											2010-08-27 00:42:03 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  | function link_queue(vhost, name, args) { | 
					
						
							|  |  |  |     return _link_to(name, '#/queues/' + esc(vhost) + '/' + esc(name), true, args); | 
					
						
							| 
									
										
										
										
											2010-08-27 17:55:32 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-08-26 01:18:31 +08:00
										 |  |  | function link_vhost(name) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     return _link_to(name, '#/vhosts/' + esc(name)) | 
					
						
							| 
									
										
										
										
											2010-08-26 01:18:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function link_user(name) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     return _link_to(name, '#/users/' + esc(name)) | 
					
						
							| 
									
										
										
										
											2010-08-26 01:18:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-11-03 01:19:14 +08:00
										 |  |  | function link_node(name) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     return _link_to(name, '#/nodes/' + esc(name)) | 
					
						
							| 
									
										
										
										
											2010-11-03 01:19:14 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-08 00:39:09 +08:00
										 |  |  | function link_policy(vhost, name) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     return _link_to(name, '#/policies/' + esc(vhost) + '/' + esc(name)) | 
					
						
							| 
									
										
										
										
											2012-05-18 22:33:13 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  | function _link_to(name, url, highlight, args) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     if (highlight == undefined) highlight = true; | 
					
						
							| 
									
										
										
										
											2013-09-05 22:27:03 +08:00
										 |  |  |     var title = null; | 
					
						
							|  |  |  |     if (args != undefined && args['x-internal-purpose'] != undefined) { | 
					
						
							|  |  |  |         var purpose = args['x-internal-purpose']; | 
					
						
							|  |  |  |         title = 'This is used internally by the ' + purpose + ' mechanism.'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return '<a href="' + url + '"' + | 
					
						
							|  |  |  |         (title ? ' title="' + title + '"' : '') + '>' + | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |         (highlight ? fmt_highlight_filter(name) : fmt_escape_html(name)) + | 
					
						
							|  |  |  |         '</a>'; | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-06 02:04:15 +08:00
										 |  |  | function fmt_highlight_filter(text) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |     if (current_filter == '') return fmt_escape_html(text); | 
					
						
							| 
									
										
										
										
											2013-03-06 02:04:15 +08:00
										 |  |  |     var ix = text.toLowerCase().indexOf(current_filter.toLowerCase()); | 
					
						
							|  |  |  |     var l = current_filter.length; | 
					
						
							|  |  |  |     if (ix == -1) { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |         return fmt_escape_html(text); | 
					
						
							| 
									
										
										
										
											2013-03-06 02:04:15 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  |         return fmt_escape_html(text.substring(0, ix)) + | 
					
						
							|  |  |  |             '<span class="filter-highlight">' + | 
					
						
							|  |  |  |             fmt_escape_html(text.substring(ix, ix + l)) + '</span>' + | 
					
						
							|  |  |  |             fmt_escape_html(text.substring(ix + l)); | 
					
						
							| 
									
										
										
										
											2013-03-06 02:04:15 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-01 01:45:26 +08:00
										 |  |  | function message_rates(id, stats) { | 
					
						
							|  |  |  |     var items = [['Publish', 'publish'], ['Confirm', 'confirm'], | 
					
						
							|  |  |  |                  ['Publish (In)', 'publish_in'], | 
					
						
							|  |  |  |                  ['Publish (Out)', 'publish_out'], | 
					
						
							|  |  |  |                  ['Deliver', 'deliver'], | 
					
						
							|  |  |  |                  ['Redelivered', 'redeliver'], | 
					
						
							|  |  |  |                  ['Acknowledge', 'ack'], | 
					
						
							|  |  |  |                  ['Get', 'get'], ['Deliver (noack)', 'deliver_no_ack'], | 
					
						
							|  |  |  |                  ['Get (noack)', 'get_no_ack'], | 
					
						
							|  |  |  |                  ['Return', 'return_unroutable']]; | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  |     return rates_chart_or_text(id, stats, items, fmt_rate, fmt_rate_large, fmt_rate_axis, true, 'Message rates', 'message-rates'); | 
					
						
							| 
									
										
										
										
											2012-12-01 01:45:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function queue_lengths(id, stats) { | 
					
						
							|  |  |  |     var items = [['Ready', 'messages_ready'], | 
					
						
							|  |  |  |                  ['Unacknowledged', 'messages_unacknowledged'], | 
					
						
							|  |  |  |                  ['Total', 'messages']]; | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  |     return rates_chart_or_text(id, stats, items, fmt_msgs, fmt_msgs_large, fmt_msgs_axis, false, 'Queued messages', 'queued-messages'); | 
					
						
							| 
									
										
										
										
											2012-12-01 01:45:26 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-19 01:13:44 +08:00
										 |  |  | function data_rates(id, stats) { | 
					
						
							|  |  |  |     var items = [['From client', 'recv_oct'], ['To client', 'send_oct']]; | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  |     return rates_chart_or_text(id, stats, items, fmt_rate_bytes, fmt_rate_bytes_large, fmt_rate_bytes_axis, true, 'Data rates'); | 
					
						
							| 
									
										
										
										
											2012-12-19 01:13:44 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  | function rates_chart_or_text(id, stats, items, chart_fmt, text_fmt, axis_fmt, chart_rates, | 
					
						
							| 
									
										
										
										
											2013-01-30 01:26:20 +08:00
										 |  |  |                              heading, heading_help) { | 
					
						
							|  |  |  |     var mode = get_pref('rate-mode-' + id); | 
					
						
							| 
									
										
										
										
											2013-02-01 02:27:20 +08:00
										 |  |  |     var range = get_pref('chart-range-' + id); | 
					
						
							| 
									
										
										
										
											2013-01-30 01:26:20 +08:00
										 |  |  |     var prefix = '<h3>' + heading + | 
					
						
							| 
									
										
										
										
											2013-02-28 22:16:18 +08:00
										 |  |  |         ' <span class="rate-options updatable" title="Click to change" for="' | 
					
						
							| 
									
										
										
										
											2013-02-01 02:27:20 +08:00
										 |  |  |         + id + '">(' + prefix_title(mode, range) + ')</span>' + | 
					
						
							| 
									
										
										
										
											2013-01-30 01:26:20 +08:00
										 |  |  |         (heading_help == undefined ? '' : | 
					
						
							|  |  |  |          ' <span class="help" id="' + heading_help + '"></span>') + | 
					
						
							|  |  |  |         '</h3>'; | 
					
						
							|  |  |  |     var res; | 
					
						
							| 
									
										
										
										
											2013-01-22 21:36:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  |     if (keys(stats).length > 0) { | 
					
						
							| 
									
										
										
										
											2012-11-16 21:27:31 +08:00
										 |  |  |         if (mode == 'chart') { | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  |             res = rates_chart(id, items, stats, chart_fmt, axis_fmt, chart_rates); | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2012-11-16 21:27:31 +08:00
										 |  |  |         else { | 
					
						
							| 
									
										
										
										
											2013-01-30 01:26:20 +08:00
										 |  |  |             res = rates_text(items, stats, mode, text_fmt); | 
					
						
							| 
									
										
										
										
											2010-10-20 18:38:05 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2013-01-30 01:26:20 +08:00
										 |  |  |         if (res == "") res = '<p>Waiting for data...</p>'; | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         res = '<p>Currently idle</p>'; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-02-28 21:23:53 +08:00
										 |  |  |     return prefix + '<div class="updatable">' + res + '</div>'; | 
					
						
							| 
									
										
										
										
											2013-01-30 01:26:20 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-01 02:27:20 +08:00
										 |  |  | function prefix_title(mode, range) { | 
					
						
							|  |  |  |     var desc = CHART_PERIODS[range]; | 
					
						
							| 
									
										
										
										
											2013-01-30 01:26:20 +08:00
										 |  |  |     if (mode == 'chart') { | 
					
						
							|  |  |  |         return 'chart: ' + desc.toLowerCase(); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-02-06 00:04:26 +08:00
										 |  |  |     else if (mode == 'curr') { | 
					
						
							|  |  |  |         return 'current value'; | 
					
						
							| 
									
										
										
										
											2013-01-30 01:26:20 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     else { | 
					
						
							|  |  |  |         return 'moving average: ' + desc.toLowerCase(); | 
					
						
							| 
									
										
										
										
											2010-09-03 00:06:59 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-09-29 21:45:40 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  | function rates_chart(id, items, stats, rate_fmt, axis_fmt, chart_rates) { | 
					
						
							| 
									
										
										
										
											2012-12-12 20:59:03 +08:00
										 |  |  |     var size = get_pref('chart-size-' + id); | 
					
						
							| 
									
										
										
										
											2012-12-18 23:56:20 +08:00
										 |  |  |     var show = []; | 
					
						
							| 
									
										
										
										
											2012-12-01 01:45:26 +08:00
										 |  |  |     chart_data[id] = {}; | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  |     chart_data[id]['data'] = {}; | 
					
						
							|  |  |  |     chart_data[id]['fmt'] = axis_fmt; | 
					
						
							| 
									
										
										
										
											2012-11-16 21:27:31 +08:00
										 |  |  |     for (var i in items) { | 
					
						
							|  |  |  |         var name = items[i][0]; | 
					
						
							| 
									
										
										
										
											2012-12-19 01:13:44 +08:00
										 |  |  |         var key = items[i][1]; | 
					
						
							|  |  |  |         var key_details = key + '_details'; | 
					
						
							|  |  |  |         if (key_details in stats) { | 
					
						
							| 
									
										
										
										
											2013-04-09 19:54:02 +08:00
										 |  |  |             chart_data[id]['data'][name] = stats[key_details]; | 
					
						
							| 
									
										
										
										
											2013-02-05 23:56:51 +08:00
										 |  |  |             show.push([name, rate_fmt(stats, key)]); | 
					
						
							| 
									
										
										
										
											2012-11-16 21:27:31 +08:00
										 |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-12-07 01:54:35 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-01-30 01:26:20 +08:00
										 |  |  |     var html = '<div class="box"><div id="chart-' + id + | 
					
						
							|  |  |  |         '" class="chart chart-' + size + | 
					
						
							| 
									
										
										
										
											2013-02-05 23:56:51 +08:00
										 |  |  |         (chart_rates ? ' chart-rates' : '') + '"></div>'; | 
					
						
							| 
									
										
										
										
											2013-01-25 23:37:22 +08:00
										 |  |  |     html += '<table class="facts facts-fixed-width">'; | 
					
						
							| 
									
										
										
										
											2012-12-18 23:56:20 +08:00
										 |  |  |     for (var i = 0; i < show.length; i++) { | 
					
						
							|  |  |  |         html += '<tr><th>' + show[i][0] + '</th><td>'; | 
					
						
							| 
									
										
										
										
											2012-12-18 23:57:34 +08:00
										 |  |  |         html += '<div class="colour-key" style="background: ' + chart_colors[i]; | 
					
						
							| 
									
										
										
										
											2012-12-18 23:56:20 +08:00
										 |  |  |         html += ';"></div>' + show[i][1] + '</td></tr>' | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-01-30 01:26:20 +08:00
										 |  |  |     html += '</table></div>'; | 
					
						
							| 
									
										
										
										
											2012-12-18 23:56:20 +08:00
										 |  |  |     return show.length > 0 ? html : ''; | 
					
						
							| 
									
										
										
										
											2010-09-29 21:45:40 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-19 01:13:44 +08:00
										 |  |  | function rates_text(items, stats, mode, rate_fmt) { | 
					
						
							| 
									
										
										
										
											2012-11-16 21:27:31 +08:00
										 |  |  |     var res = ''; | 
					
						
							|  |  |  |     for (var i in items) { | 
					
						
							|  |  |  |         var name = items[i][0]; | 
					
						
							| 
									
										
										
										
											2012-12-01 01:55:21 +08:00
										 |  |  |         var key = items[i][1]; | 
					
						
							|  |  |  |         var key_details = key + '_details'; | 
					
						
							|  |  |  |         if (key_details in stats) { | 
					
						
							|  |  |  |             var details = stats[key_details]; | 
					
						
							| 
									
										
										
										
											2012-12-19 21:31:26 +08:00
										 |  |  |             res += '<div class="highlight">' + name; | 
					
						
							| 
									
										
										
										
											2013-02-05 23:56:51 +08:00
										 |  |  |             res += rate_fmt(stats, key, mode); | 
					
						
							| 
									
										
										
										
											2012-11-16 21:27:31 +08:00
										 |  |  |             res += '</div>'; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2011-12-07 01:54:35 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-01-30 01:26:20 +08:00
										 |  |  |     return res == '' ? '' : '<div class="box">' + res + '</div>'; | 
					
						
							| 
									
										
										
										
											2011-11-25 20:48:58 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  | function filter_ui(items) { | 
					
						
							| 
									
										
										
										
											2013-04-25 23:13:44 +08:00
										 |  |  |     current_truncate = (current_truncate == null) ? | 
					
						
							|  |  |  |         parseInt(get_pref('truncate')) : current_truncate; | 
					
						
							| 
									
										
										
										
											2013-03-06 22:59:31 +08:00
										 |  |  |     var total = items.length; | 
					
						
							| 
									
										
										
										
											2011-11-25 20:48:58 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-06 02:04:15 +08:00
										 |  |  |     if (current_filter != '') { | 
					
						
							|  |  |  |         var items2 = []; | 
					
						
							|  |  |  |         for (var i in items) { | 
					
						
							|  |  |  |             var item = items[i]; | 
					
						
							|  |  |  |             if (item.name.toLowerCase().indexOf(current_filter.toLowerCase()) != -1) { | 
					
						
							|  |  |  |                 items2.push(item); | 
					
						
							|  |  |  |             } | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         items.length = items2.length; | 
					
						
							|  |  |  |         for (var i in items2) items[i] = items2[i]; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2010-09-29 21:45:40 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-07 18:43:24 +08:00
										 |  |  |     var res = '<div class="filter"><table' + | 
					
						
							|  |  |  |         (current_filter == '' ? '' : ' class="filter-active"') + | 
					
						
							| 
									
										
										
										
											2013-03-16 01:09:14 +08:00
										 |  |  |         '><tr><th>Filter:</th>' + | 
					
						
							| 
									
										
										
										
											2013-03-06 22:59:31 +08:00
										 |  |  |         '<td><input id="filter" type="text" value="' + | 
					
						
							| 
									
										
										
										
											2013-04-26 19:30:52 +08:00
										 |  |  |         fmt_escape_html(current_filter) + '"/></td></tr></table>'; | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-26 20:42:29 +08:00
										 |  |  |     function items_desc(l) { | 
					
						
							|  |  |  |         return l == 1 ? (l + ' item') : (l + ' items'); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     var selected = current_filter == '' ? (items_desc(items.length)) : | 
					
						
							|  |  |  |         (items.length + ' of ' + items_desc(total) + ' selected'); | 
					
						
							| 
									
										
										
										
											2013-03-06 20:29:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-26 19:30:52 +08:00
										 |  |  |     var truncate_input = '<input type="text" id="truncate" value="' + | 
					
						
							| 
									
										
										
										
											2013-04-25 23:13:44 +08:00
										 |  |  |         current_truncate + '">'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (items.length > current_truncate) { | 
					
						
							| 
									
										
										
										
											2013-04-26 19:30:52 +08:00
										 |  |  |         selected += '<span id="filter-warning-show"> ' + | 
					
						
							|  |  |  |             '(only showing first</span> '; | 
					
						
							| 
									
										
										
										
											2013-04-25 23:13:44 +08:00
										 |  |  |         items.length = current_truncate; | 
					
						
							| 
									
										
										
										
											2010-09-29 21:45:40 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-03-06 22:59:31 +08:00
										 |  |  |     else { | 
					
						
							| 
									
										
										
										
											2013-04-26 19:30:52 +08:00
										 |  |  |         selected += ' (show at most '; | 
					
						
							| 
									
										
										
										
											2013-03-06 22:59:31 +08:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2013-04-26 19:30:52 +08:00
										 |  |  |     res += '<p id="filter-truncate"><span class="updatable">' + selected + | 
					
						
							|  |  |  |         '</span>' + truncate_input + ')</p>'; | 
					
						
							|  |  |  |     res += '</div>'; | 
					
						
							| 
									
										
										
										
											2013-03-06 22:59:31 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return res; | 
					
						
							| 
									
										
										
										
											2011-11-25 20:48:58 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-29 21:45:40 +08:00
										 |  |  | function maybe_truncate(items) { | 
					
						
							|  |  |  |     var maximum = 500; | 
					
						
							|  |  |  |     var str = ''; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (items.length > maximum) { | 
					
						
							|  |  |  |         str = '<p class="warning">Only ' + maximum + ' of ' + | 
					
						
							|  |  |  |             items.length + ' items are shown.</p>'; | 
					
						
							|  |  |  |         items.length = maximum; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return str; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2010-10-12 00:05:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | function fmt_sort(display, sort) { | 
					
						
							|  |  |  |     var prefix = ''; | 
					
						
							|  |  |  |     if (current_sort == sort) { | 
					
						
							|  |  |  |         prefix = '<span class="arrow">' + | 
					
						
							|  |  |  |             (current_sort_reverse ? '▲ ' : '▼ ') + | 
					
						
							|  |  |  |             '</span>'; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return '<a class="sort" sort="' + sort + '">' + prefix + display + '</a>'; | 
					
						
							| 
									
										
										
										
											2011-02-17 00:00:12 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2011-03-30 20:14:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-01 00:17:05 +08:00
										 |  |  | function fmt_permissions(obj, permissions, lookup, show, warning) { | 
					
						
							|  |  |  |     var res = []; | 
					
						
							|  |  |  |     for (var i in permissions) { | 
					
						
							|  |  |  |         var permission = permissions[i]; | 
					
						
							|  |  |  |         if (permission[lookup] == obj.name) { | 
					
						
							|  |  |  |             res.push(permission[show]); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return res.length == 0 ? warning : res.join(', '); | 
					
						
							| 
									
										
										
										
											2011-04-09 00:00:05 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 22:34:15 +08:00
										 |  |  | var radio_id = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function fmt_radio(name, text, value, current) { | 
					
						
							|  |  |  |     radio_id++; | 
					
						
							|  |  |  |     return '<label class="radio" for="radio-' + radio_id + '">' + | 
					
						
							|  |  |  |         '<input type="radio" id="radio-' + radio_id + '" name="' + name +  | 
					
						
							|  |  |  |         '" value="' + value + '"' + | 
					
						
							|  |  |  |         ((value == current) ? ' checked="checked"' : '') + | 
					
						
							|  |  |  |         '>' + text + '</label>'; | 
					
						
							| 
									
										
										
										
											2012-11-16 21:27:31 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-03-30 20:14:24 +08:00
										 |  |  | function properties_size(obj) { | 
					
						
							|  |  |  |     var count = 0; | 
					
						
							|  |  |  |     for (k in obj) { | 
					
						
							|  |  |  |         if (obj.hasOwnProperty(k)) count++; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return count; | 
					
						
							| 
									
										
										
										
											2011-04-09 00:00:05 +08:00
										 |  |  | } |