Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function parsingHasil(item, index) {
- hasil[index] = parseInt(item) / parseInt(total) * 100;
- return 1;
- }
- var hasil = Array();
- var arr = Array();
- var total = 0;
- function getForm() {
- $.ajax({
- method: 'GET',
- url: sourceorigin + '/get_voting/' + fbp_id,
- success: function(dt) {
- // var result = JSON.parse(data[0]['data']);
- log_txt(data);
- data['data'].forEach(element => {
- if (typeof element.question_type != "undefined" && element.question_type == 'imagesingle') {
- var key = element.answer;
- log_txt(key);
- //if(typeof arr[key] !== 'undefined')
- if (typeof arr[key] == "undefined" || arr[key] == null) {
- arr[key] = 1;
- } else {
- arr[key]++; //kecuali mau pakai
- //arr[key]+=element.total
- }
- total++;
- //hasil[key] = parseInt(arr[key])/parseInt(data['total'])* 100;
- }
- elseif(typeof element.question_type != "undefined") {
- log_txt(element.question_type);
- }
- else {
- log_txt(element);
- }
- });
- //----------Hasil
- arr.forEach(parsingHasil);
- },
- });
- $.ajax({
- method: 'GET',
- url: sourceorigin + '/getformview/' + fbp_id,
- success: function(data) {
- var str = "";
- var poolinngresult = "";
- $("#tnc-content-href").append("<a href='#tnc' class='text-tnc'>" + data['data'][0]['campaign']['hreftnc'] + "</a>").magnificPopup({
- items: {
- src: '#tnc'
- },
- callbacks: {
- open: function() {},
- close: function() {
- // location.reload(true);
- }
- },
- type: 'inline',
- fixedContentPos: false,
- fixedBgPos: true,
- overflowY: 'auto',
- closeBtnInside: true,
- preloader: true,
- midClick: true,
- removalDelay: 300,
- mainClass: 'my-mfp-slide-bottom'
- });
- $("#success_popup").append("<button title='Close (Esc)' type='button' class='mfp-close right bat-close-button'><span><i class='fa fa-close'></i></span></button>" +
- "<div class='tandc-text'>" +
- data['data'][0]['campaign']['success_messages'] +
- "<div class='bat-voucher-code'>" +
- data['data'][0]['campaign']['code_voucher'] +
- "</div>" +
- "<a href='#' target='_blank'>" + data['data'][0]['campaign']['shop_url'] + "</a>" +
- "</div>" +
- "<div class='bat-modal-button'><button id='confirm-success-all' class='ok-button-success' type='button'>OK</button></div>")
- $('#tnc-content').append("<div id='tnc' class='campaign_popup zoom-anim-dialog mfp-hide'>" +
- "<button title='Close (Esc)' id='btn_success_close' type='button' class='mfp-close right bat-close-button'><span><i class='fa fa-close'></i></span></button>" +
- "<p class='tncTitle' style='text-align: center;'>Syarat & Ketentuan<br></p>" +
- "<div class='tandc-text'>" +
- data['data'][0]['campaign']['tnc'] +
- "</div>" +
- "<div class='bat-modal-button'><button class='ok-button-tnc' type='button'>OK</button></div></div>")
- $('#header-article').append("<div class='bat-component' id='bat-title'>" + data['data'][0]['campaign']['title'] + "</div>" +
- "<!-- beyond article banner image -->" +
- "<div class='bat-component' id='bat-banner-image'>" +
- "<img src='" + sourceorigin + "/storage/" + data['data'][0]['campaign']['image_banner'] + "'>" +
- "</div>" + " <input type='hidden' name='textfield' id='id_campaign' class='bat-input-field bat-textfield id-short-input' value='" + data['data'][0]['campaign']['_id'] + "'>")
- data['data'].forEach((element, index) => {
- if (element.question_type == 'short') {
- str = " <div class='input-short'>" +
- "<input type='text' name='" + element._id + "' class='bat-input-field bat-textfield short-input'>" +
- "</div>";
- } else if (element.question_type == 'long') {
- str = "<div class='input-long'>" +
- "<textarea rows='8' name='" + element._id + "' class='bat-input-field bat-textarea long-input'></textarea>" +
- "</div>";
- } else if (element.question_type == 'single') {
- var option = "";
- element['options'].forEach((value, index) => {
- option += "<li class='bat-radiobutton-item'>" +
- "<input class='bat-radiobutton' type='radio' name='" + element._id + "' value='" + value + "' id='radio-" + index + "'/>" +
- "<label for='radio-" + index + "'>" + value + "</label>" +
- "</li>";
- });
- str = "<ul id='radiobutton'>" + option + "</ul>";
- } else if (element.question_type == 'multiple') {
- var option = ""
- element['options'].forEach((value, index) => {
- option += "<label class='bat-checkbox'>" + value +
- "<input class='check-bx' type='checkbox' name='" + element._id + "' value='" + value + "' id='checkbox-" + index + "'/>" +
- "<span class='checkmark'></span>" +
- "</label>";
- str = option;
- });
- } else if (element.question_type == 'select') {
- var option = ""
- element['options'].forEach((value, index) => {
- option += "<option value='" + value + "'>" + value + "</option>";
- });
- str = "<div class='select-dropdown'>" +
- "<select name='" + element._id + "' id='select-dropdown' class='bat-input-field bat-select-dropdown'>" +
- "<option value=''>Pilih Jawaban</option>" + option +
- "</select>";
- } else if (element.question_type == 'imagesingle') {
- var option = ""
- element['options'].forEach((value, index) => {
- if (element.images.length != 0) {
- option += "<div class='bat-polling-image' data-for='polling-2'>" +
- "<img src='" + sourceorigin + "/storage/" + element['images'][index] + "'>" +
- "<div class='bat-polling-text'>" + value + "</div>" +
- "<input type='radio' name='" + element._id + "' id='polling-2' value='" + value + "' class='img-option'>" +
- "</div>"
- } else {
- option += "<div class='bat-polling-image' data-for='polling-2'>" +
- "<img>" +
- "<div class='bat-polling-text'>" + value + "</div>" +
- "<input type='radio' name='" + element._id + "' id='polling-2' value='" + value + "' class='img-option'>" +
- "</div>"
- }
- console.log(hasil);
- if (typeof hasil[value] !== 'undefined') {
- console.log(hasil[value]);
- poolinngresult += "<div class='bat-polling-percentage' id='percentage-1' style='width: calc(" + hasil[value] + "% - 26px);'>" +
- "<div class='bat-polling-percentage-text'>" + value + "</div>" +
- "<div class='bat-polling-percentage-number'>" + hasil[value] + "%</div>" +
- "</div>";
- }
- });
- str = "<div class='bat-component bat-quiz' id='bat-polling'>" +
- "<div class='bat-quiz-question'>Clozetters, kalau kamu mendapatkan kesempatan untuk memiliki " + data['data'][0]['campaign']['title'] + " akan kamu pakai dalam momen apa?</div>" +
- "<div class='bat-quiz-input'>" +
- "<div class='bat-polling-image-list'>" +
- option +
- "</div>" +
- "<div class='bat-polling-result'>" +
- poolinngresult "</div>" +
- "</div>" +
- "</div>"
- } else if (element.question_type == 'scale') {
- // element['options'].forEach((value,index) => {
- // option += "<option value='"+value+"'>"+value+"</option>";
- // });
- var option = "";
- var nameArr = element.range.split('-');
- for (var i = parseInt(nameArr[0]); i <= parseInt(nameArr[1]); i++) {
- option += "<div class='bat-scaling-answer'>" +
- "<div class='bat-radiobutton-item'>" +
- "<input class='bat-radiobutton scale-option' type='radio' name='" + element._id + "' value='" + i + "' id='scaling-" + i + "'>" +
- "<label for='scaling-" + i + "'>" + i + "</label>" +
- "</div>" +
- "</div>"
- }
- str = "<div class='bat-scaling-answer-list'><div class='bat-scaling-item' id='bat-scaling-tidak'>" + element.start + "</div>" +
- "<div class='bat-scaling-item' id='bat-scaling-list'>" +
- option +
- "</div>" +
- "<div class='bat-scaling-item' id='bat-scaling-ingin'>" + element.end + "</div></div>";
- }
- $('#answer-template').append("<div class='bat-component bat-quiz' id='bat-textfield'>" +
- "<div class='bat-quiz-question'>" + element.question + "</div>" +
- "<div class='bat-quiz-input'>" + str + "</div>");
- });
- }
- })
- }
- $(document).ready(function() {
- getForm();
- $(document).on('submit', '#bat-form', function(e) {
- e.preventDefault();
- if ($('#agree').is(":checked")) {
- var fd = new FormData();
- var i;
- var num = $('.bat-radiobutton-item').find('.bat-radiobutton')
- var numshortinput = $('.input-short').find('.short-input')
- var numlonginput = $('.input-long').find('.long-input')
- var numcheckbox = $('.bat-checkbox').find('.check-bx')
- var numselectbox = $('.select-dropdown').find('.bat-select-dropdown')
- var numoptionimg = $('.bat-polling-image').find('.img-option')
- var numscale = $('.bat-scaling-answer').find('.scale-option')
- fd.append('_token', '{{csrf_token()}}')
- if (num.length > 0) {
- var dataoption = [];
- num.each(function(index, item) {
- var id = $(item).attr('name')
- if (dataoption.indexOf(id) === -1) {
- dataoption.push(id);
- }
- });
- for (let index = 0; index < dataoption.length; index++) {
- const element = dataoption[index];
- var val = $('input[name=' + element + ']:checked').val();
- i = index;
- fd.append('answer[' + i + ']', val);
- fd.append('question[' + i + ']', element);
- }
- }
- if (numshortinput.length > 0) {
- numshortinput.each(function(index, item) {
- if (index == 0) {
- i += index + 1;
- } else {
- i = index;
- }
- // var val = $(item).val();
- var id = $(item).attr('name');
- var val = $(item).val()
- fd.append('answer[' + i + ']', val);
- fd.append('question[' + i + ']', id);
- });
- }
- if (numlonginput.length > 0) {
- numlonginput.each(function(index, item) {
- if (index == 0) {
- i += index + 1;
- } else {
- i = index;
- }
- var id = $(item).attr('name');
- var val = $(item).val()
- fd.append('answer[' + i + ']', val);
- fd.append('question[' + i + ']', id);
- });
- }
- if (numcheckbox.length > 0) {
- var dataceckoption = [];
- numcheckbox.each(function(index, item) {
- var id = $(item).attr('name')
- //console.log($(item));
- if (dataceckoption.indexOf(id) === -1) {
- dataceckoption.push(id);
- }
- });
- for (let index = 0; index < dataceckoption.length; index++) {
- const element = dataceckoption[index];
- //var val = $('input[name='+element+']:checked').val();
- var val = [];
- $.each($("input[name=" + element + "]:checked"), function() {
- val.push($(this).val());
- });
- if (index == 0) {
- i += index + 1;
- } else {
- i = index;
- }
- fd.append('answer[' + i + ']', val);
- fd.append('question[' + i + ']', element);
- }
- }
- if (numselectbox.length > 0) {
- numselectbox.each(function(index, item) {
- if (index == 0) {
- i += index + 1;
- } else {
- i = index;
- }
- // var val = $(item).val();
- var id = $(item).attr('name');
- var val = $(item).val();
- console.log(val);
- fd.append('answer[' + i + ']', val);
- fd.append('question[' + i + ']', id);
- });
- }
- if (numoptionimg.length > 0) {
- var dataoption = [];
- numoptionimg.each(function(index, item) {
- var id = $(item).attr('name')
- if (dataoption.indexOf(id) === -1) {
- dataoption.push(id);
- }
- });
- for (let index = 0; index < dataoption.length; index++) {
- const element = dataoption[index];
- var val = $('input[name=' + element + ']:checked').val();
- if (index == 0) {
- i += index + 1;
- } else {
- i = index;
- }
- fd.append('answer[' + i + ']', val);
- fd.append('question[' + i + ']', element);
- }
- }
- if (numscale.length > 0) {
- var datascaling = [];
- numscale.each(function(index, item) {
- var id = $(item).attr('name')
- if (dataoption.indexOf(id) === -1) {
- dataoption.push(id);
- }
- });
- for (let index = 0; index < datascaling.length; index++) {
- const element = datascaling[index];
- var val = $('input[name=' + element + ']:checked').val();
- if (index == 0) {
- i += index + 1;
- } else {
- i = index;
- }
- fd.append('answer[' + i + ']', val);
- fd.append('question[' + i + ']', element);
- }
- }
- var nama = $("#nama").val();
- var whatsapp = $("#whatsapp").val();
- var alamat = $("#alamat").val();
- var email = $("#email").val();
- var idcampaign = $("#id_campaign").val();
- var instagram = $("#instagram").val();
- fd.append('nama', nama);
- fd.append('whatsapp', whatsapp);
- fd.append('alamat', alamat);
- fd.append('email', email);
- fd.append('instagram', instagram);
- fd.append('idcampaign', idcampaign);
- $.ajax({
- url: sourceorigin + '/saveparticipant',
- method: 'POST',
- processData: false,
- contentType: false,
- data: fd,
- success: function() {
- $.magnificPopup.open({
- items: {
- src: '#success_popup'
- },
- callbacks: {
- open: function() {},
- close: function() {
- location.reload(true);
- }
- },
- type: 'inline',
- fixedContentPos: false,
- fixedBgPos: true,
- overflowY: 'auto',
- closeBtnInside: true,
- preloader: true,
- midClick: true,
- removalDelay: 300,
- mainClass: 'my-mfp-slide-bottom'
- });
- },
- error: function(xhr, status, error) {
- var err = eval("(" + xhr.responseText + ")");
- $('#errormessages').text(err.messages)
- $.magnificPopup.open({
- items: {
- src: '#failed_popup'
- },
- callbacks: {
- open: function() {},
- close: function() {
- location.reload(true);
- }
- },
- type: 'inline',
- fixedContentPos: false,
- fixedBgPos: true,
- overflowY: 'auto',
- closeBtnInside: true,
- preloader: true,
- midClick: true,
- removalDelay: 300,
- mainClass: 'my-mfp-slide-bottom'
- });
- }
- })
- } else {
- alert('please check term and condition')
- }
- });
- $(document).on('click', '.bat-polling-image', function() {
- var clickImageRadio = $(this).data('for');
- $("#" + clickImageRadio).prop("checked", true);
- $('.bat-polling-image').removeClass('bat-polling-image-active');
- $(this).addClass('bat-polling-image-active');
- });
- $(document).on('click', '.campaign_popup .fa-close', function() {
- $('.mfp-close').click();
- });
- // open tnc
- $('.text-tnc').magnificPopup({
- items: {
- src: '#tnc'
- },
- callbacks: {
- open: function() {},
- close: function() {
- // location.reload(true);
- }
- },
- type: 'inline',
- fixedContentPos: false,
- fixedBgPos: true,
- overflowY: 'auto',
- closeBtnInside: true,
- preloader: true,
- midClick: true,
- removalDelay: 300,
- mainClass: 'my-mfp-slide-bottom'
- });
- // tombol ok popup
- $('.ok-button-tnc,.ok-button-success,.ok-button-fail,.ok-button-end').click(function(event) {
- magnificPopup1 = $.magnificPopup.instance; // save instance in magnificPopup variable
- magnificPopup1.close(); // Close popup that is currently opened
- event.preventDefault();
- });
- // popup kontes selesai
- $('#open_end_popup').magnificPopup({
- items: {
- src: '#end_popup'
- },
- callbacks: {
- open: function() {}
- },
- type: 'inline',
- fixedContentPos: false,
- fixedBgPos: true,
- overflowY: 'auto',
- closeBtnInside: true,
- preloader: true,
- midClick: true,
- removalDelay: 300,
- mainClass: 'my-mfp-slide-bottom'
- });
- // open popup success submit form
- $('#open_success_popup').magnificPopup({
- items: {
- src: '#success_popup'
- },
- callbacks: {
- open: function() {},
- close: function() {
- // location.reload(true);
- }
- },
- type: 'inline',
- fixedContentPos: false,
- fixedBgPos: true,
- overflowY: 'auto',
- closeBtnInside: true,
- preloader: true,
- midClick: true,
- removalDelay: 300,
- mainClass: 'my-mfp-slide-bottom'
- });
- // open popup failed submit form
- $('#open_failed_popup').magnificPopup({
- items: {
- src: '#failed_popup'
- },
- callbacks: {
- open: function() {},
- close: function() {}
- },
- type: 'inline',
- fixedContentPos: false,
- fixedBgPos: true,
- overflowY: 'auto',
- closeBtnInside: true,
- preloader: true,
- midClick: true,
- removalDelay: 300,
- mainClass: 'my-mfp-slide-bottom'
- });
- // open popup kontes selesai submit form
- $('#open_end_popup').magnificPopup({
- items: {
- src: '#end_popup'
- },
- callbacks: {
- open: function() {}
- },
- type: 'inline',
- fixedContentPos: false,
- fixedBgPos: true,
- overflowY: 'auto',
- closeBtnInside: true,
- preloader: true,
- midClick: true,
- removalDelay: 300,
- mainClass: 'my-mfp-slide-bottom'
- });
- });
- function log_txt(param) {
- console.log(param);
- return 1;
- }
Add Comment
Please, Sign In to add comment