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
14 init : function( options ) {
15 return this.each(function(){
17 var data = $this.data('SimpleList');
18 // console.log("data" + data);
19 // looks like $this.attr('title') is undefined..
20 // console.log('iterating in simplelist.init with data='+data+' and title='+$this.attr('title'));
21 /* create an empty DOM object */
22 var SimpleList = $('<div />', { text : $this.attr('title') });
23 // If the plugin hasn't been initialized yet
25 /* Subscribe to query updates */
26 var url='/results/' + options.query_uuid + '/changed';
27 $.subscribe(url, {instance: this}, update_list);
28 window.console.log('subscribing to ' + url);
29 $this.data('SimpleList', {options: options, target : this, SimpleList : SimpleList});
33 destroy : function( ) {
34 return this.each(function(){
35 var $this = $(this), data = $this.data('SimpleList');
36 $(window).unbind('SimpleList');
37 data.SimpleList.remove();
38 $this.removeData('SimpleList');
41 update : function( content ) { }
44 $.fn.SimpleList = function( method ) {
45 /* Method calling logic */
46 if ( methods[method] ) {
47 return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
48 } else if ( typeof method === 'object' || ! method ) {
49 return methods.init.apply( this, arguments );
51 $.error( 'Method ' + method + ' does not exist on jQuery.SimpleList' );
57 function update_list(e, rows) {
58 if (rows.length == 0) {
59 e.data.instance.html('No result !');
62 if (typeof rows[0].error != 'undefined') {
63 e.data.instance.html('ERROR: ' + rows[0].error);
66 options = e.data.instance.data().SimpleList.options;
67 is_cached = options.query.ts != 'now' ? true : false;
68 e.data.instance.html(myslice_html_ul(rows, options.key, options.value, is_cached)+"<br/>");
72 function myslice_html_li(type, value, is_cached) {
75 // 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>';
76 if (type == 'slice_hrn') {
77 return "<li class='icn icn-play'><a href='/view/slice/" + value + "'>" + value + cached + "</a></li>";
78 } else if (type == 'network_hrn') {
79 return "<li class='icn icn-play'>" + value + cached + "</li>";
81 return "<li>" + value + "</li>";
85 function myslice_html_ul(data, key, value, is_cached) {
87 for (var i = 0; i < data.length; i++) {
88 out += myslice_html_li(key, data[i][value], is_cached);
89 //out += myslice_html_li(key, myslice_html_a(data[i][key], data[i][value], key), is_cached);