Badania - wstępnie, bez obsługi błędów ajaxa, z niezformatowanym widokiem
This commit is contained in:
parent
5a43d3a3f0
commit
eff141d91c
201
resources/views/bootstable.js
vendored
Normal file
201
resources/views/bootstable.js
vendored
Normal file
@ -0,0 +1,201 @@
|
||||
/*
|
||||
Bootstable
|
||||
@description Javascript library to make HMTL tables editable, using Bootstrap
|
||||
@version 1.1
|
||||
@autor Tito Hinostroza
|
||||
*/
|
||||
"use strict";
|
||||
//Global variables
|
||||
var params = null; //Parameters
|
||||
var colsEdi =null;
|
||||
var newColHtml = '<div class="btn-group pull-right">'+
|
||||
'<button id="bEdit" type="button" class="btn btn-sm btn-default" onclick="rowEdit(this);">' +
|
||||
'<span class="glyphicon glyphicon-pencil" > </span>'+
|
||||
'</button>'+
|
||||
'<button id="bElim" type="button" class="btn btn-sm btn-default" onclick="rowElim(this);">' +
|
||||
'<span class="glyphicon glyphicon-trash" > </span>'+
|
||||
'</button>'+
|
||||
'<button id="bAcep" type="button" class="btn btn-sm btn-default" style="display:none;" onclick="rowAcep(this);">' +
|
||||
'<span class="glyphicon glyphicon-ok" > </span>'+
|
||||
'</button>'+
|
||||
'<button id="bCanc" type="button" class="btn btn-sm btn-default" style="display:none;" onclick="rowCancel(this);">' +
|
||||
'<span class="glyphicon glyphicon-remove" > </span>'+
|
||||
'</button>'+
|
||||
'</div>';
|
||||
var colEdicHtml = '<td name="buttons">'+newColHtml+'</td>';
|
||||
|
||||
$.fn.SetEditable = function (options) {
|
||||
var defaults = {
|
||||
columnsEd: null, //Index to editable columns. If null all td editables. Ex.: "1,2,3,4,5"
|
||||
$addButton: null, //Jquery object of "Add" button
|
||||
onEdit: function() {}, //Called after edition
|
||||
onBeforeDelete: function() {}, //Called before deletion
|
||||
onDelete: function() {}, //Called after deletion
|
||||
onAdd: function() {} //Called when added a new row
|
||||
};
|
||||
params = $.extend(defaults, options);
|
||||
this.find('thead tr').append('<th name="buttons"></th>'); //encabezado vacío
|
||||
this.find('tbody tr').append(colEdicHtml);
|
||||
var $tabedi = this; //Read reference to the current table, to resolve "this" here.
|
||||
//Process "addButton" parameter
|
||||
if (params.$addButton != null) {
|
||||
//Se proporcionó parámetro
|
||||
params.$addButton.click(function() {
|
||||
rowAddNew($tabedi.attr("id"));
|
||||
});
|
||||
}
|
||||
//Process "columnsEd" parameter
|
||||
if (params.columnsEd != null) {
|
||||
//Extract felds
|
||||
colsEdi = params.columnsEd.split(',');
|
||||
}
|
||||
};
|
||||
function IterarCamposEdit($cols, tarea) {
|
||||
//Itera por los campos editables de una fila
|
||||
var n = 0;
|
||||
$cols.each(function() {
|
||||
n++;
|
||||
if ($(this).attr('name')=='buttons') return; //excluye columna de botones
|
||||
if (!EsEditable(n-1)) return; //noe s campo editable
|
||||
tarea($(this));
|
||||
});
|
||||
|
||||
function EsEditable(idx) {
|
||||
//Indica si la columna pasada está configurada para ser editable
|
||||
if (colsEdi==null) { //no se definió
|
||||
return true; //todas son editable
|
||||
} else { //hay filtro de campos
|
||||
//alert('verificando: ' + idx);
|
||||
for (var i = 0; i < colsEdi.length; i++) {
|
||||
if (idx == colsEdi[i]) return true;
|
||||
}
|
||||
return false; //no se encontró
|
||||
}
|
||||
}
|
||||
}
|
||||
function FijModoNormal(but) {
|
||||
$(but).parent().find('#bAcep').hide();
|
||||
$(but).parent().find('#bCanc').hide();
|
||||
$(but).parent().find('#bEdit').show();
|
||||
$(but).parent().find('#bElim').show();
|
||||
var $row = $(but).parents('tr'); //accede a la fila
|
||||
$row.attr('id', ''); //quita marca
|
||||
}
|
||||
function FijModoEdit(but) {
|
||||
$(but).parent().find('#bAcep').show();
|
||||
$(but).parent().find('#bCanc').show();
|
||||
$(but).parent().find('#bEdit').hide();
|
||||
$(but).parent().find('#bElim').hide();
|
||||
var $row = $(but).parents('tr'); //accede a la fila
|
||||
$row.attr('id', 'editing'); //indica que está en edición
|
||||
}
|
||||
function ModoEdicion($row) {
|
||||
if ($row.attr('id')=='editing') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
function rowAcep(but) {
|
||||
//Acepta los cambios de la edición
|
||||
var $row = $(but).parents('tr'); //accede a la fila
|
||||
var $cols = $row.find('td'); //lee campos
|
||||
if (!ModoEdicion($row)) return; //Ya está en edición
|
||||
//Está en edición. Hay que finalizar la edición
|
||||
IterarCamposEdit($cols, function($td) { //itera por la columnas
|
||||
var cont = $td.find('input').val(); //lee contenido del input
|
||||
$td.html(cont); //fija contenido y elimina controles
|
||||
});
|
||||
FijModoNormal(but);
|
||||
params.onEdit($row);
|
||||
}
|
||||
function rowCancel(but) {
|
||||
//Rechaza los cambios de la edición
|
||||
var $row = $(but).parents('tr'); //accede a la fila
|
||||
var $cols = $row.find('td'); //lee campos
|
||||
if (!ModoEdicion($row)) return; //Ya está en edición
|
||||
//Está en edición. Hay que finalizar la edición
|
||||
IterarCamposEdit($cols, function($td) { //itera por la columnas
|
||||
var cont = $td.find('div').html(); //lee contenido del div
|
||||
$td.html(cont); //fija contenido y elimina controles
|
||||
});
|
||||
FijModoNormal(but);
|
||||
}
|
||||
function rowEdit(but) { //Inicia la edición de una fila
|
||||
var $row = $(but).parents('tr'); //accede a la fila
|
||||
var $cols = $row.find('td'); //lee campos
|
||||
if (ModoEdicion($row)) return; //Ya está en edición
|
||||
//Pone en modo de edición
|
||||
IterarCamposEdit($cols, function($td) { //itera por la columnas
|
||||
var cont = $td.html(); //lee contenido
|
||||
var div = '<div style="display: none;">' + cont + '</div>'; //guarda contenido
|
||||
var input = '<input class="form-control input-sm" value="' + cont + '">';
|
||||
$td.html(div + input); //fija contenido
|
||||
});
|
||||
FijModoEdit(but);
|
||||
}
|
||||
function rowElim(but) { //Elimina la fila actual
|
||||
var $row = $(but).parents('tr'); //accede a la fila
|
||||
params.onBeforeDelete($row);
|
||||
$row.remove();
|
||||
params.onDelete();
|
||||
}
|
||||
function rowAddNew(tabId) { //Agrega fila a la tabla indicada.
|
||||
var $tab_en_edic = $("#" + tabId); //Table to edit
|
||||
var $filas = $tab_en_edic.find('tbody tr');
|
||||
if ($filas.length==0) {
|
||||
//No hay filas de datos. Hay que crearlas completas
|
||||
var $row = $tab_en_edic.find('thead tr'); //encabezado
|
||||
var $cols = $row.find('th'); //lee campos
|
||||
//construye html
|
||||
var htmlDat = '';
|
||||
$cols.each(function() {
|
||||
if ($(this).attr('name')=='buttons') {
|
||||
//Es columna de botones
|
||||
htmlDat = htmlDat + colEdicHtml; //agrega botones
|
||||
} else {
|
||||
htmlDat = htmlDat + '<td></td>';
|
||||
}
|
||||
});
|
||||
$tab_en_edic.find('tbody').append('<tr>'+htmlDat+'</tr>');
|
||||
} else {
|
||||
//Hay otras filas, podemos clonar la última fila, para copiar los botones
|
||||
var $ultFila = $tab_en_edic.find('tr:last');
|
||||
$ultFila.clone().appendTo($ultFila.parent());
|
||||
$ultFila = $tab_en_edic.find('tr:last');
|
||||
var $cols = $ultFila.find('td'); //lee campos
|
||||
$cols.each(function() {
|
||||
if ($(this).attr('name')=='buttons') {
|
||||
//Es columna de botones
|
||||
} else {
|
||||
$(this).html(''); //limpia contenido
|
||||
}
|
||||
});
|
||||
}
|
||||
params.onAdd();
|
||||
}
|
||||
function TableToCSV(tabId, separator) { //Convierte tabla a CSV
|
||||
var datFil = '';
|
||||
var tmp = '';
|
||||
var $tab_en_edic = $("#" + tabId); //Table source
|
||||
$tab_en_edic.find('tbody tr').each(function() {
|
||||
//Termina la edición si es que existe
|
||||
if (ModoEdicion($(this))) {
|
||||
$(this).find('#bAcep').click(); //acepta edición
|
||||
}
|
||||
var $cols = $(this).find('td'); //lee campos
|
||||
datFil = '';
|
||||
$cols.each(function() {
|
||||
if ($(this).attr('name')=='buttons') {
|
||||
//Es columna de botones
|
||||
} else {
|
||||
datFil = datFil + $(this).html() + separator;
|
||||
}
|
||||
});
|
||||
if (datFil!='') {
|
||||
datFil = datFil.substr(0, datFil.length-separator.length);
|
||||
}
|
||||
tmp = tmp + datFil + '\n';
|
||||
});
|
||||
return tmp;
|
||||
}
|
0
resources/views/trainings.blade.php
Normal file
0
resources/views/trainings.blade.php
Normal file
98
resources/views/trainingsAddFireFighters.blade.php
Normal file
98
resources/views/trainingsAddFireFighters.blade.php
Normal file
@ -0,0 +1,98 @@
|
||||
@extends('layout.app')
|
||||
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
|
||||
@section('left-menu')
|
||||
@parent
|
||||
<ul>
|
||||
<a href="sprzet/add"><li>Dodaj<img src="../img/left_menu_icon/add.png"></li></a>
|
||||
<li>Edytuj<img src="../img/left_menu_icon/edit.png"></li>
|
||||
<li>Usuń<img src="../img/left_menu_icon/delete.png"></li>
|
||||
</ul>
|
||||
@stop
|
||||
|
||||
@section('center-area')
|
||||
@parent
|
||||
|
||||
@if( auth()->check())
|
||||
@if( auth()->user()->fireStationID == NULL)
|
||||
Jednostka nie istnieje
|
||||
@else
|
||||
<form method="POST" action="/szkolenia" id="dynamic_form">
|
||||
{{ csrf_field() }}
|
||||
|
||||
<div class=form-group">
|
||||
<div id="fireFightersTrainings">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz badania</button>
|
||||
</div>
|
||||
|
||||
@include('inc.formerrors')
|
||||
</form>
|
||||
@endif
|
||||
@else
|
||||
Brak autoryzacji
|
||||
@endif
|
||||
|
||||
@stop
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
|
||||
var count = 1;
|
||||
|
||||
dynamic_field(count);
|
||||
|
||||
function dynamic_field(number)
|
||||
{
|
||||
|
||||
html = '<div id="singleFireFighter"><label for="location">Strażak:</label>';
|
||||
html += '<select name="fireFighterTraining[]" class="form-control">';
|
||||
html += '<option value="">--- Wybierz strażaka ---</option>';
|
||||
html += '@foreach ($fireFighters as $fireFighter)';
|
||||
html += '<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>';
|
||||
html += '@endforeach';
|
||||
html += '</select>';
|
||||
html += '<label>Data ukończenia: </label><input type="date" name="dateOfComplete[]">'
|
||||
html += '<label> Koniec ważności: </label><input type="date" id="dateOfExpiry">'
|
||||
html += 'Bezterminowo: <input type="checkbox" id="lifeless">'
|
||||
if(number > 1)
|
||||
{
|
||||
html += '<button type="button" name="remove" id="" class="btn btn-danger remove">Usuń</button></br></div>';
|
||||
$('#fireFightersTrainings').append(html);
|
||||
}
|
||||
else
|
||||
{
|
||||
html += '<button type="button" name="add" id="add" class="btn btn-success">Dodaj</button></br></div>';
|
||||
$('#fireFightersTrainings').html(html);
|
||||
}
|
||||
}
|
||||
|
||||
$(document).on('click', '#add', function(){
|
||||
count++;
|
||||
dynamic_field(count);
|
||||
});
|
||||
|
||||
$(document).on('click', '.remove', function(){
|
||||
count--;
|
||||
$(this).closest("#singleFireFighter").remove();
|
||||
});
|
||||
|
||||
$('#lifeless').change(function(){
|
||||
if($(this).is(':checked'))
|
||||
$('#dateOfExpiry').prop('disabled', true)
|
||||
else
|
||||
$('#dateOfExpiry').prop('disabled', false)
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
117
resources/views/trainingsAddFireFightersORG.blade.php
Normal file
117
resources/views/trainingsAddFireFightersORG.blade.php
Normal file
@ -0,0 +1,117 @@
|
||||
@extends('layout.app')
|
||||
|
||||
|
||||
<title>Add Edit Delete Table Row Example using JQuery - ItSolutionStuff.com</title>
|
||||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" />
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
|
||||
|
||||
@section('left-menu')
|
||||
@parent
|
||||
<ul>
|
||||
<a href="sprzet/add"><li>Dodaj<img src="../img/left_menu_icon/add.png"></li></a>
|
||||
<li>Edytuj<img src="../img/left_menu_icon/edit.png"></li>
|
||||
<li>Usuń<img src="../img/left_menu_icon/delete.png"></li>
|
||||
</ul>
|
||||
@stop
|
||||
|
||||
|
||||
@section('center-area')
|
||||
@parent
|
||||
|
||||
@if( auth()->check())
|
||||
@if( auth()->user()->fireStationID == NULL)
|
||||
Jednostka nie istnieje
|
||||
@else
|
||||
<center><h1>{{$training->trainingName}}</h1></center>
|
||||
<table id="editableTable" class='table table-bordered'>
|
||||
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Imię i Nazwisko</td>
|
||||
<td>Ważne od:</td>
|
||||
<td>Ważne do:</td>
|
||||
<td>Akcje</td>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@foreach($fireFighters as $fireFighter)
|
||||
<tr id="{{$fireFighter->id}}">
|
||||
<td>{{$fireFighter->name}} {{$fireFighter->surname}}</td>
|
||||
<td>{{$fireFighter->dateOfComplete}}</td>
|
||||
<td>{{$fireFighter->dateOfExpiry}}</td>
|
||||
<td><button class="btn btn-info" type="submit">Edytuj</button> <button class="btn btn-danger btn-delete" type="submit">Usuń</button></td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
@endif
|
||||
@else
|
||||
Brak autoryzacji
|
||||
@endif
|
||||
|
||||
@stop
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
// $("form").submit(function(e){
|
||||
// e.preventDefault();
|
||||
// var name = $("input[name='name']").val();
|
||||
// var email = $("input[name='email']").val();
|
||||
//
|
||||
// $(".data-table tbody").append("<tr data-name='"+name+"' data-email='"+email+"'><td>"+name+"</td><td>"+email+"</td><td><button class='btn btn-info btn-xs btn-edit'>Edit</button><button class='btn btn-danger btn-xs btn-delete'>Delete</button></td></tr>");
|
||||
//
|
||||
// $("input[name='name']").val('');
|
||||
// $("input[name='email']").val('');
|
||||
// });
|
||||
//
|
||||
// $("body").on("click", ".btn-delete", function(){
|
||||
// $(this).parents("tr").remove();
|
||||
// });
|
||||
//
|
||||
// $("body").on("click", ".btn-edit", function(){
|
||||
// var name = $(this).parents("tr").attr('data-name');
|
||||
// var email = $(this).parents("tr").attr('data-email');
|
||||
//
|
||||
// $(this).parents("tr").find("td:eq(0)").html('<input name="edit_name" value="'+name+'">');
|
||||
// $(this).parents("tr").find("td:eq(1)").html('<input name="edit_email" value="'+email+'">');
|
||||
//
|
||||
// $(this).parents("tr").find("td:eq(2)").prepend("<button class='btn btn-info btn-xs btn-update'>Update</button><button class='btn btn-warning btn-xs btn-cancel'>Cancel</button>")
|
||||
// $(this).hide();
|
||||
// });
|
||||
//
|
||||
// $("body").on("click", ".btn-cancel", function(){
|
||||
// var name = $(this).parents("tr").attr('data-name');
|
||||
// var email = $(this).parents("tr").attr('data-email');
|
||||
//
|
||||
// $(this).parents("tr").find("td:eq(0)").text(name);
|
||||
// $(this).parents("tr").find("td:eq(1)").text(email);
|
||||
//
|
||||
// $(this).parents("tr").find(".btn-edit").show();
|
||||
// $(this).parents("tr").find(".btn-update").remove();
|
||||
// $(this).parents("tr").find(".btn-cancel").remove();
|
||||
// });
|
||||
//
|
||||
// $("body").on("click", ".btn-update", function(){
|
||||
// var name = $(this).parents("tr").find("input[name='edit_name']").val();
|
||||
// var email = $(this).parents("tr").find("input[name='edit_email']").val();
|
||||
//
|
||||
// $(this).parents("tr").find("td:eq(0)").text(name);
|
||||
// $(this).parents("tr").find("td:eq(1)").text(email);
|
||||
//
|
||||
// $(this).parents("tr").attr('data-name', name);
|
||||
// $(this).parents("tr").attr('data-email', email);
|
||||
//
|
||||
// $(this).parents("tr").find(".btn-edit").show();
|
||||
// $(this).parents("tr").find(".btn-cancel").remove();
|
||||
// $(this).parents("tr").find(".btn-update").remove();
|
||||
// });
|
||||
|
||||
</script>
|
||||
|
||||
|
||||
|
||||
|
||||
|
98
resources/views/trainingsAddFireFightersv1.blade.php
Normal file
98
resources/views/trainingsAddFireFightersv1.blade.php
Normal file
@ -0,0 +1,98 @@
|
||||
@extends('layout.app')
|
||||
|
||||
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
|
||||
@section('left-menu')
|
||||
@parent
|
||||
<ul>
|
||||
<a href="sprzet/add"><li>Dodaj<img src="../img/left_menu_icon/add.png"></li></a>
|
||||
<li>Edytuj<img src="../img/left_menu_icon/edit.png"></li>
|
||||
<li>Usuń<img src="../img/left_menu_icon/delete.png"></li>
|
||||
</ul>
|
||||
@stop
|
||||
|
||||
@section('center-area')
|
||||
@parent
|
||||
|
||||
@if( auth()->check())
|
||||
@if( auth()->user()->fireStationID == NULL)
|
||||
Jednostka nie istnieje
|
||||
@else
|
||||
<form method="POST" action="/szkolenia" id="dynamic_form">
|
||||
{{ csrf_field() }}
|
||||
|
||||
<div class=form-group">
|
||||
<div id="fireFightersTrainings">
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<button style="cursor:pointer" type="submit" class="btn btn-primary">Zapisz badania</button>
|
||||
</div>
|
||||
|
||||
@include('inc.formerrors')
|
||||
</form>
|
||||
@endif
|
||||
@else
|
||||
Brak autoryzacji
|
||||
@endif
|
||||
|
||||
@stop
|
||||
|
||||
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
|
||||
var count = 1;
|
||||
|
||||
dynamic_field(count);
|
||||
|
||||
function dynamic_field(number)
|
||||
{
|
||||
|
||||
html = '<div id="singleFireFighter"><label for="location">Strażak:</label>';
|
||||
html += '<select name="fireFighterTraining[]" class="form-control">';
|
||||
html += '<option value="">--- Wybierz strażaka ---</option>';
|
||||
html += '@foreach ($fireFighters as $fireFighter)';
|
||||
html += '<option value="{{$fireFighter->id}}">{{ $fireFighter->name }} {{$fireFighter->surname }}</option>';
|
||||
html += '@endforeach';
|
||||
html += '</select>';
|
||||
html += '<label>Data ukończenia: </label><input type="date" name="dateOfComplete[]">'
|
||||
html += '<label> Koniec ważności: </label><input type="date" id="dateOfExpiry">'
|
||||
html += 'Bezterminowo: <input type="checkbox" id="lifeless">'
|
||||
if(number > 1)
|
||||
{
|
||||
html += '<button type="button" name="remove" id="" class="btn btn-danger remove">Usuń</button></br></div>';
|
||||
$('#fireFightersTrainings').append(html);
|
||||
}
|
||||
else
|
||||
{
|
||||
html += '<button type="button" name="add" id="add" class="btn btn-success">Dodaj</button></br></div>';
|
||||
$('#fireFightersTrainings').html(html);
|
||||
}
|
||||
}
|
||||
|
||||
$(document).on('click', '#add', function(){
|
||||
count++;
|
||||
dynamic_field(count);
|
||||
});
|
||||
|
||||
$(document).on('click', '.remove', function(){
|
||||
count--;
|
||||
$(this).closest("#singleFireFighter").remove();
|
||||
});
|
||||
|
||||
$('#lifeless').change(function(){
|
||||
if($(this).is(':checked'))
|
||||
$('#dateOfExpiry').prop('disabled', true)
|
||||
else
|
||||
$('#dateOfExpiry').prop('disabled', false)
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user