Content_SearchQForm = (function () { function _init($qform) { var $likeBtn = $qform.find('[data-helpful-btn=yes]'); var $dislikeBtn = $qform.find('[data-helpful-btn=no]'); var $reasonPanel = $qform.find('[data-reason]'); var $reasonCommentBox = $reasonPanel.find('textarea'); var $submitBtn = $qform.find('[data-reason-another-btn]'); var $emailBox = $(); var dislikeDate = null; $likeBtn.click(function () { registerFeedback(true); }); $dislikeBtn.click(function () { dislikeDate = new Date(); registerFeedback(false); }); function registerFeedback(isLike) { $likeBtn.unbind('click'); $dislikeBtn.unbind('click'); $.ajax({ url: $qform.data('feedback-url'), cache: false, method: 'POST', data: { isLike: isLike, culture: $qform.data('search-culture'), text: $qform.data('search-text'), category: $qform.data('search-category'), datefrom: $qform.data('search-datefrom'), dateto: $qform.data('search-dateto'), pagenum: $qform.data('search-pagenum') }, dataType: 'json', success: function (data) { $qform.data('feedback-id', data.id); $qform.data('feedback-statkey', data.statKey); if (!isLike) { $reasonCommentBox.focus(); } } }); var url = '/Content/SearchQForm/RegisterFeedback?isLike=' + isLike; var options = { title: 'Опрос по качеству поиска', referer: window.location.href }; if (typeof (yaCounter5774506) !== 'undefined') { yaCounter5774506.hit(url, options); } else if (typeof (ym) !== 'undefined') { ym(5774506, 'hit', url, options); } } $submitBtn.click(function () { registerFeedbackComment($reasonCommentBox.val(), $emailBox.val()); }); function registerFeedbackComment(comment, email) { $.ajax({ url: $qform.data('feedback-comment-url'), cache: false, method: 'POST', data: { id: $qform.data('feedback-id'), statKey: $qform.data('feedback-statkey'), culture: $qform.data('search-culture'), text: $qform.data('search-text'), category: $qform.data('search-category'), datefrom: $qform.data('search-datefrom'), dateto: $qform.data('search-dateto'), pagenum: $qform.data('search-pagenum'), comment: comment, email: email, duration: (new Date().getTime() - dislikeDate.getTime()) } }); } } return { init: _init }; })();