'; var HEADER_STRING = "フィードバックを残す"; if (false) { HEADER_STRING = "広告情報とオプション"; } var modalInstance = AM.create(trigger, { 'content': initialContent, 'header': HEADER_STRING, 'popoverLabel': HEADER_STRING, 'name': modalName }); modalInstance.show(); var serializedPayload = generatePayload(modalName); A.$.ajax({ url: "/af/multi-creative/feedback-form", type: 'POST', data: serializedPayload, headers: { 'Content-Type': 'application/json', 'Accept': 'application/json'}, success: function(response) { if (!response) { return; } modalInstance.update(response); var successMetric = DESKTOP_METRIC_PREFIX + ":formDisplayed"; if (window.ue && window.ue.count) { window.ue.count(successMetric, (window.ue.count(successMetric) || 0) + 1); } }, error: function(err) { var errorText = 'Feedback Form get failed with error: ' + err; var errorMetric = DESKTOP_METRIC_PREFIX + ':error'; P.log(errorText, 'FATAL', DESKTOP_METRIC_PREFIX); if (window.ue && window.ue.count) { window.ue.count(errorMetric, (window.ue.count(errorMetric) || 0) + 1); } modalInstance.update('' + "Error loading ad feedback form." + ''); } }); return modalInstance; } function removeModalOnClose (modalName) { A.on('a:popover:afterHide:' + modalName, function removeModal () { var isSuccess = AM.remove(modalName); if(isSuccess) { document.getElementById("sp_detail_thematic-highly_rated_feedbackMessage").focus(); } }); } function generatePayload(modalName) { var carousel = CF.getCarousel(document.getElementById("sp_detail_thematic-highly_rated")); var EMPTY_CARD_CLASS = "a-carousel-card-empty"; if (!carousel) { return; } var adPlacementMetaData = carousel.dom.$carousel.context.getAttribute("data-ad-placement-metadata"); var adDetailsList = []; if (adPlacementMetaData == "") { return; } carousel.dom.$carousel.children("li").not("." + EMPTY_CARD_CLASS).each(function (idx, item) { var divs = item.getElementsByTagName("div"); var adFeedbackDetails; for (var i = 0; i < divs.length; ++i) { if (divs[i].getAttribute("data-adfeedbackdetails")) { adFeedbackDetails = divs[i].getAttribute("data-adfeedbackdetails"); break; } } if (!adFeedbackDetails) { return; } if (adFeedbackDetails != "" && adFeedbackDetails != null) { adDetailsList.push(JSON.parse(adFeedbackDetails)); } }); var payload = { adPlacementMetaData: JSON.parse(adPlacementMetaData), adCreativeMetaData: { adCreativeDetails: adDetailsList }, feedbackFormContainerId: modalName }; var serializedPayload = { pl: encodeURI(JSON.stringify(payload)) }; return JSON.stringify(serializedPayload); } }); }));