2 * MySlice SimpleList plugin
4 * URL: http://www.myslice.info
5 * Description: Google maps display of geolocated data
7 * Author: The MySlice Team
8 * Copyright: Copyright 2012 UPMC Sorbonne Universités
15 init : function( options ) {
17 return this.each(function(){
19 var $this = jQuery(this),
20 data = $this.data('SimpleList'), SimpleList = jQuery('<div />', { text : $this.attr('title') });
22 // If the plugin hasn't been initialized yet
25 /* Plugin initialization */
27 /* Subscribe to query updates */
28 var url='/results/' + options.query_uuid + '/changed';
29 jQuery.subscribe(url, {instance: $this}, update_list);
31 /* End of plugin initialization */
33 $this.data('SimpleList', {
36 SimpleList : SimpleList
42 destroy : function( ) {
44 return this.each(function(){
45 var $this = jQuery(this), data = $this.data('SimpleList');
46 jQuery(window).unbind('SimpleList');
47 data.SimpleList.remove();
48 $this.removeData('SimpleList');
53 reposition : function( ) { // ... },
54 show : function( ) { // ... },
55 hide : function( ) { // ... },
57 update : function( content ) { }
60 jQuery.fn.SimpleList = function( method ) {
61 /* Method calling logic */
62 if ( methods[method] ) {
63 return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
64 } else if ( typeof method === 'object' || ! method ) {
65 return methods.init.apply( this, arguments );
67 jQuery.error( 'Method ' + method + ' does not exist on jQuery.SimpleList' );
74 function update_list(e, rows)
76 if (rows.length == 0) {
77 e.data.instance.html('No result !');
80 if (typeof rows[0].error != 'undefined') {
81 e.data.instance.html('ERROR: ' + rows[0].error);
84 options = e.data.instance.data().SimpleList.options;
85 is_cached = options.query.ts != 'now' ? true : false;
86 e.data.instance.html(myslice_html_ul(rows, options.key, options.value, is_cached)+"<br/>");
90 function myslice_html_li(type, value, is_cached) {
93 // 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>';
94 if (type == 'slice_hrn') {
95 return "<li class='icn icn-play'><a href='/view/slice/" + value + "'>" + value + cached + "</a></li>";
96 } else if (type == 'network_hrn') {
97 return "<li class='icn icn-play'>" + value + cached + "</li>";
99 return "<li>" + value + "</li>";
104 function myslice_html_ul(data, key, value, is_cached) {
106 for (var i = 0; i < data.length; i++) {
107 out += myslice_html_li(key, data[i][value], is_cached);
108 //out += myslice_html_li(key, myslice_html_a(data[i][key], data[i][value], key), is_cached);
116 function myslice_async_render_list(data, key, value, is_cached) {
117 // we suppose we only have one column, or we need more precisions
119 if (myslice_array_size(data[0]) == 1) {
120 for (var k in data[0]) {
125 for (var k in data[0]) {
126 if (k.substr(-4) == '_hrn') {
133 return myslice_html_ul(data, key, value, is_cached);