(function (window, document, $) { window.RatingDialog = function (page) { var self = this; self.show = function (options) { require(['jqmpopup'], function () { self.showInternal(options); }); }; self.showInternal = function (options) { options = options || {}; options.header = options.header || Globalize.translate('HeaderRateAndReview'); var html = ''; $(page).append(html); var popup = $('#popupRatingDialog').popup().trigger('create').on("popupafteropen", function () { $('#txtRatingDialogTitle', this).focus(); }).popup("open").on("popupafterclose", function () { $('form', this).off("submit"); $(this).off("popupafterclose").remove(); }); $('form', popup).on('submit', function () { if (options.callback) { var review = { id: options.id, rating: $('#txtRatingDialogRating', this).val(), title: $('#txtRatingDialogTitle', this).val(), recommend: $('#txtRatingDialogRecommend', this).checked(), review: $('#txtRatingDialogReview', this).val(), }; options.callback(review); } else Logger.log("No callback function provided"); return false; }); }; self.close = function () { $('#popupRatingDialog', page).popup("close"); }; }; window.RatingHelpers = { ratePackage: function (link) { var id = link.getAttribute('data-id'); var rating = link.getAttribute('data-rating'); var dialog = new RatingDialog($.mobile.activePage); dialog.show({ header: Globalize.translate('HeaderRateAndReview'), id: id, rating: rating, callback: function (review) { Logger.log(review); dialog.close(); ApiClient.createPackageReview(review).done(function () { Dashboard.alert({ message: Globalize.translate('MessageThankYouForYourReview'), title: Globalize.translate('HeaderThankYou') }); }); } }); }, getStoreRatingHtml: function (rating, id, name, noLinks) { var html = "
"; if (!rating) rating = 0; for (var i = 1; i <= 5; i++) { var title = noLinks ? rating + " stars" : "Rate " + i + (i > 1 ? " stars" : " star"); html += noLinks ? "" : ""; if (rating <= i - 1) { html += "
"; } else if (rating < i) { html += "
"; } else { html += "
"; } html += noLinks ? "" : "
"; } html += "
"; return html; } }; })(window, document, jQuery);