Skip to content

Commit

Permalink
trigger unico per abilitazione/disabilitazione prodotti filtrati. closes
Browse files Browse the repository at this point in the history
  • Loading branch information
madbob committed Oct 25, 2023
1 parent 53f9573 commit c834714
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 71 deletions.
2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/gasdotto.js": "/js/gasdotto.js?id=1ac74c5998995317e8c64392791ef496",
"/js/gasdotto.js": "/js/gasdotto.js?id=7977b382776a2ecae67b5bc28fe1fe58",
"/css/gasdotto.css": "/css/gasdotto.css?id=7cfc917f5221cc270b4ee4c7b1d57124"
}
30 changes: 29 additions & 1 deletion code/resources/assets/js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class Filters {
this.iconsLegendTrigger($(e.currentTarget), '.icons-legend');
});

/*
Questo serve ad intercettare tutti i pulsanti dei filtri nelle
tabelle, sia le icone che i dropdown con scelte multiple
*/
$('.table-icons-legend button, .table-icons-legend a', container).click((e) => {
e.preventDefault();
this.iconsLegendTrigger($(e.currentTarget), '.table-icons-legend');
Expand Down Expand Up @@ -120,8 +124,10 @@ class Filters {
static tableFilters(table_id)
{
var filters = $('[data-table-target="' + table_id + '"]');
var table = $('table' + table_id);
var elements = table.find('tbody tr');

$('table' + table_id + ' tbody tr').each(function() {
elements.each(function() {
var display = true;
var row = $(this);

Expand Down Expand Up @@ -190,6 +196,11 @@ class Filters {
}
}

/*
Se almeno una condizione del filtro determina che l'elemento
non deve essere visualizzato, evito di valutare le altre ed
esco subito dal ciclo each()
*/
if (display == false) {
return false;
}
Expand All @@ -203,6 +214,10 @@ class Filters {

static iconsLegendTrigger(node, legend_class)
{
/*
Se clicco l'intestazione di un dropdown, passo oltre. Qui interviene
il JS di Bootstrap per aprire e chiudere il dropdown stesso
*/
if (node.hasClass('dropdown-toggle')) {
return;
}
Expand Down Expand Up @@ -232,6 +247,7 @@ class Filters {

$(iter_selector).toggleClass('hidden', false);
this.compactFilter(master_selector, child_selector, true);
$(master_selector).trigger('inactive-filter');
}
else {
/*
Expand All @@ -248,6 +264,7 @@ class Filters {
}

var c = node.find('i').attr('class');
var count_hidden = 0;

$(iter_selector).each(function() {
var show = false;
Expand All @@ -261,9 +278,20 @@ class Filters {
});

$(this).toggleClass('hidden', show == false);

if (show == false) {
count_hidden++;
}
});

this.compactFilter(master_selector, child_selector, false);

if (count_hidden == 0) {
$(master_selector).trigger('inactive-filter');
}
else {
$(master_selector).trigger('active-filter');
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions code/resources/assets/js/gasdotto.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Lists from "./lists";
import Widgets from "./widgets";
import Triggers from "./triggers";
import Filters from "./filters";
import Products from "./products";
import Bookings from "./bookings";
import Roles from "./roles";
import Modifiers from "./modifiers";
Expand Down Expand Up @@ -139,6 +140,7 @@ function generalInit(container) {

utils.init(container);
Modifiers.init(container);
Products.init(container);
Lists.init(container);
Widgets.init(container);
Bookings.init(container);
Expand Down
26 changes: 26 additions & 0 deletions code/resources/assets/js/products.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
window.$ = window.jQuery = global.$ = global.jQuery = require('jquery');
require('bootstrap');

import utils from "./utils";

class Products {
static init(container)
{
/*
Questo mostra/nasconde il trigger addizionale per modificare in
blocco l'ordinabilità dei prodotti, nella griglia della modifica
rapida
*/
if (container.hasClass('products-grid')) {
container.on('active-filter', (e) => {
container.find('.category-toggle').removeClass('hidden');
});

container.on('inactive-filter', (e) => {
container.find('.category-toggle').addClass('hidden');
});
}
}
}

export default Products;
144 changes: 77 additions & 67 deletions code/resources/views/supplier/products_grid.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,77 +6,87 @@
?>

<div class="row d-none d-md-flex mb-1">
<div class="col flowbox">
<div class="form-group mainflow d-none d-xl-block">
<input type="text" class="form-control table-text-filter" data-table-target="#{{ $identifier }}" placeholder="{{ _i('Filtra') }}">
</div>
<div class="products-grid">
<div class="row d-none d-md-flex mb-1">
<div class="col flowbox">
<div class="form-group mainflow d-none d-xl-block">
<input type="text" class="form-control table-text-filter" data-table-target="#{{ $identifier }}" placeholder="{{ _i('Filtra') }}">
</div>

@include('commons.iconslegend', [
'class' => App\Product::class,
'target' => '#' . $identifier,
'table_filter' => true,
'contents' => $products
])
@include('commons.iconslegend', [
'class' => App\Product::class,
'target' => '#' . $identifier,
'table_filter' => true,
'contents' => $products
])
</div>
</div>
</div>

<x-larastrap::form classes="inner-form" method="POST" :action="url('products/massiveupdate')">
<input type="hidden" name="post-saved-function" value="reloadCurrentLoadable">

<div class="row">
<div class="col">
<table class="table sortable-table" id="{{ $identifier }}">
<thead>
<tr>
@if($has_manual_sorting)
<th width="5%"></th>
@endif
<th width="50%">{{ _i('Nome') }}</th>
<th width="15%">{{ _i('Unità di Misura') }}</th>
<th width="15%">{{ _i('Prezzo Unitario') }}</th>
<th width="15%">{{ _i('Disponibile') }}</th>
<th width="5%">{{ _i('Ordinabile') }}</th>
</tr>
</thead>
<tbody>
<?php $measures = App\Measure::orderBy('name', 'asc')->get() ?>
@foreach($products as $product)
<x-larastrap::enclose :obj="$product">
<tr data-element-id="{{ $product->id }}">
@if($has_manual_sorting)
<td>
<span class="btn btn-info sorter"><i class="bi bi-arrow-down-up"></i></span>
</td>
@endif
<x-larastrap::form classes="inner-form" method="POST" :action="url('products/massiveupdate')">
<input type="hidden" name="post-saved-function" value="reloadCurrentLoadable">

<td>
<div class="hidden">
@foreach($product->icons() as $icon)
<i class="bi-{{ $icon }}"></i>
@endforeach
<div class="row">
<div class="col">
<table class="table sortable-table" id="{{ $identifier }}">
<thead>
<tr>
@if($has_manual_sorting)
<th width="5%"></th>
@endif
<th width="50%">{{ _i('Nome') }}</th>
<th width="15%">{{ _i('Unità di Misura') }}</th>
<th width="15%">{{ _i('Prezzo Unitario') }}</th>
<th width="10%">{{ _i('Disponibile') }}</th>
<th width="10%">
{{ _i('Ordinabile') }}
<div class="category-toggle hidden">
<x-larastrap::check squeeze classes="triggers-all-checkbox" data-target-class="bookable:visible" />
<div class="form-text">
{{ _i('Abilita/disabilita tutti i prodotti filtrati') }}
</div>
</div>
</th>
</tr>
</thead>
<tbody>
<?php $measures = App\Measure::orderBy('name', 'asc')->get() ?>
@foreach($products as $product)
<x-larastrap::enclose :obj="$product">
<tr data-element-id="{{ $product->id }}">
@if($has_manual_sorting)
<td>
<span class="btn btn-info sorter"><i class="bi bi-arrow-down-up"></i></span>
</td>
@endif

<td>
<div class="hidden">
@foreach($product->icons() as $icon)
<i class="bi-{{ $icon }}"></i>
@endforeach
</div>

<x-larastrap::hidden name="id" npostfix="[]" />
<x-larastrap::text name="name" :label="_i('Nome')" squeeze required :nprefix="$product->id . '-'" />
</td>
<td>
<x-larastrap::selectobj name="measure_id" :label="_i('Unità di Misura')" :options="$measures" squeeze :nprefix="$product->id . '-'" />
</td>
<td>
<x-larastrap::price name="price" :label="_i('Prezzo Unitario')" squeeze required :nprefix="$product->id . '-'" />
</td>
<td>
<x-larastrap::decimal name="max_available" :label="_i('Disponibile')" squeeze required :nprefix="$product->id . '-'" />
</td>
<td>
<x-larastrap::check name="active" :label="_i('Ordinabile')" squeeze :nprefix="$product->id . '-'" />
</td>
</tr>
</x-larastrap::enclose>
@endforeach
</tbody>
</table>
<x-larastrap::hidden name="id" npostfix="[]" />
<x-larastrap::text name="name" :label="_i('Nome')" squeeze required :nprefix="$product->id . '-'" />
</td>
<td>
<x-larastrap::selectobj name="measure_id" :label="_i('Unità di Misura')" :options="$measures" squeeze :nprefix="$product->id . '-'" />
</td>
<td>
<x-larastrap::price name="price" :label="_i('Prezzo Unitario')" squeeze required :nprefix="$product->id . '-'" />
</td>
<td>
<x-larastrap::decimal name="max_available" :label="_i('Disponibile')" squeeze required :nprefix="$product->id . '-'" />
</td>
<td>
<x-larastrap::check name="active" classes="bookable" :label="_i('Ordinabile')" squeeze :nprefix="$product->id . '-'" />
</td>
</tr>
</x-larastrap::enclose>
@endforeach
</tbody>
</table>
</div>
</div>
</div>
</x-larastrap::form>
</x-larastrap::form>
</div>

0 comments on commit c834714

Please sign in to comment.