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');
|
||||
$('.copy-repo-option').initializeModal('#copy-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')
|
||||
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
|
||||
@repository = Repository.new
|
||||
respond_to do |format|
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<%= render partial: "repositories/delete_record_modal" %>
|
||||
<%= render partial: "repositories/delete_column_modal" %>
|
||||
<%= render partial: "repositories/delete_record_modal.html.erb" %>
|
||||
<%= render partial: "repositories/delete_column_modal.html.erb" %>
|
||||
|
||||
<div id="alert-container"></div>
|
||||
|
||||
|
@ -67,7 +67,7 @@
|
|||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= render partial: "repository_table",
|
||||
<%= render partial: "repositories/repository_table.html.erb",
|
||||
locals: {
|
||||
repository: repository,
|
||||
repository_index_link: repository_table_index_path(repository)
|
||||
|
|
|
@ -4,19 +4,18 @@
|
|||
<%= render partial: "repositories/breadcrumbs.html.erb",
|
||||
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 -->
|
||||
<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| %>
|
||||
<li role="presentation" class="<%= 'active' if repo == active_repo %>">
|
||||
<li role="presentation">
|
||||
<a href="#custom_repo_<%= repo.id %>"
|
||||
data-toggle="tab"
|
||||
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>
|
||||
</li>
|
||||
<% end %>
|
||||
|
||||
<!-- Add new repository tab -->
|
||||
<li role="presentation"
|
||||
<% unless can_create_repository(current_team) %>
|
||||
|
@ -37,8 +36,7 @@
|
|||
<!-- Tab panes -->
|
||||
<div class="tab-content">
|
||||
<% @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 -->
|
||||
<div id="repository-toolbar">
|
||||
<div class="dropdown text-right">
|
||||
|
@ -55,7 +53,7 @@
|
|||
<li class="dropdown-header">
|
||||
<%= t("repositories.index.options_dropdown.header") %>
|
||||
</li>
|
||||
<% if can_edit_and_destroy_repository(repo) %>
|
||||
<% if can_edit_and_destroy_repository repo %>
|
||||
<li>
|
||||
<%= link_to t('repositories.index.options_dropdown.rename'),
|
||||
team_repository_rename_modal_path(repository_id: repo),
|
||||
|
@ -71,7 +69,7 @@
|
|||
remote: true %>
|
||||
</li>
|
||||
<% end %>
|
||||
<% if can_edit_and_destroy_repository(repo) %>
|
||||
<% if can_edit_and_destroy_repository repo %>
|
||||
<li role="separator" class="divider"></li>
|
||||
<li>
|
||||
<%= link_to t('repositories.index.modal_delete.delete'),
|
||||
|
@ -83,8 +81,7 @@
|
|||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render partial: 'repository', locals: { repository: repo } %>
|
||||
<div class="tab-content-body"></div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
|
|
@ -128,6 +128,8 @@ Rails.application.routes.draw do
|
|||
get 'create_modal', to: 'repositories#create_modal',
|
||||
defaults: { format: 'json' }
|
||||
end
|
||||
get 'show_tab', to: 'repositories#show_tab',
|
||||
defaults: { format: 'json' }
|
||||
get 'destroy_modal', to: 'repositories#destroy_modal',
|
||||
defaults: { format: 'json' }
|
||||
get 'rename_modal', to: 'repositories#rename_modal',
|
||||
|
|
Loading…
Reference in a new issue