/** * Operacje klijenckie sugestera */ var $objSugester = { /** * Inicjalizacja sugestera */ init : function() { objButton = document.createElement('div'); objBtnText = document.createElement('span'); $(objBtnText).html('Zgłoś uwagi'); $(objButton).append(objBtnText); $(objButton).addClass('clsSugesterAktywator'); $(objButton).attr('onclick', '$objSugester.aafAktywuj();'); $('body').append(objButton); }, /** * Aktywacja sugestera */ aafAktywuj : function() { if (1 == $("#objSugester").length) { $("#objSugester").parent().parent().parent().css('display', 'block'); } else { strEmail = ("undefined" == typeof ($objUser)) ? '' : $objUser.stremail; strPliki = ''; strSugesterRodo = '' + '
' + '
' + 'RR' + 'Zgadzam się na przetwarzanie moich danych osobowych, które zostaną użyte jedynie
w celu realizacji tego zapytania ' + ' Polityka prywatności' + '
' + '
' + '
'; strSugester = '
' + '
' + '' + '
' + strSugesterRodo + '
' + '
' + '' + '
' + '
' + '
' + '
' + '' + '
' + '
' + '
' + '
' + strPliki + '
' + '
'; strSugesterStopka = '' + '
'; dialog = new $objOkno({ klasy : "clsEmailSzablonEdycja" }); dialog.aafNaglowekDodaj('

Zgłoś sugestię

'); dialog.aafTrescDodaj(strSugester); dialog.aafStopkaDodaj(strSugesterStopka); // dialog.aafWyswietl(); $('#objSugester textarea.ctrDataCollection.objTextarea').focus(); } }, /** * Usunięcie dialogboxa sugestera */ aafDeaktywujUsun : function() { try { $("#objSugester").parent().parent().parent().remove(); } catch (exception) { console.log(exception); } }, /** * Zapis sugestii */ aafZapisz : function() { $objRequest = { strTresc : $('[strtyp="objTextarea"][name="strTresc"]').val(), strEmail : $('[strtyp="objInput"][name="strEmail"]').val(), strTelefonNumer : $('[strtyp="objInput"][name="strTelefonNumer"]').val(), cmd : 'zapis', strUrl : window.location.href, }; $sugesterRodo = $('#sugesterRodo'); achErroryKlucze = []; strPattern = /^[A-Z0-9._%+-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i; if ("" == $objRequest.strEmail.trim()) { achErroryKlucze.push("strEmail"); new $objKomunikat("Pole email jest wymagane", "error"); } if ("" == $objRequest.strTresc.trim()) { achErroryKlucze.push("strTresc"); new $objKomunikat("Treść sugestii jest pusta", "error"); } if ($sugesterRodo.attr("value") == 0) { achErroryKlucze.push("rodo"); new $objKomunikat("Zaznacz zgodę na przetwarzanie danych osobowych. Tylko wtedy będziemy mogli odpowiedzieć na Twoją sugestię.", "error"); } if (strPattern.test($objRequest.strEmail.trim())) { } else { achErroryKlucze.push("strEmail"); new $objKomunikat("Podany adres email jest niepoprawny", "error"); } if (achErroryKlucze.length > 0) { $objSugester.aafErroryUstaw(achErroryKlucze, "#objSugester"); } else { $objAjax.request($objRequest, '/sugester', $objSugester.aafZapiszAsync); } }, aafErroryUstaw : function(achKlucze, strKontener) { try { if (achKlucze.length == 0) { } else { $(strKontener + ' .ctrDataCollection').each(function() { if ((achKlucze.indexOf($(this).attr('strKlucz')) !== (-1)) || (achKlucze.indexOf($(this).attr('name')) !== (-1))) { $(this).addClass('error'); } else { $(this).removeClass('error'); } }); } } catch (exception) { console.log(exception); } }, // zapis asynchronicznie aafZapiszAsync : function(objAjaxDane) { try { if ("undefined" == typeof (objAjaxDane)) { } else if ("undefined" == typeof (objAjaxDane[0])) { } else { $("#objSugester").parent().parent().parent().remove(); } } catch (exception) { console.log(exception); } }, Rodo : function() { $sugesterRodo = $('#sugesterRodo'); $checkboxRodo = $('#sugesterRodo .checkbox-custom') if ($sugesterRodo.attr("value") == 0) { $sugesterRodo.attr("value", 1); $($checkboxRodo).addClass('checkbox-ok'); } else { $sugesterRodo.attr("value", 0); $($checkboxRodo).removeClass('checkbox-ok'); } }, }; /** * Obiekt okna js */ var $objOkno = (function(objKonfiguracja) { try { // tworzymy nową instancję if (!this instanceof $objOkno) { return new $objOkno(); } // konfiguracja okienka if ("undefined" == typeof (objKonfiguracja)) { objKonfiguracja = {}; } var _objKonfiguracja = objKonfiguracja; /** * Szablon * * @type {null} * @private */ var _objSzablon = null; function _aafSzablonUstaw() { try { switch (_objKonfiguracja.szablon) { case "podpowiedz": // nagłówek strZamykanieBtn = '' + '' + ''; $(_objOknoNaglowek).append(strZamykanieBtn); // zawartość strHelpBody = '' + '
' + '
' + '
' + '
' + '
' + '
' + '

' + _objKonfiguracja.podtytul + '

' + '

' + _objKonfiguracja.wyjasnienie + '

' + '
' + '
' + '
'; $(_objOknoZawartosc).append(strHelpBody); // okno objOkno = document.createElement('div'); $(objOkno).addClass('clsOkno ' + _objKonfiguracja.klasy); // nagłówek $(objOkno).append(_objOknoNaglowek); // zawartość $(objOkno).append(_objOknoZawartosc); // stopka $(objOkno).append(_objOknoStopka); // szablon objSzablon = document.createElement('div'); $(objSzablon).addClass('clsOknoContainer '); $(objSzablon).append(objOkno); _objSzablon = objSzablon; break; default: // domyślne rzeczy dla tego szablonu strZamykanieBtn = '' + '' + ''; $(_objOknoNaglowek).append(strZamykanieBtn); // okno objOkno = document.createElement('div'); $(objOkno).addClass('clsOkno'); if ("undefined" == typeof (_objKonfiguracja.klasy)) { } else { $(objOkno).addClass(_objKonfiguracja.klasy); } // nagłówek $(objOkno).append(_objOknoNaglowek); // zawartość $(objOkno).append(_objOknoZawartosc); // stopka $(objOkno).append(_objOknoStopka); // szablon objSzablon = document.createElement('div'); $(objSzablon).addClass('clsOknoContainer'); $(objSzablon).append(objOkno); _objSzablon = objSzablon; break; } } catch (exception) { console.log(exception); } } /** * Dodanie do nagłówka * * @param objHtml * @private */ function _aafNaglowekDodaj(objHtml) { $(_objOknoNaglowek).append(objHtml); } var _objOknoNaglowek = document.createElement('div'); $(_objOknoNaglowek).addClass('clsOknoNaglowek'); /** * Dodanie html do dialogboxa * * @param objHtml - * node (this), lub html * @returns */ function _aafTrescDodaj(objHtml) { $(_objOknoZawartosc).append(objHtml); } var _objOknoZawartosc = document.createElement("div"); $(_objOknoZawartosc).addClass('clsOknoZawartosc'); /** * Dodanie do stopki * * @param objHtml * @private */ function _aafStopkaDodaj(objHtml) { $(_objOknoStopka).append(objHtml); } var _objOknoStopka = document.createElement('div'); $(_objOknoStopka).addClass('clsOknoStopka'); /** * Obsługa zdarzeń * * @param strSekcja - * sekcja * @param objEventy - * jakie obsługiwać np ["click","change"] * @private */ var _strEvt = false; var _objEvt = false; function _aafEvt(strSekcja, objEventy) { try { if (0 == strSekcja.length) { } else if (0 == objEventy.length) { } else { // _strEvt = strSekcja; _objEvt = objEventy; } } catch (exception) { } } /** * Wyświetla okno * * @private */ var _blnWyswietlono = false; function _aafWyswietl() { try { if (_blnWyswietlono) { } else { _aafSzablonUstaw(); $(_objSzablon).addClass('objOkno'); if ("undefined" == typeof (_objKonfiguracja.klasyObj)) { } else { $(_objSzablon).addClass(_objKonfiguracja.klasyObj); } if (!_strEvt) { } else { for (ev in _objEvt) { switch (_objEvt[ev]) { case "click": $(_objSzablon).click(function(event) { $eventDispatcher.aafDispatch(event, _strEvt, 'click'); }); break; case "change": $(_objSzablon).change(function(event) { $eventDispatcher.aafDispatch(event, _strEvt, 'change'); }); break; } } } $("body").append(_objSzablon); _blnWyswietlono = true; } } catch (exception) { console.log(exception); } } } catch (exception) { console.log(exception); } /** * Zwraca obiekt dialogboxa */ return { aafNaglowekDodaj : _aafNaglowekDodaj, aafTrescDodaj : _aafTrescDodaj, aafStopkaDodaj : _aafStopkaDodaj, aafWyswietl : _aafWyswietl, aafEvt : _aafEvt } }); var $objKomunikat = (function(strText, strTyp) { $(".clsKomunikatKontener").clearQueue(); $('.clsKomunikat').remove(); objKomunikat = document.createElement("div"); // icon = ''; if (strTyp == 'error') { icon = ''; } else if (strTyp == 'info') { icon = ''; } else if (strTyp == 'warning') { icon = ''; } clsKomunikatNieaktywny = 'clsKomunikatNieaktywny'; close = ''; $(objKomunikat).addClass(strTyp + " clsKomunikat "); $(objKomunikat).html('' + strText + ' ' + icon + close); $(objKomunikat).delay(6000).queue(function() { $(this).addClass('clsKomunikatNieaktywny').dequeue(); }).delay(10000).queue(function() { $(this).remove().dequeue(); }); // if (0 == $(".clsKomunikatKontener").length) { $('body').append('
'); } // $(".clsKomunikatKontener").append(objKomunikat); return {}; }); /** * Obiekt ajax */ var $objAjax = { /** * obiekt odpowiedzi s serwera */ response : {}, /** * Funkcja odpytania serwera * * @param strDane - * base64 danych jakie chcemy wysłać * @param strUrl - * url na jaki chcemy wysłać dane * @param objFunction - * callback - po zakończeniu transakcji ajax */ request : function(strDane, strUrl, objFunction) { try { if ("object" == typeof (strDane)) { strDane = Base64.encode(JSON.stringify(strDane)); } var objResponse = null; $.ajax({ // url:"/ajax" + strUrl + '?XDEBUG_SESSION_START=1', url : "/ajax" + strUrl, data : { ajaxDane : strDane }, type : "POST", success : function(response) { try { this.response = Base64.decode(response); this.response = JSON.parse(this.response); if (this.response.error.length > 0) { strAjaxError = ''; for ( var i in this.response.error) { if (i > 0) { strAjaxError = strAjaxError + '
'; } strAjaxError = strAjaxError + '
' + this.response.error[i] + '
'; } new $objKomunikat(strAjaxError, "error"); } if ('undefined' == typeof (objFunction)) { } else { objFunction(this.response.output, this.response.error); } if (this.response.warning.length > 0) { for ( var i in this.response.warning) { new $objKomunikat(this.response.warning[i], "warning"); } } if (this.response.info.length > 0) { strAjaxInfo = ''; for ( var i in this.response.info) { if (i > 0) { strAjaxInfo = strAjaxInfo + '
'; } strAjaxInfo = strAjaxInfo + '
' + this.response.info[i] + '
'; } new $objKomunikat(strAjaxInfo, "info"); } if (this.response.fnc.length > 0) { for ( var i in this.response.fnc) { eval(this.response.fnc[i]); } } } catch (exception) { console.log(exception); } }, }); return this.response; } catch (exception) { console.log(exception); } }, }; /** * Base64 encode / decode http://www.webtoolkit.info/ */ var Base64 = { // private property _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", // public method for encoding encode : function(input) { var output = ""; var chr1, chr2, chr3, enc1, enc2, enc3, enc4; var i = 0; input = Base64._utf8_encode(input); while (i < input.length) { chr1 = input.charCodeAt(i++); chr2 = input.charCodeAt(i++); chr3 = input.charCodeAt(i++); enc1 = chr1 >> 2; enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); enc4 = chr3 & 63; if (isNaN(chr2)) { enc3 = enc4 = 64; } else if (isNaN(chr3)) { enc4 = 64; } output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(enc3) + this._keyStr.charAt(enc4); } return output; }, // public method for decoding decode : function(input) { var output = ""; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); while (i < input.length) { enc1 = this._keyStr.indexOf(input.charAt(i++)); enc2 = this._keyStr.indexOf(input.charAt(i++)); enc3 = this._keyStr.indexOf(input.charAt(i++)); enc4 = this._keyStr.indexOf(input.charAt(i++)); chr1 = (enc1 << 2) | (enc2 >> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; output = output + String.fromCharCode(chr1); if (enc3 != 64) { output = output + String.fromCharCode(chr2); } if (enc4 != 64) { output = output + String.fromCharCode(chr3); } } output = Base64._utf8_decode(output); return output; }, // private method for UTF-8 encoding _utf8_encode : function(string) { string = string.replace(/\r\n/g, "\n"); var utftext = ""; for (var n = 0; n < string.length; n++) { var c = string.charCodeAt(n); if (c < 128) { utftext += String.fromCharCode(c); } else if ((c > 127) && (c < 2048)) { utftext += String.fromCharCode((c >> 6) | 192); utftext += String.fromCharCode((c & 63) | 128); } else { utftext += String.fromCharCode((c >> 12) | 224); utftext += String.fromCharCode(((c >> 6) & 63) | 128); utftext += String.fromCharCode((c & 63) | 128); } } return utftext; }, // private method for UTF-8 decoding _utf8_decode : function(utftext) { var string = ""; var i = 0; var c = c1 = c2 = 0; while (i < utftext.length) { c = utftext.charCodeAt(i); if (c < 128) { string += String.fromCharCode(c); i++; } else if ((c > 191) && (c < 224)) { c2 = utftext.charCodeAt(i + 1); string += String.fromCharCode(((c & 31) << 6) | (c2 & 63)); i += 2; } else { c2 = utftext.charCodeAt(i + 1); c3 = utftext.charCodeAt(i + 2); string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63)); i += 3; } } return string; } };