1 function format_instance(inst)
3 return ("<li class=\"instance\"><a href=\"" + location.pathname
4 + "?action=show_instance;" + inst.params + "\">" + inst.description
8 function format_instance_list(instances)
10 var ret = "<ul class=\"instance_list\">";
13 if (instances.length == 0)
16 for (i = 0; i < instances.length; i++)
17 ret += format_instance (instances[i]);
24 function format_graph(graph)
26 return ("<li class=\"graph\">" + graph.title + format_instance_list (graph.instances) + "</li>");
29 function update_search_suggestions ()
31 var term = $("#search-input").val ();
34 $("#search-suggest").hide ();
38 $("#search-suggest").show ();
39 $.getJSON ("collection.fcgi",
40 { "action": "search_json", "q": term},
44 $("#search-suggest").html ("");
45 for (i = 0; i < data.length; i++)
48 $("#search-suggest").append (format_graph (graph));
52 } /* update_search_suggestions */
54 function zoom_redraw (jq_obj)
56 var url = jq_obj.data ("base_url");
58 if ((jq_obj == null) || (url == null))
61 if (jq_obj.data ('begin') != null)
62 url += ";begin=" + jq_obj.data ('begin');
63 if (jq_obj.data ('end') != null)
64 url += ";end=" + jq_obj.data ('end');
66 jq_obj.attr ("src", url);
70 function zoom_reset (graph_id, diff)
76 jq_obj = $("#" + graph_id);
80 end = new Number ((new Date ()).getTime () / 1000);
81 begin = new Number (end - diff);
83 jq_obj.data ('begin', begin.toFixed (0));
84 jq_obj.data ('end', end.toFixed (0));
86 return (zoom_redraw (jq_obj));
89 function zoom_hour (graph_id)
91 zoom_reset (graph_id, 3600);
94 function zoom_day (graph_id)
96 zoom_reset (graph_id, 86400);
99 function zoom_week (graph_id)
101 zoom_reset (graph_id, 7 * 86400);
104 function zoom_month (graph_id)
106 zoom_reset (graph_id, 31 * 86400);
109 function zoom_year (graph_id)
111 zoom_reset (graph_id, 366 * 86400);
114 function zoom_relative (graph_id, factor_begin, factor_end)
121 jq_obj = $("#" + graph_id);
125 begin = jq_obj.data ('begin');
126 end = jq_obj.data ('end');
127 if ((begin == null) || (end == null))
128 return (zoom_day (graph_id));
130 begin = new Number (begin);
131 end = new Number (end);
134 if ((diff <= 300) && (factor_begin > 0.0) && (factor_end < 0.0))
137 jq_obj.data ('begin', begin + (diff * factor_begin));
138 jq_obj.data ('end', end + (diff * factor_end));
140 return (zoom_redraw (jq_obj));
143 function zoom_earlier (graph_id) /* {{{ */
145 return (zoom_relative (graph_id, -0.2, -0.2));
146 } /* }}} function zoom_earlier */
148 function zoom_later (graph_id) /* {{{ */
150 return (zoom_relative (graph_id, +0.2, +0.2));
151 } /* }}} function zoom_later */
153 function zoom_in (graph_id) /* {{{ */
155 return (zoom_relative (graph_id, +0.2, -0.2));
156 } /* }}} function zoom_earlier */
158 function zoom_out (graph_id) /* {{{ */
160 return (zoom_relative (graph_id, (-1.0 / 3.0), (1.0 / 3.0)));
161 } /* }}} function zoom_earlier */
163 $(document).ready(function() {
164 /* $("#layout-middle-right").html ("<ul id=\"search-suggest\" class=\"graph_list\"></ul>"); */
165 $("#search-form").append ("<ul id=\"search-suggest\" class=\"graph_list\"></ul>");
166 $("#search-suggest").hide ();
168 $("#search-input").blur (function()
170 window.setTimeout (function ()
172 $("#search-suggest").hide ();
176 $("#search-input").focus (function()
178 var term = $("#search-input").val ();
181 $("#search-suggest").hide ();
185 $("#search-suggest").show ();
189 $("#search-input").keyup (function()
191 update_search_suggestions ();
195 $(".graph-img").each (function (index, elem)
197 var id = "graph" + graph_count;
200 $(this).find ("img").each (function (img_index, img_elem)
204 $(this).attr ("id", id);
206 base_url = $(this).attr ("src").replace (/;(begin|end)=[^;]*/g, '');
207 $(this).data ("base_url", base_url);
210 $(this).append ("<div class=\"graph-buttons presets\">"
211 + "<div class=\"graph-button\" onClick=\"zoom_hour ('"+id+"');\">H</div>"
212 + "<div class=\"graph-button\" onClick=\"zoom_day ('"+id+"');\">D</div>"
213 + "<div class=\"graph-button\" onClick=\"zoom_week ('"+id+"');\">W</div>"
214 + "<div class=\"graph-button\" onClick=\"zoom_month ('"+id+"');\">M</div>"
215 + "<div class=\"graph-button\" onClick=\"zoom_year ('"+id+"');\">Y</div>"
216 + "<div class=\"graph-button\" >!</div>"
218 + "<div class=\"graph-buttons navigation\">"
219 + "<div class=\"graph-button\" onClick=\"zoom_earlier ('"+id+"');\">←</div>"
220 + "<div class=\"graph-button\" onClick=\"zoom_out ('"+id+"');\">−</div>"
221 + "<div class=\"graph-button\" onClick=\"zoom_in ('"+id+"');\">+</div>"
222 + "<div class=\"graph-button\" onClick=\"zoom_later ('"+id+"');\">→</div>"
228 /* vim: set sw=2 sts=2 et fdm=marker : */