2961: Added checks if we are rendering a tab partial and skips expensive calls
[arvados.git] / apps / workbench / app / views / application / _content.html.erb
1 <% content_for :js do %>
2   function ajaxRefreshTabPane(pane) {
3     $.ajax('<%= url_for @object %>?tab_pane='+pane, {dataType: 'html', type: 'GET'}).
4       done(function(data, status, jqxhr) {
5         $('#' + pane + ' > div > div').html(data);
6         $(document).trigger('ajax:complete')
7       });
8   }
9
10   $(window).on('load', smart_scroll_fixup);
11
12   $(document).on('shown.bs.tab', 'ul.nav-tabs > li > a', smart_scroll_fixup);
13   $(document).on('shown.bs.tab', function(e) {
14     ajaxRefreshTabPane(e.target.id.slice(0, -4));
15   });
16
17   $(document).on('arv-log-event', function() {
18     ajaxRefreshTabPane($('.tab-pane.active')[0].id);
19   });
20 <% end %>
21
22 <% content_for :tab_panes do %>
23
24 <% comparable = controller.respond_to? :compare %>
25
26 <ul class="nav nav-tabs">
27   <% pane_list.each_with_index do |pane, i| %>
28     <li class="<%= 'active' if i==0 %>"><a href="#<%= pane %>" data-toggle="tab" id="<%= pane %>-tab"> <%= pane.gsub('_', ' ') %></a></li>
29   <% end %>
30 </ul>
31 <div class="tab-content">
32 <% pane_list.each_with_index do |pane, i| %>
33   <div id="<%= pane %>"
34        class="tab-pane fade <%= 'in active' if i==0 %> arv-log-event-listener"
35 <% if controller.action_name == "index" %>
36        data-object-kind="arvados#<%= ArvadosApiClient.class_kind controller.model_class %>"
37 <% else %>
38        data-object-uuid="<%= @object.uuid %>"
39 <% end %>
40 >
41
42 <% content_for :js do %>
43   <% if i != 0 %>
44     $(document).on('ready', function() {
45       ajaxRefreshTabPane('<%= pane %>');
46     });
47   <% end %>
48 <% end %>
49
50     <div class="smart-scroll" style="margin-top:0.5em;">
51       <div class="pane-content">
52         <% if i == 0 %>
53           <%= render(partial: 'show_' + pane.downcase,
54                      locals: { comparable: comparable, objects: @objects }) %>
55           <% else %>
56             <%= image_tag 'ajax-loader.gif' %>
57         <% end %>
58       </div>
59     </div>
60   </div>
61 <% end %>
62 </div>
63
64 <% end %>