Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.69 KB | None | 0 0
  1. /**
  2. * Created by Dominika on 07.07.2017.
  3. */
  4.  
  5. var myPage=1;
  6. var downloadNext = true;
  7. var loadIcon = false;
  8. var myFilter="";
  9. var recaptcha = $(".g-recaptcha");
  10.  
  11. showCaptcha();
  12. myContent(myPage);
  13.  
  14.  
  15. function showCaptcha(){
  16. if($(window).width()<=380) {
  17. var newScaleFactor = recaptcha.parent().innerWidth() / 304;
  18. recaptcha.css('transform', 'scale(' + newScaleFactor + ')');
  19. recaptcha.css('transform-origin', '0 0');
  20. }
  21. else if (($(window).width()>380)&&($(window).width()<=574)) {
  22. var newScaleFactor = recaptcha.parent().innerWidth() / 403;
  23. recaptcha.css('transform', 'scale(' + newScaleFactor + ')');
  24. recaptcha.css('transform-origin', '0 0');
  25. }
  26. else if ($(window).width()>574){
  27. recaptcha.css('transform', 'scale(1.035)');
  28. recaptcha.css('transform-origin', '0 0');
  29. }
  30. }
  31. function myContent(myPage){
  32. $.get("http://localhost/offers/public/api/offer",{page:myPage, filter:myFilter}, function (response) {
  33.  
  34. if(response.next_page_url == '' || response.next_page_url == null){
  35. downloadNext=false;
  36. $(".icon").hide();
  37. }
  38.  
  39. $tablica = $('#tableBody');
  40. $div = $('#divMobile');
  41. $icon = $('.icon');
  42.  
  43. if(myPage==1){
  44. $tablica.html('');
  45. $div.html('');
  46. $(".icon").show();
  47. $('.singleTextt').html('Znaleziono: ');
  48. downloadNext=true;
  49. loadIcon=false;
  50. }
  51.  
  52. $.each(response.data, function (key, value) {
  53.  
  54. var newDate = moment(value.time_begin, "YYYY-MM-DD").format("DD.MM.YYYY");
  55. var newDatee = moment(value.time_end, "YYYY-MM-DD").format("DD.MM.YYYY");
  56.  
  57. $tablica.append(
  58. '<tr email="' + value.email + '" contact="' + value.contact.phone + '">' +
  59. '<td><details><summary>' + value.name + '</summary><p>' + value.comment + '</p></details></td>' +
  60. '<td nowrap="nowrap">' + newDate + '</td>' +
  61. '<td nowrap="nowrap">' + newDatee + '</td>' +
  62. '<td>' + value.value + '</td>' +
  63. '<td>' + value.localization + '</td>' +
  64. '<td><button type="submit" class="contactButton">Skontaktuj się!</button></td>' +
  65. '</tr>'
  66. );
  67.  
  68. $div.append(
  69. '<div email="' + value.email + '" contact="' + value.contact.phone + '" class="row box">' +
  70. '<div class="col-12">' +
  71. '<details>' +
  72. '<summary><strong>' + value.name + '</strong></summary>' +
  73. '<p>' + value.comment + '</p>' +
  74. '</details></div>' +
  75. '<div class="col-12"><strong>' + value.localization + '</strong></div>' +
  76. '<div class="col-12"><strong>Dostępność:</strong></div>' +
  77. '<div class="col-12">' + newDate + ' - ' + newDatee + '</div>' +
  78. '<div class="col-12"><strong>Stawka: </strong>' + value.value + '</div>' +
  79. '<div class="col-12"><button type="submit" class="contactButton">Skontaktuj się!</button></div>' +
  80. '</div>'
  81. );
  82. });
  83. showContact();
  84. if (loadIcon === false){
  85.  
  86. $('.singleTextt').append(' '+ response.total);
  87.  
  88. if(response.total==0){
  89. $(".icon").hide();
  90. $tab = $('#tableNotMobile');
  91. $tab.html('');
  92. $('.singleTextt').html(' ');
  93. $('.singleTextt').append('<p style="font-size:25px; text-align:center; height:30vh;margin-top:50px;">Niestety nie znaleziono interesującej Ciebie oferty</p>');
  94. }
  95. $icon.html( '<i class="fa fa-spinner fa-pulse fa-2x fa-fw"></i><span class="sr-only">Loading...</span>' );
  96. loadIcon = true;
  97. }
  98. });
  99. }
  100. function showContact(){
  101.  
  102. $(".contactButton").unbind('click');
  103.  
  104. $(".contactButton").on('click', function (e) {
  105. e.preventDefault();
  106. var w = $(window).width();
  107.  
  108. if (w > 767) {
  109. $tr = $(this).closest('tr');
  110. $('#contactModal').find('#mail').html($tr.attr('email'));
  111. $('#contactModal').find('#ontact').html($tr.attr('contact'));
  112. }
  113. else if (w <= 767) {
  114. $div = $(this).parent().parent();
  115. $('#contactModal').find('#mail').html($div.attr('email'));
  116. $('#contactModal').find('#ontact').html($div.attr('contact'));
  117. }
  118.  
  119. $("#contactModal").modal("show");
  120. });
  121. }
  122. $(window).scroll(function(){
  123. if(($(window).scrollTop() + $(window).height() === $(document).height()) && downloadNext) {
  124. myPage++;
  125. myContent(myPage);
  126. }
  127. });
  128. $(window).resize(function() {
  129. showCaptcha();
  130. });
  131.  
  132.  
  133. $(document).ready(function(){
  134.  
  135. var today = new Date();
  136. var dd = today.getDate();
  137. var mm = today.getMonth()+1;
  138. var yyyy = today.getFullYear();
  139.  
  140. if(dd<10) {
  141. dd = '0'+dd;
  142. }
  143. if(mm<10) {
  144. mm = '0'+mm;
  145. }
  146. today = dd + '.' + mm + '.' + yyyy;
  147.  
  148. // document.getElementById('time_begin').value = today;
  149. // document.getElementById('time_end').value = today;
  150. document.getElementById('from').value = today;
  151. document.getElementById('to').value = today;
  152.  
  153. $('.datetime').datepicker({
  154. language: "pl",
  155. format: "dd.mm.yyyy",
  156. startDate: today,
  157. autoclose: true,
  158. todayHighlight: true,
  159. widgetPositioning: {
  160. horizontal: 'auto',
  161. vertical: 'bottom'
  162. }
  163. });
  164.  
  165. $('#szukaj').click(function() {
  166.  
  167. var name = document.getElementById("name").value;
  168. var localization = document.getElementById("localization").value;
  169. var time_begin = document.getElementById("time_begin").value;
  170. var time_end = document.getElementById("time_end").value;
  171. var newDate = moment(time_begin, "DD.MM.YYYY").format("YYYY-MM-DD");
  172. var newDatee = moment(time_end, "DD.MM.YYYY").format("YYYY-MM-DD");
  173.  
  174. if (time_begin=="" && time_end==""){
  175. myFilter = JSON.stringify({value: name, localization: localization});
  176. }
  177. else if (time_begin!="" && time_end==""){
  178. myFilter = JSON.stringify({value: name, localization: localization, time_begin: newDate});
  179. }
  180. else if (time_begin=="" && time_end!=""){
  181. myFilter = JSON.stringify({value: name, localization: localization, time_end: newDatee});
  182. }
  183. else myFilter = JSON.stringify({value: name, localization: localization,time_begin: newDate, time_end: newDatee});
  184.  
  185.  
  186. console.log(myFilter);
  187. myPage = 1;
  188. myContent(myPage);
  189. $('#collapse').collapse('hide');
  190. });
  191.  
  192.  
  193.  
  194. $(".submitButton").click(function(){
  195. $("#submitModal").find('.form-control').val('');
  196. $("#submitModal").find('.help-block').html('');
  197. $("input, textarea").removeClass("err");
  198. $("#submitModal").find("button").removeClass("disabled");
  199. $("#msgSubmit").html("");
  200. $("#submitModal").modal("show");
  201. });
  202.  
  203.  
  204.  
  205. /* $("input").keyup(function(){
  206.  
  207. var name = document.forms['dodaj_oferte'].elements['name'].value;
  208. var time_begin = document.forms['dodaj_oferte'].elements['time-begin'].value;
  209. var time_end = document.forms['dodaj_oferte'].elements['time-end'].value;
  210. var value = document.forms['dodaj_oferte'].elements['value'].value;
  211. var localization = document.forms['dodaj_oferte'].elements['localization'].value;
  212. var email = document.forms['dodaj_oferte'].elements['email'].value;
  213. var comment = document.forms['dodaj_oferte'].elements['comment'].value;
  214. var contact = document.forms['dodaj_oferte'].elements['contact'].value;
  215. var newDate = moment(time_begin, "DD.MM.YYYY").format("YYYY-MM-DD");
  216. var newDatee = moment(time_end, "DD.MM.YYYY").format("YYYY-MM-DD");
  217.  
  218. if(name !== "" && newDate !== "" && newDatee !== "" && value !== ""&& localization !== "" && email !== "" && comment !== "" && contact !== "" ) {
  219. $("#captcontainer").slideDown(450);
  220. }
  221. });*/
  222.  
  223.  
  224. $('#addOffer').validator().submit(function(event){
  225. event.preventDefault();
  226.  
  227. var verified = grecaptcha.getResponse();
  228.  
  229. var name = document.forms['dodaj_oferte'].elements['name'].value;
  230. var time_begin = document.forms['dodaj_oferte'].elements['time-begin'].value;
  231. var time_end = document.forms['dodaj_oferte'].elements['time-end'].value;
  232. var value = document.forms['dodaj_oferte'].elements['value'].value;
  233. var localization = document.forms['dodaj_oferte'].elements['localization'].value;
  234. var email = document.forms['dodaj_oferte'].elements['email'].value;
  235. var comment = document.forms['dodaj_oferte'].elements['comment'].value;
  236. var contact = document.forms['dodaj_oferte'].elements['contact'].value;
  237. var newDate = moment(time_begin, "DD.MM.YYYY").format("YYYY-MM-DD");
  238. var newDatee = moment(time_end, "DD.MM.YYYY").format("YYYY-MM-DD");
  239.  
  240.  
  241. // var captchaVal = $("#g-recaptcha-response").val();
  242. //var captchaR = grecaptcha.getResponse();
  243.  
  244. //console.log('g-recaptcha: ' + captchaVal);
  245. //console.log('response: ' + captchaR);
  246.  
  247. // console.log('g-recaptcha: ' + captchaVal);
  248. // console.log('response: ' + captchaR);
  249. if (verified.length === 0) {
  250. event.preventDefault();
  251. $('#msgSubmit').append("<br>" +"Udowodnij, że nie jesteś robotem!");
  252. }
  253. else{
  254. $.ajax({
  255.  
  256. type: "POST",
  257. url: "http://localhost/offers/public/api/offer",
  258. dataType: 'json',
  259. contentType: "application/json; charset=utf-8",
  260. data: JSON.stringify( { name: name, localization: localization, time_begin: newDate, time_end: newDatee, value: value, email: email, comment: comment, contact: {"phone": contact } }),
  261. success: function(response){
  262. if (response.success){
  263. $('#msgSubmit').html('Sprawdź swój email w celu aktywowania oferty.'); //Nie moge przetestować bo nie działa!
  264. } else {
  265. $('#msgSubmit').html("Czy poprawnie wypełniłeś wszystkie pola?");
  266. $("input:invalid").addClass("err");
  267. $("input:valid").removeClass("err");
  268. $("textarea:invalid").addClass("err");
  269. $("textarea:valid").removeClass("err");
  270. }
  271. }
  272. });
  273. }
  274. });
  275.  
  276.  
  277. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement