(function (window, document, $) {
window.RatingDialog = function (page) {
var self = this;
self.show = 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 console.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) {
console.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 = "";
return html;
}
};
})(window, document, jQuery);