function setQuickInterfaceEdit(interface_edit) { if (interface_edit) { $('button').removeAttr('onclick'); $('input[type="submit"]').each(function (i, v) { var value = $(this).attr('value'); var obj = $(value); $(this).attr('value', obj.html()).attr('id', obj.attr('id')).addClass(obj.attr('class')).css('background-color', '#D7F4CA').bind('click', function () { interfaceEdit(this); return false; }); }); } $("span.interface_link").parent().attr('href', '#edycja_interfejsu'); $("span.interface_link").parent().removeAttr('onclick'); $("span.interface_link").live('click', function () { interfaceEdit(this); }); } function loadHelp(url, _title) { ajax(url, null, '#help_dialog_content'); return false; } function cKEditorUpdate() { var myinstances = []; //this is the foreach loop for (var i in CKEDITOR.instances) { /* this returns each instance as object try it with alert(CKEDITOR.instances[i]) */ // CKEDITOR.instances[i]; /* this returns the names of the textareas/id of the instances. */ // CKEDITOR.instances[i].name; /* returns the initial value of the textarea */ // CKEDITOR.instances[i].value; /* this updates the value of the textarea from the CK instances.. */ CKEDITOR.instances[i].updateElement(); /* this retrieve the data of each instances and store it into an associative array with the names of the textareas as keys... */ myinstances[CKEDITOR.instances[i].name] = CKEDITOR.instances[i].getData(); } } function saveAndRedirect(form_id, url) { setLoadingShadow(); cKEditorUpdate(); var forms = form_id.split(','); $.each(forms, function (index, value) { if ($('#' + value).length) { form_id = value; return; } }); $('#' + form_id).ajaxForm( { success: function (responseText, statusText, xhr, form) { // clearLoadingShadow(); if (statusText == 'success') { window.location = url; } } } ); $('#' + form_id).submit(); } function saveAndPrint(form_id, url_print, window_name, params) { setLoadingShadow(); cKEditorUpdate(); if (window_name == undefined) { window_name = 'Wydruk systemowy'; } if (params == undefined) { params = 'width=850, height=600, scrollbars=1'; } $('#' + form_id).ajaxForm( { success: function (responseText, statusText, xhr, form) { if (statusText == 'success') { window.open(url_print, window_name, params); } clearLoadingShadow(); } } ); $('#' + form_id).submit(); $('#' + form_id).unbind('submit').find('input:submit:not(.print_button),input:image:not(.print_button),button:submit:not(.print_button)').unbind('click'); } function singleSmsSend(mobile, url, validate) { if (validate == undefined) { validate = true; } if (validate) { if (mobile == '') { alert("Wprowadź numer telefonu"); return false; } mobile = onlyDigit(mobile); if (mobile[0] == '0') { mobile = mobile.slice(1, mobile.length); } if (mobile == '' || mobile.length != 9) { alert("Wprowadź numer telefonu"); return false; } } window.send_sms_dialog = new Dialog('send_sms_dialog', {title: 'Wysyłanie wiadomości SMS', width: 550, close: 'send_sms_dialog'}); ajax(url, null, '#send_sms_dialog_content'); return false; } function sendEmail(element, email_element_id) { if ($('#' + email_element_id).val() == '') { $(element).attr('href', '#send_email'); return false; } $(element).attr('href', 'mailto:' + $('#' + email_element_id).val()); return true; } function LoadToElement(id, url, key, edit, callback) { edit = edit || 1; key = key || ''; callback = callback || null; $(id).css('opacity', '0.2'); $(id).parent().show(); $.ajax({ method: "POST", url: url, data: {query: key, edit: edit} }).done(function (responseText) { // var json = JSON.parse(responseText); // $(id).html(json[0].html); $(id).html(responseText); clearLoadingShadow(); if (callback) { callback(responseText); } $(id).css('opacity', '1'); if ($('#loader').length) { $('#loader').hide(); } }); } function blockedInput(main_order) { $('form input:not(input[type="submit"]), form select, form textarea').attr('disabled', true); $('form a:not(.download_link)').attr('href', '#'); $('form a:not(.download_link)').removeAttr('onclick'); $('form #add').removeAttr('onclick'); $('form a:not(.download_link)').attr('onclick', 'return false'); $('form #add').attr('onclick', 'return false'); $('form input[name="order[save]"]').remove(); $('form input[name="order[not_save]"]').remove(); if (main_order == true) { $('form input[name="query[save]"]').remove(); $('form input[name="query[save_anad_add]"]').remove(); } } function setOrderStyle() { // $('fieldset:not(#main_order_menu)').addClass('fieldset_order'); } function autoSave() { // console.log('autoSave'); // setInactiveLink($('a:not(.order_form_id table.list a, .order_form_id a, #user_info a)')); // setInactiveLink($('a:not(.order_form_id table.list a, .order_form_id a, #user_info a, #all_orders_list a)')); // setInactiveLink($('a:not(.order_form_id table.list a, .order_form_id a, #main_order_form_id table.list a, #main_order_form_id a, #user_info a, #all_orders_list a, #left .left_menu_item a)')); // setInactiveLink($('a')); // // $('#order_typ').attr('disabled', true); } function lockError(json) { if (json != null && json.code == 'LOCK') { console.log('test'); var d_start = new Date(); var d_end = MySqlDateToJacascript(json.lock_info.created_at); var dif = date_dif(d_end.datetime, d_start); var html = "
Zlecenie zostało zablokowane przed edycją.
W tej chwili pracuje nad nim: " + json.lock_info.user_info + ". Blokadę założono: " + json.lock_info.created_at + ". Blokada trwa: " + dif + " min
"; window.lock_info_dialog = new Dialog('lock_info_dialog', {title: 'Informacja systemowa', width: 660, close: 'lock_info_dialog', on_close: 'location.reload(true)'}); window.lock_info_dialog.getContent().html(html); // var text = "Zlecenie zostało zablokowane przed edycją. W tej chwili pracuje nad nim: " + json.lock_info.user_info + ". Blokadę założono: " + json.lock_info.created_at + "."; // alert(text); } else if (json != null && json.code == 'ADMIN_LOCK') { var html = "
Zlecenie zostało zablokowane przed edycją.
"; window.lock_info_dialog = new Dialog('lock_info_dialog', {title: 'Informacja systemowa', width: 660, close: 'lock_info_dialog', on_close: 'location.reload(true)'}); window.lock_info_dialog.getContent().html(html); } } function setInactiveLink(obj) { obj.css('color', '#b6b3b3'); obj.css('font-style', 'italic'); obj.css('text-decoration', 'none'); obj.css('cursor', 'default'); obj.attr('href', '#'); obj.click(function () { return false; }); } function recountMargin(contener) { if (contener == undefined || contener == '') { contener_margin_file = '#margin_file'; contener_margin = '#margin'; contener_start_y = '#start_y'; } else { contener_margin_file = '#' + contener + ' #margin_file'; contener_margin = '#' + contener + ' #margin'; contener_start_y = '#' + contener + ' #start_y'; } var margin_file = 0; var margin = 0; if ($(contener_margin_file).val() == '' || $(contener_margin_file).length == 0) { margin_file = 0; } else { margin_file = toNumber($(contener_margin_file).val()); } if ($(contener_margin).val() == '') { margin = 0; } else { margin = toNumber($(contener_margin).val()); } var m = parseFloat(margin - margin_file - 1.7); // $('#start_y').val( m.toFixed(2) ); $(contener_start_y).val(m.toFixed(2)); } function representativeJoin(obj) { if ($(obj).attr('checked')) { $('#order_representative_name').html($('#sales_representative_name').html()); $('#order_representative_id').val($('#sales_representative_id').val()); } else { $('#order_representative_name').html(''); $('#order_representative_id').val(''); } } function countVat(id) { var netto = $("#price_" + id + "_netto").val().replace(",", "."); var vat = $("#" + id + "_vat").val().replace(",", "."); if (vat == '' || vat == undefined) { vat = 23; $("#" + id + "_vat").val('23'); } if ($("#price_sale_netto").val() == '' && $("#price_buy_netto").val() != '') { $("#price_sale_netto").val($("#price_buy_netto").val()); } if (netto != '' && netto != undefined) { $("#" + id + "_vat").val(); var brutto = parseFloat(netto) + parseFloat((parseFloat(vat) * netto) / 100); $("#price_" + id + "_brutto").val(brutto.toFixed(2).toString().replace(".", ",")); } } function recountAmount(obj, id) { if ($('#' + id + ' .price_for_unite input').length) { var q = toNumber($(obj).val()); var p = toNumber($('#' + id + ' .price_for_unite input').val()); $('#' + id + ' .amount input').val((q * p).toFixed(4)) } } function removeItem(id, index) { if (id == '' || id == undefined) { $('#' + index).remove(); return false; } return false; } function findInSelect(text, select) { $(select).children().each(function (index, value) { if (value.text.substring(0, text.length) == text) { $(select).attr('selectedIndex', index); return; } }); } function only(AEvent, zm, litPatt, tekst, przywroc) { var kodKlawisza = ''; if (window.event) // IE { kodKlawisza = AEvent.keyCode; } else if (AEvent.which) // Netscape/Firefox/Opera { kodKlawisza = AEvent.which; } if (kodKlawisza == 37) { return true; // arrow } ; if (kodKlawisza == 38) { return true; // arrow } ; if (kodKlawisza == 39) { return true; // arrow } ; if (kodKlawisza == 40) { return true; // arrow } ; if (kodKlawisza == 13) { return true; // Enter } ; if (kodKlawisza == 8) { return true; // Backspace } ; if (kodKlawisza == 9) { return true; // TAB } ; if (kodKlawisza == 0) { return true; // klawisze sterujące } ; klawisz = String.fromCharCode(kodKlawisza); wynik = klawisz.match(litPatt); if (wynik == null) { alert(tekst); return false; } else { return true; } } function inArray(tab, p_val) { for (var i = 0, l = tab.length; i < l; i++) { if (trim_js(tab[i]) == trim_js(p_val)) { return true; } } return false; } function removeFromArray(tab, p_val) { for (var i = 0, l = tab.length; i < l; i++) { if (tab[i] == p_val || tab[i] == '') { tab.splice(i, 1); // return true; } } return false; } function implode(glue, pieces) { // Joins array elements placing glue string between items and return one string var i = '', retVal = '', tGlue = ''; if (arguments.length === 1) { pieces = glue; glue = ''; } if (typeof (pieces) === 'object') { if (pieces instanceof Array) { return pieces.join(glue); } else { for (i in pieces) { retVal += tGlue + pieces[i]; tGlue = glue; } return retVal; } } else { return pieces; } } function trim_js(stringToTrim) { return stringToTrim.replace(/^\s+|\s+$/g, ""); } function onlyDigit(stringToTrim) { return stringToTrim.replace(/\D+/g, ""); } //pokazanie/ukrycie boksu function showBox(id) { if ($("#" + id).is(":hidden")) { $("#" + id).slideDown("slow"); } else { $("#" + id).slideUp("slow"); } } //pokazanie/ukrycie boksu function showBox(id) { if ($("#" + id).is(":hidden")) { $("#" + id).slideDown("slow"); } else { $("#" + id).slideUp("slow"); } } //pokazanie/ukrycie boksu function showBox2(query) { if ($(query).is(":hidden")) { $(query).slideDown("slow"); } else { $(query).slideUp("slow"); } } //pokazanie/ukrycie boksu function showBoxAndText(id, text_id, text_show, text_hide) { if ($("#" + id).is(":hidden")) { $("#" + id).slideDown("slow"); $('#' + text_id).html(text_show); } else { $("#" + id).slideUp("slow"); $('#' + text_id).html(text_hide); } } /** * t - obiekt $(#id) - obiek na wartośc którego ma reagowować metoda * value - string - porównywana wartość * box - string - box który ma zostać pokazany/ukryty */ function showDefaultValue(t, value, box) { if (typeof value == 'object') { var test = inArray(value, $(t).val()) if (test) { $('#' + box).show(); } else { $('#' + box).hide(); } } else { if ($(t).val() == value) { $('#' + box).show(); } else { $('#' + box).hide(); } } } function callBack(url, data, succFun, paramFuncSucc) { $.ajax({ url: url, async: false, dataType: "html", // jsonp: "callback", cache: false, data: data, error: function () { alert('ERROR') }, complete: function () { }, success: function (msg) { if (succFun != '') { if (paramFuncSucc != '') { fun = succFun + '(' + paramFuncSucc + ')'; } else { fun = succFun + '()'; } eval(fun); } } }); } function toNumber(str) { // if (fixed == undefined || fixed == ''){ // fixed = 4; // } var n = str.replace(/[\s]/g, ''); n = n.replace(/[,]/g, '.'); return n; } function setLoadingShadow(id, level, loadingGif = false) { if (id == undefined || id == '') { id = 'loading_id_shadow'; } if (level == undefined || level == '') { level = 10; } if ($("#" + id + "_bg").length != 0) { return; } var gif; if (loadingGif == true) { gif = ""; } else { gif = ""; } $("
" + gif + "
").css({ width: $(window).width(), height: $(document).height() }).css('z-index', level).appendTo('body'); } function clearLoadingShadow(id) { if (id == undefined || id == '') { id = 'loading_id_shadow'; } // console.log($("#" + id +"_bg").length, 'clear'); if ($("#" + id + "_bg").length == 0) { return; } $("#" + id + "_bg").remove(); } function setLoading(element) { $(element).html('
'); } function isJson(str) { try { var json = JSON.parse(str); } catch (e) { return false; } return json; } // number formatting function // copyright Stephen Chapman 24th March 2006, 10th February 2007 // permission to use this function is granted provided // that this copyright notice is retained intact function formatNumber(num, dec, thou, pnt, curr1, curr2, n1, n2) { var x = Math.round(num * Math.pow(10, dec)); if (x >= 0) n1 = n2 = ''; var y = ('' + Math.abs(x)).split(''); var z = y.length - dec; if (z < 0) z--; for (var i = z; i < 0; i++) y.unshift('0'); y.splice(z, 0, pnt); if (y[0] == pnt) y.unshift('0'); while (z > 3) { z -= 3; y.splice(z, 0, thou); } var r = curr1 + n1 + y.join('') + n2 + curr2; return r; } // This function removes non-numeric characters function stripNonNumeric(str) { str += ''; var rgx = /^\d|\.|-$/; var out = ''; for (var i = 0; i < str.length; i++) { if (rgx.test(str.charAt(i))) { if (!((str.charAt(i) == '.' && out.indexOf('.') != -1) || (str.charAt(i) == '-' && out.length != 0))) { out += str.charAt(i); } } } return out; } function MySqlDateToJacascript(date) { var d_arr = date.split(' '); var d_arr_date = d_arr[0].split('-'); var d_arr_time = d_arr[1].split(':'); // new Date(year, month, day, hours, minutes, seconds, milliseconds) var my_date = new Date( parseInt(d_arr_date[0], 10), parseInt(d_arr_date[1], 10) - 1, parseInt(d_arr_date[2], 10), parseInt(d_arr_time[0], 10), parseInt(d_arr_time[1], 10), parseInt(d_arr_time[2], 10) ); var ret = {'date': d_arr_date, 'time': d_arr_time, 'datetime': my_date} return ret; } function date_dif(start, end) { var s_min = start.getTime(); var e_min = end.getTime(); //aktualnie różnica w minutach. var dif = parseInt((e_min - s_min) / (1000 * 60)); return dif; } function JavascriptDateToMsql(date) { var y = date.getFullYear(); var m = date.getMonth(); if (m < 10) { m = '0' + m; } var d = date.getDate(); if (d < 10) { d = '0' + d; } var h = date.getHours(); if (h < 10) { h = '0' + h; } var min = date.getMinutes(); if (min < 10) { min = '0' + min; } var s = date.getSeconds(); if (s < 10) { s = '0' + s; } return y + '-' + m + '-' + d + ' ' + h + ':' + min + ':' + s; } function countValue(t, start, counter, text) { var v = $(t).val(); var length = $(t).val().length;// + (count_br); if (length > start)// - count_br) { $(t).val(v.substr(0, start)); } newl = (start - $(t).val().length); $("#counter_" + counter).html(text + newl); } function countChar(obj) { var text = $(obj).val(); var length = text.length; if (length > 140) { $(obj).val(text.substr(0, 140)); } } function clearPolishChar(text, obj) { var t = ''; text = text.replace(/ę/g, "e"); text = text.replace(/ó/g, "o"); text = text.replace(/ą/g, "a"); text = text.replace(/ś/g, "s"); text = text.replace(/ł/g, "l"); text = text.replace(/ż/g, "z"); text = text.replace(/ź/g, "z"); text = text.replace(/ć/g, "c"); text = text.replace(/ń/g, "n"); //Wielkie litery text = text.replace(/Ę/g, "E"); text = text.replace(/Ó/g, "O"); text = text.replace(/Ą/g, "A"); text = text.replace(/Ś/g, "S"); text = text.replace(/Ł/g, "L"); text = text.replace(/Ż/g, "Z"); text = text.replace(/Ź/g, "Z"); text = text.replace(/Ć/g, "C"); text = text.replace(/Ń/g, "N"); $(obj).val(text); } function chat(element, section, section_id, temporary_id, hash, user_id, disable = false) { ajax(window.base_url + 'chat/index', {hash: hash, section: section, section_id: section_id, temporary_id: temporary_id, user_id: user_id, disable: disable}, element); } function chatLoadMessages(chat_element) { var section = $(chat_element).find('input[name="section"]').val(); var temporary_id = $(chat_element).find('input[name="temporary_id"]').val(); var section_id = $(chat_element).find('input[name="section_id"]').val(); var user_id = $(chat_element).find('input[name="user_id"]').val(); var hash = $(chat_element).find('input[name="hash"]').val(); var max_id = $(chat_element).find('input[name="max_id"]').val(); $.ajax({ type: "POST", url: window.base_url + 'chat/messages', data: {hash: hash, section: section, section_id: section_id, temporary_id: temporary_id, max_id: max_id, user_id: user_id}, async: false, dataType: "html", global: false, success: function (values) { // if (values[0].html != '0') { $(chat_element).find('div.messages').html(values); // } }, error: function () { console.log('chatLoadMessages: error'); } }); } function jsValidatorNormalText(){ $( "form" ).on( "keypress", ".validator_normal_text", function(event) { return only(event, this, /^[żźćńąśłęóŻŹĆŃĄŚŁĘÓ\/a-zA-Z0-9\s-,\.]$/, "Możesz używać normalnych znaków od a do z, cyfr oraz polskich znaków dialektycznych.",""); }) } function jsValidatorOnlyDigits(){ $( "form" ).on( "keypress", ".validator_only_digits", function(event) { return only(event, this, /^[0-9]$/, "Proszę wprowadzić liczbę",""); }) } function defaultNotificationsCode() { notification = 0; if($('#checkboxEmail').is(':checked')) { notification += 1; } if($('#checkboxSms').is(':checked')) { notification += 2; } if($('#checkboxSmsLink').is(':checked')) { notification += 4; } return notification; } function defaultNotificationsEncode(code) { if( code >= 4 ) { $('#checkboxSmsLink').attr('checked','checked'); code = code - 4; } if( code > 1 && code < 4) { $('#checkboxSms').attr('checked','checked'); code = code - 2; } if( code == 1 ) { $('#checkboxEmail').attr('checked','checked'); code = code - 1; } } function calculateNetto(netto_selector, value_selector, quantity_selector){ var value = toNumber( $(value_selector).val() ); var quantity = toNumber( $(quantity_selector).val() ); var netto = (parseFloat(value) * parseFloat(quantity)).toFixed(2); $(netto_selector).val( formatNumber(netto,2,' ',',','','','-','') ); } function calculateBrutto(brutto_selector, netto_selector, vat_selector){ var netto = toNumber( $(netto_selector).val() ); netto = (netto)?toNumber($(netto_selector).val()):0; var vat = toNumber( $(vat_selector).find(":selected").val() ); var vat_value = parseFloat(netto * vat/100); var brutto = (parseFloat(netto) + parseFloat(vat_value)).toFixed(2); $(brutto_selector).val( formatNumber(brutto,2,' ',',','','','-','') ); } function validatePhoneNumber(target, only_one) { if(only_one === undefined || only_one === '') { only_one = true; } var number = $(target).val(); var numbers = []; if (only_one) { numbers.push(number); } else { numbers = number.split(';'); } var number_after = ''; var numbers_after = []; var error = false; for (var num in numbers) { number_after = onlyDigit(numbers[num]); if ((num !== '' && number_after !== '' && number_after.length !== 9) || ( numbers[num] !== '' && number_after == '')) { error = true; // Jeśli numer ma 11 znaków i rozpoczyna sie od 48, traktujemy go jako poprawny, // usuwamy 48 i wstawaimy sam numer telefonu (9 cyfr) if(number_after.length == 11) { prefix = number_after.substring(0, 2); if(prefix === '48') { // Usuwamy 48 i wstawiamy 9 cyfr number_after = number_after.substring(2, 11); error = false; } else { number_after = ''; } } else { number_after = ''; } } if(number_after !== '') { numbers_after.push(number_after); } } if (error) { alert('Wprowadź poprawny numer telefonu. Numer powinien zawierać 9 cyfr.'); } $(target).val(numbers_after.join("; ")); } function displayPhoneNumber(number) { number = onlyDigit(number); var array = number.split(''); var text = ''; if(array.length == 9) { var i; for (i = 0; i < array.length; i++) { if(i == 3 || i == 6) { text += ' '; } text += array[i]; } } else if(array.length == 11) { var i; for (i = 0; i < array.length; i++) { if(i == 2 || i == 5 || i == 8) { text += ' '; } text += array[i]; } } else { text = number; } return text; }