From eff141d91cdab369ec500a4e8ce2d24664194e3e Mon Sep 17 00:00:00 2001 From: czup Date: Mon, 23 Dec 2019 06:25:58 +0100 Subject: [PATCH] =?UTF-8?q?Badania=20-=20wst=C4=99pnie,=20bez=20obs=C5=82u?= =?UTF-8?q?gi=20b=C5=82=C4=99d=C3=B3w=20ajaxa,=20z=20niezformatowanym=20wi?= =?UTF-8?q?dokiem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- resources/views/bootstable.js | 201 ++++++++++++++++++ resources/views/trainings.blade.php | 0 .../views/trainingsAddFireFighters.blade.php | 98 +++++++++ .../trainingsAddFireFightersORG.blade.php | 117 ++++++++++ .../trainingsAddFireFightersv1.blade.php | 98 +++++++++ 5 files changed, 514 insertions(+) create mode 100644 resources/views/bootstable.js create mode 100644 resources/views/trainings.blade.php create mode 100644 resources/views/trainingsAddFireFighters.blade.php create mode 100644 resources/views/trainingsAddFireFightersORG.blade.php create mode 100644 resources/views/trainingsAddFireFightersv1.blade.php diff --git a/resources/views/bootstable.js b/resources/views/bootstable.js new file mode 100644 index 0000000..061a97f --- /dev/null +++ b/resources/views/bootstable.js @@ -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 = '
'+ + ''+ + ''+ + ''+ + ''+ + '
'; +var colEdicHtml = ''+newColHtml+''; + +$.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(''); //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 = '
' + cont + '
'; //guarda contenido + var input = ''; + $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 + ''; + } + }); + $tab_en_edic.find('tbody').append(''+htmlDat+''); + } 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; +} diff --git a/resources/views/trainings.blade.php b/resources/views/trainings.blade.php new file mode 100644 index 0000000..e69de29 diff --git a/resources/views/trainingsAddFireFighters.blade.php b/resources/views/trainingsAddFireFighters.blade.php new file mode 100644 index 0000000..076fa58 --- /dev/null +++ b/resources/views/trainingsAddFireFighters.blade.php @@ -0,0 +1,98 @@ +@extends('layout.app') + + + +@section('left-menu') + @parent + +@stop + +@section('center-area') + @parent + + @if( auth()->check()) + @if( auth()->user()->fireStationID == NULL) + Jednostka nie istnieje + @else +
+ {{ csrf_field() }} + +
+
+ +
+
+ +
+ +
+ + @include('inc.formerrors') +
+ @endif + @else + Brak autoryzacji + @endif + +@stop + + + diff --git a/resources/views/trainingsAddFireFightersORG.blade.php b/resources/views/trainingsAddFireFightersORG.blade.php new file mode 100644 index 0000000..2552197 --- /dev/null +++ b/resources/views/trainingsAddFireFightersORG.blade.php @@ -0,0 +1,117 @@ +@extends('layout.app') + + +Add Edit Delete Table Row Example using JQuery - ItSolutionStuff.com + + + +@section('left-menu') + @parent + +@stop + + +@section('center-area') + @parent + + @if( auth()->check()) + @if( auth()->user()->fireStationID == NULL) + Jednostka nie istnieje + @else +

{{$training->trainingName}}

+ + + + + + + + + + + + + @foreach($fireFighters as $fireFighter) + + + + + + + @endforeach + +
Imię i NazwiskoWażne od:Ważne do:Akcje
{{$fireFighter->name}} {{$fireFighter->surname}}{{$fireFighter->dateOfComplete}}{{$fireFighter->dateOfExpiry}}
+ + + @endif + @else + Brak autoryzacji + @endif + +@stop + + + + + + + diff --git a/resources/views/trainingsAddFireFightersv1.blade.php b/resources/views/trainingsAddFireFightersv1.blade.php new file mode 100644 index 0000000..076fa58 --- /dev/null +++ b/resources/views/trainingsAddFireFightersv1.blade.php @@ -0,0 +1,98 @@ +@extends('layout.app') + + + +@section('left-menu') + @parent + +@stop + +@section('center-area') + @parent + + @if( auth()->check()) + @if( auth()->user()->fireStationID == NULL) + Jednostka nie istnieje + @else +
+ {{ csrf_field() }} + +
+
+ +
+
+ +
+ +
+ + @include('inc.formerrors') +
+ @endif + @else + Brak autoryzacji + @endif + +@stop + + +