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 jQuery.subscribe('/results/' + options.query_uuid + '/changed', {instance: $this}, update_list);
30 /* End of plugin initialization */
32 $this.data('SimpleList', {
35 SimpleList : SimpleList
41 destroy : function( ) {
43 return this.each(function(){
44 var $this = jQuery(this), data = $this.data('SimpleList');
45 jQuery(window).unbind('SimpleList');
46 data.SimpleList.remove();
47 $this.removeData('SimpleList');
52 reposition : function( ) { // ... },
53 show : function( ) { // ... },
54 hide : function( ) { // ... },
56 update : function( content ) { }
59 jQuery.fn.SimpleList = function( method ) {
60 /* Method calling logic */
61 if ( methods[method] ) {
62 return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
63 } else if ( typeof method === 'object' || ! method ) {
64 return methods.init.apply( this, arguments );
66 jQuery.error( 'Method ' + method + ' does not exist on jQuery.SimpleList' );
73 function update_list(e, rows)
75 if (rows.length == 0) {
76 e.data.instance.html('No result !');
79 if (typeof rows[0].error != 'undefined') {
80 e.data.instance.html('ERROR: ' + rows[0].error);
83 options = e.data.instance.data().SimpleList.options;
84 is_cached = options.query.ts != 'now' ? true : false;
85 e.data.instance.html(myslice_html_ul(rows, options.key, options.value, is_cached)+"<br/>");
89 function myslice_html_li(type, value, is_cached) {
92 // 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>';
93 if (type == 'slice_hrn') {
94 return "<li class='icn icn-play'><a href='/view/slice/" + value + "'>" + value + cached + "</a></li>";
95 } else if (type == 'network_hrn') {
96 return "<li class='icn icn-play'>" + value + cached + "</li>";
98 return "<li>" + value + "</li>";
103 function myslice_html_ul(data, key, value, is_cached) {
105 for (var i = 0; i < data.length; i++) {
106 out += myslice_html_li(key, data[i][value], is_cached);
107 //out += myslice_html_li(key, myslice_html_a(data[i][key], data[i][value], key), is_cached);
115 function myslice_async_render_list(data, key, value, is_cached) {
116 // we suppose we only have one column, or we need more precisions
118 if (myslice_array_size(data[0]) == 1) {
119 for (var k in data[0]) {
124 for (var k in data[0]) {
125 if (k.substr(-4) == '_hrn') {
132 return myslice_html_ul(data, key, value, is_cached);