Files
shopPRO/libraries/functions.js
Jacek Pyziak 4de5479c41 ver. 0.309: ApiloLogger + cache-busting CSS/JS + poprawki UI
- ApiloLogger: logowanie operacji Apilo do pp_log z kontekstem JSON
- Cache-busting: ?ver=filemtime() dla CSS i JS w admin main-layout
- Fix: inicjalizacja $mdb przed SettingsRepository w admin/index.php
- Fix: rzutowanie (string) w ShopProductController::escapeHtml()
- UI: text-overflow ellipsis dla kategorii produktow + title tooltip
- JS: navigator.clipboard API w copyToClipboard() z fallbackiem
- CSS: uproszczenie .site-content, usuniecie .with-menu
- Migracja: pp_log + kolumny action, order_id, context

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 09:31:28 +01:00

204 lines
5.3 KiB
JavaScript

window.copyToClipboard = function( element )
{
var text = $( '#' + element ).text().trim();
if ( navigator.clipboard && navigator.clipboard.writeText )
{
navigator.clipboard.writeText( text );
}
else
{
var $temp = $( "<textarea>" );
$temp.css({ position: 'fixed', left: '-9999px', top: '-9999px' });
$( "body" ).append( $temp );
$temp.val( text ).select();
document.execCommand( "copy" );
$temp.remove();
}
}
function checkForm(id)
{
check = true;
$('form#' + id + ' input[type="text"]').each(function () {
if ($(this).hasClass('require') && $(this).val() === '')
{
$(this).parents('.form-group').addClass('has-error');
check = false;
} else
$(this).parents('.form-group').removeClass('has-error');
});
$('form#' + id + ' textarea').each(function () {
if ($(this).hasClass('require') && $(this).val() === '')
{
$(this).parents('.form-group').addClass('has-error');
check = false;
} else
$(this).parents('.form-group').removeClass('has-error');
});
if (check)
$('form#' + id).submit();
return false;
}
function number_format(number, decimals, dec_point, thousands_sep)
{
number = (number + '').replace(/[^0-9+\-Ee.]/g, '');
var n = !isFinite(+number) ? 0 : +number,
prec = !isFinite(+decimals) ? 0 : Math.abs(decimals),
sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep,
dec = (typeof dec_point === 'undefined') ? '.' : dec_point,
s = '',
toFixedFix = function (n, prec) {
var k = Math.pow(10, prec);
return '' + Math.round(n * k) / k;
};
// Fix for IE parseFloat(0.55).toFixed(0) = 0;
s = (prec ? toFixedFix(n, prec) : '' + Math.round(n)).split('.');
if (s[0].length > 3) {
s[0] = s[0].replace(/\B(?=(?:\d{3})+(?!\d))/g, sep);
}
if ((s[1] || '').length < prec) {
s[1] = s[1] || '';
s[1] += new Array(prec - s[1].length + 1).join('0');
}
return s.join(dec);
}
$(document).ready(function ()
{
$('.date').datetimepicker({
format: "YYYY-MM-DD",
pickTime: false
});
$('body').on('click', '.date-range', function ()
{
$(this).daterangepicker().focus();
});
$('body').on('change', '.int-format', function ()
{
var value = $(this).val();
value = value.replace(' ', '');
value = parseFloat(value.replace(',', '.') * 1);
value = number_format(value, 0, '.', '');
$(this).val(value);
});
$('body').on('change', '.number-format', function ()
{
var value = $(this).val();
if (value === '')
return true;
value = value.replace(' ', '');
value = parseFloat(value.replace(',', '.') * 1);
value = number_format(value, 2, '.', '');
$(this).val(value);
});
});
function alert_message( message )
{
$.alert({
title: 'Informacja',
content: message,
type: 'orange',
closeIcon: true,
closeIconClass: 'fa fa-close',
typeAnimated: true,
animation: 'opacity',
autoClose: 'confirm|10000',
useBootstrap: false,
theme: 'modern',
autoClose: 'cancel|10000',
icon: 'fa fa-exclamation',
buttons:
{
cancel:
{
text: 'zamknij',
btnClass: 'btn-blue',
action: function() {}
}
}
});
}
function disable_menu()
{
$('.sidebar-menu li ul').remove();
$('.sidebar-menu li ').addClass("disable_menu");
$('.sidebar-menu li:last-child').removeClass("disable_menu");
}
$.fn.serializeObject = function() {
var data = {};
function buildInputObject(arr, val) {
if (arr.length < 1) {
return val;
}
var objkey = arr[0];
if (objkey.slice(-1) == "]") {
objkey = objkey.slice(0,-1);
}
var result = {};
if (arr.length == 1){
result[objkey] = val;
} else {
arr.shift();
var nestedVal = buildInputObject(arr,val);
result[objkey] = nestedVal;
}
return result;
}
function gatherMultipleValues( that ) {
var final_array = [];
$.each(that.serializeArray(), function( key, field ) {
// Copy normal fields to final array without changes
if( field.name.indexOf('[]') < 0 ){
final_array.push( field );
return true; // That's it, jump to next iteration
}
// Remove "[]" from the field name
var field_name = field.name.split('[]')[0];
// Add the field value in its array of values
var has_value = false;
$.each( final_array, function( final_key, final_field ){
if( final_field.name === field_name ) {
has_value = true;
final_array[ final_key ][ 'value' ].push( field.value );
}
});
// If it doesn't exist yet, create the field's array of values
if( ! has_value ) {
final_array.push( { 'name': field_name, 'value': [ field.value ] } );
}
});
return final_array;
}
// Manage fields allowing multiple values first (they contain "[]" in their name)
var final_array = gatherMultipleValues( this );
// Then, create the object
$.each(final_array, function() {
var val = this.value;
var c = this.name.split('[');
var a = buildInputObject(c, val);
$.extend(true, data, a);
});
return data;
};