Aknaproff/resources/views/home.blade.php

530 lines
23 KiB
PHP
Raw Normal View History

2023-09-21 12:45:08 +00:00
@extends('layouts.app')
@section('content')
2023-09-21 14:20:06 +00:00
<div class="container">
2023-09-21 12:45:08 +00:00
2023-09-21 14:20:06 +00:00
<div class="row">
<div class="col-md-12">
@include('layouts/partials/status')
</div>
2023-09-21 12:45:08 +00:00
</div>
2024-03-18 14:33:31 +00:00
@if (auth()->user()->hasRole(\App\Enums\User\RoleEnum::SUPERVISOR->value) || auth()->user()->can_create_form)
2023-09-21 14:20:06 +00:00
<div class="row mb-5">
<div class="col-12 col-sm-6 col-md-3">
<div class="info-box">
<span class="info-box-icon bg-info elevation-1"><i class="fas fa-file-alt"></i></span>
2023-09-21 12:45:08 +00:00
2023-09-21 14:20:06 +00:00
<div class="info-box-content">
<span class="info-box-text">@lang('messages.forms')</span>
2024-03-18 14:33:31 +00:00
<span class="info-box-number">{{ $form_count }}</span>
2023-09-21 14:20:06 +00:00
</div>
2023-09-21 12:45:08 +00:00
</div>
</div>
2024-03-18 14:33:31 +00:00
@if (!auth()->user()->hasRole(\App\Enums\User\RoleEnum::ADMIN->value))
2023-09-21 14:20:06 +00:00
<div class="col-12 col-sm-6 col-md-3">
<div class="info-box">
2024-03-18 14:33:31 +00:00
<span class="info-box-icon bg-danger elevation-1"><i class="fas fa-align-justify"></i></span>
2023-09-21 12:45:08 +00:00
2023-09-21 14:20:06 +00:00
<div class="info-box-content">
<span class="info-box-text">@lang('messages.templates')</span>
2024-03-18 14:33:31 +00:00
<span class="info-box-number">{{ $template_count }}</span>
2023-09-21 14:20:06 +00:00
</div>
</div>
2023-09-21 12:45:08 +00:00
</div>
2023-09-21 14:20:06 +00:00
@endif
2023-09-21 12:45:08 +00:00
2023-09-21 14:20:06 +00:00
<div class="col-12 col-sm-6 col-md-3">
<div class="info-box">
<span class="info-box-icon bg-green elevation-1"><i class="fas fa-hand-pointer"></i></span>
2023-09-21 12:45:08 +00:00
2023-09-21 14:20:06 +00:00
<div class="info-box-content">
<span class="info-box-text">@lang('messages.submissions')</span>
2024-03-18 14:33:31 +00:00
<span class="info-box-number">{{ $submission_count }}</span>
2023-09-21 14:20:06 +00:00
</div>
2023-09-21 12:45:08 +00:00
</div>
</div>
2023-09-21 14:20:06 +00:00
<div class="col-12 col-sm-6 col-md-3">
2024-03-18 14:33:31 +00:00
<button type="button" data-href="{{ action([\App\Http\Controllers\FormController::class, 'create']) }}"
class="btn btn-primary float-right col-md-9 createForm mt-3">
2023-09-21 14:20:06 +00:00
<i class="fas fa-plus" aria-hidden="true"></i> @lang('messages.new_form')</button>
</div>
2023-09-21 12:45:08 +00:00
</div>
2023-09-21 14:20:06 +00:00
@endif
<div class="row">
<div class="col-12 col-sm-12">
<div class="card card-primary card-outline card-outline-tabs">
<div class="card-header p-0 border-bottom-0">
<ul class="nav nav-tabs
2024-03-18 14:33:31 +00:00
@if (auth()->user()->hasRole(\App\Enums\User\RoleEnum::SUPERVISOR->value) || auth()->user()->can_create_form) nav-justified @endif"
2023-09-21 14:20:06 +00:00
id="custom-tabs-four-tab" role="tablist">
2024-03-18 14:33:31 +00:00
@if (auth()->user()->hasRole([\App\Enums\User\RoleEnum::SUPERVISOR->value]) || auth()->user()->can_create_form)
2023-09-21 14:20:06 +00:00
<li class="nav-item">
<a class="nav-link active" id="custome-tabs-all-forms" data-toggle="pill"
2024-03-18 14:33:31 +00:00
href="#custome-tabs-forms" role="tab" aria-controls="custome-tabs-forms"
aria-selected="true">
2023-09-21 14:20:06 +00:00
<i class="fas fa-file-alt" aria-hidden="true"></i> @lang('messages.all_forms')
</a>
</li>
2024-03-18 14:33:31 +00:00
@if (!auth()->user()->hasRole(\App\Enums\User\RoleEnum::ADMIN->value))
2023-09-21 14:20:06 +00:00
<li class="nav-item">
<a class="nav-link" id="custome-tabs-all-templates" data-toggle="pill"
2024-03-18 14:33:31 +00:00
href="#custome-tabs-templates" role="tab"
aria-controls="custome-tabs-templates">
<i class="fas fa-align-justify" aria-hidden="true"></i> @lang('messages.all_templates')
2023-09-21 14:20:06 +00:00
</a>
</li>
@endif
@endif
2023-09-21 12:45:08 +00:00
<li class="nav-item">
2023-09-21 14:20:06 +00:00
<a class="nav-link
2024-03-18 14:33:31 +00:00
@if (!auth()->user()->hasRole(\App\Enums\User\RoleEnum::SUPERVISOR->value) && !auth()->user()->can_create_form) active @endif
"
id="custome-tabs-shared-forms" data-toggle="pill"
href="#custome-tabs-shared-forms-assigned" role="tab"
aria-controls="custome-tabs-shared-forms-assigned"
@if (!auth()->user()->hasRole(\App\Enums\User\RoleEnum::SUPERVISOR->value) && !auth()->user()->can_create_form) aria-selected="true" @endif>
<i class="fas fa-file-alt" aria-hidden="true"></i> @lang('messages.assigned_forms')
2023-09-21 14:20:06 +00:00
</a>
</li>
</ul>
</div>
<div class="card-body">
<div class="tab-content" id="custom-tabs-four-tabContent">
2024-03-18 14:33:31 +00:00
@if (auth()->user()->hasRole(\App\Enums\User\RoleEnum::SUPERVISOR->value) || auth()->user()->can_create_form)
2023-09-21 14:20:06 +00:00
<div class="tab-pane fade active show" id="custome-tabs-forms" role="tabpanel"
2024-03-18 14:33:31 +00:00
aria-labelledby="custome-tabs-all-forms">
2023-09-21 14:20:06 +00:00
<div class="table-responsive">
<table class="table" id="form_table" style="width: 100%;">
<thead>
2024-03-18 14:33:31 +00:00
<tr>
<th>@lang('messages.description')</th>
<th>@lang('messages.name')</th>
<th>@lang('messages.created_at')</th>
<th>@lang('messages.submissions')</th>
<th>@lang('messages.action')</th>
</tr>
2023-09-21 14:20:06 +00:00
</thead>
<tbody></tbody>
</table>
</div>
2023-09-21 12:45:08 +00:00
</div>
2023-09-21 14:20:06 +00:00
<div class="tab-pane fade" id="custome-tabs-templates" role="tabpanel"
2024-03-18 14:33:31 +00:00
aria-labelledby="custome-tabs-all-templates">
2023-09-21 14:20:06 +00:00
<div class="table-responsive">
<table class="table" id="template_table" style="width: 100%;">
<thead>
2024-03-18 14:33:31 +00:00
<tr>
<th>@lang('messages.description')</th>
<th>@lang('messages.name')</th>
@if (auth()->user()->can('superadmin'))
<th>
@lang('messages.is_global_template')
<i class="fas fa-info-circle" data-toggle="tooltip"
title="@lang('messages.is_global_template_tooltip')"></i>
</th>
@endif
<th>@lang('messages.action')</th>
</tr>
2023-09-21 14:20:06 +00:00
</thead>
<tbody></tbody>
</table>
</div>
2023-09-21 12:45:08 +00:00
</div>
2023-09-21 14:20:06 +00:00
@endif
<div class="tab-pane fade
2024-03-18 14:33:31 +00:00
@if (!auth()->user()->hasRole(\App\Enums\User\RoleEnum::SUPERVISOR->value) || !auth()->user()->can_create_form) active show @endif
"
id="custome-tabs-shared-forms-assigned" role="tabpanel"
aria-labelledby="custome-tabs-shared-forms">
2023-09-21 14:20:06 +00:00
<div class="table-responsive">
<table class="table" id="assigned_form_table" style="width: 100%;">
<thead>
2024-04-25 18:40:12 +00:00
2024-03-18 14:33:31 +00:00
<tr>
<th>@lang('messages.description')</th>
2024-04-25 18:40:12 +00:00
<th>@lang('messages.name')</th>
2024-03-18 14:33:31 +00:00
@if (auth()->user()->hasRole(\App\Enums\User\RoleEnum::SUPERVISOR->value))
<th>@lang('messages.created_by')</th>
@endif
<th>@lang('messages.action')</th>
</tr>
2023-09-21 14:20:06 +00:00
</thead>
<tbody></tbody>
</table>
</div>
2023-09-21 12:45:08 +00:00
</div>
</div>
</div>
2023-09-21 14:20:06 +00:00
<!-- /.card -->
2023-09-21 12:45:08 +00:00
</div>
</div>
</div>
</div>
2023-09-21 14:20:06 +00:00
<div class="modal fade" id="collab_modal" role="dialog" aria-hidden="true"></div>
2023-09-21 12:45:08 +00:00
@endsection
@section('footer')
2023-09-21 14:20:06 +00:00
<script type="text/javascript">
2024-03-18 14:33:31 +00:00
$(document).ready(function() {
var lang = `{{ session()->get('locale') }}`
2024-03-06 18:11:10 +00:00
var titleColName = 'name';
2024-03-18 14:33:31 +00:00
if (lang === 'est') {
titleColName = 'name_est'
} else if (lang === 'ru') {
titleColName = 'name_ru'
}
var descColName = 'description';
if (lang === 'est') {
descColName = 'description_est'
} else if (lang === 'ru') {
descColName = 'description_ru'
}
2023-09-21 12:45:08 +00:00
2023-09-21 14:20:06 +00:00
// form dataTable
var form_table = $('#form_table').DataTable({
2023-09-21 12:45:08 +00:00
processing: true,
serverSide: true,
ajax: '/home',
buttons: [],
dom: 'lfrtip',
fixedHeader: false,
2024-03-18 14:33:31 +00:00
aaSorting: [
[1, 'desc']
2023-09-21 12:45:08 +00:00
],
2024-03-18 14:33:31 +00:00
"columnDefs": [{
"width": "22%",
"targets": 0
},
{
"width": "40%",
"targets": 1
},
{
"width": "15%",
"targets": 2
},
{
"width": "3%",
"targets": 3
},
2024-03-06 18:11:10 +00:00
{
2024-03-18 14:33:31 +00:00
"width": "20%",
"targets": 4
}
],
columns: [{
data: descColName,
name: descColName,
createdCell: function(td, cellData, rowData, row, col) {
2024-03-06 18:11:10 +00:00
if (td.innerHTML.length === 0) {
td.innerHTML = rowData.name
}
},
},
2024-03-18 14:33:31 +00:00
{
data: titleColName,
name: titleColName,
createdCell: function(td, cellData, rowData, row, col) {
if (td.innerHTML.length === 0) {
td.innerHTML = rowData.name
}
},
},
{
data: 'created_at',
name: 'created_at'
},
{
data: 'data_count',
name: 'data_count',
searchable: false
},
{
data: 'action',
name: 'action',
sortable: false
}
2023-09-21 12:45:08 +00:00
]
});
2023-09-21 14:20:06 +00:00
// template dataTable
var template_table = $('#template_table').DataTable({
2023-09-21 12:45:08 +00:00
processing: true,
serverSide: true,
ajax: '/home-template',
buttons: [],
dom: 'lfrtip',
fixedHeader: false,
2024-03-18 14:33:31 +00:00
columns: [{
data: descColName,
name: descColName,
createdCell: function(td, cellData, rowData, row, col) {
if (td.innerHTML.length === 0) {
td.innerHTML = rowData.name
}
},
2023-09-21 14:20:06 +00:00
},
{
2024-03-18 14:33:31 +00:00
data: titleColName,
name: titleColName,
createdCell: function(td, cellData, rowData, row, col) {
if (td.innerHTML.length === 0) {
td.innerHTML = rowData.name
}
},
},
@if (auth()->user()->can('superadmin'))
{
data: 'is_global_template',
name: 'is_global_template',
sortable: false,
searchable: false
},
@endif {
data: 'action',
name: 'action',
sortable: false
2023-09-21 14:20:06 +00:00
}
2023-09-21 12:45:08 +00:00
]
});
2023-09-21 14:20:06 +00:00
//delete form
2024-03-18 14:33:31 +00:00
$(document).on('click', '.delete_form', function() {
2023-09-21 14:20:06 +00:00
var url = $(this).data("href");
var result = confirm('Are You Sure?');
if (result == true) {
$.ajax({
method: "DELETE",
url: url,
dataType: "json",
2024-03-18 14:33:31 +00:00
success: function(result) {
2023-09-21 14:20:06 +00:00
if (result.success == true) {
toastr.success(result.msg);
form_table.ajax.reload();
} else {
toastr.error(result.msg);
}
}
});
}
});
//delete template
2024-03-18 14:33:31 +00:00
$(document).on('click', '.delete_template', function() {
2023-09-21 14:20:06 +00:00
var url = $(this).data("href");
var result = confirm('Are You Sure?');
if (result == true) {
$.ajax({
method: "DELETE",
url: url,
dataType: "json",
2024-03-18 14:33:31 +00:00
success: function(result) {
2023-09-21 14:20:06 +00:00
if (result.success == true) {
toastr.success(result.msg);
template_table.ajax.reload();
} else {
toastr.error(result.msg);
}
}
});
}
});
// create form
2024-03-18 14:33:31 +00:00
$(document).on('click', '.createForm', function() {
2023-09-21 14:20:06 +00:00
var url = $(this).data('href');
2023-09-21 12:45:08 +00:00
$.ajax({
2023-09-21 14:20:06 +00:00
method: "GET",
2023-09-21 12:45:08 +00:00
url: url,
2023-09-21 14:20:06 +00:00
dataType: "html",
2024-03-18 14:33:31 +00:00
success: function(response) {
2023-09-21 14:20:06 +00:00
$("#modal_div").html(response).modal("show");
2023-09-21 12:45:08 +00:00
}
});
2023-09-21 14:20:06 +00:00
});
2023-09-21 12:45:08 +00:00
2023-09-21 14:20:06 +00:00
// create widget
2024-03-18 14:33:31 +00:00
$(document).on('click', '.generate_widget', function() {
2023-09-21 14:20:06 +00:00
var url = $(this).data('href');
2023-09-21 12:45:08 +00:00
$.ajax({
2023-09-21 14:20:06 +00:00
method: "GET",
2023-09-21 12:45:08 +00:00
url: url,
2023-09-21 14:20:06 +00:00
dataType: "html",
2024-03-18 14:33:31 +00:00
success: function(response) {
2023-09-21 14:20:06 +00:00
$("#modal_div").html(response).modal("show");
2023-09-21 12:45:08 +00:00
}
});
});
2023-09-21 14:20:06 +00:00
//copy form
2024-03-18 14:33:31 +00:00
$(document).on('click', '.copy_form', function() {
2023-09-21 14:20:06 +00:00
var url = $(this).data('href');
$.ajax({
method: "GET",
url: url,
dataType: "html",
2024-03-18 14:33:31 +00:00
success: function(response) {
2023-09-21 14:20:06 +00:00
$("#modal_div").html(response).modal("show");
}
});
2023-09-21 12:45:08 +00:00
});
2023-09-21 14:20:06 +00:00
//assigned form to user
var assigned_form_table = $('#assigned_form_table').DataTable({
processing: true,
serverSide: true,
ajax: '/home-assigned-forms',
buttons: [],
dom: 'lfrtip',
fixedHeader: false,
2024-03-18 14:33:31 +00:00
aaSorting: [
[0, 'desc']
],
"columnDefs": [{
"width": "25%",
"targets": 0
2023-09-21 14:20:06 +00:00
},
{
2024-03-18 14:33:31 +00:00
"width": "40%",
"targets": 1
},
@if (auth()->user()->hasRole(\App\Enums\User\RoleEnum::SUPERVISOR->value))
{
"width": "15%",
"targets": 2
},
@endif {
2023-09-21 14:20:06 +00:00
"width": "20%",
2024-03-18 14:33:31 +00:00
"targets": @php
echo auth()
->user()
->hasRole(\App\Enums\User\RoleEnum::SUPERVISOR->value)
? 3
: 2;
@endphp
}
2023-09-21 14:20:06 +00:00
],
2024-03-18 14:33:31 +00:00
columns: [{
2024-04-25 18:29:44 +00:00
data: descColName,
name: 'forms.' + descColName,
createdCell: function(td, cellData, rowData, row, col) {
if (td.innerHTML.length === 0) {
td.innerHTML = rowData.description
}
},
2023-09-21 14:20:06 +00:00
},
{
2024-04-25 18:29:44 +00:00
data: titleColName,
name: 'forms.' + titleColName,
createdCell: function(td, cellData, rowData, row, col) {
if (td.innerHTML.length === 0) {
td.innerHTML = rowData.name
}
},
2024-03-18 14:33:31 +00:00
},
@if (auth()->user()->hasRole(\App\Enums\User\RoleEnum::SUPERVISOR->value))
{
data: 'created_by',
name: 'forms.created_by'
},
@endif {
data: 'action',
name: 'action',
sortable: false
2023-09-21 14:20:06 +00:00
}
]
2023-09-21 12:45:08 +00:00
});
2024-04-25 18:40:12 +00:00
2023-09-21 14:20:06 +00:00
//form collaborate
2024-03-18 14:33:31 +00:00
$(document).on('click', '.collab_btn', function() {
2023-09-21 14:20:06 +00:00
var url = $(this).data('href');
$.ajax({
method: "GET",
url: url,
dataType: "html",
2024-03-18 14:33:31 +00:00
success: function(response) {
2023-09-21 14:20:06 +00:00
$("#collab_modal").html(response).modal("show");
}
});
});
2023-09-21 12:45:08 +00:00
2024-03-18 14:33:31 +00:00
$("#collab_modal").on('shown.bs.modal', function() {
2023-09-21 14:20:06 +00:00
if ($("#form_design").length) {
2024-03-18 14:33:31 +00:00
$(document).on('change', '#form_design', function() {
2023-09-21 14:20:06 +00:00
if ($("#form_design").is(":checked")) {
$("#form_view").attr('checked', true);
} else {
$("#form_view").attr('checked', false);
}
});
2023-09-21 12:45:08 +00:00
}
});
2024-03-18 14:33:31 +00:00
$(document).on('submit', 'form#collaborate_form', function(e) {
2023-09-21 14:20:06 +00:00
e.preventDefault();
var data = $("form#collaborate_form").serialize();
var url = $("form#collaborate_form").attr('action');
var ladda = Ladda.create(document.querySelector('.submit_btn'));
ladda.start();
$.ajax({
method: "POST",
url: url,
dataType: "json",
data: data,
2024-03-18 14:33:31 +00:00
success: function(response) {
2023-09-21 14:20:06 +00:00
ladda.stop();
if (response.success) {
$("#collab_modal").modal('hide');
toastr.success(response.msg);
} else {
toastr.error(response.msg);
}
2023-09-21 12:45:08 +00:00
}
});
2023-09-21 14:20:06 +00:00
});
2023-09-21 12:45:08 +00:00
2024-03-18 14:33:31 +00:00
$('a[data-toggle="pill"]').on('shown.bs.tab', function(e) {
2023-09-21 14:20:06 +00:00
var target = $(e.target).attr('href');
if (target == '#custome-tabs-forms') {
if (typeof form_table != 'undefined') {
form_table.ajax.reload();
}
} else if (target == '#custome-tabs-templates') {
if (typeof template_table != 'undefined') {
template_table.ajax.reload();
}
} else if (target == '#custome-tabs-shared-forms-assigned') {
if (typeof assigned_form_table != 'undefined') {
assigned_form_table.ajax.reload();
2023-09-21 12:45:08 +00:00
}
}
});
2024-03-18 14:33:31 +00:00
@if (auth()->user()->can('superadmin'))
$(document).on('click', '.toggle_global_template', function() {
$.ajax({
method: "POST",
url: "{{ route('toggle.global.template') }}",
dataType: "json",
data: {
is_checked: $(this).is(":checked") ? 1 : 0,
form_id: $(this).data("form_id"),
},
success: function(response) {
if (response.success) {
template_table.ajax.reload();
} else {
toastr.error(response.msg);
}
2023-09-21 12:45:08 +00:00
}
2024-03-18 14:33:31 +00:00
});
2023-09-21 12:45:08 +00:00
});
2023-09-21 14:20:06 +00:00
@endif
});
</script>
2023-09-21 14:01:58 +00:00
@endsection