Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Created by Dominika on 07.07.2017.
- */
- var myPage=1;
- var downloadNext = true;
- var loadIcon = false;
- var myFilter="";
- var recaptcha = $(".g-recaptcha");
- showCaptcha();
- myContent(myPage);
- function showCaptcha(){
- if($(window).width()<=380) {
- var newScaleFactor = recaptcha.parent().innerWidth() / 304;
- recaptcha.css('transform', 'scale(' + newScaleFactor + ')');
- recaptcha.css('transform-origin', '0 0');
- }
- else if (($(window).width()>380)&&($(window).width()<=574)) {
- var newScaleFactor = recaptcha.parent().innerWidth() / 403;
- recaptcha.css('transform', 'scale(' + newScaleFactor + ')');
- recaptcha.css('transform-origin', '0 0');
- }
- else if ($(window).width()>574){
- recaptcha.css('transform', 'scale(1.035)');
- recaptcha.css('transform-origin', '0 0');
- }
- }
- function myContent(myPage){
- $.get("http://localhost/offers/public/api/offer",{page:myPage, filter:myFilter}, function (response) {
- if(response.next_page_url == '' || response.next_page_url == null){
- downloadNext=false;
- $(".icon").hide();
- }
- $tablica = $('#tableBody');
- $div = $('#divMobile');
- $icon = $('.icon');
- if(myPage==1){
- $tablica.html('');
- $div.html('');
- $(".icon").show();
- $('.singleTextt').html('Znaleziono: ');
- downloadNext=true;
- loadIcon=false;
- }
- $.each(response.data, function (key, value) {
- var newDate = moment(value.time_begin, "YYYY-MM-DD").format("DD.MM.YYYY");
- var newDatee = moment(value.time_end, "YYYY-MM-DD").format("DD.MM.YYYY");
- $tablica.append(
- '<tr email="' + value.email + '" contact="' + value.contact.phone + '">' +
- '<td><details><summary>' + value.name + '</summary><p>' + value.comment + '</p></details></td>' +
- '<td nowrap="nowrap">' + newDate + '</td>' +
- '<td nowrap="nowrap">' + newDatee + '</td>' +
- '<td>' + value.value + '</td>' +
- '<td>' + value.localization + '</td>' +
- '<td><button type="submit" class="contactButton">Skontaktuj się!</button></td>' +
- '</tr>'
- );
- $div.append(
- '<div email="' + value.email + '" contact="' + value.contact.phone + '" class="row box">' +
- '<div class="col-12">' +
- '<details>' +
- '<summary><strong>' + value.name + '</strong></summary>' +
- '<p>' + value.comment + '</p>' +
- '</details></div>' +
- '<div class="col-12"><strong>' + value.localization + '</strong></div>' +
- '<div class="col-12"><strong>Dostępność:</strong></div>' +
- '<div class="col-12">' + newDate + ' - ' + newDatee + '</div>' +
- '<div class="col-12"><strong>Stawka: </strong>' + value.value + '</div>' +
- '<div class="col-12"><button type="submit" class="contactButton">Skontaktuj się!</button></div>' +
- '</div>'
- );
- });
- showContact();
- if (loadIcon === false){
- $('.singleTextt').append(' '+ response.total);
- if(response.total==0){
- $(".icon").hide();
- $tab = $('#tableNotMobile');
- $tab.html('');
- $('.singleTextt').html(' ');
- $('.singleTextt').append('<p style="font-size:25px; text-align:center; height:30vh;margin-top:50px;">Niestety nie znaleziono interesującej Ciebie oferty</p>');
- }
- $icon.html( '<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i><span class="sr-only">Loading...</span>' );
- loadIcon = true;
- }
- });
- }
- function showContact(){
- $(".contactButton").unbind('click');
- $(".contactButton").on('click', function (e) {
- e.preventDefault();
- var w = $(window).width();
- if (w > 767) {
- $tr = $(this).closest('tr');
- $('#contactModal').find('#mail').html($tr.attr('email'));
- $('#contactModal').find('#ontact').html($tr.attr('contact'));
- }
- else if (w <= 767) {
- $div = $(this).parent().parent();
- $('#contactModal').find('#mail').html($div.attr('email'));
- $('#contactModal').find('#ontact').html($div.attr('contact'));
- }
- $("#contactModal").modal("show");
- });
- }
- $(window).scroll(function(){
- if(($(window).scrollTop() + $(window).height() === $(document).height()) && downloadNext) {
- myPage++;
- myContent(myPage);
- }
- });
- $(window).resize(function() {
- showCaptcha();
- });
- $(document).ready(function(){
- var today = new Date();
- var dd = today.getDate();
- var mm = today.getMonth()+1;
- var yyyy = today.getFullYear();
- if(dd<10) {
- dd = '0'+dd;
- }
- if(mm<10) {
- mm = '0'+mm;
- }
- today = dd + '.' + mm + '.' + yyyy;
- // document.getElementById('time_begin').value = today;
- // document.getElementById('time_end').value = today;
- document.getElementById('from').value = today;
- document.getElementById('to').value = today;
- $('.datetime').datepicker({
- language: "pl",
- format: "dd.mm.yyyy",
- startDate: today,
- autoclose: true,
- todayHighlight: true,
- widgetPositioning: {
- horizontal: 'auto',
- vertical: 'bottom'
- }
- });
- $('#szukaj').click(function() {
- var name = document.getElementById("name").value;
- var localization = document.getElementById("localization").value;
- var time_begin = document.getElementById("time_begin").value;
- var time_end = document.getElementById("time_end").value;
- var newDate = moment(time_begin, "DD.MM.YYYY").format("YYYY-MM-DD");
- var newDatee = moment(time_end, "DD.MM.YYYY").format("YYYY-MM-DD");
- if (time_begin=="" && time_end==""){
- myFilter = JSON.stringify({value: name, localization: localization});
- }
- else if (time_begin!="" && time_end==""){
- myFilter = JSON.stringify({value: name, localization: localization, time_begin: newDate});
- }
- else if (time_begin=="" && time_end!=""){
- myFilter = JSON.stringify({value: name, localization: localization, time_end: newDatee});
- }
- else myFilter = JSON.stringify({value: name, localization: localization,time_begin: newDate, time_end: newDatee});
- console.log(myFilter);
- myPage = 1;
- myContent(myPage);
- $('#collapse').collapse('hide');
- });
- $(".submitButton").click(function(){
- $("#submitModal").find('.form-control').val('');
- $("#submitModal").find('.help-block').html('');
- $("input, textarea").removeClass("err");
- $("#submitModal").find("button").removeClass("disabled");
- $("#msgSubmit").html("");
- $("#submitModal").modal("show");
- });
- /* $("input").keyup(function(){
- var name = document.forms['dodaj_oferte'].elements['name'].value;
- var time_begin = document.forms['dodaj_oferte'].elements['time-begin'].value;
- var time_end = document.forms['dodaj_oferte'].elements['time-end'].value;
- var value = document.forms['dodaj_oferte'].elements['value'].value;
- var localization = document.forms['dodaj_oferte'].elements['localization'].value;
- var email = document.forms['dodaj_oferte'].elements['email'].value;
- var comment = document.forms['dodaj_oferte'].elements['comment'].value;
- var contact = document.forms['dodaj_oferte'].elements['contact'].value;
- var newDate = moment(time_begin, "DD.MM.YYYY").format("YYYY-MM-DD");
- var newDatee = moment(time_end, "DD.MM.YYYY").format("YYYY-MM-DD");
- if(name !== "" && newDate !== "" && newDatee !== "" && value !== ""&& localization !== "" && email !== "" && comment !== "" && contact !== "" ) {
- $("#captcontainer").slideDown(450);
- }
- });*/
- $('#addOffer').validator().submit(function(event){
- event.preventDefault();
- var verified = grecaptcha.getResponse();
- var name = document.forms['dodaj_oferte'].elements['name'].value;
- var time_begin = document.forms['dodaj_oferte'].elements['time-begin'].value;
- var time_end = document.forms['dodaj_oferte'].elements['time-end'].value;
- var value = document.forms['dodaj_oferte'].elements['value'].value;
- var localization = document.forms['dodaj_oferte'].elements['localization'].value;
- var email = document.forms['dodaj_oferte'].elements['email'].value;
- var comment = document.forms['dodaj_oferte'].elements['comment'].value;
- var contact = document.forms['dodaj_oferte'].elements['contact'].value;
- var newDate = moment(time_begin, "DD.MM.YYYY").format("YYYY-MM-DD");
- var newDatee = moment(time_end, "DD.MM.YYYY").format("YYYY-MM-DD");
- // var captchaVal = $("#g-recaptcha-response").val();
- //var captchaR = grecaptcha.getResponse();
- //console.log('g-recaptcha: ' + captchaVal);
- //console.log('response: ' + captchaR);
- // console.log('g-recaptcha: ' + captchaVal);
- // console.log('response: ' + captchaR);
- if (verified.length === 0) {
- event.preventDefault();
- $('#msgSubmit').append("<br>" +"Udowodnij, że nie jesteś robotem!");
- }
- else{
- $.ajax({
- type: "POST",
- url: "http://localhost/offers/public/api/offer",
- dataType: 'json',
- contentType: "application/json; charset=utf-8",
- data: JSON.stringify( { name: name, localization: localization, time_begin: newDate, time_end: newDatee, value: value, email: email, comment: comment, contact: {"phone": contact } }),
- success: function(response){
- if (response.success){
- $('#msgSubmit').html('Sprawdź swój email w celu aktywowania oferty.'); //Nie moge przetestować bo nie działa!
- } else {
- $('#msgSubmit').html("Czy poprawnie wypełniłeś wszystkie pola?");
- $("input:invalid").addClass("err");
- $("input:valid").removeClass("err");
- $("textarea:invalid").addClass("err");
- $("textarea:valid").removeClass("err");
- }
- }
- });
- }
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement