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 /* create an empty DOM object */
21 var SimpleList = $('<div />', { text : $this.attr('title') });
22 // If the plugin hasn't been initialized yet
24 /* Subscribe to query updates */
25 var channel='/results/' + options.query_uuid + '/changed';
26 /* passing $this as 2nd arg: callbacks will retrieve $this as e.data */
27 $.subscribe(channel, $this, update_list);
28 if (simplelist_debug) window.console.log('subscribing to ' + channel);
29 $this.data('SimpleList', {options: options, 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' );
56 function update_list(e, rows) {
57 if (rows.length == 0) {
58 e.data.html('No result !');
61 if (typeof rows[0].error != 'undefined') {
62 e.data.html('ERROR: ' + rows[0].error);
65 var options = e.data.data().SimpleList.options;
66 var is_cached = options.query.timestamp != 'now' ? true : false;
67 html_code=myslice_html_ul(rows, options.key, options.value, is_cached)+"<br/>";
68 e.data.html(html_code);
70 if (simplelist_debug) console.log("about to unspin with elt #" + $elt.attr('id') + " class " + $elt.attr('class'));
71 $elt.closest('.need-spin').spin(false);
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);
83 function myslice_html_li(key, value,is_cached) {
84 var cached = is_cached ? "(cached)" : "";
85 if (key == 'slice_hrn') {
86 return "<li class='slice-hrn'><i class='icon-play-circle'></i><a href='/slice/" + value + "'>" + value + cached + "</a></li>";
87 } else if (key == 'network_hrn') {
88 return "<li class='network-hrn'><i class='icon-play-circle'></i>" + value + cached + "</li>";
90 return "<li>" + value + "</li>";