X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Ftestbeds%2Fstatic%2Fjs%2Ftestbeds.js;h=dfe88553b43dd5195275c371afbac0fbbd6ef04d;hb=dcc65257573225bcb6c97038268397745a5e3e6c;hp=e424c248468685dd0d1d815cf53114a9fd41a8ef;hpb=63d2f644e35cfca2af9b60c0f45374c6331350dd;p=myslice.git diff --git a/plugins/testbeds/static/js/testbeds.js b/plugins/testbeds/static/js/testbeds.js index e424c248..dfe88553 100644 --- a/plugins/testbeds/static/js/testbeds.js +++ b/plugins/testbeds/static/js/testbeds.js @@ -22,12 +22,13 @@ * applied, which allows to maintain chainability of calls */ init: function(options, element) { - // for debugging tools - this.classname="testbedsplugin"; + // for debugging tools + this.classname="testbedsplugin"; // Call the parent constructor, see FAQ when forgotten this._super(options, element); /* Member variables */ + this.filters = Array(); /* Plugin events */ @@ -80,9 +81,34 @@ // no prefix + /* When a filter is added/removed, update the list of filters local to the plugin */ on_filter_added: function(filter) { - + this.filters.push(filter); + if(filter[0]=='network_hrn'){ + if(filter[1]=='included'){ + $.each(filter[2], function(value){ + $("#testbeds-filter_"+value).addClass("active"); + }); + }else if(filter[1]=='=' || filter[1]=='=='){ + $("#testbeds-filter_"+filter[2]).addClass("active"); + } + } + }, + on_filter_removed: function(filter) + { + this.filters = $.grep(this.filters, function(x) { + return x == filter; + }); + if(filter[0]=='network_hrn'){ + if(filter[1]=='included'){ + $.each(filter[2], function(value){ + $("#testbeds-filter_"+value).removeClass("active"); + }); + }else if(filter[1]=='=' || filter[1]=='=='){ + $("#testbeds-filter_"+filter[2]).removeClass("active"); + } + } }, // ... be sure to list all events here @@ -90,18 +116,83 @@ /* RECORD HANDLERS */ on_network_new_record: function(record) { - console.log(record); - row = ''; + row = ''; row += ''+record["platform"]+''; //row += ''+record["network_hrn"]+''; row += '

'+record["network_hrn"]+'

'; $('#testbeds-filter').append(row); }, + /* When the network query is done, add the click event to the elements */ + on_network_query_done: function() { + var self = this; + console.log('query network DONE'); + $("[id^='testbeds-filter_']").on('click',function(e) { + $(this).toggleClass("active"); + + // avoid multiple calls when an event is raised to manifold.js + e.stopPropagation(); + + value = this.dataset['platform']; + key = "network_hrn"; + op = "included"; + return $(this).hasClass('active') ? self._addFilter(key, op, value) : self._removeFilter(key, op, value); + }); + + }, + /* INTERNAL FUNCTIONS */ _dummy: function() { // only convention, not strictly enforced at the moment }, + _addFilter: function(key, op, value) + { + console.log("add "+value); + var self = this; + values = Array(); + // get the previous list of values for this key, ex: [ple,nitos] + // remove the previous filter + network_filter = $.grep(this.filters, function(x) { + return x[0] == "network_hrn"; + }); + if(network_filter.length > 0){ + $.each(network_filter, function(i,f){ + values = f[2]; + manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, [key, op, values]); + }); + } + // Add the new value to list of values, ex: wilab + values.push(value); + + // Update the filter with the new list of values, ex: [ple,nitos,wilab] + manifold.raise_event(this.options.query_uuid, FILTER_ADDED, [key, op, values]); + }, + _removeFilter: function(key, op, value) + { + console.log("remove "+value); + var self = this; + values = Array(); + // get the previous list of values for this key, ex: [ple,nitos,wilab] + // remove the previous filter + network_filter = $.grep(this.filters, function(x) { + return x[0] == "network_hrn"; + }); + if(network_filter.length > 0){ + $.each(network_filter, function(i,f){ + values = f[2]; + manifold.raise_event(self.options.query_uuid, FILTER_REMOVED, [key, op, values]); + }); + } + + // remove the value from the list of values, ex: wilab + values = $.grep(values, function(x) { + return x != value; + }); + if(values.length>0){ + // Update the filter with the new list of values, ex: [ple,nitos] + manifold.raise_event(this.options.query_uuid, FILTER_ADDED, [key, op, values]); + } + } });