X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/abe8fc4c5818165ffb696448c81b3bf1bb5dc1dd..900b548097c68649ae2874ded5849f1d8164384c:/apps/workbench/app/assets/javascripts/infinite_scroll.js?ds=sidebyside diff --git a/apps/workbench/app/assets/javascripts/infinite_scroll.js b/apps/workbench/app/assets/javascripts/infinite_scroll.js index 7bdf574ed9..047858c5a0 100644 --- a/apps/workbench/app/assets/javascripts/infinite_scroll.js +++ b/apps/workbench/app/assets/javascripts/infinite_scroll.js @@ -1,3 +1,37 @@ +// infinite_scroll.js displays a tab's content using automatic scrolling +// when the user scrolls to the bottom of the page and there is more data. +// +// Usage: +// +// 1. Adding infinite scrolling to a tab pane using "show" method +// +// The steps below describe adding scrolling to the project#show action. +// +// a. In the "app/views/projects/" folder add a file for your tab +// (ex: _show_jobs_and_pipelines.html.erb) +// In this file, add a div or tbody with data-infinite-scroller. +// Note: This page uses _show_tab_contents.html.erb so that +// several tabs can reuse this implementation. +// Also add the filters to be used for loading the tab content. +// +// b. Add a file named "_show_contents_rows.html.erb" that loads +// the data (by invoking get_objects_and_names from the controller). +// +// c. In the "app/controllers/projects_controller.rb, +// Update the show method to add a block for "params[:partial]" +// that loads the show_contents_rows partial. +// Optionally, add a "tab_counts" method that loads the total number +// of objects count to be displayed for this tab. +// +// 2. Adding infinite scrolling to the "Recent" tab in "index" page +// The steps below describe adding scrolling to the pipeline_instances index page. +// +// a. In the "app/views/pipeline_instances/_show_recent.html.erb/" file +// add a div or tbody with data-infinite-scroller. +// +// b. Add the partial "_show_recent_rows.html.erb" that displays the +// page contents on scroll using the @objects + function maybe_load_more_content(event) { var scroller = this; var $container = $(event.data.container); @@ -38,7 +72,7 @@ function maybe_load_more_content(event) { } $container.find(".spinner").detach(); $container.append(spinner); - $container.attr('data-infinite-serial', serial); + $container.data('data-infinite-serial', serial); if (src == $container.attr('data-infinite-content-href0')) { // If we're loading the first page, collect filters from @@ -69,12 +103,12 @@ function maybe_load_more_content(event) { fail(function(jqxhr, status, error) { var $faildiv; var $container = this.container; - if ($container.attr('data-infinite-serial') != this.serial) { + if ($container.data('data-infinite-serial') != this.serial) { // A newer request is already in progress. return; } if (jqxhr.readyState == 0 || jqxhr.status == 0) { - message = "Cancelled." + message = "Cancelled."; } else if (jqxhr.responseJSON && jqxhr.responseJSON.errors) { message = jqxhr.responseJSON.errors.join("; "); } else { @@ -89,7 +123,7 @@ function maybe_load_more_content(event) { $container.find('div.spinner').replaceWith($faildiv); }). done(function(data, status, jqxhr) { - if ($container.attr('data-infinite-serial') != this.serial) { + if ($container.data('data-infinite-serial') != this.serial) { // A newer request is already in progress. return; } @@ -225,6 +259,10 @@ $(document). trigger('scroll'); }); }). + on('shown.bs.tab', 'a[data-toggle="tab"]', function(event) { + $(event.target.getAttribute('href') + ' [data-infinite-scroller]'). + trigger('scroll'); + }). on('click', 'th[data-sort-order]', function() { var direction = $(this).data('sort-order-direction'); // reverse the current direction, or do ascending if none @@ -241,8 +279,8 @@ $(document). // put it in the browser history state if browser allows it if( hasHTML5History() ) { var tabId = $(this).closest('div.tab-pane').attr('id'); - var state = history.state; - if( state.order === undefined) { + var state = history.state || {}; + if( state.order === undefined ) { state.order = {}; } state.order[tabId] = order;