SHOW:
|
|
- or go back to the newest paste.
1 | - | function getForm(){ |
1 | + | function parsingHasil(item, index) { |
2 | - | var hasil = Array(); |
2 | + | hasil[index] = parseInt(item) / parseInt(total) * 100; |
3 | - | $.ajax({ |
3 | + | return 1; |
4 | - | method:'GET', |
4 | + | |
5 | - | url:sourceorigin+'/get_voting/'+fbp_id, |
5 | + | var hasil = Array(); |
6 | - | success:function(data){ |
6 | + | var arr = Array(); |
7 | - | // var result = JSON.parse(data[0]['data']); |
7 | + | var total = 0; |
8 | - | var arr = Array(); |
8 | + | |
9 | - | console.log(data); |
9 | + | function getForm() { |
10 | - | data['data'].forEach(element => { |
10 | + | |
11 | - | if(element.question_type == 'imagesingle'){ |
11 | + | $.ajax({ |
12 | - | var key = element.answer; |
12 | + | method: 'GET', |
13 | - | console.log(key); |
13 | + | url: sourceorigin + '/get_voting/' + fbp_id, |
14 | - | if(typeof arr[key] !== 'undefined'){ |
14 | + | success: function(dt) { |
15 | - | arr[key] += 1 |
15 | + | // var result = JSON.parse(data[0]['data']); |
16 | - | }else{ |
16 | + | |
17 | - | arr[key] = 1 |
17 | + | log_txt(data); |
18 | data['data'].forEach(element => { | |
19 | - | hasil[key] = parseInt(arr[key])/parseInt(data['total'])* 100; |
19 | + | if (typeof element.question_type != "undefined" && element.question_type == 'imagesingle') { |
20 | - | } |
20 | + | var key = element.answer; |
21 | - | }); |
21 | + | log_txt(key); |
22 | - | }, |
22 | + | //if(typeof arr[key] !== 'undefined') |
23 | - | }); |
23 | + | if (typeof arr[key] == "undefined" || arr[key] == null) { |
24 | - | $.ajax({ |
24 | + | arr[key] = 1; |
25 | - | method:'GET', |
25 | + | } else { |
26 | - | url:sourceorigin+'/getformview/'+fbp_id, |
26 | + | arr[key]++; //kecuali mau pakai |
27 | - | success:function(data){ |
27 | + | //arr[key]+=element.total |
28 | - | var str = ""; |
28 | + | } |
29 | - | var poolinngresult = ""; |
29 | + | total++; |
30 | - | $("#tnc-content-href").append("<a href='#tnc' class='text-tnc'>"+data['data'][0]['campaign']['hreftnc']+"</a>").magnificPopup({ |
30 | + | //hasil[key] = parseInt(arr[key])/parseInt(data['total'])* 100; |
31 | - | items: {src: '#tnc'}, |
31 | + | |
32 | elseif(typeof element.question_type != "undefined") { | |
33 | - | open: function () {} |
33 | + | log_txt(element.question_type); |
34 | - | , |
34 | + | |
35 | - | close: function () { |
35 | + | else { |
36 | - | // location.reload(true); |
36 | + | log_txt(element); |
37 | - | } |
37 | + | |
38 | }); | |
39 | - | type: 'inline', fixedContentPos: false, fixedBgPos: true, overflowY: 'auto', closeBtnInside: true, preloader: true, midClick: true, removalDelay: 300, mainClass: 'my-mfp-slide-bottom' |
39 | + | //----------Hasil |
40 | - | }); |
40 | + | arr.forEach(parsingHasil); |
41 | - | $("#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>"+ |
41 | + | }, |
42 | - | "<div class='tandc-text'>"+ |
42 | + | }); |
43 | - | data['data'][0]['campaign']['success_messages']+ |
43 | + | |
44 | - | "<div class='bat-voucher-code'>"+ |
44 | + | $.ajax({ |
45 | - | data['data'][0]['campaign']['code_voucher']+ |
45 | + | method: 'GET', |
46 | - | "</div>"+ |
46 | + | url: sourceorigin + '/getformview/' + fbp_id, |
47 | - | "<a href='#' target='_blank'>"+data['data'][0]['campaign']['shop_url']+"</a>"+ |
47 | + | success: function(data) { |
48 | - | "</div>"+ |
48 | + | var str = ""; |
49 | - | "<div class='bat-modal-button'><button id='confirm-success-all' class='ok-button-success' type='button'>OK</button></div>") |
49 | + | var poolinngresult = ""; |
50 | - | $('#tnc-content').append("<div id='tnc' class='campaign_popup zoom-anim-dialog mfp-hide'>"+ |
50 | + | $("#tnc-content-href").append("<a href='#tnc' class='text-tnc'>" + data['data'][0]['campaign']['hreftnc'] + "</a>").magnificPopup({ |
51 | - | "<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>"+ |
51 | + | items: { |
52 | - | "<p class='tncTitle' style='text-align: center;'>Syarat & Ketentuan<br></p>"+ |
52 | + | src: '#tnc' |
53 | - | "<div class='tandc-text'>"+ |
53 | + | |
54 | - | data['data'][0]['campaign']['tnc']+ |
54 | + | |
55 | - | "</div>"+ |
55 | + | open: function() {}, |
56 | - | "<div class='bat-modal-button'><button class='ok-button-tnc' type='button'>OK</button></div></div>") |
56 | + | close: function() { |
57 | - | $('#header-article').append("<div class='bat-component' id='bat-title'>"+data['data'][0]['campaign']['title']+"</div>"+ |
57 | + | // location.reload(true); |
58 | - | "<!-- beyond article banner image -->"+ |
58 | + | } |
59 | - | "<div class='bat-component' id='bat-banner-image'>"+ |
59 | + | |
60 | - | "<img src='"+sourceorigin+"/storage/"+data['data'][0]['campaign']['image_banner']+"'>"+ |
60 | + | type: 'inline', |
61 | - | "</div>"+" <input type='hidden' name='textfield' id='id_campaign' class='bat-input-field bat-textfield id-short-input' value='"+data['data'][0]['campaign']['_id']+"'>") |
61 | + | fixedContentPos: false, |
62 | - | data['data'].forEach((element,index) => { |
62 | + | fixedBgPos: true, |
63 | - | if(element.question_type== 'short'){ |
63 | + | overflowY: 'auto', |
64 | - | str = " <div class='input-short'>"+ |
64 | + | closeBtnInside: true, |
65 | - | "<input type='text' name='"+element._id+"' class='bat-input-field bat-textfield short-input'>"+ |
65 | + | preloader: true, |
66 | - | "</div>"; |
66 | + | midClick: true, |
67 | - | }else if(element.question_type == 'long'){ |
67 | + | removalDelay: 300, |
68 | - | str = "<div class='input-long'>"+ |
68 | + | mainClass: 'my-mfp-slide-bottom' |
69 | - | "<textarea rows='8' name='"+element._id+"' class='bat-input-field bat-textarea long-input'></textarea>"+ |
69 | + | }); |
70 | - | "</div>"; |
70 | + | $("#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>" + |
71 | - | }else if(element.question_type == 'single'){ |
71 | + | "<div class='tandc-text'>" + |
72 | - | var option = ""; |
72 | + | data['data'][0]['campaign']['success_messages'] + |
73 | - | element['options'].forEach((value,index) => { |
73 | + | "<div class='bat-voucher-code'>" + |
74 | - | option += "<li class='bat-radiobutton-item'>"+ |
74 | + | data['data'][0]['campaign']['code_voucher'] + |
75 | - | "<input class='bat-radiobutton' type='radio' name='"+element._id+"' value='"+value+"' id='radio-"+index+"'/>"+ |
75 | + | "</div>" + |
76 | - | "<label for='radio-"+index+"'>"+value+"</label>"+ |
76 | + | "<a href='#' target='_blank'>" + data['data'][0]['campaign']['shop_url'] + "</a>" + |
77 | - | "</li>"; |
77 | + | "</div>" + |
78 | "<div class='bat-modal-button'><button id='confirm-success-all' class='ok-button-success' type='button'>OK</button></div>") | |
79 | - | str = "<ul id='radiobutton'>"+option+"</ul>"; |
79 | + | $('#tnc-content').append("<div id='tnc' class='campaign_popup zoom-anim-dialog mfp-hide'>" + |
80 | - | }else if(element.question_type == 'multiple'){ |
80 | + | "<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>" + |
81 | - | var option = "" |
81 | + | "<p class='tncTitle' style='text-align: center;'>Syarat & Ketentuan<br></p>" + |
82 | - | element['options'].forEach((value,index) => { |
82 | + | "<div class='tandc-text'>" + |
83 | - | option += "<label class='bat-checkbox'>"+value+ |
83 | + | data['data'][0]['campaign']['tnc'] + |
84 | - | "<input class='check-bx' type='checkbox' name='"+element._id+"' value='"+value+"' id='checkbox-"+index+"'/>"+ |
84 | + | "</div>" + |
85 | - | "<span class='checkmark'></span>"+ |
85 | + | "<div class='bat-modal-button'><button class='ok-button-tnc' type='button'>OK</button></div></div>") |
86 | - | "</label>"; |
86 | + | $('#header-article').append("<div class='bat-component' id='bat-title'>" + data['data'][0]['campaign']['title'] + "</div>" + |
87 | - | str = option; |
87 | + | "<!-- beyond article banner image -->" + |
88 | "<div class='bat-component' id='bat-banner-image'>" + | |
89 | - | }else if(element.question_type == 'select'){ |
89 | + | "<img src='" + sourceorigin + "/storage/" + data['data'][0]['campaign']['image_banner'] + "'>" + |
90 | - | var option = "" |
90 | + | "</div>" + " <input type='hidden' name='textfield' id='id_campaign' class='bat-input-field bat-textfield id-short-input' value='" + data['data'][0]['campaign']['_id'] + "'>") |
91 | - | element['options'].forEach((value,index) => { |
91 | + | data['data'].forEach((element, index) => { |
92 | - | option += "<option value='"+value+"'>"+value+"</option>"; |
92 | + | if (element.question_type == 'short') { |
93 | str = " <div class='input-short'>" + | |
94 | - | str = "<div class='select-dropdown'>"+ |
94 | + | "<input type='text' name='" + element._id + "' class='bat-input-field bat-textfield short-input'>" + |
95 | - | "<select name='"+element._id+"' id='select-dropdown' class='bat-input-field bat-select-dropdown'>"+ |
95 | + | "</div>"; |
96 | - | "<option value=''>Pilih Jawaban</option>"+option+ |
96 | + | } else if (element.question_type == 'long') { |
97 | - | "</select>"; |
97 | + | str = "<div class='input-long'>" + |
98 | - | }else if(element.question_type == 'imagesingle'){ |
98 | + | "<textarea rows='8' name='" + element._id + "' class='bat-input-field bat-textarea long-input'></textarea>" + |
99 | - | var option = "" |
99 | + | "</div>"; |
100 | - | element['options'].forEach((value,index) => { |
100 | + | } else if (element.question_type == 'single') { |
101 | - | if (element.images.length != 0) { |
101 | + | var option = ""; |
102 | - | option +="<div class='bat-polling-image' data-for='polling-2'>"+ |
102 | + | element['options'].forEach((value, index) => { |
103 | - | "<img src='"+sourceorigin+"/storage/"+element['images'][index]+"'>"+ |
103 | + | option += "<li class='bat-radiobutton-item'>" + |
104 | - | "<div class='bat-polling-text'>"+value+"</div>"+ |
104 | + | "<input class='bat-radiobutton' type='radio' name='" + element._id + "' value='" + value + "' id='radio-" + index + "'/>" + |
105 | - | "<input type='radio' name='"+element._id+"' id='polling-2' value='"+value+"' class='img-option'>"+ |
105 | + | "<label for='radio-" + index + "'>" + value + "</label>" + |
106 | - | "</div>" |
106 | + | "</li>"; |
107 | - | }else{ |
107 | + | }); |
108 | - | option += "<div class='bat-polling-image' data-for='polling-2'>"+ |
108 | + | str = "<ul id='radiobutton'>" + option + "</ul>"; |
109 | - | "<img>"+ |
109 | + | } else if (element.question_type == 'multiple') { |
110 | - | "<div class='bat-polling-text'>"+value+"</div>"+ |
110 | + | var option = "" |
111 | - | "<input type='radio' name='"+element._id+"' id='polling-2' value='"+value+"' class='img-option'>"+ |
111 | + | element['options'].forEach((value, index) => { |
112 | - | "</div>" |
112 | + | option += "<label class='bat-checkbox'>" + value + |
113 | - | |
113 | + | "<input class='check-bx' type='checkbox' name='" + element._id + "' value='" + value + "' id='checkbox-" + index + "'/>" + |
114 | - | } |
114 | + | "<span class='checkmark'></span>" + |
115 | - | console.log(hasil); |
115 | + | "</label>"; |
116 | - | if(typeof hasil[value] !== 'undefined'){ |
116 | + | str = option; |
117 | - | console.log(hasil[value]); |
117 | + | }); |
118 | - | poolinngresult += "<div class='bat-polling-percentage' id='percentage-1' style='width: calc("+hasil[value]+"% - 26px);'>"+ |
118 | + | } else if (element.question_type == 'select') { |
119 | - | "<div class='bat-polling-percentage-text'>"+value+"</div>"+ |
119 | + | var option = "" |
120 | - | "<div class='bat-polling-percentage-number'>"+hasil[value]+"%</div>"+ |
120 | + | element['options'].forEach((value, index) => { |
121 | - | "</div>"; |
121 | + | option += "<option value='" + value + "'>" + value + "</option>"; |
122 | - | } |
122 | + | }); |
123 | str = "<div class='select-dropdown'>" + | |
124 | - | str = "<div class='bat-component bat-quiz' id='bat-polling'>"+ |
124 | + | "<select name='" + element._id + "' id='select-dropdown' class='bat-input-field bat-select-dropdown'>" + |
125 | - | "<div class='bat-quiz-question'>Clozetters, kalau kamu mendapatkan kesempatan untuk memiliki "+data['data'][0]['campaign']['title']+" akan kamu pakai dalam momen apa?</div>"+ |
125 | + | "<option value=''>Pilih Jawaban</option>" + option + |
126 | - | "<div class='bat-quiz-input'>"+ |
126 | + | "</select>"; |
127 | - | "<div class='bat-polling-image-list'>"+ |
127 | + | } else if (element.question_type == 'imagesingle') { |
128 | - | option+ |
128 | + | var option = "" |
129 | - | "</div>"+ |
129 | + | element['options'].forEach((value, index) => { |
130 | - | "<div class='bat-polling-result'>"+ |
130 | + | if (element.images.length != 0) { |
131 | - | poolinngresult |
131 | + | option += "<div class='bat-polling-image' data-for='polling-2'>" + |
132 | - | "</div>"+ |
132 | + | "<img src='" + sourceorigin + "/storage/" + element['images'][index] + "'>" + |
133 | - | "</div>"+ |
133 | + | "<div class='bat-polling-text'>" + value + "</div>" + |
134 | - | "</div>" |
134 | + | "<input type='radio' name='" + element._id + "' id='polling-2' value='" + value + "' class='img-option'>" + |
135 | - | }else if(element.question_type == 'scale'){ |
135 | + | "</div>" |
136 | - | // element['options'].forEach((value,index) => { |
136 | + | } else { |
137 | - | // option += "<option value='"+value+"'>"+value+"</option>"; |
137 | + | option += "<div class='bat-polling-image' data-for='polling-2'>" + |
138 | - | // }); |
138 | + | "<img>" + |
139 | - | var option = ""; |
139 | + | "<div class='bat-polling-text'>" + value + "</div>" + |
140 | - | var nameArr = element.range.split('-'); |
140 | + | "<input type='radio' name='" + element._id + "' id='polling-2' value='" + value + "' class='img-option'>" + |
141 | - | for(var i = parseInt(nameArr[0]); i <= parseInt(nameArr[1]); i++){ |
141 | + | "</div>" |
142 | - | option += "<div class='bat-scaling-answer'>"+ |
142 | + | |
143 | - | "<div class='bat-radiobutton-item'>"+ |
143 | + | } |
144 | - | "<input class='bat-radiobutton scale-option' type='radio' name='"+element._id+"' value='"+i+"' id='scaling-"+i+"'>"+ |
144 | + | console.log(hasil); |
145 | - | "<label for='scaling-"+i+"'>"+i+"</label>"+ |
145 | + | if (typeof hasil[value] !== 'undefined') { |
146 | - | "</div>"+ |
146 | + | console.log(hasil[value]); |
147 | - | "</div>" |
147 | + | poolinngresult += "<div class='bat-polling-percentage' id='percentage-1' style='width: calc(" + hasil[value] + "% - 26px);'>" + |
148 | "<div class='bat-polling-percentage-text'>" + value + "</div>" + | |
149 | - | str = "<div class='bat-scaling-answer-list'><div class='bat-scaling-item' id='bat-scaling-tidak'>"+element.start+"</div>"+ |
149 | + | "<div class='bat-polling-percentage-number'>" + hasil[value] + "%</div>" + |
150 | - | "<div class='bat-scaling-item' id='bat-scaling-list'>"+ |
150 | + | "</div>"; |
151 | - | option+ |
151 | + | } |
152 | - | "</div>"+ |
152 | + | }); |
153 | - | "<div class='bat-scaling-item' id='bat-scaling-ingin'>"+element.end+"</div></div>"; |
153 | + | str = "<div class='bat-component bat-quiz' id='bat-polling'>" + |
154 | - | } |
154 | + | "<div class='bat-quiz-question'>Clozetters, kalau kamu mendapatkan kesempatan untuk memiliki " + data['data'][0]['campaign']['title'] + " akan kamu pakai dalam momen apa?</div>" + |
155 | - | $('#answer-template').append("<div class='bat-component bat-quiz' id='bat-textfield'>"+ |
155 | + | "<div class='bat-quiz-input'>" + |
156 | - | "<div class='bat-quiz-question'>"+element.question+"</div>"+ |
156 | + | "<div class='bat-polling-image-list'>" + |
157 | - | "<div class='bat-quiz-input'>"+str+"</div>"); |
157 | + | option + |
158 | - | }); |
158 | + | "</div>" + |
159 | "<div class='bat-polling-result'>" + | |
160 | - | |
160 | + | poolinngresult "</div>" + |
161 | - | } |
161 | + | "</div>" + |
162 | - | }) |
162 | + | "</div>" |
163 | } else if (element.question_type == 'scale') { | |
164 | - | $(document).ready(function(){ |
164 | + | // element['options'].forEach((value,index) => { |
165 | - | getForm(); |
165 | + | // option += "<option value='"+value+"'>"+value+"</option>"; |
166 | - | $(document).on('submit', '#bat-form', function(e){ |
166 | + | // }); |
167 | - | e.preventDefault(); |
167 | + | var option = ""; |
168 | - | if ($('#agree').is(":checked")) |
168 | + | var nameArr = element.range.split('-'); |
169 | - | { |
169 | + | for (var i = parseInt(nameArr[0]); i <= parseInt(nameArr[1]); i++) { |
170 | - | var fd = new FormData(); |
170 | + | option += "<div class='bat-scaling-answer'>" + |
171 | - | var i; |
171 | + | "<div class='bat-radiobutton-item'>" + |
172 | - | var num = $('.bat-radiobutton-item').find('.bat-radiobutton') |
172 | + | "<input class='bat-radiobutton scale-option' type='radio' name='" + element._id + "' value='" + i + "' id='scaling-" + i + "'>" + |
173 | - | var numshortinput = $('.input-short').find('.short-input') |
173 | + | "<label for='scaling-" + i + "'>" + i + "</label>" + |
174 | - | var numlonginput = $('.input-long').find('.long-input') |
174 | + | "</div>" + |
175 | - | var numcheckbox = $('.bat-checkbox').find('.check-bx') |
175 | + | "</div>" |
176 | - | var numselectbox = $('.select-dropdown').find('.bat-select-dropdown') |
176 | + | } |
177 | - | var numoptionimg = $('.bat-polling-image').find('.img-option') |
177 | + | str = "<div class='bat-scaling-answer-list'><div class='bat-scaling-item' id='bat-scaling-tidak'>" + element.start + "</div>" + |
178 | - | var numscale = $('.bat-scaling-answer').find('.scale-option') |
178 | + | "<div class='bat-scaling-item' id='bat-scaling-list'>" + |
179 | - | fd.append('_token','{{csrf_token()}}') |
179 | + | option + |
180 | - | if(num.length > 0){ |
180 | + | "</div>" + |
181 | - | var dataoption = []; |
181 | + | "<div class='bat-scaling-item' id='bat-scaling-ingin'>" + element.end + "</div></div>"; |
182 | - | num.each(function(index, item){ |
182 | + | |
183 | - | var id = $(item).attr('name') |
183 | + | $('#answer-template').append("<div class='bat-component bat-quiz' id='bat-textfield'>" + |
184 | - | if(dataoption.indexOf(id) === -1) { |
184 | + | "<div class='bat-quiz-question'>" + element.question + "</div>" + |
185 | - | dataoption.push(id); |
185 | + | "<div class='bat-quiz-input'>" + str + "</div>"); |
186 | }); | |
187 | - | }); |
187 | + | |
188 | - | for (let index = 0; index < dataoption.length; index++) { |
188 | + | |
189 | - | const element = dataoption[index]; |
189 | + | }) |
190 | - | var val = $('input[name='+element+']:checked').val(); |
190 | + | |
191 | - | i = index; |
191 | + | $(document).ready(function() { |
192 | - | fd.append('answer['+i+']',val); |
192 | + | getForm(); |
193 | - | fd.append('question['+i+']',element); |
193 | + | $(document).on('submit', '#bat-form', function(e) { |
194 | - | } |
194 | + | e.preventDefault(); |
195 | if ($('#agree').is(":checked")) { | |
196 | - | if(numshortinput.length > 0){ |
196 | + | var fd = new FormData(); |
197 | - | numshortinput.each(function(index, item){ |
197 | + | var i; |
198 | - | |
198 | + | var num = $('.bat-radiobutton-item').find('.bat-radiobutton') |
199 | - | if(index == 0){ |
199 | + | var numshortinput = $('.input-short').find('.short-input') |
200 | - | i += index + 1; |
200 | + | var numlonginput = $('.input-long').find('.long-input') |
201 | - | }else{ |
201 | + | var numcheckbox = $('.bat-checkbox').find('.check-bx') |
202 | - | i = index; |
202 | + | var numselectbox = $('.select-dropdown').find('.bat-select-dropdown') |
203 | var numoptionimg = $('.bat-polling-image').find('.img-option') | |
204 | - | // var val = $(item).val(); |
204 | + | var numscale = $('.bat-scaling-answer').find('.scale-option') |
205 | - | var id = $(item).attr('name'); |
205 | + | fd.append('_token', '{{csrf_token()}}') |
206 | - | var val = $(item).val() |
206 | + | if (num.length > 0) { |
207 | - | fd.append('answer['+i+']',val); |
207 | + | var dataoption = []; |
208 | - | fd.append('question['+i+']',id); |
208 | + | num.each(function(index, item) { |
209 | - | }); |
209 | + | var id = $(item).attr('name') |
210 | if (dataoption.indexOf(id) === -1) { | |
211 | - | if(numlonginput.length > 0){ |
211 | + | dataoption.push(id); |
212 | - | numlonginput.each(function(index, item){ |
212 | + | } |
213 | - | |
213 | + | |
214 | - | if(index == 0){ |
214 | + | for (let index = 0; index < dataoption.length; index++) { |
215 | - | i += index + 1; |
215 | + | const element = dataoption[index]; |
216 | - | }else{ |
216 | + | var val = $('input[name=' + element + ']:checked').val(); |
217 | - | i = index; |
217 | + | i = index; |
218 | fd.append('answer[' + i + ']', val); | |
219 | - | var id = $(item).attr('name'); |
219 | + | fd.append('question[' + i + ']', element); |
220 | - | var val = $(item).val() |
220 | + | |
221 | - | fd.append('answer['+i+']',val); |
221 | + | } |
222 | - | fd.append('question['+i+']',id); |
222 | + | if (numshortinput.length > 0) { |
223 | - | }); |
223 | + | numshortinput.each(function(index, item) { |
224 | ||
225 | - | if(numcheckbox.length > 0){ |
225 | + | if (index == 0) { |
226 | - | var dataceckoption = []; |
226 | + | i += index + 1; |
227 | - | numcheckbox.each(function(index, item){ |
227 | + | } else { |
228 | - | var id = $(item).attr('name') |
228 | + | i = index; |
229 | - | //console.log($(item)); |
229 | + | } |
230 | - | if(dataceckoption.indexOf(id) === -1) { |
230 | + | // var val = $(item).val(); |
231 | - | dataceckoption.push(id); |
231 | + | var id = $(item).attr('name'); |
232 | var val = $(item).val() | |
233 | - | }); |
233 | + | fd.append('answer[' + i + ']', val); |
234 | - | for (let index = 0; index < dataceckoption.length; index++) { |
234 | + | fd.append('question[' + i + ']', id); |
235 | - | const element = dataceckoption[index]; |
235 | + | |
236 | - | //var val = $('input[name='+element+']:checked').val(); |
236 | + | } |
237 | - | var val = []; |
237 | + | if (numlonginput.length > 0) { |
238 | - | $.each($("input[name="+element+"]:checked"), function(){ |
238 | + | numlonginput.each(function(index, item) { |
239 | - | val.push($(this).val()); |
239 | + | |
240 | if (index == 0) { | |
241 | - | |
241 | + | i += index + 1; |
242 | - | if(index == 0){ |
242 | + | } else { |
243 | - | i += index + 1; |
243 | + | i = index; |
244 | - | }else{ |
244 | + | } |
245 | - | i = index; |
245 | + | var id = $(item).attr('name'); |
246 | var val = $(item).val() | |
247 | - | fd.append('answer['+i+']',val); |
247 | + | fd.append('answer[' + i + ']', val); |
248 | - | fd.append('question['+i+']',element); |
248 | + | fd.append('question[' + i + ']', id); |
249 | - | } |
249 | + | |
250 | } | |
251 | - | if(numselectbox.length > 0){ |
251 | + | if (numcheckbox.length > 0) { |
252 | - | numselectbox.each(function(index, item){ |
252 | + | var dataceckoption = []; |
253 | - | |
253 | + | numcheckbox.each(function(index, item) { |
254 | - | if(index == 0){ |
254 | + | var id = $(item).attr('name') |
255 | - | i += index + 1; |
255 | + | //console.log($(item)); |
256 | - | }else{ |
256 | + | if (dataceckoption.indexOf(id) === -1) { |
257 | - | i = index; |
257 | + | dataceckoption.push(id); |
258 | } | |
259 | - | // var val = $(item).val(); |
259 | + | |
260 | - | var id = $(item).attr('name'); |
260 | + | for (let index = 0; index < dataceckoption.length; index++) { |
261 | - | var val = $(item).val(); |
261 | + | const element = dataceckoption[index]; |
262 | - | console.log(val); |
262 | + | //var val = $('input[name='+element+']:checked').val(); |
263 | - | fd.append('answer['+i+']',val); |
263 | + | var val = []; |
264 | - | fd.append('question['+i+']',id); |
264 | + | $.each($("input[name=" + element + "]:checked"), function() { |
265 | - | }); |
265 | + | val.push($(this).val()); |
266 | }); | |
267 | - | if(numoptionimg.length > 0){ |
267 | + | |
268 | - | var dataoption = []; |
268 | + | if (index == 0) { |
269 | - | numoptionimg.each(function(index, item){ |
269 | + | i += index + 1; |
270 | - | var id = $(item).attr('name') |
270 | + | } else { |
271 | - | if(dataoption.indexOf(id) === -1) { |
271 | + | i = index; |
272 | - | dataoption.push(id); |
272 | + | } |
273 | fd.append('answer[' + i + ']', val); | |
274 | - | }); |
274 | + | fd.append('question[' + i + ']', element); |
275 | - | for (let index = 0; index < dataoption.length; index++) { |
275 | + | |
276 | - | const element = dataoption[index]; |
276 | + | } |
277 | - | var val = $('input[name='+element+']:checked').val(); |
277 | + | if (numselectbox.length > 0) { |
278 | - | if(index == 0){ |
278 | + | numselectbox.each(function(index, item) { |
279 | - | i += index + 1; |
279 | + | |
280 | - | }else{ |
280 | + | if (index == 0) { |
281 | - | i = index; |
281 | + | i += index + 1; |
282 | } else { | |
283 | - | fd.append('answer['+i+']',val); |
283 | + | i = index; |
284 | - | fd.append('question['+i+']',element); |
284 | + | } |
285 | - | } |
285 | + | // var val = $(item).val(); |
286 | var id = $(item).attr('name'); | |
287 | - | if(numscale.length > 0){ |
287 | + | var val = $(item).val(); |
288 | - | var datascaling = []; |
288 | + | console.log(val); |
289 | - | numscale.each(function(index, item){ |
289 | + | fd.append('answer[' + i + ']', val); |
290 | - | var id = $(item).attr('name') |
290 | + | fd.append('question[' + i + ']', id); |
291 | - | if(dataoption.indexOf(id) === -1) { |
291 | + | |
292 | - | dataoption.push(id); |
292 | + | } |
293 | if (numoptionimg.length > 0) { | |
294 | - | }); |
294 | + | var dataoption = []; |
295 | - | for (let index = 0; index < datascaling.length; index++) { |
295 | + | numoptionimg.each(function(index, item) { |
296 | - | const element = datascaling[index]; |
296 | + | var id = $(item).attr('name') |
297 | - | var val = $('input[name='+element+']:checked').val(); |
297 | + | if (dataoption.indexOf(id) === -1) { |
298 | - | if(index == 0){ |
298 | + | dataoption.push(id); |
299 | - | i += index + 1; |
299 | + | } |
300 | - | }else{ |
300 | + | |
301 | - | i = index; |
301 | + | for (let index = 0; index < dataoption.length; index++) { |
302 | const element = dataoption[index]; | |
303 | - | fd.append('answer['+i+']',val); |
303 | + | var val = $('input[name=' + element + ']:checked').val(); |
304 | - | fd.append('question['+i+']',element); |
304 | + | if (index == 0) { |
305 | - | } |
305 | + | i += index + 1; |
306 | } else { | |
307 | - | var nama = $("#nama").val(); |
307 | + | i = index; |
308 | - | var whatsapp = $("#whatsapp").val(); |
308 | + | } |
309 | - | var alamat = $("#alamat").val(); |
309 | + | fd.append('answer[' + i + ']', val); |
310 | - | var email = $("#email").val(); |
310 | + | fd.append('question[' + i + ']', element); |
311 | - | var idcampaign = $("#id_campaign").val(); |
311 | + | |
312 | - | var instagram = $("#instagram").val(); |
312 | + | } |
313 | - | fd.append('nama',nama); |
313 | + | if (numscale.length > 0) { |
314 | - | fd.append('whatsapp',whatsapp); |
314 | + | var datascaling = []; |
315 | - | fd.append('alamat',alamat); |
315 | + | numscale.each(function(index, item) { |
316 | - | fd.append('email',email); |
316 | + | var id = $(item).attr('name') |
317 | - | fd.append('instagram',instagram); |
317 | + | if (dataoption.indexOf(id) === -1) { |
318 | - | fd.append('idcampaign',idcampaign); |
318 | + | dataoption.push(id); |
319 | - | $.ajax({ |
319 | + | } |
320 | - | url:sourceorigin+'/saveparticipant', |
320 | + | |
321 | - | method:'POST', |
321 | + | for (let index = 0; index < datascaling.length; index++) { |
322 | - | processData: false, |
322 | + | const element = datascaling[index]; |
323 | - | contentType: false, |
323 | + | var val = $('input[name=' + element + ']:checked').val(); |
324 | - | data:fd, |
324 | + | if (index == 0) { |
325 | - | success:function(){ |
325 | + | i += index + 1; |
326 | - | $.magnificPopup.open({ |
326 | + | } else { |
327 | - | items: {src: '#success_popup'}, |
327 | + | i = index; |
328 | } | |
329 | - | open: function () {} |
329 | + | fd.append('answer[' + i + ']', val); |
330 | - | , |
330 | + | fd.append('question[' + i + ']', element); |
331 | - | close: function () { |
331 | + | |
332 | } | |
333 | - | } |
333 | + | var nama = $("#nama").val(); |
334 | - | }, |
334 | + | var whatsapp = $("#whatsapp").val(); |
335 | - | type: 'inline', fixedContentPos: false, fixedBgPos: true, overflowY: 'auto', closeBtnInside: true, preloader: true, midClick: true, removalDelay: 300, mainClass: 'my-mfp-slide-bottom' |
335 | + | var alamat = $("#alamat").val(); |
336 | - | }); |
336 | + | var email = $("#email").val(); |
337 | - | }, |
337 | + | var idcampaign = $("#id_campaign").val(); |
338 | - | error:function(xhr, status, error){ |
338 | + | var instagram = $("#instagram").val(); |
339 | - | var err = eval("(" + xhr.responseText + ")"); |
339 | + | fd.append('nama', nama); |
340 | - | $('#errormessages').text(err.messages) |
340 | + | fd.append('whatsapp', whatsapp); |
341 | - | $.magnificPopup.open({ |
341 | + | fd.append('alamat', alamat); |
342 | - | items: {src: '#failed_popup'}, |
342 | + | fd.append('email', email); |
343 | fd.append('instagram', instagram); | |
344 | - | open: function () {} |
344 | + | fd.append('idcampaign', idcampaign); |
345 | - | , |
345 | + | $.ajax({ |
346 | - | close: function () { |
346 | + | url: sourceorigin + '/saveparticipant', |
347 | method: 'POST', | |
348 | - | } |
348 | + | processData: false, |
349 | - | }, |
349 | + | contentType: false, |
350 | - | type: 'inline', fixedContentPos: false, fixedBgPos: true, overflowY: 'auto', closeBtnInside: true, preloader: true, midClick: true, removalDelay: 300, mainClass: 'my-mfp-slide-bottom' |
350 | + | data: fd, |
351 | - | }); |
351 | + | success: function() { |
352 | - | } |
352 | + | $.magnificPopup.open({ |
353 | - | }) |
353 | + | items: { |
354 | - | }else{ |
354 | + | src: '#success_popup' |
355 | - | alert('please check term and condition') |
355 | + | }, |
356 | - | } |
356 | + | |
357 | - | }); |
357 | + | open: function() {}, |
358 | - | $(document).on('click', '.bat-polling-image', function(){ |
358 | + | close: function() { |
359 | - | var clickImageRadio = $(this).data('for'); |
359 | + | |
360 | - | $("#"+clickImageRadio).prop("checked", true); |
360 | + | } |
361 | - | $('.bat-polling-image').removeClass('bat-polling-image-active'); |
361 | + | }, |
362 | - | $(this).addClass('bat-polling-image-active'); |
362 | + | type: 'inline', |
363 | - | }); |
363 | + | fixedContentPos: false, |
364 | - | $(document).on('click', '.campaign_popup .fa-close', function(){ |
364 | + | fixedBgPos: true, |
365 | - | $('.mfp-close').click(); |
365 | + | overflowY: 'auto', |
366 | - | }); |
366 | + | closeBtnInside: true, |
367 | - | // open tnc |
367 | + | preloader: true, |
368 | - | $('.text-tnc').magnificPopup({ |
368 | + | midClick: true, |
369 | - | items: {src: '#tnc'}, |
369 | + | removalDelay: 300, |
370 | - | callbacks: { |
370 | + | mainClass: 'my-mfp-slide-bottom' |
371 | - | open: function () {} |
371 | + | }); |
372 | - | , |
372 | + | |
373 | - | close: function () { |
373 | + | error: function(xhr, status, error) { |
374 | var err = eval("(" + xhr.responseText + ")"); | |
375 | $('#errormessages').text(err.messages) | |
376 | - | }, |
376 | + | $.magnificPopup.open({ |
377 | - | type: 'inline', fixedContentPos: false, fixedBgPos: true, overflowY: 'auto', closeBtnInside: true, preloader: true, midClick: true, removalDelay: 300, mainClass: 'my-mfp-slide-bottom' |
377 | + | items: { |
378 | - | }); |
378 | + | src: '#failed_popup' |
379 | - | |
379 | + | }, |
380 | - | // tombol ok popup |
380 | + | |
381 | - | $('.ok-button-tnc,.ok-button-success,.ok-button-fail,.ok-button-end').click(function(event){ |
381 | + | open: function() {}, |
382 | - | magnificPopup1 = $.magnificPopup.instance; // save instance in magnificPopup variable |
382 | + | close: function() { |
383 | - | magnificPopup1.close(); // Close popup that is currently opened |
383 | + | |
384 | - | event.preventDefault(); |
384 | + | } |
385 | - | }); |
385 | + | }, |
386 | type: 'inline', | |
387 | - | // popup kontes selesai |
387 | + | fixedContentPos: false, |
388 | - | $('#open_end_popup').magnificPopup({ |
388 | + | fixedBgPos: true, |
389 | - | items: {src: '#end_popup'}, |
389 | + | overflowY: 'auto', |
390 | - | callbacks: { |
390 | + | closeBtnInside: true, |
391 | - | open: function () {} |
391 | + | preloader: true, |
392 | - | }, |
392 | + | midClick: true, |
393 | - | type: 'inline', fixedContentPos: false, fixedBgPos: true, overflowY: 'auto', closeBtnInside: true, preloader: true, midClick: true, removalDelay: 300, mainClass: 'my-mfp-slide-bottom' |
393 | + | removalDelay: 300, |
394 | - | }); |
394 | + | mainClass: 'my-mfp-slide-bottom' |
395 | }); | |
396 | - | // open popup success submit form |
396 | + | |
397 | - | $('#open_success_popup').magnificPopup({ |
397 | + | }) |
398 | - | items: {src: '#success_popup'}, |
398 | + | } else { |
399 | alert('please check term and condition') | |
400 | - | open: function () {} |
400 | + | |
401 | - | , |
401 | + | }); |
402 | - | close: function () { |
402 | + | $(document).on('click', '.bat-polling-image', function() { |
403 | - | // location.reload(true); |
403 | + | var clickImageRadio = $(this).data('for'); |
404 | - | } |
404 | + | $("#" + clickImageRadio).prop("checked", true); |
405 | - | }, |
405 | + | $('.bat-polling-image').removeClass('bat-polling-image-active'); |
406 | - | type: 'inline', fixedContentPos: false, fixedBgPos: true, overflowY: 'auto', closeBtnInside: true, preloader: true, midClick: true, removalDelay: 300, mainClass: 'my-mfp-slide-bottom' |
406 | + | $(this).addClass('bat-polling-image-active'); |
407 | - | }); |
407 | + | }); |
408 | $(document).on('click', '.campaign_popup .fa-close', function() { | |
409 | - | // open popup failed submit form |
409 | + | $('.mfp-close').click(); |
410 | - | $('#open_failed_popup').magnificPopup({ |
410 | + | }); |
411 | - | items: {src: '#failed_popup'}, |
411 | + | // open tnc |
412 | $('.text-tnc').magnificPopup({ | |
413 | - | open: function () {} |
413 | + | items: { |
414 | - | , |
414 | + | src: '#tnc' |
415 | - | close: function () {} |
415 | + | }, |
416 | - | }, |
416 | + | callbacks: { |
417 | - | type: 'inline', fixedContentPos: false, fixedBgPos: true, overflowY: 'auto', closeBtnInside: true, preloader: true, midClick: true, removalDelay: 300, mainClass: 'my-mfp-slide-bottom' |
417 | + | open: function() {}, |
418 | - | }); |
418 | + | close: function() { |
419 | - | |
419 | + | |
420 | - | // open popup kontes selesai submit form |
420 | + | } |
421 | - | $('#open_end_popup').magnificPopup({ |
421 | + | }, |
422 | - | items: {src: '#end_popup'}, |
422 | + | type: 'inline', |
423 | fixedContentPos: false, | |
424 | - | open: function () {} |
424 | + | fixedBgPos: true, |
425 | - | }, |
425 | + | overflowY: 'auto', |
426 | - | type: 'inline', fixedContentPos: false, fixedBgPos: true, overflowY: 'auto', closeBtnInside: true, preloader: true, midClick: true, removalDelay: 300, mainClass: 'my-mfp-slide-bottom' |
426 | + | closeBtnInside: true, |
427 | - | }); |
427 | + | preloader: true, |
428 | - | }); |
428 | + | midClick: true, |
429 | removalDelay: 300, | |
430 | mainClass: 'my-mfp-slide-bottom' | |
431 | }); | |
432 | ||
433 | // tombol ok popup | |
434 | $('.ok-button-tnc,.ok-button-success,.ok-button-fail,.ok-button-end').click(function(event) { | |
435 | magnificPopup1 = $.magnificPopup.instance; // save instance in magnificPopup variable | |
436 | magnificPopup1.close(); // Close popup that is currently opened | |
437 | event.preventDefault(); | |
438 | }); | |
439 | ||
440 | // popup kontes selesai | |
441 | $('#open_end_popup').magnificPopup({ | |
442 | items: { | |
443 | src: '#end_popup' | |
444 | }, | |
445 | callbacks: { | |
446 | open: function() {} | |
447 | }, | |
448 | type: 'inline', | |
449 | fixedContentPos: false, | |
450 | fixedBgPos: true, | |
451 | overflowY: 'auto', | |
452 | closeBtnInside: true, | |
453 | preloader: true, | |
454 | midClick: true, | |
455 | removalDelay: 300, | |
456 | mainClass: 'my-mfp-slide-bottom' | |
457 | }); | |
458 | ||
459 | // open popup success submit form | |
460 | $('#open_success_popup').magnificPopup({ | |
461 | items: { | |
462 | src: '#success_popup' | |
463 | }, | |
464 | callbacks: { | |
465 | open: function() {}, | |
466 | close: function() { | |
467 | // location.reload(true); | |
468 | } | |
469 | }, | |
470 | type: 'inline', | |
471 | fixedContentPos: false, | |
472 | fixedBgPos: true, | |
473 | overflowY: 'auto', | |
474 | closeBtnInside: true, | |
475 | preloader: true, | |
476 | midClick: true, | |
477 | removalDelay: 300, | |
478 | mainClass: 'my-mfp-slide-bottom' | |
479 | }); | |
480 | ||
481 | // open popup failed submit form | |
482 | $('#open_failed_popup').magnificPopup({ | |
483 | items: { | |
484 | src: '#failed_popup' | |
485 | }, | |
486 | callbacks: { | |
487 | open: function() {}, | |
488 | close: function() {} | |
489 | }, | |
490 | type: 'inline', | |
491 | fixedContentPos: false, | |
492 | fixedBgPos: true, | |
493 | overflowY: 'auto', | |
494 | closeBtnInside: true, | |
495 | preloader: true, | |
496 | midClick: true, | |
497 | removalDelay: 300, | |
498 | mainClass: 'my-mfp-slide-bottom' | |
499 | }); | |
500 | ||
501 | // open popup kontes selesai submit form | |
502 | $('#open_end_popup').magnificPopup({ | |
503 | items: { | |
504 | src: '#end_popup' | |
505 | }, | |
506 | callbacks: { | |
507 | open: function() {} | |
508 | }, | |
509 | type: 'inline', | |
510 | fixedContentPos: false, | |
511 | fixedBgPos: true, | |
512 | overflowY: 'auto', | |
513 | closeBtnInside: true, | |
514 | preloader: true, | |
515 | midClick: true, | |
516 | removalDelay: 300, | |
517 | mainClass: 'my-mfp-slide-bottom' | |
518 | }); | |
519 | }); | |
520 | ||
521 | function log_txt(param) { | |
522 | console.log(param); | |
523 | return 1; | |
524 | } |