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 = "
"; 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 = " "; 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 = ""; } $("