(function($) { /** * A widget that enables to switch the facet focus to a different type using * tabs. * */ AjaxSolr.FocusFacetWidget = AjaxSolr.AbstractWidget .extend({ /** * The field used as facet focus. * * @field * @public * @type String */ focus_field : null, init : function() { // we want the values and counts of the focus field this.manager.store.addByValue('facet.field', this.focus_field); // TODO create request to get the focus values dynamically instead of // using the hardcoded // class values // create tabs and listeners for focus switch var tabs = $(this.target).tabs(); var manager = this.manager; // store as local variable to make work in // callback (closure) // iterate through available classes to create tabs and handlers jQuery.each(this.manager.classes, function(key, value) { tabs.tabs('add', '#' + key, key); // add event listener to change focus on tab selection tabs.tabs({ select : function(event, ui) { /* if(showTooltips){ showTooltips = false; destroyTooltips(); destroyHelpButton(); setTimeout(function(){ showHelpButton(); },500); } */ manager.setFocus(manager.classes, ui.tab.hash.substr(1)); } }); }); }, afterRequest : function() { // will be called when we get the response of the count query var callback = function(response) { var field_count = response.response.numFound; var focus = response.responseHeader.params.ff; //console.log('field_count ' + field_count); //console.log('focus '+focus); var tab_name = tabs.find('ul:first li a[href="#' + focus + '"]'); tab_name.text(focus + ' (' + field_count + ')'); }; var tabs = $(this.target); var filter_params = [ 'qt=siren-facet', 'indent=true', 'wt=json' ]; // we want to apply all current filters to the query to get the count // based on that for ( var focus in this.manager.classes) { var filter_values = this.manager.store.values(focus); for ( var i = 0; i < filter_values.length; i++) { filter_params.push(focus + '=' + encodeURIComponent(filter_values[i])); } } // request counts for each facet focus for ( var focus in this.manager.classes) { var params = filter_params.slice(); // copy array params.push('ff=' + focus); //jQuery.getJSON(this.manager.solrUrl + 'select?' + params.join('&') + '&json.wrf=?', {}, callback); jQuery.ajax({ url:this.manager.solrUrl+'select?' + params.join('&') + '&json.wrf=?', dataType:"jsonp", data:{"jsonp":"json.wrf"}, success:callback }); } } }); })(jQuery);