From 2b6970d33afd75be5bfef951dc3691d492004d43 Mon Sep 17 00:00:00 2001 From: George Halkiadakis Date: Tue, 18 Apr 2023 01:11:37 +0300 Subject: admin back-office environment (skeleton); admin categories --- .../assets/js/_pythia/dataTables/pythiaDropDown.js | 104 +++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 public/assets/js/_pythia/dataTables/pythiaDropDown.js (limited to 'public/assets/js/_pythia/dataTables/pythiaDropDown.js') diff --git a/public/assets/js/_pythia/dataTables/pythiaDropDown.js b/public/assets/js/_pythia/dataTables/pythiaDropDown.js new file mode 100644 index 0000000..cad6032 --- /dev/null +++ b/public/assets/js/_pythia/dataTables/pythiaDropDown.js @@ -0,0 +1,104 @@ +//-----------------------IMPORTANT---------------------------- +// parameters' specs +// options: +// JSon with structure +// EXAMPLE +// [0] [ + // data_table: 'store_deliveries', + // title: 'Πεδία' +// ] +// [1] [ +// checked: "true" --> required +// class: "js-filter_checkbox checkbox_top" --> required +// data_column: "dt-order_quantity" +// value: "Προϊόντα" +// ] + +// -------------------------------------------------------- +// container id optional +// when given the drop down menu will be generated inside +// else the default 'filter' value will take place +function generate_drop_down_fields(options, container_id) { + $('#'+(typeof container_id == 'undefined' ? 'filter' : container_id)).append(generate_drop_down_menu_fields(options)); + generate_drop_down_functionality_fields(options[0].data_table); + $('.dropdown-toggle').dropdown(); + // Calculate dropdown height. + var dropdown_height = parseInt($('#' + (typeof container_id == 'undefined' ? 'filter' : container_id) + ' .dropdown-menu').css('height')); + + // Adjust table wrapper height to fit, dropdown menu. + $('#'+(typeof container_id == 'undefined' ? 'filter' : container_id)).closest('.table-responsive').css('min-height' , `${dropdown_height + 192}px`); +} + +//Given the drop down options "draw" the drop down menu FIELDS +function generate_drop_down_menu_fields(options) { + var result =''+ + ''; + return result; +} + $(document).on('click', '.container_checkbox', function (e) { + e.stopPropagation(); + }); + +//Given the datatable_id(!required) generate the functionality (checked or not) for dropdown +function generate_drop_down_functionality_fields(data_table_id) { + + var table = $('#'+data_table_id); + $(".js-filter_checkbox[data-default='true']").prop("checked", true); + $(".js-filter_checkbox").each(function () { + table.DataTable().columns('.' + $(this).attr('data-column')).visible($(this).is(':checked')); + }); + $(".js-filter_checkbox").change(function () { + table.DataTable().columns('.' + $(this).attr('data-column')).visible($(this).is(':checked')); + }); +} + +//Given the drop down options "draw" the drop down menu FILTERS +function generate_drop_down_menu_filters (options) { + var result =''+ + ''; + //activate the dropdown + $('.dropdown-toggle').dropdown(); + return result; +} + +$(document).on('click', '.container_generated_checkbox', function (e) { + e.stopPropagation(); +}); + +function build_fuctionality(types, table) { + $('.js-filter_row_checkbox').change(function () { + var terms = []; + types.forEach(element => { + if ($('.js-' + element + '-checkbox').is(':checked')) { + terms.push(element); + } + }) + var search_terms = terms.join('|'); + table.columns('.dt-type').search(search_terms, true, false).draw(); + }) +}; \ No newline at end of file -- cgit v1.2.3