X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fstatic%2Fjs%2Fsimplelist.js;h=ab320e5efbe9e9aae554011da0d4240aa6283323;hb=df482c9a6212b2b7134e8130358d213562b9df44;hp=58c656a2dc539bf7cd932bc44e66c33968fcff4c;hpb=fb7dbecd4a79019e40139a8bde65f8737b44ae76;p=myslice.git diff --git a/plugins/static/js/simplelist.js b/plugins/static/js/simplelist.js index 58c656a2..ab320e5e 100644 --- a/plugins/static/js/simplelist.js +++ b/plugins/static/js/simplelist.js @@ -1,95 +1,130 @@ /** * MySlice SimpleList plugin - * Version: 0.1.0 - * URL: http://www.myslice.info + * URL: http://trac.myslice.info * Description: display simple lists like slices or testbeds - * Requires: * Author: The MySlice Team * Copyright (c) 2012 UPMC Sorbonne Universite - INRIA * License: GPLv3 */ +simplelist_debug=false; +//simplelist_debug=true; + (function($){ + + $.fn.SimpleList = function( method ) { + /* Method calling logic */ + if ( methods[method] ) { + return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); + } else if ( typeof method === 'object' || ! method ) { + return methods.init.apply( this, arguments ); + } else { + $.error( 'Method ' + method + ' does not exist on jQuery.SimpleList' ); + } + }; + var methods = { init : function( options ) { return this.each(function(){ - var $this = $(this); - var data = $this.data('SimpleList'); - console.log("data" + data); -// looks like $this.attr('title') in undefined.. -// console.log('iterating in simplelist.init with data='+data+' and title='+$this.attr('title')); - /* create an empty DOM object */ - var SimpleList = $('
', { text : $this.attr('title') }); + var $this = $(this), data = $this.data('SimpleList'); // If the plugin hasn't been initialized yet if ( ! data ) { /* Subscribe to query updates */ - var url='/results/' + options.query_uuid + '/changed'; - $.subscribe(url, {instance: this}, update_list); - window.console.log('subscribing to ' + url); - $this.data('SimpleList', {options: options, target : this, SimpleList : SimpleList}); + var channel='/results/' + options.query_uuid + '/changed'; + /* passing $this as 2nd arg: callbacks will retrieve $this as e.data */ + $.subscribe(channel, $this, update_plugin); + if (simplelist_debug) window.console.log('subscribing to ' + channel); + $this.data('SimpleList', {options: options}); } }); }, destroy : function( ) { + if (simplelist_debug) console.log("SimpleList.destroy..."); return this.each(function(){ var $this = $(this), data = $this.data('SimpleList'); + // xxx not too sure what this is about $(window).unbind('SimpleList'); - data.SimpleList.remove(); $this.removeData('SimpleList'); - }) - }, - update : function( content ) { } - }; - - $.fn.SimpleList = function( method ) { - /* Method calling logic */ - if ( methods[method] ) { - return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 )); - } else if ( typeof method === 'object' || ! method ) { - return methods.init.apply( this, arguments ); - } else { - $.error( 'Method ' + method + ' does not exist on jQuery.SimpleList' ); - } - }; + }); + }, + update : function( content ) { + if (simplelist_debug) console.log("SimpleList.update..."); + }, + }; // methods /* Private methods */ + // complexity here is mostly because a datatables-enabled table cannot + // be updated in a "normal" way using .html() + function update_plugin(e, rows) { + // e.data is what we passed in second argument to subscribe + // so here it is the jquery object attached to the plugin"+message+" |
"+cell+" |