In my spring application, I'm using the bootstrap in my views to create the user interface. In one of the views, called listagem
, I have four tabs, and initially only one is visible (the one that gets the same name as the view, listing).
The remaining tabs should only be made visible when the user clicks available buttons in the inner area of the listagem
tab. When this happens, a jquery function reads the requested page, extracts the contents of the '' tag and adds that content to the specified tag.
The html code of my view listagem
is as follows:
<!-- Nav tabs -->
<ul class="nav nav-tabs">
<li class="active"><a href="#listagem" data-toggle="tab">Listagem</a></li>
<sec:authorize access="hasPermission(#user, 'cadastra_${param.name}')">
<li><a href="#cadastro" data-toggle="tab" style="display: none;">Cadastro</a></li>
</sec:authorize>
<sec:authorize access="hasPermission(#user, 'altera_${param.name}')">
<li><a href="#alteracao" data-toggle="tab" style="display: none;">Alteração</a></li>
</sec:authorize>
<sec:authorize access="hasPermission(#user, 'remove_${param.name}')">
<li><a href="#remocao" data-toggle="tab" style="display: none;">Remoção</a></li>
</sec:authorize>
</ul>
<!-- Tab panes -->
<div class="tab-content">
<div class="tab-pane active" id="listagem">
<div class="panel panel-default">
<div class="panel-heading">
Listagem
</div>
<div class="panel-body">
<p>...</p>
</div>
<table class="bordered">
<thead>
<tr>
<th class="col" data-property="#">#</th>
<c:forEach var="item" items="${paramValues.elements}" varStatus="status">
<th class="col" data-property="<c:out value="${item}"/>">
<c:out value="${paramValues.label[status.index]}"/>
</th>
</c:forEach>
<th class="col" data-property=""></th>
</tr>
</thead>
<tbody class="content">
</tbody>
<tfoot>
<tr>
<sec:authorize access="hasPermission(#user, 'altera_${param.name}')">
<td class="comando" data-nome="altera" data-action="${altera}"></td>
</sec:authorize>
<sec:authorize access="hasPermission(#user, 'remove_${param.name}')">
<td class="comando" data-nome="remove" data-action="${altera}"></td>
</sec:authorize>
</tr>
</tfoot>
</table>
</div>
</div>
<div class="tab-pane" id="cadastro" style="display: none;">
...
</div>
<div class="tab-pane" id="alteracao" style="display: none;">
...
</div>
<div class="tab-pane" id="remocao" style="display: none;">
...
</div>
</div>
Can anyone give me an idea how I can make the tab visible as long as the tag specifies that tab to receive the appropriate content?
ps: The code that handles the click button and adds the content to the specific tag is as follows:
function open_interna(url, target) {
target.toggle();
if($(target).is(":visible") ) {
$.ajax({
type: "GET",
url: url
}).done(function( data ) {
var $temp = $('<div/>', {html:data});
var conteudo = $temp.remove('head').html();
target.empty();
target.html(conteudo);
});
}
}
$(document).on('click', '.action', function (event) {
event.preventDefault();
event.stopPropagation();
var action = $(this).data('action');
var target = $(this).data('target');
var div = $('#'+target);
open_interna(action, div);
});