2 * MySlice SimpleList plugin
4 * URL: http://www.myslice.info
5 * Description: display simple lists like slices or testbeds
7 * Author: The MySlice Team
8 * Copyright (c) 2012 UPMC Sorbonne Universite - INRIA
12 simplelist_debug=false;
16 init : function( options ) {
17 return this.each(function(){
19 var data = $this.data('SimpleList');
20 // console.log("data" + data);
21 // looks like $this.attr('title') is undefined..
22 // console.log('iterating in simplelist.init with data='+data+' and title='+$this.attr('title'));
23 /* create an empty DOM object */
24 var SimpleList = $('<div />', { text : $this.attr('title') });
25 // If the plugin hasn't been initialized yet
27 /* Subscribe to query updates */
28 var url='/results/' + options.query_uuid + '/changed';
29 $.subscribe(url, {instance: $this}, update_list);
30 if (simplelist_debug) window.console.log('subscribing to ' + url);
31 $this.data('SimpleList', {options: options, target : this, SimpleList : SimpleList});
35 destroy : function( ) {
36 return this.each(function(){
37 var $this = $(this), data = $this.data('SimpleList');
38 $(window).unbind('SimpleList');
39 data.SimpleList.remove();
40 $this.removeData('SimpleList');
43 update : function( content ) { }
46 $.fn.SimpleList = function( method ) {
47 /* Method calling logic */
48 if ( methods[method] ) {
49 return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
50 } else if ( typeof method === 'object' || ! method ) {
51 return methods.init.apply( this, arguments );
53 $.error( 'Method ' + method + ' does not exist on jQuery.SimpleList' );
58 function update_list(e, rows) {
59 if (rows.length == 0) {
60 e.data.instance.html('No result !');
63 if (typeof rows[0].error != 'undefined') {
64 e.data.instance.html('ERROR: ' + rows[0].error);
67 options = e.data.instance.data().SimpleList.options;
68 is_cached = options.query.ts != 'now' ? true : false;
69 html_code=myslice_html_ul(rows, options.key, options.value, is_cached)+"<br/>";
70 e.data.instance.html(html_code);
74 function myslice_html_ul(data, key, value, is_cached) {
76 for (var i = 0; i < data.length; i++) {
77 out += myslice_html_li(key, data[i][value], is_cached);
78 //out += myslice_html_li(key, myslice_html_a(data[i][key], data[i][value], key), is_cached);
84 function myslice_html_li(type, value, is_cached) {
87 // cached='<div class="cache"><span><b>Cached information from the database</b><br/>Timestamp: XX/XX/XX XX:XX:XX<br/><br/><i>Refresh in progress...</i></span></div>';
88 if (type == 'slice_hrn') {
89 return "<li class='icn icn-play'><a href='/slice/" + value + "'>" + value + cached + "</a></li>";
90 } else if (type == 'network_hrn') {
91 return "<li class='icn icn-play'>" + value + cached + "</li>";
93 return "<li>" + value + "</li>";