mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-29 19:51:01 +08:00
Merge pull request #661 from mlorb/ml_sci_1266_vol2
load tabs with javascript [SCI-1266]
This commit is contained in:
commit
5ac0ed4505
5 changed files with 66 additions and 14 deletions
|
@ -5,4 +5,43 @@
|
||||||
$('.rename-repo-option').initializeModal('#rename-repo-modal');
|
$('.rename-repo-option').initializeModal('#rename-repo-modal');
|
||||||
$('.copy-repo-option').initializeModal('#copy-repo-modal');
|
$('.copy-repo-option').initializeModal('#copy-repo-modal');
|
||||||
$('.create-repository').initializeModal('#create-repo-modal');
|
$('.create-repository').initializeModal('#create-repo-modal');
|
||||||
|
|
||||||
|
loadRepositoryTab();
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
|
||||||
|
function loadRepositoryTab() {
|
||||||
|
$('#repository-tabs a').on("click", function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
var pane = $(this);
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: $(this).attr("data-url"),
|
||||||
|
type: "GET",
|
||||||
|
dataType: "json",
|
||||||
|
success: function (data) {
|
||||||
|
var tabBody = $(pane.context.hash).find(".tab-content-body");
|
||||||
|
tabBody.html(data.html);
|
||||||
|
pane.tab('show');
|
||||||
|
},
|
||||||
|
error: function (error) {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// on page load
|
||||||
|
if( param = getParam('repository') ){
|
||||||
|
// load selected tab
|
||||||
|
$('a[href="#custom_repo_'+param+'"]').click();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// load first tab content
|
||||||
|
$('#repository-tabs a:first').click();
|
||||||
|
}
|
||||||
|
|
||||||
|
// clean tab content
|
||||||
|
$('a[data-toggle="tab"]').on('hide.bs.tab', function (e) {
|
||||||
|
$(".tab-content-body").html("");
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -12,6 +12,20 @@ class RepositoriesController < ApplicationController
|
||||||
render('repositories/index')
|
render('repositories/index')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def show_tab
|
||||||
|
@repository = Repository.find_by_id(params[:repository_id])
|
||||||
|
respond_to do |format|
|
||||||
|
format.json do
|
||||||
|
render json: {
|
||||||
|
html: render_to_string(
|
||||||
|
partial: 'repositories/repository.html.erb',
|
||||||
|
locals: { repository: @repository }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def create_modal
|
def create_modal
|
||||||
@repository = Repository.new
|
@repository = Repository.new
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
<%= render partial: "repositories/delete_record_modal" %>
|
<%= render partial: "repositories/delete_record_modal.html.erb" %>
|
||||||
<%= render partial: "repositories/delete_column_modal" %>
|
<%= render partial: "repositories/delete_column_modal.html.erb" %>
|
||||||
|
|
||||||
<div id="alert-container"></div>
|
<div id="alert-container"></div>
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= render partial: "repository_table",
|
<%= render partial: "repositories/repository_table.html.erb",
|
||||||
locals: {
|
locals: {
|
||||||
repository: repository,
|
repository: repository,
|
||||||
repository_index_link: repository_table_index_path(repository)
|
repository_index_link: repository_table_index_path(repository)
|
||||||
|
|
|
@ -4,19 +4,18 @@
|
||||||
<%= render partial: "repositories/breadcrumbs.html.erb",
|
<%= render partial: "repositories/breadcrumbs.html.erb",
|
||||||
locals: { teams: @teams, current_team: current_team, type: @type } %>
|
locals: { teams: @teams, current_team: current_team, type: @type } %>
|
||||||
|
|
||||||
<% active_repo = @repositories.find_by_id(params[:repository]) %>
|
|
||||||
<% active_repo = @repositories.first if !active_repo %>
|
|
||||||
|
|
||||||
<!-- Nav tabs -->
|
<!-- Nav tabs -->
|
||||||
<ul class="nav nav-tabs nav-settings" role="tablist" id="tabs">
|
<ul class="nav nav-tabs nav-settings" role="tablist" id="repository-tabs">
|
||||||
<% @repositories.each do |repo| %>
|
<% @repositories.each do |repo| %>
|
||||||
<li role="presentation" class="<%= 'active' if repo == active_repo %>">
|
<li role="presentation">
|
||||||
<a href="#custom_repo_<%= repo.id %>"
|
<a href="#custom_repo_<%= repo.id %>"
|
||||||
data-toggle="tab"
|
data-toggle="tab"
|
||||||
aria-controls="custom_repo_<%= repo.id %>"
|
aria-controls="custom_repo_<%= repo.id %>"
|
||||||
|
data-url="<%=team_repository_show_tab_path(current_team, repo)%>"
|
||||||
title="<%=repo.name%>"><%= truncate(repo.name, length: Constants::NAME_TRUNCATION_LENGTH) %></a>
|
title="<%=repo.name%>"><%= truncate(repo.name, length: Constants::NAME_TRUNCATION_LENGTH) %></a>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
<!-- Add new repository tab -->
|
<!-- Add new repository tab -->
|
||||||
<li role="presentation"
|
<li role="presentation"
|
||||||
<% unless can_create_repository(current_team) %>
|
<% unless can_create_repository(current_team) %>
|
||||||
|
@ -37,8 +36,7 @@
|
||||||
<!-- Tab panes -->
|
<!-- Tab panes -->
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<% @repositories.each do |repo| %>
|
<% @repositories.each do |repo| %>
|
||||||
<div class="tab-pane tab-pane-settings <%= 'active' if repo == active_repo %>" id="custom_repo_<%= repo.id %>">
|
<div class="tab-pane tab-pane-settings" id="custom_repo_<%= repo.id %>">
|
||||||
|
|
||||||
<!-- Tab Content -->
|
<!-- Tab Content -->
|
||||||
<div id="repository-toolbar">
|
<div id="repository-toolbar">
|
||||||
<div class="dropdown text-right">
|
<div class="dropdown text-right">
|
||||||
|
@ -55,7 +53,7 @@
|
||||||
<li class="dropdown-header">
|
<li class="dropdown-header">
|
||||||
<%= t("repositories.index.options_dropdown.header") %>
|
<%= t("repositories.index.options_dropdown.header") %>
|
||||||
</li>
|
</li>
|
||||||
<% if can_edit_and_destroy_repository(repo) %>
|
<% if can_edit_and_destroy_repository repo %>
|
||||||
<li>
|
<li>
|
||||||
<%= link_to t('repositories.index.options_dropdown.rename'),
|
<%= link_to t('repositories.index.options_dropdown.rename'),
|
||||||
team_repository_rename_modal_path(repository_id: repo),
|
team_repository_rename_modal_path(repository_id: repo),
|
||||||
|
@ -71,7 +69,7 @@
|
||||||
remote: true %>
|
remote: true %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if can_edit_and_destroy_repository(repo) %>
|
<% if can_edit_and_destroy_repository repo %>
|
||||||
<li role="separator" class="divider"></li>
|
<li role="separator" class="divider"></li>
|
||||||
<li>
|
<li>
|
||||||
<%= link_to t('repositories.index.modal_delete.delete'),
|
<%= link_to t('repositories.index.modal_delete.delete'),
|
||||||
|
@ -83,8 +81,7 @@
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="tab-content-body"></div>
|
||||||
<%= render partial: 'repository', locals: { repository: repo } %>
|
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -128,6 +128,8 @@ Rails.application.routes.draw do
|
||||||
get 'create_modal', to: 'repositories#create_modal',
|
get 'create_modal', to: 'repositories#create_modal',
|
||||||
defaults: { format: 'json' }
|
defaults: { format: 'json' }
|
||||||
end
|
end
|
||||||
|
get 'show_tab', to: 'repositories#show_tab',
|
||||||
|
defaults: { format: 'json' }
|
||||||
get 'destroy_modal', to: 'repositories#destroy_modal',
|
get 'destroy_modal', to: 'repositories#destroy_modal',
|
||||||
defaults: { format: 'json' }
|
defaults: { format: 'json' }
|
||||||
get 'rename_modal', to: 'repositories#rename_modal',
|
get 'rename_modal', to: 'repositories#rename_modal',
|
||||||
|
|
Loading…
Reference in a new issue