Commit 364df050 authored by alinetenorio's avatar alinetenorio
Browse files

ajustes em editar

parent 3b89ee9a
...@@ -593,6 +593,7 @@ class TrabalhoController extends Controller ...@@ -593,6 +593,7 @@ class TrabalhoController extends Controller
if (in_array($request->emailParticipante[$key], $emailParticipantes, false)) { if (in_array($request->emailParticipante[$key], $emailParticipantes, false)) {
$userParticipante = User::where('email', $value)->first(); $userParticipante = User::where('email', $value)->first();
if($userParticipante != null){ if($userParticipante != null){
$user = User::where('email', $request->emailParticipante[$key])->first(); $user = User::where('email', $request->emailParticipante[$key])->first();
$participante = Participante::where([['user_id', '=', $user->id], ['trabalho_id', '=', $trabalho->id]])->first(); $participante = Participante::where([['user_id', '=', $user->id], ['trabalho_id', '=', $trabalho->id]])->first();
...@@ -612,6 +613,8 @@ class TrabalhoController extends Controller ...@@ -612,6 +613,8 @@ class TrabalhoController extends Controller
$arquivo->delete(); $arquivo->delete();
} }
//atualizar plano
if($request->semPlano[$key] == null){
$path = 'trabalhos/' . $request->editalId . '/' . $trabalho->id .'/'; $path = 'trabalhos/' . $request->editalId . '/' . $trabalho->id .'/';
$nome = $request->nomePlanoTrabalho[$key] .".pdf"; $nome = $request->nomePlanoTrabalho[$key] .".pdf";
$file = $request->anexoPlanoTrabalho[$key]; $file = $request->anexoPlanoTrabalho[$key];
...@@ -628,6 +631,18 @@ class TrabalhoController extends Controller ...@@ -628,6 +631,18 @@ class TrabalhoController extends Controller
} }
} }
} }
//removendo planos de trabalho
if($request->nomePlanoTrabalho != null && array_key_exists($key, $request->nomePlanoTrabalho)){
if($request->semPlano[$key] == 'sim'){
$arquivo = Arquivo::where('participanteId', $participante->id)->first();
//se plano já existir, deletar
if($arquivo != null){
Storage::delete($arquivo->nome);
$arquivo->delete();
}
}
}
}
} }
} }
...@@ -636,12 +651,13 @@ class TrabalhoController extends Controller ...@@ -636,12 +651,13 @@ class TrabalhoController extends Controller
$users = User::whereIn('id', $participantesUsersIds)->get(); $users = User::whereIn('id', $participantesUsersIds)->get();
foreach ($users as $user) { foreach ($users as $user) {
//dd($user);
if (!(in_array($user->email, $request->emailParticipante, false))) { if (!(in_array($user->email, $request->emailParticipante, false))) {
$participante = Participante::where([['user_id', '=', $user->id], ['trabalho_id', '=', $trabalho->id]])->first(); $participante = Participante::where([['user_id', '=', $user->id], ['trabalho_id', '=', $trabalho->id]])->first();
$arquivo = Arquivo::where('participanteId', $participante->id); $arquivo = Arquivo::where('participanteId', $participante->id)->first();
if($arquivo != null){
Storage::delete($arquivo->nome); Storage::delete($arquivo->nome);
$arquivo->delete(); $arquivo->delete();
}
$participante->delete(); $participante->delete();
} }
} }
......
...@@ -267,6 +267,7 @@ ...@@ -267,6 +267,7 @@
<hr> <hr>
<h3>Participantes</h3> <h3>Participantes</h3>
<input type="hidden" value="{{sizeof($participantes)}}" id="qtdParticipantes">
{{-- Participantes --}} {{-- Participantes --}}
<div class="row" style="margin-top:20px"> <div class="row" style="margin-top:20px">
...@@ -322,6 +323,7 @@ ...@@ -322,6 +323,7 @@
<h6 class="mb-1">Possui plano de trabalho?</h6> <h6 class="mb-1">Possui plano de trabalho?</h6>
<button class="btn btn-primary mt-2 mb-2 simPlano" id="simPlano">Sim</button> <button class="btn btn-primary mt-2 mb-2 simPlano" id="simPlano">Sim</button>
<button class="btn btn-primary mt-2 mb-2 naoPlano">Não</button> <button class="btn btn-primary mt-2 mb-2 naoPlano">Não</button>
<input type="hidden" name="semPlano[]" value="">
</div> </div>
<div class="col-sm-1 deletarSemPlano" > <div class="col-sm-1 deletarSemPlano" >
<a class="delete"> <a class="delete">
...@@ -379,6 +381,7 @@ ...@@ -379,6 +381,7 @@
@endif @endif
@endforeach @endforeach
</div> </div>
</div>
@endif @endif
@endforeach @endforeach
@endforeach @endforeach
...@@ -411,7 +414,7 @@ ...@@ -411,7 +414,7 @@
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {
var qtdLinhas = 1; var qtdLinhas = 1;
var qtdParticipantes = 1; var qtdParticipantes = $('#qtdParticipantes').val();
// Coautores // Coautores
$('#addCoautor').click(function(e) { $('#addCoautor').click(function(e) {
if (qtdParticipantes < 100) { if (qtdParticipantes < 100) {
...@@ -422,19 +425,6 @@ ...@@ -422,19 +425,6 @@
} }
}); });
$('.simPlano').click(function(e) {
var possuiPlano = $(this).parent().parent().next();
if(possuiPlano[0].firstElementChild == null){
e.preventDefault();
linha = linhaPlanoTrabalho();
possuiPlano.append(linha);
}else if(possuiPlano[0].firstElementChild.className == 'exibirPlano'){
possuiPlano[0].style.display = 'block';
}
deletar = $(this).parent().next()[0];
deletar.style.display = "none";
});
// $('#addPlanoTrabalho').click(function(e) { // $('#addPlanoTrabalho').click(function(e) {
// e.preventDefault(); // e.preventDefault();
...@@ -471,7 +461,7 @@ ...@@ -471,7 +461,7 @@
//replace the "Choose a file" label //replace the "Choose a file" label
$(this).next('#custom-file-label').html(fileName); $(this).next('#custom-file-label').html(fileName);
}) })
// F
$('#buttonSim').on('click', function(e) { $('#buttonSim').on('click', function(e) {
e.preventDefault(); e.preventDefault();
$('#inputEtica').prop('disabled', false); $('#inputEtica').prop('disabled', false);
...@@ -481,35 +471,49 @@ ...@@ -481,35 +471,49 @@
e.preventDefault(); e.preventDefault();
$('#inputEtica').prop('disabled', true); $('#inputEtica').prop('disabled', true);
$('#inputJustificativa').prop('disabled', false); $('#inputJustificativa').prop('disabled', false);
console.log('button nao');
}); });
$(document).on('click', '.simPlano', function(e) {
// Habilitando / desabilitando plano de trabalho
$('.simPlano').click(function(e) {
e.preventDefault(); e.preventDefault();
$(this).next()[0].className = 'btn btn-primary mt-2 mb-2 naoPlano'; var possuiPlano = $(this).parent().parent().next();
console.log('button sim');
//se o participante não tem plano, adicionar; se ele já tem, apenas exibir
if(possuiPlano[0].firstElementChild == null){
linha = linhaPlanoTrabalho();
possuiPlano.append(linha);
possuiPlano[0].style.display = 'block';
}else if(possuiPlano[0].firstElementChild.className == 'exibirPlano'){
possuiPlano[0].style.display = 'block';
}
//esconder a imagem de deletar
deletar = $(this).parent().next()[0];
deletar.style.display = "none";
}); });
// se não há plano de trabalho, esconder a div planoHabilitado e exibir imagem de deletar
$(document).on('click', '.naoPlano', function(e) { $(document).on('click', '.naoPlano', function(e) {
e.preventDefault(); e.preventDefault();
var plano = $(this).parent().parent().next()[0]; var plano = $(this).parent().parent().next()[0];
plano.style.display = 'none'; plano.style.display = 'none';
$(this).prev()[0].className = 'btn btn-primary mt-2 mb-2 simPlano';
deletar = $(this).parent().next()[0] deletar = $(this).parent().next()[0]
deletar.style.display = "block"; deletar.style.display = "block";
console.log('button nao');
//comunicar ao controller para deletar somente o plano
$(this).next().val('sim');
}); });
//se há plano de trabalho, esconder a imagem de deletar
$(function() { $(function() {
var simPlano = document.getElementsByClassName('simPlano'); var simPlano = document.getElementsByClassName('simPlano');
for(var i=0; i< simPlano.length;i++){ for(var i=0; i< simPlano.length;i++){
var planoHabilitado = simPlano[i].parentElement.parentElement.nextElementSibling; var planoHabilitado = simPlano[i].parentElement.parentElement.nextElementSibling;
//se há plano de trabalho
if(planoHabilitado.firstElementChild != null && planoHabilitado.firstElementChild.className == 'exibirPlano'){ if(planoHabilitado.firstElementChild != null && planoHabilitado.firstElementChild.className == 'exibirPlano'){
simPlano[i].parentElement.nextElementSibling.style.display = "none"; simPlano[i].parentElement.nextElementSibling.style.display = "none";
simPlano[i].nextElementSibling.className = 'btn btn-primary mt-2 mb-2 naoPlano';
simPlano[i].className = 'btn btn-primary focus mt-2 mb-2 simPlano';
}else{
simPlano[i].nextElementSibling.className = 'btn btn-primary focus mt-2 mb-2 naoPlano';
} }
} }
}); });
...@@ -638,7 +642,8 @@ ...@@ -638,7 +642,8 @@
// } // }
function linhaPlanoTrabalho(){ function linhaPlanoTrabalho(){
return "<h5>Dados do plano de trabalho</h5>" + return "<input"+" type="+"hidden"+" class="+"exibirPlano"+">"+
"<h5>Dados do plano de trabalho</h5>" +
"<div class="+"row"+">"+ "<div class="+"row"+">"+
"<div class="+"col-sm-4"+">"+ "<div class="+"col-sm-4"+">"+
"<label>Titulo*</label>"+ "<label>Titulo*</label>"+
...@@ -673,15 +678,6 @@ ...@@ -673,15 +678,6 @@
"<img src="+"/img/icons/user-times-solid.svg"+" style="+"width:25px;margin-top:35px"+">"+ "<img src="+"/img/icons/user-times-solid.svg"+" style="+"width:25px;margin-top:35px"+">"+
"</a>"+ "</a>"+
"</div>"+ "</div>"+
//"</div>"+
"</div>";
}
function addDeletar(){
return "<div class="+"col-sm-1"+" style="+"display:inline;"+">"+
"<a class="+"delete"+">"+
"<img src="+"/img/icons/user-times-solid.svg"+" style="+"width:25px;margin-top:35px"+">"+
"</a>"+
"</div>"; "</div>";
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment