rabbitmq-server/deps/rabbitmq_management/priv/www/js/formatters.js

814 lines
22 KiB
JavaScript
Raw Normal View History

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']];
function fmt_string(str, unknown) {
if (unknown == undefined) unknown = UNKNOWN_REPR;
if (str == undefined) return unknown;
return fmt_escape_html("" + str);
}
function fmt_bytes(bytes) {
if (bytes == undefined) return UNKNOWN_REPR;
return fmt_si_prefix(bytes, bytes, 1024, false) + 'B';
}
function fmt_si_prefix(num0, max0, thousand, allow_fractions) {
if (num == 0) return 0;
function f(n, m, p) {
if (m > thousand) return f(n / thousand, m / thousand, p + 1);
else return [n, m, p];
}
var num_power = f(num0, max0, 0);
2010-09-01 00:56:33 +08:00
var num = num_power[0];
var max = num_power[1];
var power = num_power[2];
var powers = ['', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'];
return (((power != 0 || allow_fractions) && max <= 10) ? num.toFixed(1) :
num.toFixed(0)) + powers[power];
}
function fmt_boolean(b, unknown) {
if (unknown == undefined) unknown = UNKNOWN_REPR;
if (b == undefined) return unknown;
return b ? "&#9679;" : "&#9675;";
}
2011-01-14 19:45:45 +08:00
function fmt_date(d) {
2014-06-25 19:11:07 +08:00
var res = fmt_date0(d);
return res[0] + ' ' + res[1];
}
function fmt_date_mini(d) {
var res = fmt_date0(d);
return res[1] + '<sub>' + res[0] + '</sub>';
}
function fmt_date0(d) {
2011-01-14 19:45:45 +08:00
function f(i) {
return i < 10 ? "0" + i : i;
}
2014-06-25 19:11:07 +08:00
return [d.getFullYear() + "-" + f(d.getMonth() + 1) + "-" +
f(d.getDate()), f(d.getHours()) + ":" + f(d.getMinutes()) +
":" + f(d.getSeconds())];
2011-01-14 19:45:45 +08:00
}
function fmt_timestamp(ts) {
return fmt_date(new Date(ts));
}
2014-06-25 19:11:07 +08:00
function fmt_timestamp_mini(ts) {
return fmt_date_mini(new Date(ts));
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
}
function fmt_features(obj) {
return fmt_table_short(args_to_features(obj));
}
function fmt_policy_short(obj) {
if (obj.policy != undefined && obj.policy != '') {
return '<acronym class="policy" title="Policy: ' + obj.policy +
'">' + obj.policy + '</acronym> ';
} else {
return '';
}
}
function fmt_features_short(obj) {
var res = '';
var features = args_to_features(obj);
if (obj.owner_pid_details != undefined) {
res += '<acronym title="Exclusive queue: click for owning connection">'
2014-10-29 21:29:53 +08:00
+ link_conn(obj.owner_pid_details.name, "Excl") + '</acronym> ';
}
for (var k in ALL_ARGS) {
if (features[k] != undefined) {
res += '<acronym title="' + k + ': ' + fmt_string(features[k]) +
'">' + ALL_ARGS[k].short + '</acronym> ';
}
}
if (features.arguments) {
res += '<acronym title="' + fmt_table_flat(features.arguments) +
2014-10-29 21:29:53 +08:00
'">Args</acronym> ';
}
return res;
}
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;
}
function args_to_features(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];
}
}
if (obj.durable) {
res['durable'] = true;
}
if (obj.auto_delete) {
res['auto-delete'] = true;
}
if (obj.internal != undefined && obj.internal) {
res['internal'] = true;
}
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-12-10 22:28:33 +08:00
function fmt_sync_state(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);
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) {
if (r == undefined) return '';
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';
}
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);
else return fmt_num_thousands(num.toFixed(0));
}
function fmt_num_thousands(num) {
if (num == undefined) return UNKNOWN_REPR;
2013-06-29 00:30:08 +08:00
num = '' + num;
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
}
function fmt_percent(num) {
2013-11-20 19:18:13 +08:00
if (num === '') {
return 'N/A';
} else {
return Math.round(num * 100) + '%';
}
}
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');
}
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>');
}
function fmt_bytes_obj(obj, name, mode) {
return fmt_bytes(obj[name]);
}
function fmt_num_obj(obj, name, mode) {
return obj[name];
}
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';
}
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);
}
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'];
return mode == 'avg' ? fmt_rate_num(details.avg) :
2013-06-29 00:30:08 +08:00
fmt_num_thousands(obj[name]);
}
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 '&nbsp;';
}
function fmt_rate_axis(num, max) {
return fmt_si_prefix(num, max, 1000, true) + '/s';
2013-04-09 19:54:02 +08:00
}
function fmt_num_axis(num, max) {
return fmt_si_prefix(num, max, 1000, true);
2013-04-09 19:54:02 +08:00
}
function fmt_bytes_axis(num, max) {
num = parseInt(num);
return fmt_bytes(isNaN(num) ? 0 : num);
}
function fmt_rate_bytes_axis(num, max) {
return fmt_bytes_axis(num, max) + '/s';
}
2014-08-07 21:20:10 +08:00
function fmt_maybe_vhost(name) {
return vhosts_interesting ?
' in virtual host <b>' + fmt_escape_html(name) + '</b>'
: '';
}
2010-08-27 00:42:03 +08:00
function fmt_exchange(name) {
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) {
return name == '' ? 'amq.default' : fmt_escape_html(name);
2010-08-27 00:42:03 +08:00
}
function fmt_download_filename(host) {
var now = new Date();
return host.replace('@', '_') + "_" + now.getFullYear() + "-" +
(now.getMonth() + 1) + "-" + now.getDate() + ".json";
}
2010-10-12 21:08:17 +08:00
function fmt_table_short(table) {
return '<table class="mini">' + fmt_table_body(table, ':') + '</table>';
}
function fmt_table_long(table) {
return '<table class="facts">' + fmt_table_body(table, '') +
'</table>';
}
function fmt_table_body(table, x) {
2010-10-12 21:08:17 +08:00
var res = '';
for (k in table) {
res += '<tr><th>' + k + x + '</th><td>' + fmt_amqp_value(table[k]) +
'</td>';
2010-10-12 21:08:17 +08:00
}
return res;
}
function fmt_amqp_value(val) {
if (val instanceof Array) {
var val2 = new Array();
for (var i = 0; i < val.length; i++) {
val2[i] = fmt_amqp_value(val[i]);
}
return val2.join("<br/>");
} else if (val instanceof Object) {
2011-02-17 19:47:23 +08:00
return fmt_table_short(val);
} else {
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>';
}
}
}
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;
}
}
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';
}
function fmt_plugins_small(node) {
if (node.applications === undefined) return '';
var plugins = [];
for (var i = 0; i < node.applications.length; i++) {
var application = node.applications[i];
if (node.enabled_plugins.indexOf(application.name) != -1) {
plugins.push(application.name);
}
}
return '<acronym title="Plugins: ' + plugins.join(", ") + '">' +
plugins.length + '</acronym>';
}
function get_plugins_list(node) {
var result = [];
for (var i = 0; i < node.applications.length; i++) {
var application = node.applications[i];
if (node.enabled_plugins.indexOf(application.name) != -1) {
result.push(application);
}
}
return result;
}
function fmt_rabbit_version(applications) {
for (var i in applications) {
if (applications[i].name == 'rabbit') {
return applications[i].version;
}
}
return 'unknown';
}
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, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\"/g, '&quot;');
}
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);
}
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);
return node == 'rabbit' ? host : (node + '@' + host);
2011-06-14 00:36:26 +08:00
}
function fmt_object_state(obj) {
if (obj.state == undefined) return '';
2012-01-13 23:10:30 +08:00
var colour = 'green';
var text = obj.state;
2012-01-13 23:10:30 +08:00
var explanation;
if (obj.idle_since !== undefined) {
colour = 'grey';
explanation = 'Idle since ' + obj.idle_since;
text = 'idle';
}
// Only connections can be 'blocked' or 'blocking'
else if (obj.state == 'blocked') {
2012-01-13 23:10:30 +08:00
colour = 'red';
explanation = 'Resource alarm: connection blocked.';
2012-01-13 23:10:30 +08:00
}
else if (obj.state == 'blocking') {
2012-01-13 23:10:30 +08:00
colour = 'yellow';
explanation = 'Resource alarm: connection will block on publish.';
2012-01-13 23:10:30 +08:00
}
else if (obj.state == 'flow') {
colour = 'yellow';
explanation = 'Publishing rate recently restricted by server.';
}
else if (obj.state == 'down') {
colour = 'red';
explanation = 'The queue is located on a cluster node or nodes that ' +
'are down.';
}
2014-09-11 19:05:18 +08:00
else if (obj.state == 'crashed') {
colour = 'red';
explanation = 'The queue has crashed repeatedly and been unable to ' +
'restart.';
}
2014-01-21 23:36:17 +08:00
return fmt_state(colour, text, explanation);
}
function fmt_state(colour, text, explanation) {
var key;
2012-01-13 23:10:30 +08:00
if (explanation) {
2014-01-21 23:36:17 +08:00
key = '<acronym class="normal" title="' + explanation + '">' +
text + '</acronym>';
}
else {
2014-01-21 23:36:17 +08:00
key = text;
}
2014-01-21 23:36:17 +08:00
return '<div class="colour-key status-key-' + colour + '"></div>' + key;
}
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>';
}
}
function fmt_client_name(properties) {
var res = [];
if (properties.product != undefined) {
res.push(fmt_trunc(properties.product, 10));
}
if (properties.platform != undefined) {
res.push(fmt_trunc(properties.platform, 10));
}
res = res.join(" / ");
if (properties.version != undefined) {
res += '<sub>' + fmt_trunc(properties.version) + '</sub>';
}
return res;
}
function fmt_trunc(str, max_length) {
return fmt_escape_html(fmt_trunc0(str, max_length));
}
function fmt_trunc0(str, max_length) {
return str.length > max_length ?
('<acronym class="normal" title="' + str + '">' +
str.substring(0, max_length) + '...</acronym>') : str;
}
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-08-24 18:37:54 +08:00
function esc(str) {
return encodeURIComponent(str);
}
function link_conn(name, desc) {
if (desc == undefined) {
return _link_to(short_conn(name), '#/connections/' + esc(name));
}
else {
return _link_to(desc, '#/connections/' + esc(name), false);
}
}
2010-09-03 00:06:59 +08:00
function link_channel(name) {
return _link_to(short_chan(name), '#/channels/' + esc(name))
2010-09-03 00:06:59 +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));
return _link_to(fmt_exchange0(name), '#/exchanges/' + url, true, args);
2010-08-27 00:42: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
}
function link_vhost(name) {
return _link_to(name, '#/vhosts/' + esc(name))
}
function link_user(name) {
return _link_to(name, '#/users/' + esc(name))
}
function link_node(name) {
return _link_to(name, '#/nodes/' + esc(name))
}
2012-08-08 00:39:09 +08:00
function link_policy(vhost, name) {
return _link_to(name, '#/policies/' + esc(vhost) + '/' + esc(name))
2012-05-18 22:33:13 +08:00
}
function _link_to(name, url, highlight, args) {
if (highlight == undefined) highlight = true;
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 + '"' : '') + '>' +
(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) {
if (current_filter == '') return fmt_escape_html(text);
2013-11-13 00:41:31 +08:00
var text_to_match = current_filter.toLowerCase();
if (current_filter_regex) {
var potential_match = current_filter_regex.exec(text.toLowerCase());
if (potential_match) {
text_to_match = potential_match[0];
}
}
var ix = text.toLowerCase().indexOf(text_to_match);
var l = text_to_match.length;
2013-03-06 02:04:15 +08:00
if (ix == -1) {
return fmt_escape_html(text);
2013-03-06 02:04:15 +08:00
}
else {
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
}
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;
2013-03-06 02:04:15 +08:00
if (current_filter != '') {
var items2 = [];
for (var i in items) {
var item = items[i];
2013-11-13 00:41:31 +08:00
var item_name = item.name.toLowerCase();
if ((current_filter_regex_on &&
current_filter_regex &&
current_filter_regex.test(item_name)) ||
item_name.indexOf(current_filter.toLowerCase()) != -1) {
2013-03-06 02:04:15 +08:00
items2.push(item);
}
}
items.length = items2.length;
for (var i in items2) items[i] = items2[i];
}
var res = '<div class="filter"><table' +
2013-03-07 18:43:24 +08:00
(current_filter == '' ? '' : ' class="filter-active"') +
'><tr><th>Filter:</th>' +
2013-03-06 22:59:31 +08:00
'<td><input id="filter" type="text" value="' +
2013-11-13 00:41:31 +08:00
fmt_escape_html(current_filter) + '"/>' +
'<input type="checkbox" name="filter-regex-mode" id="filter-regex-mode"' +
(current_filter_regex_on ? ' checked' : '') +
'/><label for="filter-regex-mode">Regex</label> <span class="help" id="filter-regex">(?)</span>' +
'</td></tr></table>';
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');
var truncate_input = '<input type="text" id="truncate" value="' +
2013-04-25 23:13:44 +08:00
current_truncate + '">';
if (items.length > current_truncate) {
selected += '<span id="filter-warning-show"> ' +
'(only showing first</span> ';
2013-04-25 23:13:44 +08:00
items.length = current_truncate;
}
2013-03-06 22:59:31 +08:00
else {
selected += ' (show at most ';
2013-03-06 22:59:31 +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;
}
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 ? '&#9650; ' : '&#9660; ') +
'</span>';
}
return '<a class="sort" sort="' + sort + '">' + prefix + display + '</a>';
}
2014-09-27 01:09:25 +08:00
function group_count(mode, group, bools) {
2014-09-19 22:44:43 +08:00
var count = 0;
for (var i = 0; i < bools.length; i++) {
if (bools[i]) count++;
}
var options = COLUMNS[mode][group];
for (var i = 0; i < options.length; i++) {
var column = options[i][0];
if (show_column(mode, column)) count++;
}
2014-09-27 01:09:25 +08:00
return count;
}
2014-09-19 22:44:43 +08:00
2014-09-27 01:09:25 +08:00
function group_heading(mode, group, bools) {
var count = group_count(mode, group, bools);
2014-09-19 22:44:43 +08:00
if (count == 0) {
return '';
}
else {
return '<th colspan="' + count + '">' + group + '</th>';
}
}
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 +
2013-01-28 22:34:15 +08:00
'" value="' + value + '"' +
((value == current) ? ' checked="checked"' : '') +
'>' + text + '</label>';
}
function fmt_checkbox(name, text, current) {
return '<label class="checkbox" for="checkbox-' + name + '">' +
'<input type="checkbox" id="checkbox-' + name + '" name="' + name +
'"' + (current ? ' checked="checked"' : '') + '>' + text + '</label>';
}
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
}