updating changes and ambits during the project in progress and creating a structure in the database
This commit is contained in:
parent
1bbbdc279e
commit
a2eca495db
|
|
@ -6,6 +6,7 @@
|
||||||
use App\Models\AssociationCompanyUser;
|
use App\Models\AssociationCompanyUser;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\EquipmentWorkHistory;
|
use App\Models\EquipmentWorkHistory;
|
||||||
|
use App\Models\HistoryOfEquipmentAmbitsInTheProject;
|
||||||
use App\Models\ProjectExcelLog;
|
use App\Models\ProjectExcelLog;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
@ -83,7 +84,6 @@ public function deleteProject($projectId)
|
||||||
|
|
||||||
public function changeAmbitEquipment(Request $request)
|
public function changeAmbitEquipment(Request $request)
|
||||||
{
|
{
|
||||||
|
|
||||||
$receiveAmbitEquipmentId = $request->receveAmbit;
|
$receiveAmbitEquipmentId = $request->receveAmbit;
|
||||||
$equipmentId = $request->equipmentID;
|
$equipmentId = $request->equipmentID;
|
||||||
|
|
||||||
|
|
@ -93,11 +93,32 @@ public function changeAmbitEquipment(Request $request)
|
||||||
->where('company_projects_id', $receiveEquipment->company_projects_id)
|
->where('company_projects_id', $receiveEquipment->company_projects_id)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
$receiveDataEquipmentAssociationAmbit = EquipmentAssociationAmbit::where('equipmentWorkHistorys_id', $receiveEquipmentWorkHistorys->equipmentWorkHistorys_id)->first();
|
$receiveDataEquipmentAssociationAmbit = EquipmentAssociationAmbit::where('equipmentWorkHistorys_id', $receiveEquipmentWorkHistorys->equipmentWorkHistorys_id)
|
||||||
|
->first();
|
||||||
|
|
||||||
|
// Se o ambito atual for igual ao antigo ambito
|
||||||
if ($receiveDataEquipmentAssociationAmbit->ambits_id == $receiveAmbitEquipmentId) {
|
if ($receiveDataEquipmentAssociationAmbit->ambits_id == $receiveAmbitEquipmentId) {
|
||||||
return back()->with('danger', 'Âmbito selecionado é igual ao anterior!');
|
return back()->with('danger', 'Âmbito selecionado é igual ao anterior!');
|
||||||
} else {
|
} else {
|
||||||
|
// Verificar se existe um histórico de âmbito sem timestamp (time_change_ambit)
|
||||||
|
$existingHistory = HistoryOfEquipmentAmbitsInTheProject::where('equipmentWorkHistorys_id', $receiveEquipmentWorkHistorys->equipmentWorkHistorys_id)
|
||||||
|
->where('ambits_id', $receiveDataEquipmentAssociationAmbit->ambits_id)
|
||||||
|
->whereNull('time_change_ambit')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
// Se existir e o time_change_ambit for nulo, atualiza com o timestamp atual
|
||||||
|
if ($existingHistory) {
|
||||||
|
$existingHistory->time_change_ambit = now();
|
||||||
|
$existingHistory->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Criar um novo registro em HistoryOfEquipmentAmbitsInTheProject para o novo âmbito
|
||||||
|
$newHistoryOfEquipmentAmbits = new HistoryOfEquipmentAmbitsInTheProject;
|
||||||
|
$newHistoryOfEquipmentAmbits->equipmentWorkHistorys_id = $receiveEquipmentWorkHistorys->equipmentWorkHistorys_id;
|
||||||
|
$newHistoryOfEquipmentAmbits->ambits_id = $receiveAmbitEquipmentId;
|
||||||
|
$newHistoryOfEquipmentAmbits->time_change_ambit = null; // Novo registro sem timestamp
|
||||||
|
$newHistoryOfEquipmentAmbits->save();
|
||||||
|
|
||||||
// Deleta as tarefas associadas ao equipamento no âmbito atual
|
// Deleta as tarefas associadas ao equipamento no âmbito atual
|
||||||
OrderEquipmentTasks::where('equipmentWorkHistorys_id', $receiveEquipmentWorkHistorys->equipmentWorkHistorys_id)->delete();
|
OrderEquipmentTasks::where('equipmentWorkHistorys_id', $receiveEquipmentWorkHistorys->equipmentWorkHistorys_id)->delete();
|
||||||
|
|
||||||
|
|
@ -119,9 +140,9 @@ public function changeAmbitEquipment(Request $request)
|
||||||
|
|
||||||
return back()->with('success', 'Equipamento: ' . $receiveEquipment->equipment_id . ' trocado de âmbito com sucesso!');
|
return back()->with('success', 'Equipamento: ' . $receiveEquipment->equipment_id . ' trocado de âmbito com sucesso!');
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function deleteEquipmentInProject(Request $request)
|
public function deleteEquipmentInProject(Request $request)
|
||||||
{
|
{
|
||||||
$receiveEquipment = Equipment::where('equipment_id', $request->equipmentId)->first();
|
$receiveEquipment = Equipment::where('equipment_id', $request->equipmentId)->first();
|
||||||
|
|
@ -1228,7 +1249,6 @@ public function processStep2(Request $request)
|
||||||
// $ignoredLines = [];
|
// $ignoredLines = [];
|
||||||
// $duplicateLines = [];
|
// $duplicateLines = [];
|
||||||
|
|
||||||
|
|
||||||
// Separa o nome do arquivo para obter o tipo de documento e a data-hora
|
// Separa o nome do arquivo para obter o tipo de documento e a data-hora
|
||||||
$parts = explode('_', $originalFileName);
|
$parts = explode('_', $originalFileName);
|
||||||
$documentType = $parts[2]; // 98
|
$documentType = $parts[2]; // 98
|
||||||
|
|
@ -1279,7 +1299,7 @@ function normalize($value)
|
||||||
|
|
||||||
// vai guardar todos os campos de possiveis novos equipamentos, cada um em um array para multiplos inserts, na base de dados
|
// vai guardar todos os campos de possiveis novos equipamentos, cada um em um array para multiplos inserts, na base de dados
|
||||||
$datas = array_filter($joinArrays, function ($chave) {
|
$datas = array_filter($joinArrays, function ($chave) {
|
||||||
return !empty ($chave);
|
return !empty($chave);
|
||||||
}, ARRAY_FILTER_USE_KEY);
|
}, ARRAY_FILTER_USE_KEY);
|
||||||
|
|
||||||
// Verifica se a coluna 'fábrica' (primeiro campo) está vazia
|
// Verifica se a coluna 'fábrica' (primeiro campo) está vazia
|
||||||
|
|
@ -1445,6 +1465,13 @@ function normalize($value)
|
||||||
|
|
||||||
$AssociationEquipmentAmbit->save();
|
$AssociationEquipmentAmbit->save();
|
||||||
|
|
||||||
|
|
||||||
|
// Criar um registro em HistoryOfEquipmentAmbitsInTheProject
|
||||||
|
$newHistoryOfEquipmentAmbits = new HistoryOfEquipmentAmbitsInTheProject;
|
||||||
|
$newHistoryOfEquipmentAmbits->equipmentWorkHistorys_id = $newEquipmentWorkHistory->equipmentWorkHistorys_id;
|
||||||
|
$newHistoryOfEquipmentAmbits->ambits_id = $ambit->ambits_id;
|
||||||
|
$newHistoryOfEquipmentAmbits->save();
|
||||||
|
|
||||||
//Recebe a tabela com as associoacoes entre Âmbitos e tarefas Elementares
|
//Recebe a tabela com as associoacoes entre Âmbitos e tarefas Elementares
|
||||||
$TasksAssociationAmbits = TasksAssociationAmbits::all()->where('ambits_equipment_id', $AssociationEquipmentAmbit->ambits_id);
|
$TasksAssociationAmbits = TasksAssociationAmbits::all()->where('ambits_equipment_id', $AssociationEquipmentAmbit->ambits_id);
|
||||||
$execution_order = 1;
|
$execution_order = 1;
|
||||||
|
|
@ -1458,6 +1485,8 @@ function normalize($value)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
continue; // Pula para a próxima iteração
|
continue; // Pula para a próxima iteração
|
||||||
|
|
||||||
//----- Para equipamento novos, nao pendentes. ---------
|
//----- Para equipamento novos, nao pendentes. ---------
|
||||||
|
|
@ -1525,6 +1554,12 @@ function normalize($value)
|
||||||
|
|
||||||
$AssociationEquipmentAmbit->save();
|
$AssociationEquipmentAmbit->save();
|
||||||
|
|
||||||
|
// Criar um registro em HistoryOfEquipmentAmbitsInTheProject
|
||||||
|
$newHistoryOfEquipmentAmbits = new HistoryOfEquipmentAmbitsInTheProject;
|
||||||
|
$newHistoryOfEquipmentAmbits->equipmentWorkHistorys_id = $newEquipmentWorkHistory->equipmentWorkHistorys_id;
|
||||||
|
$newHistoryOfEquipmentAmbits->ambits_id = $ambit->ambits_id;
|
||||||
|
$newHistoryOfEquipmentAmbits->save();
|
||||||
|
|
||||||
//Recebe a tabela com as associoacoes entre Âmbitos e tarefas Elementares
|
//Recebe a tabela com as associoacoes entre Âmbitos e tarefas Elementares
|
||||||
$TasksAssociationAmbits = TasksAssociationAmbits::all()->where('ambits_equipment_id', $AssociationEquipmentAmbit->ambits_id);
|
$TasksAssociationAmbits = TasksAssociationAmbits::all()->where('ambits_equipment_id', $AssociationEquipmentAmbit->ambits_id);
|
||||||
$execution_order = 1;
|
$execution_order = 1;
|
||||||
|
|
|
||||||
|
|
@ -101,12 +101,13 @@ public function getDataEquipment(Request $request)
|
||||||
'equipmentType',
|
'equipmentType',
|
||||||
'unit',
|
'unit',
|
||||||
'equipmentWorkHistory' => function ($query) {
|
'equipmentWorkHistory' => function ($query) {
|
||||||
$query->where('extra_equipment', 1);
|
//Assim a tabela recebe os equipamentos normais e extras e evita devolver equipamentos ja finalizados
|
||||||
|
$query->whereIn('extra_equipment', [0, 1]);
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
->where('company_projects_id', $numberProject)
|
->where('company_projects_id', $numberProject)
|
||||||
->whereHas('equipmentWorkHistory', function ($query) {
|
->whereHas('equipmentWorkHistory', function ($query) {
|
||||||
$query->where('extra_equipment', 1);
|
$query->whereIn('extra_equipment', [0, 1]);
|
||||||
})
|
})
|
||||||
->select(['equipment_id', 'equipment_tag', 'unit_id', 'equipment_type_id', 'equipment_description']);
|
->select(['equipment_id', 'equipment_tag', 'unit_id', 'equipment_type_id', 'equipment_description']);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
use App\Models\Equipment;
|
use App\Models\Equipment;
|
||||||
use App\Models\EquipmentComment;
|
use App\Models\EquipmentComment;
|
||||||
use App\Models\EquipmentWorkHistory;
|
use App\Models\EquipmentWorkHistory;
|
||||||
|
use App\Models\HistoryOfEquipmentAmbitsInTheProject;
|
||||||
use App\Models\OrderEquipmentTasks;
|
use App\Models\OrderEquipmentTasks;
|
||||||
use App\Models\workstationsTaskAnswers;
|
use App\Models\workstationsTaskAnswers;
|
||||||
use App\Models\ReceiveImagesControlEquipmentWorkstation; // Ajuste o namespace conforme necessário
|
use App\Models\ReceiveImagesControlEquipmentWorkstation; // Ajuste o namespace conforme necessário
|
||||||
|
|
@ -80,7 +81,7 @@ public function receiveQuestionsEquipment($equipmentID)
|
||||||
}
|
}
|
||||||
public function receiveAnswersEquipment(Request $request, $control_equipment_workstation_id)
|
public function receiveAnswersEquipment(Request $request, $control_equipment_workstation_id)
|
||||||
{
|
{
|
||||||
|
// dd($control_equipment_workstation_id);
|
||||||
//No request recebemos ID(NUmero da tarela elementar) , esta variavel vai receber este ID apos selerar o id da string
|
//No request recebemos ID(NUmero da tarela elementar) , esta variavel vai receber este ID apos selerar o id da string
|
||||||
// $elementalTaskID = 0;
|
// $elementalTaskID = 0;
|
||||||
// Deve receber as perguntas e respostas para a tarefa selecionada
|
// Deve receber as perguntas e respostas para a tarefa selecionada
|
||||||
|
|
@ -147,6 +148,13 @@ public function receiveAnswersEquipment(Request $request, $control_equipment_wor
|
||||||
$receiveDataControlWs->elemental_tasks_id = $elementalTaskID;
|
$receiveDataControlWs->elemental_tasks_id = $elementalTaskID;
|
||||||
$receiveDataControlWs->departure_date = now();
|
$receiveDataControlWs->departure_date = now();
|
||||||
|
|
||||||
|
// Vai sempre procurar o primeira ocorrencia que tem o campo : time_change_ambit como null, pois outros dados para este mesmo equipamento seriam considerados Ambitos antigos e ja alterados de acordo com o valor de seu timestamp
|
||||||
|
$receiveHistoryEquipmentAmbits = HistoryOfEquipmentAmbitsInTheProject::where('equipmentWorkHistorys_id', $receiveDataControlWs->equipmentWorkHistorys_id)
|
||||||
|
->whereNull('time_change_ambit')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
$receiveDataControlWs->history_of_equipment_ambits_id = $receiveHistoryEquipmentAmbits->history_of_equipment_ambits_id;
|
||||||
|
|
||||||
$requestData = $request->all();
|
$requestData = $request->all();
|
||||||
|
|
||||||
// Iterar sobre o array de parâmetros do request
|
// Iterar sobre o array de parâmetros do request
|
||||||
|
|
|
||||||
|
|
@ -167,19 +167,20 @@ public function edit($id)
|
||||||
|
|
||||||
public function update(Request $request, User $user)
|
public function update(Request $request, User $user)
|
||||||
{
|
{
|
||||||
|
// dd($request);
|
||||||
//Por enquanto foi retirado o 'user_type' pois ainda não é necessario alterar o tipo de utilizador na edição.
|
//Por enquanto foi retirado o 'user_type' pois ainda não é necessario alterar o tipo de utilizador na edição.
|
||||||
|
|
||||||
$request->validate([
|
// $request->validate([
|
||||||
'name' => 'required',
|
// 'name' => 'required',
|
||||||
'email' => 'required|email|unique:users,email,' . $user->user_id . ',user_id',
|
// 'email' => 'required|email|unique:users,email,' . $user->user_id . ',user_id',
|
||||||
'password' => 'nullable|min:8|confirmed',
|
// 'password' => 'nullable|min:8|confirmed',
|
||||||
// 'user_type' => 'required',
|
// // 'user_type' => 'required',
|
||||||
'user_phone' => 'required',
|
// 'user_phone' => 'required',
|
||||||
'user_nif' => 'required',
|
// 'user_nif' => 'required',
|
||||||
]);
|
// ]);
|
||||||
|
|
||||||
$user->update([
|
$user->update([
|
||||||
'name' => $request->get('name'),
|
'user_name' => $request->get('user_name'),
|
||||||
'email' => $request->get('email'),
|
'email' => $request->get('email'),
|
||||||
'password' => $request->filled('password') ? Hash::make($request->get('password')) : $user->password,
|
'password' => $request->filled('password') ? Hash::make($request->get('password')) : $user->password,
|
||||||
// 'user_type' => $request->get('user_type'),
|
// 'user_type' => $request->get('user_type'),
|
||||||
|
|
|
||||||
|
|
@ -22,4 +22,9 @@ class AmbitsEquipment extends Model
|
||||||
public function equipmentAssociationAmbit(){
|
public function equipmentAssociationAmbit(){
|
||||||
return $this->hasMany(EquipmentAssociationAmbit::class, 'ambits_id', 'ambits_id');
|
return $this->hasMany(EquipmentAssociationAmbit::class, 'ambits_id', 'ambits_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function HistoryOfEquipmentAmbitsInTheProject (){
|
||||||
|
return $this->hasMany(HistoryOfEquipmentAmbitsInTheProject::class, 'ambits_id', 'ambits_id');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,4 +37,8 @@ public function equipmentAssociationAmbit()
|
||||||
return $this->hasOne(EquipmentAssociationAmbit::class, 'equipmentWorkHistorys_id', 'equipmentWorkHistorys_id');
|
return $this->hasOne(EquipmentAssociationAmbit::class, 'equipmentWorkHistorys_id', 'equipmentWorkHistorys_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function HistoryOfEquipmentAmbitsInTheProject (){
|
||||||
|
return $this->hasMany(HistoryOfEquipmentAmbitsInTheProject::class, 'ambits_id', 'ambits_id');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
31
app/Models/HistoryOfEquipmentAmbitsInTheProject.php
Normal file
31
app/Models/HistoryOfEquipmentAmbitsInTheProject.php
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class HistoryOfEquipmentAmbitsInTheProject extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $table = 'history_of_equipment_ambits_in_the_project';
|
||||||
|
protected $primaryKey = 'ambits_id';
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'history_of_equipment_ambits_id',
|
||||||
|
'equipmentWorkHistorys_id',
|
||||||
|
'ambits_id',
|
||||||
|
'time_change_ambit',
|
||||||
|
];
|
||||||
|
|
||||||
|
public $timestamps = false;
|
||||||
|
|
||||||
|
public function AmbitsEquipment (){
|
||||||
|
return $this->belongsTo(AmbitsEquipment::class, 'ambits_id', 'ambits_id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function EquipmentWorkHistory (){
|
||||||
|
return $this->belongsTo(EquipmentWorkHistory::class, 'ambits_id', 'ambits_id');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -15,11 +15,13 @@
|
||||||
<ol class="breadcrumb float-sm-right">
|
<ol class="breadcrumb float-sm-right">
|
||||||
@if ($user->type_users == 3)
|
@if ($user->type_users == 3)
|
||||||
<li class="breadcrumb-item"><a href="{{ route('users.company') }}"> Empresas</a></li>
|
<li class="breadcrumb-item"><a href="{{ route('users.company') }}"> Empresas</a></li>
|
||||||
<li class="breadcrumb-item"><a href="{{ route('users.Show', [$user->user_id]) }}"> Detalhes da Empresa</a></li>
|
<li class="breadcrumb-item"><a href="{{ route('users.Show', [$user->user_id]) }}"> Detalhes da
|
||||||
|
Empresa</a></li>
|
||||||
<li class="breadcrumb-item active">Editar Empresa</li>
|
<li class="breadcrumb-item active">Editar Empresa</li>
|
||||||
@else
|
@else
|
||||||
<li class="breadcrumb-item"><a href="{{ route('users.list') }}"> Utilizadores</a></li>
|
<li class="breadcrumb-item"><a href="{{ route('users.list') }}"> Utilizadores</a></li>
|
||||||
<li class="breadcrumb-item"><a href="{{ route('users.Show', [$user->user_id]) }}"> Detalhes do utilizador</a></li>
|
<li class="breadcrumb-item"><a href="{{ route('users.Show', [$user->user_id]) }}"> Detalhes do
|
||||||
|
utilizador</a></li>
|
||||||
<li class="breadcrumb-item active">Editar Utilizador</li>
|
<li class="breadcrumb-item active">Editar Utilizador</li>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|
@ -49,7 +51,7 @@
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="form-group text-primary">
|
<div class="form-group text-primary">
|
||||||
<label for="name">Nome:</label>
|
<label for="name">Nome:</label>
|
||||||
<input type="text" class="form-control" id="name" name="name"
|
<input type="text" class="form-control" id="user_name" name="user_name"
|
||||||
value="{{ $user->user_name }}" required>
|
value="{{ $user->user_name }}" required>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -57,24 +59,51 @@
|
||||||
<div class="form-group text-primary">
|
<div class="form-group text-primary">
|
||||||
<label for="email">Email:</label>
|
<label for="email">Email:</label>
|
||||||
<input type="email" class="form-control" id="email" name="email"
|
<input type="email" class="form-control" id="email" name="email"
|
||||||
value="{{ $user->email }}" required>
|
value="{{ $user->email }}" readonly style="pointer-events: none;">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
{{-- <div class="col-sm-6">
|
||||||
|
<div class="form-group text-primary">
|
||||||
|
<label for="password">Palavra-passe:</label>
|
||||||
|
<input type="password" class="form-control" id="password" name="password"
|
||||||
|
placeholder="Alterar senha">
|
||||||
|
</div>
|
||||||
|
<div class="password-requirements">
|
||||||
|
<ul id="password-criteria" style=" display: none;">
|
||||||
|
<li id="min-length">Pelo menos 8 caracteres</li>
|
||||||
|
<li id="upper-case">Uma letra maiúscula</li>
|
||||||
|
<li id="lower-case">Uma letra minúscula</li>
|
||||||
|
<li id="one-number">Um número</li>
|
||||||
|
<li id="special-char">Um caractere especial (@$!%*?&)</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div> --}}
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="form-group text-primary">
|
<div class="form-group text-primary">
|
||||||
<label for="password">Palavra-passe:</label>
|
<label for="password">Palavra-passe:</label>
|
||||||
<input type="password" class="form-control" id="password" name="password"
|
<input type="password" class="form-control" id="password" name="password"
|
||||||
placeholder="Alterar senha">
|
placeholder="Alterar senha">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="password-requirements">
|
||||||
|
<ul id="password-criteria" style="display: none;">
|
||||||
|
<li id="min-length">Pelo menos 8 caracteres</li>
|
||||||
|
<li id="upper-case">Uma letra maiúscula</li>
|
||||||
|
<li id="lower-case">Uma letra minúscula</li>
|
||||||
|
<li id="one-number">Um número</li>
|
||||||
|
<li id="special-char">Um caractere especial (@$!%*?&)</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="form-group text-primary">
|
<div class="form-group text-primary">
|
||||||
<label for="password_confirmation">Confirme a palavra-passe:</label>
|
<label for="password_confirmation">Confirme a palavra-passe:</label>
|
||||||
<input type="password" class="form-control" id="password_confirmation"
|
<input type="password" class="form-control" id="password_confirmation"
|
||||||
name="password_confirmation">
|
name="password_confirmation">
|
||||||
|
<div id="project-password-confirm-valid"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -82,9 +111,12 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="form-group text-primary">
|
<div class="form-group text-primary">
|
||||||
<label for="user_nif">NIF:</label>
|
|
||||||
|
<label for="nif">NIF:</label>
|
||||||
<input type="text" class="form-control" id="user_nif" name="user_nif"
|
<input type="text" class="form-control" id="user_nif" name="user_nif"
|
||||||
value="{{ $user->user_nif }}" required>
|
data-type="nif" value="{{ $user->user_nif }}" required>
|
||||||
|
<div id="project-number-exists-nif"></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
|
|
@ -114,7 +146,7 @@
|
||||||
</select>
|
</select>
|
||||||
</div> --}}
|
</div> --}}
|
||||||
|
|
||||||
<button type="submit" class="btn btn-light float-right">Salvar</button>
|
<button type="submit" id="submitBtn" class="btn btn-light float-right">Salvar</button>
|
||||||
<a href="{{ route('users.list') }}" class="btn btn-danger float-left">Retornar</a>
|
<a href="{{ route('users.list') }}" class="btn btn-danger float-left">Retornar</a>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
@ -125,4 +157,602 @@
|
||||||
</div>
|
</div>
|
||||||
{{-- /.container-fluid" --}}
|
{{-- /.container-fluid" --}}
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
<script src={{ asset('assets/dist/js/countryFlags.js') }}></script>
|
||||||
|
|
||||||
|
|
||||||
|
{{-- <script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
// Esta funcao foi necessaria, pois devido ao css e script para funcionar a exibicao das bandeiras, sem esta funcao, sempre que click no input, a selecao de bandeiras some, ate click fora do input
|
||||||
|
//Nao mexer !!! se voce quiser, ter um select de paises bonito dentro do input XD
|
||||||
|
function ensureFlagContainerVisibility() {
|
||||||
|
const flagContainer = document.querySelector('.flag-container');
|
||||||
|
const countryList = document.querySelector('.country-list');
|
||||||
|
|
||||||
|
// Verifica se o .country-list está ativo
|
||||||
|
const isCountryListActive = countryList && countryList.classList.contains('active');
|
||||||
|
|
||||||
|
// if (!flagContainer) {
|
||||||
|
// console.log('Flag container não encontrado, inserindo novamente...');
|
||||||
|
// // Insira o código para reinserir o .flag-container no DOM aqui
|
||||||
|
// } else {
|
||||||
|
// if (isCountryListActive) {
|
||||||
|
// // Se .country-list estiver ativo, esconde .flag-container
|
||||||
|
// flagContainer.style.display = 'none';
|
||||||
|
// } else {
|
||||||
|
// // Se .country-list não estiver ativo, mostra .flag-container
|
||||||
|
// flagContainer.style.display = 'block'; // Garantindo que não esteja escondido
|
||||||
|
// flagContainer.style.position = 'absolute'; // Mantendo a posição
|
||||||
|
// flagContainer.style.left = '0px'; // Ajustando a posição horizontal conforme necessário
|
||||||
|
// flagContainer.style.top = '0px'; // Ajustando a posição vertical conforme necessário
|
||||||
|
// flagContainer.style.zIndex = '9999'; // Garantindo que esteja acima de outros elementos
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chamando a função imediatamente para aplicar os estilos e configurações iniciais
|
||||||
|
ensureFlagContainerVisibility();
|
||||||
|
// Configurando um intervalo para verificar e aplicar os estilos periodicamente
|
||||||
|
setInterval(ensureFlagContainerVisibility, 50); // Verifica a cada 0.05 segundo
|
||||||
|
|
||||||
|
// Todas as Validacoes comecam a 'false' e se alteram em tempo real de acordo com o text em cada input
|
||||||
|
var validationState = {
|
||||||
|
|
||||||
|
nif: false,
|
||||||
|
// pending_phone: false,
|
||||||
|
password: false,
|
||||||
|
password_confirmation: false
|
||||||
|
};
|
||||||
|
|
||||||
|
// Validação AJAX
|
||||||
|
function validateField(type, value) {
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ route('validateForm') }}',
|
||||||
|
type: 'GET',
|
||||||
|
data: {
|
||||||
|
_token: $('input[name="_token"]').val(), // CSRF token
|
||||||
|
type: type,
|
||||||
|
value: value
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
// o ERRO do Nif esta vinda desta parte, pois parece que nao fica a success
|
||||||
|
if (response['result_' + type] === 0) {
|
||||||
|
validationState[type] = true;
|
||||||
|
updateSubmitButtonState();
|
||||||
|
|
||||||
|
} else {
|
||||||
|
validationState[type] = false;
|
||||||
|
updateSubmitButtonState();
|
||||||
|
}
|
||||||
|
|
||||||
|
updateUI(type, response['result_' + type]);
|
||||||
|
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
console.error("Erro na validação: ", error);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Função para atualizar a interface com base no resultado (Logs de resposta para cada Input)
|
||||||
|
function updateUI(type, result) {
|
||||||
|
console.log(result);
|
||||||
|
var message;
|
||||||
|
var borderColor;
|
||||||
|
|
||||||
|
//Validacoes da resposta API
|
||||||
|
switch (result) {
|
||||||
|
case 1:
|
||||||
|
message = 'O ' + type + ' já está registrado.';
|
||||||
|
borderColor = 'red';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
message = 'O ' + type + ' está pendente de aprovação.';
|
||||||
|
borderColor = 'red';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
message = 'O ' + type + ' já está registrado e também pendente de aprovação.';
|
||||||
|
borderColor = 'red';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
message = 'O ' + type + ' está disponível.';
|
||||||
|
borderColor = 'green';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Atualiza a mensagem e a cor da borda do input
|
||||||
|
$('#project-number-exists-' + type).text(message).css('color', borderColor);
|
||||||
|
$('input[name="pending_' + type + '"]').css('border', '2px solid ' + borderColor).removeClass(
|
||||||
|
'valid-input invalid-input').addClass(borderColor === 'red' ? 'invalid-input' :
|
||||||
|
'valid-input');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Função para atualizar o estado do botão de submissão
|
||||||
|
function updateSubmitButtonState() {
|
||||||
|
var allValid = Object.values(validationState).every(isValid => isValid);
|
||||||
|
$('#submitBtn').prop('disabled', !allValid);
|
||||||
|
console.log(validationState); // Log do estado atual de validação
|
||||||
|
}
|
||||||
|
|
||||||
|
// Campo de Nif
|
||||||
|
$('input[name="user_nif"]').on('input', function() {
|
||||||
|
var nif = $(this).val();
|
||||||
|
var type = $(this).data('type');
|
||||||
|
|
||||||
|
// Verifica se o NIF tem o comprimento correto
|
||||||
|
if (nif.length < 9) {
|
||||||
|
// Se for menor que 9 dígitos, mostra uma mensagem de erro
|
||||||
|
$(this).css('border', '2px solid red').removeClass('valid-input').addClass(
|
||||||
|
'invalid-input');
|
||||||
|
$('#project-number-exists-nif').text('O tamanho do NIF é incorreto.').css('color',
|
||||||
|
'red');
|
||||||
|
} else {
|
||||||
|
// Se tiver exatamente 9 dígitos, prossegue com a validação no sistema
|
||||||
|
console.log('O type e : '+ type);
|
||||||
|
validateField(type, nif);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Se for necessario adicioanr um regulador para o tamanho do Nif.
|
||||||
|
// else {
|
||||||
|
// // Se tiver mais de 9 dígitos, também considera como inválido
|
||||||
|
// $(this).css('border', '2px solid red').removeClass('valid-input').addClass(
|
||||||
|
// 'invalid-input');
|
||||||
|
// $('#project-number-exists-nif').text('O NIF não deve exceder 9 dígitos.').css('color',
|
||||||
|
// 'red');
|
||||||
|
// }
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// // Campo phone
|
||||||
|
// $('input[name="pending_phone"]').on('input', function() {
|
||||||
|
// var phone = $(this).val();
|
||||||
|
// var type = $(this).data('type');
|
||||||
|
|
||||||
|
// if (phone.length < 9) {
|
||||||
|
// // Se for menor que 9 dígitos, mostra uma mensagem de erro
|
||||||
|
// $(this).css('border', '2px solid red').removeClass('valid-input').addClass(
|
||||||
|
// 'invalid-input');
|
||||||
|
// $('#project-number-exists-phone').text('Numero de telemovel inexistente.').css(
|
||||||
|
// 'color',
|
||||||
|
// 'red');
|
||||||
|
// } else {
|
||||||
|
// validateField(type, phone);
|
||||||
|
// $(this).css('border', '1px solid #ced4da').removeClass('valid-input invalid-input');
|
||||||
|
// $('#project-number-exists-phone').text('');
|
||||||
|
// }
|
||||||
|
// });
|
||||||
|
|
||||||
|
// +
|
||||||
|
$('input[name="password"]').on('focus', function() {
|
||||||
|
$('#password-criteria').show();
|
||||||
|
});
|
||||||
|
$('input[name="password"]').on('blur', function() {
|
||||||
|
// Você pode adicionar condições aqui para decidir quando esconder
|
||||||
|
// Por exemplo, só esconder se a senha passar em todos os critérios
|
||||||
|
$('#password-criteria').hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Campo de Password
|
||||||
|
$('input[name="password"]').on('input', function() {
|
||||||
|
|
||||||
|
var password = $(this).val();
|
||||||
|
|
||||||
|
// Verifica o comprimento da senha
|
||||||
|
var minLength = password.length >= 8;
|
||||||
|
$('#min-length').css('color', minLength ? 'green' : 'red');
|
||||||
|
|
||||||
|
// Verifica a presença de uma letra maiúscula
|
||||||
|
var upperCase = /[A-Z]/.test(password);
|
||||||
|
$('#upper-case').css('color', upperCase ? 'green' : 'red');
|
||||||
|
|
||||||
|
// Verifica a presença de uma letra minúscula
|
||||||
|
var lowerCase = /[a-z]/.test(password);
|
||||||
|
$('#lower-case').css('color', lowerCase ? 'green' : 'red');
|
||||||
|
|
||||||
|
// Verifica a presença de um número
|
||||||
|
var oneNumber = /\d/.test(password);
|
||||||
|
$('#one-number').css('color', oneNumber ? 'green' : 'red');
|
||||||
|
|
||||||
|
// Verifica a presença de um caractere especial
|
||||||
|
var specialChar = /[@$!%*?&]/.test(password);
|
||||||
|
$('#special-char').css('color', specialChar ? 'green' : 'red');
|
||||||
|
|
||||||
|
// Verifica se todos os requisitos foram atendidos
|
||||||
|
validationState.password = minLength && upperCase && lowerCase && oneNumber &&
|
||||||
|
specialChar;
|
||||||
|
if (validationState.password) {
|
||||||
|
$(this).css('border', '2px solid green').removeClass('invalid-input').addClass(
|
||||||
|
'valid-input');
|
||||||
|
$('#project-password-valid').text('Senha forte.').css('color', 'green');
|
||||||
|
} else {
|
||||||
|
$(this).css('border', '2px solid red').removeClass('valid-input').addClass(
|
||||||
|
'invalid-input');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chama a função para atualizar o estado do botão de submissão, se necessário
|
||||||
|
updateSubmitButtonState();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
$('input[name="password_confirmation"]').on('input', function() {
|
||||||
|
var password = $('input[name="password"]').val();
|
||||||
|
var confirmPassword = $(this).val();
|
||||||
|
|
||||||
|
// Verifica se as senhas são iguais e se a confirmação da senha tem comprimento igual à senha
|
||||||
|
if (password === confirmPassword && confirmPassword.length === password.length) {
|
||||||
|
$(this).css('border', '2px solid green').removeClass('invalid-input').addClass(
|
||||||
|
'valid-input');
|
||||||
|
$('#project-password-confirm-valid').text('As senhas coincidem.').css('color', 'green');
|
||||||
|
validationState.password_confirmation = true;
|
||||||
|
} else if (confirmPassword.length < password.length) {
|
||||||
|
// Se a confirmação da senha é menor do que a senha, não faz nada (não mostra erro ainda)
|
||||||
|
$(this).css('border', '1px solid #ced4da').removeClass('invalid-input valid-input');
|
||||||
|
$('#project-password-confirm-valid').text(''); // Limpa qualquer mensagem anterior
|
||||||
|
validationState.password_confirmation =
|
||||||
|
false; // Considera inválido até que os comprimentos batam
|
||||||
|
} else {
|
||||||
|
// Mostra mensagem de erro somente se os comprimentos são iguais mas as senhas não coincidem
|
||||||
|
$(this).css('border', '2px solid red').removeClass('valid-input').addClass(
|
||||||
|
'invalid-input');
|
||||||
|
$('#project-password-confirm-valid').text('As senhas não coincidem.').css('color',
|
||||||
|
'red');
|
||||||
|
validationState.password_confirmation = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Atualiza o estado do botão de submissão a cada alteração
|
||||||
|
updateSubmitButtonState();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
// caso o usuário comece a corrigir a senha principal depois de um erro de confirmação
|
||||||
|
$('input[name="pending_password"]').on('input', function() {
|
||||||
|
// Limpa a mensagem de erro se o usuário começar a corrigir a senha principal
|
||||||
|
if ($('input[name="password_confirmation"]').val() !== '') {
|
||||||
|
$('input[name="password_confirmation"]').trigger('input');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script> --}}
|
||||||
|
|
||||||
|
{{-- <script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
// Mantém a função de visibilidade da bandeira (conforme seu comentário original)
|
||||||
|
function ensureFlagContainerVisibility() {
|
||||||
|
const flagContainer = document.querySelector('.flag-container');
|
||||||
|
const countryList = document.querySelector('.country-list');
|
||||||
|
|
||||||
|
const isCountryListActive = countryList && countryList.classList.contains('active');
|
||||||
|
}
|
||||||
|
|
||||||
|
ensureFlagContainerVisibility();
|
||||||
|
setInterval(ensureFlagContainerVisibility, 50);
|
||||||
|
|
||||||
|
// Estados de validação agora separados
|
||||||
|
var validationState = {
|
||||||
|
nif: false,
|
||||||
|
password: false,
|
||||||
|
password_confirmation: false
|
||||||
|
};
|
||||||
|
|
||||||
|
// Validação AJAX para NIF
|
||||||
|
function validateNIF(value) {
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ route('validateForm') }}',
|
||||||
|
type: 'GET',
|
||||||
|
data: {
|
||||||
|
_token: $('input[name="_token"]').val(), // CSRF token
|
||||||
|
type: 'nif',
|
||||||
|
value: value
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
if (response.result_nif === 0) {
|
||||||
|
validationState.nif = true;
|
||||||
|
} else {
|
||||||
|
validationState.nif = false;
|
||||||
|
}
|
||||||
|
updateNIFUI(response.result_nif);
|
||||||
|
updateSubmitButtonState();
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
console.error("Erro na validação do NIF: ", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Função para atualizar a interface com base no resultado da validação do NIF
|
||||||
|
function updateNIFUI(result) {
|
||||||
|
var message;
|
||||||
|
var borderColor;
|
||||||
|
|
||||||
|
switch (result) {
|
||||||
|
case 1:
|
||||||
|
message = 'O NIF já está registrado.';
|
||||||
|
borderColor = 'red';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
message = 'O NIF está pendente de aprovação.';
|
||||||
|
borderColor = 'red';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
message = 'O NIF já está registrado e também pendente de aprovação.';
|
||||||
|
borderColor = 'red';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
message = 'O NIF está disponível.';
|
||||||
|
borderColor = 'green';
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#project-number-exists-nif').text(message).css('color', borderColor);
|
||||||
|
$('input[name="user_nif"]').css('border', '2px solid ' + borderColor).removeClass(
|
||||||
|
'valid-input invalid-input').addClass(borderColor === 'red' ? 'invalid-input' :
|
||||||
|
'valid-input');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Função para atualizar o estado do botão de submissão
|
||||||
|
function updateSubmitButtonState() {
|
||||||
|
// Habilita o botão se o NIF for válido ou se as senhas forem válidas e coincidirem
|
||||||
|
var isNifValid = validationState.nif;
|
||||||
|
var arePasswordsValid = validationState.password && validationState.password_confirmation;
|
||||||
|
|
||||||
|
$('#submitBtn').prop('disabled', !(isNifValid || arePasswordsValid));
|
||||||
|
console.log(validationState); // Log do estado atual de validação
|
||||||
|
}
|
||||||
|
|
||||||
|
// Campo de NIF
|
||||||
|
$('input[name="user_nif"]').on('input', function() {
|
||||||
|
var nif = $(this).val();
|
||||||
|
|
||||||
|
if (nif.length < 9) {
|
||||||
|
$(this).css('border', '2px solid red').removeClass('valid-input').addClass(
|
||||||
|
'invalid-input');
|
||||||
|
$('#project-number-exists-nif').text('O tamanho do NIF é incorreto.').css('color',
|
||||||
|
'red');
|
||||||
|
validationState.nif = false;
|
||||||
|
updateSubmitButtonState();
|
||||||
|
} else {
|
||||||
|
validateNIF(nif);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Validação das senhas
|
||||||
|
$('input[name="password"]').on('input', function() {
|
||||||
|
var password = $(this).val();
|
||||||
|
|
||||||
|
var minLength = password.length >= 8;
|
||||||
|
$('#min-length').css('color', minLength ? 'green' : 'red');
|
||||||
|
|
||||||
|
var upperCase = /[A-Z]/.test(password);
|
||||||
|
$('#upper-case').css('color', upperCase ? 'green' : 'red');
|
||||||
|
|
||||||
|
var lowerCase = /[a-z]/.test(password);
|
||||||
|
$('#lower-case').css('color', lowerCase ? 'green' : 'red');
|
||||||
|
|
||||||
|
var oneNumber = /\d/.test(password);
|
||||||
|
$('#one-number').css('color', oneNumber ? 'green' : 'red');
|
||||||
|
|
||||||
|
var specialChar = /[@$!%*?&]/.test(password);
|
||||||
|
$('#special-char').css('color', specialChar ? 'green' : 'red');
|
||||||
|
|
||||||
|
validationState.password = minLength && upperCase && lowerCase && oneNumber && specialChar;
|
||||||
|
|
||||||
|
if (validationState.password) {
|
||||||
|
$(this).css('border', '2px solid green').removeClass('invalid-input').addClass(
|
||||||
|
'valid-input');
|
||||||
|
$('#project-password-valid').text('Senha forte.').css('color', 'green');
|
||||||
|
} else {
|
||||||
|
$(this).css('border', '2px solid red').removeClass('valid-input').addClass(
|
||||||
|
'invalid-input');
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSubmitButtonState();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('input[name="password_confirmation"]').on('input', function() {
|
||||||
|
var password = $('input[name="password"]').val();
|
||||||
|
var confirmPassword = $(this).val();
|
||||||
|
|
||||||
|
if (password === confirmPassword && confirmPassword.length === password.length) {
|
||||||
|
$(this).css('border', '2px solid green').removeClass('invalid-input').addClass(
|
||||||
|
'valid-input');
|
||||||
|
$('#project-password-confirm-valid').text('As senhas coincidem.').css('color', 'green');
|
||||||
|
validationState.password_confirmation = true;
|
||||||
|
} else if (confirmPassword.length < password.length) {
|
||||||
|
$(this).css('border', '1px solid #ced4da').removeClass('invalid-input valid-input');
|
||||||
|
$('#project-password-confirm-valid').text('');
|
||||||
|
validationState.password_confirmation = false;
|
||||||
|
} else {
|
||||||
|
$(this).css('border', '2px solid red').removeClass('valid-input').addClass(
|
||||||
|
'invalid-input');
|
||||||
|
$('#project-password-confirm-valid').text('As senhas não coincidem.').css('color',
|
||||||
|
'red');
|
||||||
|
validationState.password_confirmation = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSubmitButtonState();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Caso o usuário comece a corrigir a senha principal depois de um erro de confirmação
|
||||||
|
$('input[name="pending_password"]').on('input', function() {
|
||||||
|
if ($('input[name="password_confirmation"]').val() !== '') {
|
||||||
|
$('input[name="password_confirmation"]').trigger('input');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script> --}}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
// Estados de validação
|
||||||
|
var validationState = {
|
||||||
|
nif: false,
|
||||||
|
password: false,
|
||||||
|
password_confirmation: false
|
||||||
|
};
|
||||||
|
|
||||||
|
// Validação AJAX para NIF
|
||||||
|
function validateNIF(value) {
|
||||||
|
$.ajax({
|
||||||
|
url: '{{ route('validateForm') }}',
|
||||||
|
type: 'GET',
|
||||||
|
data: {
|
||||||
|
_token: $('input[name="_token"]').val(), // CSRF token
|
||||||
|
type: 'nif',
|
||||||
|
value: value
|
||||||
|
},
|
||||||
|
success: function(response) {
|
||||||
|
if (response.result_nif === 0) {
|
||||||
|
validationState.nif = true;
|
||||||
|
} else {
|
||||||
|
validationState.nif = false;
|
||||||
|
}
|
||||||
|
updateNIFUI(response.result_nif);
|
||||||
|
updateSubmitButtonState();
|
||||||
|
},
|
||||||
|
error: function(xhr, status, error) {
|
||||||
|
console.error("Erro na validação do NIF: ", error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Função para atualizar a interface com base no resultado da validação do NIF
|
||||||
|
function updateNIFUI(result) {
|
||||||
|
var message;
|
||||||
|
var borderColor;
|
||||||
|
|
||||||
|
switch (result) {
|
||||||
|
case 1:
|
||||||
|
message = 'O NIF já está registrado.';
|
||||||
|
borderColor = 'red';
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
message = 'O NIF está pendente de aprovação.';
|
||||||
|
borderColor = 'red';
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
message = 'O NIF já está registrado e também pendente de aprovação.';
|
||||||
|
borderColor = 'red';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
message = 'O NIF está disponível.';
|
||||||
|
borderColor = 'green';
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#project-number-exists-nif').text(message).css('color', borderColor);
|
||||||
|
$('input[name="user_nif"]').css('border', '2px solid ' + borderColor).removeClass(
|
||||||
|
'valid-input invalid-input').addClass(borderColor === 'red' ? 'invalid-input' :
|
||||||
|
'valid-input');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Função para atualizar o estado do botão de submissão
|
||||||
|
function updateSubmitButtonState() {
|
||||||
|
var isNifValid = validationState.nif;
|
||||||
|
var arePasswordsValid = validationState.password && validationState.password_confirmation;
|
||||||
|
|
||||||
|
$('#submitBtn').prop('disabled', !(isNifValid || arePasswordsValid));
|
||||||
|
console.log(validationState); // Log do estado atual de validação
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Campo de NIF
|
||||||
|
$('input[name="user_nif"]').on('input', function() {
|
||||||
|
var nif = $(this).val();
|
||||||
|
|
||||||
|
if (nif.length < 9) {
|
||||||
|
$(this).css('border', '2px solid red').removeClass('valid-input').addClass(
|
||||||
|
'invalid-input');
|
||||||
|
$('#project-number-exists-nif').text('O tamanho do NIF é incorreto.').css('color',
|
||||||
|
'red');
|
||||||
|
validationState.nif = false;
|
||||||
|
updateSubmitButtonState();
|
||||||
|
} else {
|
||||||
|
validateNIF(nif);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Mostrar e esconder os critérios de senha ao focar e desfocar no campo de senha
|
||||||
|
$('input[name="password"]').on('focus', function() {
|
||||||
|
$('#password-criteria').show();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('input[name="password"]').on('blur', function() {
|
||||||
|
if (validationState.password) {
|
||||||
|
$('#password-criteria').hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Validação das senhas
|
||||||
|
$('input[name="password"]').on('input', function() {
|
||||||
|
var password = $(this).val();
|
||||||
|
|
||||||
|
var minLength = password.length >= 8;
|
||||||
|
$('#min-length').css('color', minLength ? 'green' : 'red');
|
||||||
|
|
||||||
|
var upperCase = /[A-Z]/.test(password);
|
||||||
|
$('#upper-case').css('color', upperCase ? 'green' : 'red');
|
||||||
|
|
||||||
|
var lowerCase = /[a-z]/.test(password);
|
||||||
|
$('#lower-case').css('color', lowerCase ? 'green' : 'red');
|
||||||
|
|
||||||
|
var oneNumber = /\d/.test(password);
|
||||||
|
$('#one-number').css('color', oneNumber ? 'green' : 'red');
|
||||||
|
|
||||||
|
var specialChar = /[@$!%*?&]/.test(password);
|
||||||
|
$('#special-char').css('color', specialChar ? 'green' : 'red');
|
||||||
|
|
||||||
|
validationState.password = minLength && upperCase && lowerCase && oneNumber && specialChar;
|
||||||
|
|
||||||
|
if (validationState.password) {
|
||||||
|
$(this).css('border', '2px solid green').removeClass('invalid-input').addClass(
|
||||||
|
'valid-input');
|
||||||
|
$('#project-password-valid').text('Senha forte.').css('color', 'green');
|
||||||
|
} else {
|
||||||
|
$(this).css('border', '2px solid red').removeClass('valid-input').addClass(
|
||||||
|
'invalid-input');
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSubmitButtonState();
|
||||||
|
});
|
||||||
|
|
||||||
|
$('input[name="password_confirmation"]').on('input', function() {
|
||||||
|
var password = $('input[name="password"]').val();
|
||||||
|
var confirmPassword = $(this).val();
|
||||||
|
|
||||||
|
if (password === confirmPassword && confirmPassword.length === password.length) {
|
||||||
|
$(this).css('border', '2px solid green').removeClass('invalid-input').addClass(
|
||||||
|
'valid-input');
|
||||||
|
$('#project-password-confirm-valid').text('As senhas coincidem.').css('color', 'green');
|
||||||
|
validationState.password_confirmation = true;
|
||||||
|
} else if (confirmPassword.length < password.length) {
|
||||||
|
$(this).css('border', '1px solid #ced4da').removeClass('invalid-input valid-input');
|
||||||
|
$('#project-password-confirm-valid').text('');
|
||||||
|
validationState.password_confirmation = false;
|
||||||
|
} else {
|
||||||
|
$(this).css('border', '2px solid red').removeClass('valid-input').addClass(
|
||||||
|
'invalid-input');
|
||||||
|
$('#project-password-confirm-valid').text('As senhas não coincidem.').css('color',
|
||||||
|
'red');
|
||||||
|
validationState.password_confirmation = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateSubmitButtonState();
|
||||||
|
});
|
||||||
|
|
||||||
|
// Caso o usuário comece a corrigir a senha principal depois de um erro de confirmação
|
||||||
|
$('input[name="pending_password"]').on('input', function() {
|
||||||
|
if ($('input[name="password_confirmation"]').val() !== '') {
|
||||||
|
$('input[name="password_confirmation"]').trigger('input');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
</script>
|
||||||
@endsection
|
@endsection
|
||||||
|
|
|
||||||
|
|
@ -252,7 +252,7 @@
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
|
|
||||||
// Esta funcao foi necessaria, pois devido ao css e script para funcionar a exibicao das bandeiras, sem esta funcao, sempre que click no input, a selecao de bandeiras some, ate click fora do input
|
// Esta funcao foi necessaria, pois devido ao css e script para funcionar a exibicao das bandeiras, sem esta funcao, sempre que click no input, a selecao de bandeiras some, ate click fora do input
|
||||||
//Nao mexer se voce quiser, ter um select de paises bonito dentro do input XD
|
//Nao mexer !!! se voce quiser, ter um select de paises bonito dentro do input XD
|
||||||
function ensureFlagContainerVisibility() {
|
function ensureFlagContainerVisibility() {
|
||||||
const flagContainer = document.querySelector('.flag-container');
|
const flagContainer = document.querySelector('.flag-container');
|
||||||
const countryList = document.querySelector('.country-list');
|
const countryList = document.querySelector('.country-list');
|
||||||
|
|
@ -312,7 +312,6 @@ function validateField(type, value) {
|
||||||
validationState['pending_' + type] = false;
|
validationState['pending_' + type] = false;
|
||||||
updateSubmitButtonState();
|
updateSubmitButtonState();
|
||||||
}
|
}
|
||||||
// console.log(response);
|
|
||||||
|
|
||||||
updateUI(type, response['result_' + type]);
|
updateUI(type, response['result_' + type]);
|
||||||
|
|
||||||
|
|
@ -395,6 +394,7 @@ function updateSubmitButtonState() {
|
||||||
'red');
|
'red');
|
||||||
} else {
|
} else {
|
||||||
// Se tiver exatamente 9 dígitos, prossegue com a validação no sistema
|
// Se tiver exatamente 9 dígitos, prossegue com a validação no sistema
|
||||||
|
console.log('O type e : '+ type);
|
||||||
validateField(type, nif);
|
validateField(type, nif);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user